Code review comment for lp://staging/~michael.nelson/goose/test-instance-state

Revision history for this message
Michael Nelson (michael.nelson) wrote :

Reviewers: mp+180788_code.launchpad.net,

Message:
Please take a look.

Description:
Enable server status to be set via control point.

I'm not sure if goose is used outside of juju-core. Within juju-core the
addServer function isn't accessed via a control point in any tests.

This (or something similar) is needed to allow creating test servers
within juju-core tests with a specified status [1]

[1]
https://code.launchpad.net/~michael.nelson/juju-core/1208504-post-bootstrap-hp-no-instances-found-try2/+merge/179899

https://code.launchpad.net/~michael.nelson/goose/test-instance-state/+merge/180788

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/12897044/

Affected files:
   A [revision details]
   M nova/nova.go
   M testservices/novaservice/service.go
   M testservices/novaservice/service_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20130701072216-t1v2cjfevu6zt0lt
+New revision: <email address hidden>

Index: nova/nova.go
=== modified file 'nova/nova.go'
--- nova/nova.go 2013-06-22 11:39:35 +0000
+++ nova/nova.go 2013-08-19 06:31:40 +0000
@@ -26,20 +26,21 @@

  // Server status values.
  const (
- StatusActive = "ACTIVE" // The server is active.
- StatusBuild = "BUILD" // The server has not finished the
original build process.
- StatusDeleted = "DELETED" // The server is deleted.
- StatusError = "ERROR" // The server is in error.
- StatusHardReboot = "HARD_REBOOT" // The server is hard rebooting.
- StatusPassword = "PASSWORD" // The password is being reset on
the server.
- StatusReboot = "REBOOT" // The server is in a soft reboot
state.
- StatusRebuild = "REBUILD" // The server is currently being
rebuilt from an image.
- StatusRescue = "RESCUE" // The server is in rescue mode.
- StatusResize = "RESIZE" // Server is performing the
differential copy of data that changed during its initial copy.
- StatusShutoff = "SHUTOFF" // The virtual machine (VM) was
powered down by the user, but not through the OpenStack Compute API.
- StatusSuspended = "SUSPENDED" // The server is suspended, either
by request or necessity.
- StatusUnknown = "UNKNOWN" // The state of the server is
unknown. Contact your cloud provider.
- StatusVerifyResize = "VERIFY_RESIZE" // System is awaiting confirmation
that the server is operational after a move or resize.
+ StatusActive = "ACTIVE" // The server is active.
+ StatusBuild = "BUILD" // The server has not finished
the original build process.
+ StatusBuildSpawning = "BUILD(spawning)" // The HP server has not finished
the original build process but does have networking.
+ StatusDeleted = "DELETED" // The server is deleted.
+ StatusError = "ERROR" // The server is in error.
+ StatusHardReboot = "HARD_REBOOT" // The server is hard rebooting.
+ StatusPassword = "PASSWORD" // The password is being reset on
the server.
+ StatusReboot = "REBOOT" // The server is in a soft reboot
state.
+ StatusRebuild = "REBUILD" // The server is currently being
rebuilt from an image.
+ StatusRescue = "RESCUE" // The server is in rescue mode.
+ StatusResize = "RESIZE" // Server is performing the
differential copy of data that changed during its initial copy.
+ StatusShutoff = "SHUTOFF" // The virtual machine (VM) was
powered down by the user, but not through the OpenStack Compute API.
+ StatusSuspended = "SUSPENDED" // The server is suspended,
either by request or necessity.
+ StatusUnknown = "UNKNOWN" // The state of the server is
unknown. Contact your cloud provider.
+ StatusVerifyResize = "VERIFY_RESIZE" // System is awaiting
confirmation that the server is operational after a move or resize.
  )

  // Filter keys.

Index: testservices/novaservice/service.go
=== modified file 'testservices/novaservice/service.go'
--- testservices/novaservice/service.go 2013-06-22 11:39:35 +0000
+++ testservices/novaservice/service.go 2013-08-19 06:32:54 +0000
@@ -210,7 +210,7 @@

  // addServer creates a new server.
  func (n *Nova) addServer(server nova.ServerDetail) error {
- if err := n.ProcessFunctionHook(n, server); err != nil {
+ if err := n.ProcessFunctionHook(n, &server); err != nil {
    return err
   }
   if _, err := n.server(server.Id); err == nil {

Index: testservices/novaservice/service_test.go
=== modified file 'testservices/novaservice/service_test.go'
--- testservices/novaservice/service_test.go 2013-06-22 11:39:35 +0000
+++ testservices/novaservice/service_test.go 2013-08-19 06:32:54 +0000
@@ -6,6 +6,7 @@
   "fmt"
   . "launchpad.net/gocheck"
   "launchpad.net/goose/nova"
+ "launchpad.net/goose/testservices/hook"
  )

  type NovaSuite struct {
@@ -240,6 +241,29 @@
   c.Assert(err, ErrorMatches, `a server with id "test" already exists`)
  }

+// A control point can be used to change the status of the added server.
+func (s *NovaSuite) TestAddServerControlPoint(c *C) {
+ cleanup := s.service.RegisterControlPoint(
+ "addServer",
+ func(sc hook.ServiceControl, args ...interface{}) error {
+ details := args[0].(*nova.ServerDetail)
+ details.Status = nova.StatusBuildSpawning
+ return nil
+ },
+ )
+ defer cleanup()
+
+ server := nova.ServerDetail{
+ Id: "test",
+ Status: nova.StatusActive,
+ }
+ s.createServer(c, server)
+ defer s.deleteServer(c, server)
+
+ sr, _ := s.service.server(server.Id)
+ c.Assert(sr.Status, Equals, nova.StatusBuildSpawning)
+}
+
  func (s *NovaSuite) TestRemoveServerTwiceFails(c *C) {
   server := nova.ServerDetail{Id: "test"}
   s.createServer(c, server)

« Back to merge proposal