launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15338
[Merge] lp:~rvb/juju-core/stop-instances into lp:~maas-maintainers/juju-core/maas-provider-skeleton
Raphaël Badin has proposed merging lp:~rvb/juju-core/stop-instances into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/juju-core/stop-instances/+merge/152886
--
https://code.launchpad.net/~rvb/juju-core/stop-instances/+merge/152886
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/juju-core/stop-instances into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
=== modified file 'environs/maas/environ.go'
--- environs/maas/environ.go 2013-03-12 03:51:49 +0000
+++ environs/maas/environ.go 2013-03-12 11:11:19 +0000
@@ -243,14 +243,22 @@
if len(instances) == 0 {
return nil
}
- // Tell MAAS to shut down each of the instances. If there are errors,
- // return only the first one (but shut down all instances regardless).
+ // Tell MAAS to shut down then release each of the instances. If
+ // there are errors, return only the first one (but shut down and
+ // release all instances regardless).
var firstErr error
for _, instance := range instances {
+ // Stop instance first as it requires the user to have
+ // ownership of the instance.
err := environ.stopInstance(instance)
if firstErr == nil {
firstErr = err
}
+ // After the instance has been stopped, release the instance.
+ err = environ.releaseInstance(instance)
+ if firstErr == nil {
+ firstErr = err
+ }
}
return firstErr
}
@@ -261,6 +269,21 @@
maasInst := inst.(*maasInstance)
maasObj := maasInst.maasObject
_, err := maasObj.CallPost("stop", nil)
+ if err != nil {
+ log.Debugf("environs/maas: error stopping instance %v", maasInst)
+ }
+
+ return err
+}
+
+// releaseInstance releases a single instance.
+func (environ *maasEnviron) releaseInstance(inst environs.Instance) error {
+ maasInst := inst.(*maasInstance)
+ maasObj := maasInst.maasObject
+ _, err := maasObj.CallPost("release", nil)
+ if err != nil {
+ log.Debugf("environs/maas: error releasing instance %v", maasInst)
+ }
return err
}
=== modified file 'environs/maas/environ_test.go'
--- environs/maas/environ_test.go 2013-03-12 03:46:14 +0000
+++ environs/maas/environ_test.go 2013-03-12 11:11:19 +0000
@@ -197,7 +197,7 @@
c.Check(operations, DeepEquals, map[string][]string{})
}
-func (suite *EnvironSuite) TestStopInstancesStopsInstances(c *C) {
+func (suite *EnvironSuite) TestStopInstancesStopsAndReleasesInstances(c *C) {
instance1 := suite.getInstance("test1")
instance2 := suite.getInstance("test2")
suite.getInstance("test3")
@@ -207,7 +207,7 @@
c.Check(err, IsNil)
operations := suite.testMAASObject.TestServer.NodeOperations()
- expectedOperations := map[string][]string{"test1": {"stop"}, "test2": {"stop"}}
+ expectedOperations := map[string][]string{"test1": {"stop", "release"}, "test2": {"stop", "release"}}
c.Check(operations, DeepEquals, expectedOperations)
}
Follow ups