← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/gomaasapi/record-node-acquire into lp:gomaasapi

 

Raphaël Badin has proposed merging lp:~rvb/gomaasapi/record-node-acquire into lp:gomaasapi.

Commit message:
Record acquire operation.

Requested reviews:
  MAAS Maintainers (maas-maintainers)

For more details, see:
https://code.launchpad.net/~rvb/gomaasapi/record-node-acquire/+merge/159404

This is required to test that the constraints are passed correctly in the MAAS provider in juju-core.
-- 
https://code.launchpad.net/~rvb/gomaasapi/record-node-acquire/+merge/159404
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/gomaasapi/record-node-acquire into lp:gomaasapi.
=== modified file 'testservice.go'
--- testservice.go	2013-04-12 13:11:35 +0000
+++ testservice.go	2013-04-18 07:05:29 +0000
@@ -341,11 +341,13 @@
 	if node == nil {
 		w.WriteHeader(http.StatusConflict)
 	} else {
-		systemID, err := node.GetField("system_id")
+		systemId, err := node.GetField("system_id")
 		checkError(err)
-		server.OwnedNodes()[systemID] = true
+		server.OwnedNodes()[systemId] = true
 		res, err := json.Marshal(node)
 		checkError(err)
+		// Record operation.
+		server.addNodeOperation(systemId, "acquire", r)
 		w.WriteHeader(http.StatusOK)
 		fmt.Fprint(w, string(res))
 	}

=== modified file 'testservice_test.go'
--- testservice_test.go	2013-04-11 07:21:07 +0000
+++ testservice_test.go	2013-04-18 07:05:29 +0000
@@ -459,6 +459,31 @@
 	c.Check(operations, DeepEquals, []string{"start"})
 }
 
+func (suite *TestMAASObjectSuite) TestAcquireOperationGetsRecorded(c *C) {
+	input := `{"system_id": "mysystemid"}`
+	suite.TestMAASObject.TestServer.NewNode(input)
+	nodesObj := suite.TestMAASObject.GetSubObject("nodes/")
+	params := url.Values{"key": []string{"value"}}
+
+	jsonResponse, err := nodesObj.CallPost("acquire", params)
+	c.Assert(err, IsNil)
+	acquiredNode, err := jsonResponse.GetMAASObject()
+	c.Assert(err, IsNil)
+	systemId, err := acquiredNode.GetField("system_id")
+	c.Assert(err, IsNil)
+
+	// The 'acquire' operation has been recorded.
+	nodeOperations := suite.TestMAASObject.TestServer.NodeOperations()
+	operations := nodeOperations[systemId]
+	c.Check(operations, DeepEquals, []string{"acquire"})
+
+	// The parameters used to 'acquire' the node have been recorded as well.
+	values := suite.TestMAASObject.TestServer.NodeOperationRequestValues()
+	value := values[systemId]
+	c.Check(len(value), Equals, 1)
+	c.Check(value[0], DeepEquals, params)
+}
+
 func (suite *TestMAASObjectSuite) TestUploadFile(c *C) {
 	const filename = "myfile.txt"
 	const fileContent = "uploaded contents"