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

Delta Between Two Patch Sets: environs/jujutest/livetests.go

Issue 6490067: state: remove ProposedTools.
Left Patch Set: Created 12 years, 7 months ago
Right Patch Set: state: remove ProposedTools. Created 12 years, 7 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 | « cmd/jujud/upgrade_test.go ('k') | state/machine_test.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 package jujutest 1 package jujutest
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
5 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
6 "launchpad.net/juju-core/environs" 6 "launchpad.net/juju-core/environs"
7 "launchpad.net/juju-core/environs/config"
7 "launchpad.net/juju-core/juju" 8 "launchpad.net/juju-core/juju"
8 "launchpad.net/juju-core/state" 9 "launchpad.net/juju-core/state"
9 "launchpad.net/juju-core/version" 10 "launchpad.net/juju-core/version"
10 "time" 11 "time"
11 ) 12 )
12 13
13 // TestStartStop is similar to Tests.TestStartStop except 14 // TestStartStop is similar to Tests.TestStartStop except
14 // that it does not assume a pristine environment. 15 // that it does not assume a pristine environment.
15 func (t *LiveTests) TestStartStop(c *C) { 16 func (t *LiveTests) TestStartStop(c *C) {
16 insts, err := t.Env.Instances(nil) 17 insts, err := t.Env.Instances(nil)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // check that we can bootstrap after destroy 151 // check that we can bootstrap after destroy
151 t.BootstrapOnce(c) 152 t.BootstrapOnce(c)
152 } 153 }
153 154
154 func (t *LiveTests) TestBootstrapProvisioner(c *C) { 155 func (t *LiveTests) TestBootstrapProvisioner(c *C) {
155 if !t.CanOpenState || !t.HasProvisioner { 156 if !t.CanOpenState || !t.HasProvisioner {
156 c.Skip(fmt.Sprintf("skipping provisioner test, CanOpenState: %v, HasProvisioner: %v", t.CanOpenState, t.HasProvisioner)) 157 c.Skip(fmt.Sprintf("skipping provisioner test, CanOpenState: %v, HasProvisioner: %v", t.CanOpenState, t.HasProvisioner))
157 } 158 }
158 t.BootstrapOnce(c) 159 t.BootstrapOnce(c)
159 160
160 » // TODO(dfc) constructing a juju.Conn by hand is a code smell. 161 » conn, err := juju.NewConn(t.Env)
161 » conn, err := juju.NewConnFromAttrs(t.Env.Config().AllAttrs()) 162 » c.Assert(err, IsNil)
162 » c.Assert(err, IsNil) 163 » defer conn.Close()
163
164 » st, err := conn.State()
165 » c.Assert(err, IsNil)
166 164
167 // Check that we can upgrade the machine agent on the bootstrap machine. 165 // Check that we can upgrade the machine agent on the bootstrap machine.
168 » m, err := st.Machine(0) 166 » m, err := conn.State.Machine(0)
169 » c.Assert(err, IsNil) 167 » c.Assert(err, IsNil)
170 168
171 » t.checkUpgradeMachineAgent(c, st, m) 169 » // Check that the agent version has made it through the
170 » // bootstrap process (it's optional in the config.Config)
171 » cfg, err := conn.State.EnvironConfig()
172 » c.Assert(err, IsNil)
173 » c.Check(cfg.AgentVersion(), Equals, version.Current.Number)
174
175 » t.checkUpgradeMachineAgent(c, conn.State, m)
172 176
173 // place a new machine into the state 177 // place a new machine into the state
174 » m, err = st.AddMachine() 178 » m, err = conn.State.AddMachine()
175 c.Assert(err, IsNil) 179 c.Assert(err, IsNil)
176 180
177 t.assertStartInstance(c, m) 181 t.assertStartInstance(c, m)
178 182
179 // now remove it 183 // now remove it
180 » c.Assert(st.RemoveMachine(m.Id()), IsNil) 184 » c.Assert(conn.State.RemoveMachine(m.Id()), IsNil)
181 185
182 // watch the PA remove it 186 // watch the PA remove it
183 t.assertStopInstance(c, m) 187 t.assertStopInstance(c, m)
184 assertInstanceId(c, m, nil) 188 assertInstanceId(c, m, nil)
185
186 err = st.Close()
187 c.Assert(err, IsNil)
188 } 189 }
189 190
190 func (t *LiveTests) checkUpgradeMachineAgent(c *C, st *state.State, m *state.Mac hine) { 191 func (t *LiveTests) checkUpgradeMachineAgent(c *C, st *state.State, m *state.Mac hine) {
191 // First watch the machine agent's to make sure that the its 192 // First watch the machine agent's to make sure that the its
192 // current tools are set appropriately. 193 // current tools are set appropriately.
193 w := m.Watch() 194 w := m.Watch()
194 195
195 var gotTools *state.Tools 196 var gotTools *state.Tools
196 for _ = range w.Changes() { 197 for _ = range w.Changes() {
197 tools, err := m.AgentTools() 198 tools, err := m.AgentTools()
(...skipping 10 matching lines...) Expand all
208 209
209 c.Logf("putting testing version of juju tools") 210 c.Logf("putting testing version of juju tools")
210 211
211 newVersion := version.Current 212 newVersion := version.Current
212 newVersion.Patch++ 213 newVersion.Patch++
213 upgradeTools, err := environs.PutTools(t.Env.Storage(), &newVersion) 214 upgradeTools, err := environs.PutTools(t.Env.Storage(), &newVersion)
214 c.Assert(err, IsNil) 215 c.Assert(err, IsNil)
215 216
216 // Check that the put version really is the version we expect. 217 // Check that the put version really is the version we expect.
217 c.Assert(upgradeTools.Binary, Equals, newVersion) 218 c.Assert(upgradeTools.Binary, Equals, newVersion)
218 » err = st.SetAgentVersion(newVersion.Number) 219 » err = setStateAgentVersion(st, newVersion.Number)
220 » c.Assert(err, IsNil)
219 221
220 c.Logf("waiting for upgrade") 222 c.Logf("waiting for upgrade")
221 _, ok := <-w.Changes() 223 _, ok := <-w.Changes()
222 if !ok { 224 if !ok {
223 c.Fatalf("watcher died: %v", w.Err()) 225 c.Fatalf("watcher died: %v", w.Err())
224 } 226 }
225 tools, err := m.AgentTools() 227 tools, err := m.AgentTools()
226 c.Assert(err, IsNil) 228 c.Assert(err, IsNil)
227 » c.Assert(tools, DeepEquals, upgradeTools) 229 » // N.B. We can't test that the URL is the same because there's
230 » // no guarantee that it is, even though it might be referring to
231 » // the same thing.
232 » c.Assert(tools.Binary, DeepEquals, upgradeTools.Binary)
228 c.Logf("upgrade successful!") 233 c.Logf("upgrade successful!")
234 }
235
236 // setStateAgentVersion sets the current agent version in the
237 // state's environment configuration.
238 func setStateAgentVersion(st *state.State, vers version.Number) error {
239 cfg, err := st.EnvironConfig()
240 if err != nil {
241 return err
242 }
243 attrs := cfg.AllAttrs()
244 attrs["agent-version"] = vers.String()
245 cfg, err = config.New(attrs)
246 if err != nil {
247 panic(fmt.Errorf("config refused agent-version: %v", err))
248 }
249 return st.SetEnvironConfig(cfg)
229 } 250 }
230 251
231 var waitAgent = environs.AttemptStrategy{ 252 var waitAgent = environs.AttemptStrategy{
232 Total: 30 * time.Second, 253 Total: 30 * time.Second,
233 Delay: 1 * time.Second, 254 Delay: 1 * time.Second,
234 } 255 }
235 256
236 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) { 257 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) {
237 // Wait for machine to get an instance id. 258 // Wait for machine to get an instance id.
238 for a := waitAgent.Start(); a.Next(); { 259 for a := waitAgent.Start(); a.Next(); {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 366 }
346 367
347 inst, err := t.Env.StartInstance(4, InvalidStateInfo, tools) 368 inst, err := t.Env.StartInstance(4, InvalidStateInfo, tools)
348 if inst != nil { 369 if inst != nil {
349 err := t.Env.StopInstances([]environs.Instance{inst}) 370 err := t.Env.StopInstances([]environs.Instance{inst})
350 c.Check(err, IsNil) 371 c.Check(err, IsNil)
351 } 372 }
352 c.Assert(inst, IsNil) 373 c.Assert(inst, IsNil)
353 c.Assert(err, ErrorMatches, "cannot find image.*") 374 c.Assert(err, ErrorMatches, "cannot find image.*")
354 } 375 }
LEFTRIGHT

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