Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(855)

Delta Between Two Patch Sets: state/machine_test.go

Issue 54230044: state: deprecate JobManageState
Left Patch Set: state: deprecate JobManageState Created 11 years, 2 months ago
Right Patch Set: state: deprecate JobManageState Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « state/machine.go ('k') | state/open.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package state_test 4 package state_test
5 5
6 import ( 6 import (
7 "sort" 7 "sort"
8 8
9 gc "launchpad.net/gocheck" 9 gc "launchpad.net/gocheck"
10 10
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 410
411 m, err := s.State.Machine(s.machine.Id()) 411 m, err := s.State.Machine(s.machine.Id())
412 c.Assert(err, gc.IsNil) 412 c.Assert(err, gc.IsNil)
413 id, err := m.InstanceId() 413 id, err := m.InstanceId()
414 c.Assert(err, gc.IsNil) 414 c.Assert(err, gc.IsNil)
415 c.Assert(string(id), gc.Equals, "umbrella/0") 415 c.Assert(string(id), gc.Equals, "umbrella/0")
416 c.Assert(s.machine.CheckProvisioned("fake_nonce"), gc.Equals, true) 416 c.Assert(s.machine.CheckProvisioned("fake_nonce"), gc.Equals, true)
417 // Clear the deprecated machineDoc InstanceId attribute and ensure that CheckProvisioned() 417 // Clear the deprecated machineDoc InstanceId attribute and ensure that CheckProvisioned()
418 // still works as expected with the new data model. 418 // still works as expected with the new data model.
419 state.SetMachineInstanceId(s.machine, "") 419 state.SetMachineInstanceId(s.machine, "")
420 id, err = s.machine.InstanceId()
421 c.Assert(err, gc.IsNil)
422 c.Assert(string(id), gc.Equals, "umbrella/0")
420 c.Assert(s.machine.CheckProvisioned("fake_nonce"), gc.Equals, true) 423 c.Assert(s.machine.CheckProvisioned("fake_nonce"), gc.Equals, true)
421 424
422 // Try it twice, it should fail. 425 // Try it twice, it should fail.
423 err = s.machine.SetProvisioned("doesn't-matter", "phony", nil) 426 err = s.machine.SetProvisioned("doesn't-matter", "phony", nil)
424 c.Assert(err, gc.ErrorMatches, `cannot set instance data for machine "0" : already set`) 427 c.Assert(err, gc.ErrorMatches, `cannot set instance data for machine "0" : already set`)
425 428
426 // Check it with invalid nonce. 429 // Check it with invalid nonce.
427 c.Assert(s.machine.CheckProvisioned("not-really"), gc.Equals, false) 430 c.Assert(s.machine.CheckProvisioned("not-really"), gc.Equals, false)
428 } 431 }
429 432
430 func (s *MachineSuite) TestMachineSetProvisionedWhenNotAlive(c *gc.C) { 433 func (s *MachineSuite) TestMachineSetProvisionedWhenNotAlive(c *gc.C) {
431 testWhenDying(c, s.machine, notAliveErr, notAliveErr, func() error { 434 testWhenDying(c, s.machine, notAliveErr, notAliveErr, func() error {
432 return s.machine.SetProvisioned("umbrella/0", "fake_nonce", nil) 435 return s.machine.SetProvisioned("umbrella/0", "fake_nonce", nil)
433 }) 436 })
437 }
438
439 func (s *MachineSuite) TestMachineSetInstanceStatus(c *gc.C) {
440 // Machine needs to be provisioned first.
441 err := s.machine.SetProvisioned("umbrella/0", "fake_nonce", nil)
442 c.Assert(err, gc.IsNil)
443
444 err = s.machine.SetInstanceStatus("ALIVE")
445 c.Assert(err, gc.IsNil)
446
447 // Reload machine and check result.
448 err = s.machine.Refresh()
449 c.Assert(err, gc.IsNil)
450 status, err := s.machine.InstanceStatus()
451 c.Assert(err, gc.IsNil)
452 c.Assert(status, gc.DeepEquals, "ALIVE")
453 }
454
455 func (s *MachineSuite) TestNotProvisionedMachineSetInstanceStatus(c *gc.C) {
456 err := s.machine.SetInstanceStatus("ALIVE")
457 c.Assert(err, gc.ErrorMatches, ".* not provisioned")
458 }
459
460 func (s *MachineSuite) TestNotProvisionedMachineInstanceStatus(c *gc.C) {
461 _, err := s.machine.InstanceStatus()
462 c.Assert(err, jc.Satisfies, state.IsNotProvisionedError)
463 }
464
465 // SCHEMACHANGE
466 func (s *MachineSuite) TestInstanceStatusOldSchema(c *gc.C) {
467 // Machine needs to be provisioned first.
468 err := s.machine.SetProvisioned("umbrella/0", "fake_nonce", nil)
469 c.Assert(err, gc.IsNil)
470
471 // Remove the InstanceId from instanceData doc to simulate an old schema .
472 state.ClearInstanceDocId(c, s.machine)
473
474 err = s.machine.SetInstanceStatus("ALIVE")
475 c.Assert(err, gc.IsNil)
476
477 // Reload machine and check result.
478 err = s.machine.Refresh()
479 c.Assert(err, gc.IsNil)
480 status, err := s.machine.InstanceStatus()
481 c.Assert(err, gc.IsNil)
482 c.Assert(status, gc.DeepEquals, "ALIVE")
434 } 483 }
435 484
436 func (s *MachineSuite) TestMachineRefresh(c *gc.C) { 485 func (s *MachineSuite) TestMachineRefresh(c *gc.C) {
437 m0, err := s.State.AddMachine("quantal", state.JobHostUnits) 486 m0, err := s.State.AddMachine("quantal", state.JobHostUnits)
438 c.Assert(err, gc.IsNil) 487 c.Assert(err, gc.IsNil)
439 oldTools, _ := m0.AgentTools() 488 oldTools, _ := m0.AgentTools()
440 m1, err := s.State.Machine(m0.Id()) 489 m1, err := s.State.Machine(m0.Id())
441 c.Assert(err, gc.IsNil) 490 c.Assert(err, gc.IsNil)
442 err = m0.SetAgentVersion(version.MustParseBinary("0.0.3-series-arch")) 491 err = m0.SetAgentVersion(version.MustParseBinary("0.0.3-series-arch"))
443 c.Assert(err, gc.IsNil) 492 c.Assert(err, gc.IsNil)
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 err = container.Refresh() 1328 err = container.Refresh()
1280 c.Assert(err, gc.IsNil) 1329 c.Assert(err, gc.IsNil)
1281 status, info, data, err := container.Status() 1330 status, info, data, err := container.Status()
1282 c.Assert(err, gc.IsNil) 1331 c.Assert(err, gc.IsNil)
1283 c.Assert(status, gc.Equals, params.StatusError) 1332 c.Assert(status, gc.Equals, params.StatusError)
1284 c.Assert(info, gc.Equals, "unsupported container") 1333 c.Assert(info, gc.Equals, "unsupported container")
1285 containerType := state.ContainerTypeFromId(container.Id()) 1334 containerType := state.ContainerTypeFromId(container.Id())
1286 c.Assert(data, gc.DeepEquals, params.StatusData{"type": string(c ontainerType)}) 1335 c.Assert(data, gc.DeepEquals, params.StatusData{"type": string(c ontainerType)})
1287 } 1336 }
1288 } 1337 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b