Left: | ||
Right: |
OLD | NEW |
---|---|
1 package maas | 1 package maas |
2 | 2 |
3 import ( | 3 import ( |
4 "encoding/base64" | 4 "encoding/base64" |
5 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
6 "launchpad.net/gomaasapi" | 6 "launchpad.net/gomaasapi" |
7 "launchpad.net/goyaml" | 7 "launchpad.net/goyaml" |
8 "launchpad.net/juju-core/constraints" | 8 "launchpad.net/juju-core/constraints" |
9 "launchpad.net/juju-core/environs" | 9 "launchpad.net/juju-core/environs" |
10 "launchpad.net/juju-core/environs/config" | 10 "launchpad.net/juju-core/environs/config" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 c.Assert(found, Equals, true) | 254 c.Assert(found, Equals, true) |
255 userData := nodeRequestValues[0].Get("user_data") | 255 userData := nodeRequestValues[0].Get("user_data") |
256 decodedUserData, err := decodeUserData(userData) | 256 decodedUserData, err := decodeUserData(userData) |
257 c.Assert(err, IsNil) | 257 c.Assert(err, IsNil) |
258 info := machineInfo{string(instance.Id()), "host1"} | 258 info := machineInfo{string(instance.Id()), "host1"} |
259 cloudinitRunCmd, err := info.cloudinitRunCmd() | 259 cloudinitRunCmd, err := info.cloudinitRunCmd() |
260 c.Assert(err, IsNil) | 260 c.Assert(err, IsNil) |
261 data, err := goyaml.Marshal(cloudinitRunCmd) | 261 data, err := goyaml.Marshal(cloudinitRunCmd) |
262 c.Assert(err, IsNil) | 262 c.Assert(err, IsNil) |
263 c.Check(string(decodedUserData), Matches, "(.|\n)*"+string(data)+"(\n|.) *") | 263 c.Check(string(decodedUserData), Matches, "(.|\n)*"+string(data)+"(\n|.) *") |
264 | |
265 // Trash the tools and try to start another instance. | |
266 envtesting.RemoveTools(c, env.Storage()) | |
267 instance, err = env.StartInstance("2", "xxxxx", series, constraints.Valu e{}, stateInfo, apiInfo) | |
dimitern
2013/04/15 17:27:23
s/xxxxx/fake_nonce/
fwereade
2013/04/16 07:39:13
Done.
| |
268 c.Check(instance, IsNil) | |
269 c.Check(err, ErrorMatches, "no tools available") | |
270 c.Check(err, FitsTypeOf, (*environs.NotFoundError)(nil)) | |
dimitern
2013/04/15 17:27:23
shouldn't this be c.Check(environs.IsNotFound(err)
fwereade
2013/04/16 07:39:13
Don't think we have one of those. Pondered tweakin
| |
264 } | 271 } |
265 | 272 |
266 func (suite *EnvironSuite) getInstance(systemId string) *maasInstance { | 273 func (suite *EnvironSuite) getInstance(systemId string) *maasInstance { |
267 input := `{"system_id": "` + systemId + `"}` | 274 input := `{"system_id": "` + systemId + `"}` |
268 node := suite.testMAASObject.TestServer.NewNode(input) | 275 node := suite.testMAASObject.TestServer.NewNode(input) |
269 return &maasInstance{&node, suite.environ} | 276 return &maasInstance{&node, suite.environ} |
270 } | 277 } |
271 | 278 |
272 func (suite *EnvironSuite) TestStopInstancesReturnsIfParameterEmpty(c *C) { | 279 func (suite *EnvironSuite) TestStopInstancesReturnsIfParameterEmpty(c *C) { |
273 suite.getInstance("test1") | 280 suite.getInstance("test1") |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 c.Check(listing, DeepEquals, []string{}) | 344 c.Check(listing, DeepEquals, []string{}) |
338 } | 345 } |
339 | 346 |
340 // It would be nice if we could unit-test Bootstrap() in more detail, but | 347 // It would be nice if we could unit-test Bootstrap() in more detail, but |
341 // at the time of writing that would require more support from gomaasapi's | 348 // at the time of writing that would require more support from gomaasapi's |
342 // testing service than we have. | 349 // testing service than we have. |
343 func (suite *EnvironSuite) TestBootstrapSucceeds(c *C) { | 350 func (suite *EnvironSuite) TestBootstrapSucceeds(c *C) { |
344 suite.setupFakeTools(c) | 351 suite.setupFakeTools(c) |
345 env := suite.makeEnviron() | 352 env := suite.makeEnviron() |
346 suite.testMAASObject.TestServer.NewNode(`{"system_id": "thenode", "hostn ame": "host"}`) | 353 suite.testMAASObject.TestServer.NewNode(`{"system_id": "thenode", "hostn ame": "host"}`) |
347 » cert := []byte{1, 2, 3} | 354 » err := env.Bootstrap(constraints.Value{}) |
348 » key := []byte{4, 5, 6} | 355 » c.Assert(err, IsNil) |
356 } | |
349 | 357 |
350 » err := env.Bootstrap(constraints.Value{}, cert, key) | 358 func (suite *EnvironSuite) TestBootstrapFailsIfNoTools(c *C) { |
351 » c.Assert(err, IsNil) | 359 » suite.setupFakeTools(c) |
360 » env := suite.makeEnviron() | |
361 » // Can't RemoveAllTools, no public storage. | |
362 » envtesting.RemoveTools(c, env.Storage()) | |
363 » err := env.Bootstrap(constraints.Value{}) | |
364 » c.Check(err, ErrorMatches, "no tools available") | |
365 » c.Check(err, FitsTypeOf, (*environs.NotFoundError)(nil)) | |
dimitern
2013/04/15 17:27:23
ditto
| |
352 } | 366 } |
353 | 367 |
354 func (suite *EnvironSuite) TestBootstrapFailsIfNoNodes(c *C) { | 368 func (suite *EnvironSuite) TestBootstrapFailsIfNoNodes(c *C) { |
355 suite.setupFakeTools(c) | 369 suite.setupFakeTools(c) |
356 env := suite.makeEnviron() | 370 env := suite.makeEnviron() |
357 » cert := []byte{1, 2, 3} | 371 » err := env.Bootstrap(constraints.Value{}) |
358 » key := []byte{4, 5, 6} | |
359 » err := env.Bootstrap(constraints.Value{}, cert, key) | |
360 // Since there are no nodes, the attempt to allocate one returns a | 372 // Since there are no nodes, the attempt to allocate one returns a |
361 // 409: Conflict. | 373 // 409: Conflict. |
362 c.Check(err, ErrorMatches, ".*409.*") | 374 c.Check(err, ErrorMatches, ".*409.*") |
363 } | 375 } |
364 | 376 |
365 func (suite *EnvironSuite) TestBootstrapIntegratesWithEnvirons(c *C) { | 377 func (suite *EnvironSuite) TestBootstrapIntegratesWithEnvirons(c *C) { |
366 suite.setupFakeTools(c) | 378 suite.setupFakeTools(c) |
367 env := suite.makeEnviron() | 379 env := suite.makeEnviron() |
368 suite.testMAASObject.TestServer.NewNode(`{"system_id": "bootstrapnode", "hostname": "host"}`) | 380 suite.testMAASObject.TestServer.NewNode(`{"system_id": "bootstrapnode", "hostname": "host"}`) |
369 | 381 |
370 // environs.Bootstrap calls Environ.Bootstrap. This works. | 382 // environs.Bootstrap calls Environ.Bootstrap. This works. |
371 err := environs.Bootstrap(env, constraints.Value{}) | 383 err := environs.Bootstrap(env, constraints.Value{}) |
372 c.Assert(err, IsNil) | 384 c.Assert(err, IsNil) |
373 } | 385 } |
374 | 386 |
375 func (suite *EnvironSuite) TestAssignmentPolicy(c *C) { | 387 func (suite *EnvironSuite) TestAssignmentPolicy(c *C) { |
376 env := suite.makeEnviron() | 388 env := suite.makeEnviron() |
377 | 389 |
378 c.Check(env.AssignmentPolicy(), Equals, state.AssignUnused) | 390 c.Check(env.AssignmentPolicy(), Equals, state.AssignUnused) |
379 } | 391 } |
OLD | NEW |