← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/juju-core/fix-test-start-instance into lp:~maas-maintainers/juju-core/maas-provider-skeleton

 

Raphaël Badin has proposed merging lp:~rvb/juju-core/fix-test-start-instance into lp:~maas-maintainers/juju-core/maas-provider-skeleton.

Commit message:
Use the new method in gomaasapi to fix the test TestStartInstanceStartsInstance.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~rvb/juju-core/fix-test-start-instance/+merge/158116

Using the new method from gomaasapi (TestServer.NodeOperationRequestValues) added in  https://code.launchpad.net/~rvb/gomaasapi/record-action-params/+merge/158117, make sure that the "user data" used when nodes are started contains the command to write the "machine file" which contains the instanceId and the hostname.

Drive-by fix: use trivial.ReadYaml machineInfo.load().
-- 
https://code.launchpad.net/~rvb/juju-core/fix-test-start-instance/+merge/158116
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/juju-core/fix-test-start-instance into lp:~maas-maintainers/juju-core/maas-provider-skeleton.
=== modified file 'environs/maas/environ_test.go'
--- environs/maas/environ_test.go	2013-04-10 13:54:31 +0000
+++ environs/maas/environ_test.go	2013-04-10 14:03:23 +0000
@@ -2,15 +2,18 @@
 
 import (
 	"bytes"
+	"encoding/base64"
 	"fmt"
 	. "launchpad.net/gocheck"
 	"launchpad.net/gomaasapi"
+	"launchpad.net/goyaml"
 	"launchpad.net/juju-core/constraints"
 	"launchpad.net/juju-core/environs"
 	"launchpad.net/juju-core/environs/config"
 	envtesting "launchpad.net/juju-core/environs/testing"
 	"launchpad.net/juju-core/state"
 	"launchpad.net/juju-core/testing"
+	"launchpad.net/juju-core/trivial"
 	"launchpad.net/juju-core/version"
 )
 
@@ -189,6 +192,14 @@
 	return fmt.Errorf("unexpected call to writeCertAndKey")
 }
 
+func decodeUserData(userData string) ([]byte, error) {
+	data, err := base64.StdEncoding.DecodeString(userData)
+	if err != nil {
+		return []byte(""), err
+	}
+	return trivial.Gunzip(data)
+}
+
 func (suite *EnvironSuite) TestStartInstanceStartsInstance(c *C) {
 	suite.setupFakeTools(c)
 	env := suite.makeEnviron()
@@ -216,12 +227,23 @@
 	// The instance number 1 has been started.
 	actions, found = operations["node1"]
 	c.Check(found, Equals, true)
-	// TODO: check that cloudinit config include the creation of the
-	// "machine file" containing the instanceId and the hostname.
-	// In order to do that, the testservice in gomaasapi needs to be
-	// improved to get it to record the parameters sent during the "node
-	// start" operation.
 	c.Check(actions, DeepEquals, []string{"start"})
+
+	// The value of the "user data" parameter used when starting the node
+	// contains the run cmd used to write the machine information onto
+	// the node's filesystem.
+	requestValues := suite.testMAASObject.TestServer.NodeOperationRequestValues()
+	nodeRequestValues, found := requestValues["node1"]
+	c.Check(found, Equals, true)
+	userData := nodeRequestValues[0].Get("user_data")
+	decodedUserData, err := decodeUserData(userData)
+	c.Assert(err, IsNil)
+	info := machineInfo{string(instance.Id()), "host1"}
+	cloudinitRunCmd, err := info.cloudinitRunCmd()
+	c.Assert(err, IsNil)
+	data, err := goyaml.Marshal(cloudinitRunCmd)
+	c.Assert(err, IsNil)
+	c.Check(string(decodedUserData), Matches, "(.|\n)*"+string(data)+"(\n|.)*")
 }
 
 func (suite *EnvironSuite) getInstance(systemId string) *maasInstance {

=== modified file 'environs/maas/util.go'
--- environs/maas/util.go	2013-04-09 13:11:35 +0000
+++ environs/maas/util.go	2013-04-10 14:03:23 +0000
@@ -2,7 +2,6 @@
 
 import (
 	"fmt"
-	"io/ioutil"
 	"launchpad.net/goyaml"
 	cloudinit_core "launchpad.net/juju-core/cloudinit"
 	"launchpad.net/juju-core/environs/cloudinit"
@@ -85,9 +84,5 @@
 // load loads the "machine info" file and parse the content into the info
 // object.
 func (info *machineInfo) load() error {
-	content, err := ioutil.ReadFile(_MAASInstanceFilename)
-	if err != nil {
-		return err
-	}
-	return goyaml.Unmarshal(content, info)
+	return trivial.ReadYaml(_MAASInstanceFilename, info)
 }