OLD | NEW |
1 package state_test | 1 package state_test |
2 | 2 |
3 import ( | 3 import ( |
4 . "launchpad.net/gocheck" | 4 . "launchpad.net/gocheck" |
5 "launchpad.net/juju-core/state" | 5 "launchpad.net/juju-core/state" |
6 "launchpad.net/juju-core/version" | 6 "launchpad.net/juju-core/version" |
7 "sort" | 7 "sort" |
8 "time" | 8 "time" |
9 ) | 9 ) |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 err = s.machine.EnsureDead() | 73 err = s.machine.EnsureDead() |
74 c.Assert(err, IsNil) | 74 c.Assert(err, IsNil) |
75 err = s.machine.Remove() | 75 err = s.machine.Remove() |
76 c.Assert(err, IsNil) | 76 c.Assert(err, IsNil) |
77 err = s.machine.Refresh() | 77 err = s.machine.Refresh() |
78 c.Assert(state.IsNotFound(err), Equals, true) | 78 c.Assert(state.IsNotFound(err), Equals, true) |
79 err = s.machine.Remove() | 79 err = s.machine.Remove() |
80 c.Assert(err, IsNil) | 80 c.Assert(err, IsNil) |
81 } | 81 } |
82 | 82 |
| 83 func (s *MachineSuite) TestDestroyMachines(c *C) { |
| 84 m0 := s.machine |
| 85 m1, err := s.State.AddMachine("series", state.JobManageEnviron) |
| 86 c.Assert(err, IsNil) |
| 87 m2, err := s.State.AddMachine("series", state.JobHostUnits) |
| 88 c.Assert(err, IsNil) |
| 89 |
| 90 sch := s.AddTestingCharm(c, "wordpress") |
| 91 wordpress, err := s.State.AddService("wordpress", sch) |
| 92 c.Assert(err, IsNil) |
| 93 u, err := wordpress.AddUnit() |
| 94 c.Assert(err, IsNil) |
| 95 err = u.AssignToMachine(m0) |
| 96 c.Assert(err, IsNil) |
| 97 |
| 98 err = s.State.DestroyMachines("0", "1", "2") |
| 99 c.Assert(err, ErrorMatches, `some machines were not destroyed: machine 0
has unit "wordpress/0" assigned; machine 1 is required by the environment`) |
| 100 assertLife := func(m *state.Machine, life state.Life) { |
| 101 err := m.Refresh() |
| 102 c.Assert(err, IsNil) |
| 103 c.Assert(m.Life(), Equals, life) |
| 104 } |
| 105 assertLife(m0, state.Alive) |
| 106 assertLife(m1, state.Alive) |
| 107 assertLife(m2, state.Dying) |
| 108 |
| 109 err = u.UnassignFromMachine() |
| 110 c.Assert(err, IsNil) |
| 111 err = s.State.DestroyMachines("0", "1", "2") |
| 112 c.Assert(err, ErrorMatches, `some machines were not destroyed: machine 1
is required by the environment`) |
| 113 assertLife(m0, state.Dying) |
| 114 assertLife(m1, state.Alive) |
| 115 assertLife(m2, state.Dying) |
| 116 } |
| 117 |
83 func (s *MachineSuite) TestMachineSetAgentAlive(c *C) { | 118 func (s *MachineSuite) TestMachineSetAgentAlive(c *C) { |
84 alive, err := s.machine.AgentAlive() | 119 alive, err := s.machine.AgentAlive() |
85 c.Assert(err, IsNil) | 120 c.Assert(err, IsNil) |
86 c.Assert(alive, Equals, false) | 121 c.Assert(alive, Equals, false) |
87 | 122 |
88 pinger, err := s.machine.SetAgentAlive() | 123 pinger, err := s.machine.SetAgentAlive() |
89 c.Assert(err, IsNil) | 124 c.Assert(err, IsNil) |
90 c.Assert(pinger, NotNil) | 125 c.Assert(pinger, NotNil) |
91 defer pinger.Stop() | 126 defer pinger.Stop() |
92 | 127 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 err := s.machine.SetAnnotations(annotations) | 663 err := s.machine.SetAnnotations(annotations) |
629 c.Assert(err, IsNil) | 664 c.Assert(err, IsNil) |
630 err = s.machine.EnsureDead() | 665 err = s.machine.EnsureDead() |
631 c.Assert(err, IsNil) | 666 c.Assert(err, IsNil) |
632 err = s.machine.Remove() | 667 err = s.machine.Remove() |
633 c.Assert(err, IsNil) | 668 c.Assert(err, IsNil) |
634 ann, err := s.machine.Annotations() | 669 ann, err := s.machine.Annotations() |
635 c.Assert(err, IsNil) | 670 c.Assert(err, IsNil) |
636 c.Assert(ann, DeepEquals, make(map[string]string)) | 671 c.Assert(ann, DeepEquals, make(map[string]string)) |
637 } | 672 } |
OLD | NEW |