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

Side by Side Diff: environs/jujutest/livetests.go

Issue 6500089: environs/ec2: authorize internal traffic
Patch Set: environs/ec2: authorize internal traffic Created 5 years, 4 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:
View unified diff | Download patch
« no previous file with comments | « environs/ec2/live_test.go ('k') | mstate/state_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/environs/config"
8 "launchpad.net/juju-core/juju" 8 "launchpad.net/juju-core/juju"
9 "launchpad.net/juju-core/state" 9 "launchpad.net/juju-core/state"
10 "launchpad.net/juju-core/testing"
10 "launchpad.net/juju-core/version" 11 "launchpad.net/juju-core/version"
11 "time" 12 "time"
12 ) 13 )
13 14
14 // TestStartStop is similar to Tests.TestStartStop except 15 // TestStartStop is similar to Tests.TestStartStop except
15 // that it does not assume a pristine environment. 16 // that it does not assume a pristine environment.
16 func (t *LiveTests) TestStartStop(c *C) { 17 func (t *LiveTests) TestStartStop(c *C) {
17 insts, err := t.Env.Instances(nil) 18 insts, err := t.Env.Instances(nil)
18 c.Assert(err, IsNil) 19 c.Assert(err, IsNil)
19 c.Check(insts, HasLen, 0) 20 c.Check(insts, HasLen, 0)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 err := t.Env.Bootstrap(false) 146 err := t.Env.Bootstrap(false)
146 c.Assert(err, ErrorMatches, "environment is already bootstrapped") 147 c.Assert(err, ErrorMatches, "environment is already bootstrapped")
147 148
148 c.Logf("destroy env") 149 c.Logf("destroy env")
149 t.Destroy(c) 150 t.Destroy(c)
150 151
151 // check that we can bootstrap after destroy 152 // check that we can bootstrap after destroy
152 t.BootstrapOnce(c) 153 t.BootstrapOnce(c)
153 } 154 }
154 155
155 func (t *LiveTests) TestBootstrapProvisioner(c *C) { 156 func (t *LiveTests) TestBootstrapAndDeploy(c *C) {
156 if !t.CanOpenState || !t.HasProvisioner { 157 if !t.CanOpenState || !t.HasProvisioner {
157 c.Skip(fmt.Sprintf("skipping provisioner test, CanOpenState: %v, HasProvisioner: %v", t.CanOpenState, t.HasProvisioner)) 158 c.Skip(fmt.Sprintf("skipping provisioner test, CanOpenState: %v, HasProvisioner: %v", t.CanOpenState, t.HasProvisioner))
158 } 159 }
159 t.BootstrapOnce(c) 160 t.BootstrapOnce(c)
160 161
162 c.Logf("opening connection")
161 conn, err := juju.NewConn(t.Env) 163 conn, err := juju.NewConn(t.Env)
162 c.Assert(err, IsNil) 164 c.Assert(err, IsNil)
163 defer conn.Close() 165 defer conn.Close()
164 166
165 // Check that we can upgrade the machine agent on the bootstrap machine.
166 m, err := conn.State.Machine(0)
167 c.Assert(err, IsNil)
168
169 // Check that the agent version has made it through the 167 // Check that the agent version has made it through the
170 // bootstrap process (it's optional in the config.Config) 168 // bootstrap process (it's optional in the config.Config)
171 cfg, err := conn.State.EnvironConfig() 169 cfg, err := conn.State.EnvironConfig()
172 c.Assert(err, IsNil) 170 c.Assert(err, IsNil)
173 c.Check(cfg.AgentVersion(), Equals, version.Current.Number) 171 c.Check(cfg.AgentVersion(), Equals, version.Current.Number)
174 172
175 » t.checkUpgradeMachineAgent(c, conn.State, m) 173 » // Wait for machine agent to come up on the bootstrap
174 » // machine and find the deployed series from that.
175 » m0, err := conn.State.Machine(0)
176 » c.Assert(err, IsNil)
177 » w0, tools0 := t.machineAgentTools(c, m0)
178 » defer w0.Stop()
176 179
177 » // place a new machine into the state 180 » // Create a new service and deploy a unit of it.
178 » m, err = conn.State.AddMachine() 181 » c.Logf("deploying service")
182 » repo := &testing.Repo{c.MkDir()}
183 » repo.DirWithSeries(tools0.Series, "dummy")
184 » sch, err := conn.PutCharm(repo.URL(tools0.Series, "dummy"), repo.Path, f alse)
179 c.Assert(err, IsNil) 185 c.Assert(err, IsNil)
186 svc, err := conn.AddService("", sch)
187 c.Assert(err, IsNil)
188 units, err := conn.AddUnits(svc, 1)
189 c.Assert(err, IsNil)
190 unit := units[0]
180 191
181 » t.assertStartInstance(c, m) 192 » // Wait for the unit's machine and associated agent to come up
193 » // and announce itself.
194 » mid, err := unit.AssignedMachineId()
195 » c.Assert(err, IsNil)
196 » m1, err := conn.State.Machine(mid)
197 » c.Assert(err, IsNil)
198 » w1, tools1 := t.machineAgentTools(c, m1)
199 » defer w1.Stop()
200 » c.Assert(tools1.Binary, Equals, tools0.Binary)
182 201
183 » // now remove it 202 » // Check that we can upgrade the environment.
184 » c.Assert(conn.State.RemoveMachine(m.Id()), IsNil) 203 » newVersion := tools1.Binary
204 » newVersion.Patch++
205 » t.checkUpgrade(c, conn, newVersion, w0, w1)
185 206
186 » // watch the PA remove it 207 » c.Logf("removing unit")
187 » t.assertStopInstance(c, m) 208 » // Now remove the unit and its assigned machine and
188 » assertInstanceId(c, m, nil) 209 » // check that the PA removes it.
210 » err = svc.RemoveUnit(unit)
211 » c.Assert(err, IsNil)
212 » err = conn.State.RemoveMachine(m1.Id())
213 » c.Assert(err, IsNil)
214 » c.Logf("waiting for instance to be removed")
215 » t.assertStopInstance(c, m1)
216 » assertInstanceId(c, m1, nil)
189 } 217 }
190 218
191 func (t *LiveTests) checkUpgradeMachineAgent(c *C, st *state.State, m *state.Mac hine) { 219 // machineAgentTools waits for the given machine agent
192 » // First watch the machine agent's to make sure that the its 220 // to start and returns the machine watcher and the tools that it's running.
193 » // current tools are set appropriately. 221 func (t *LiveTests) machineAgentTools(c *C, m *state.Machine) (w *state.MachineW atcher, tools *state.Tools) {
194 » w := m.Watch() 222 » c.Logf("waiting for machine %d to signal agent version", m.Id())
223 » w = m.Watch()
195 224
196 var gotTools *state.Tools 225 var gotTools *state.Tools
197 for _ = range w.Changes() { 226 for _ = range w.Changes() {
198 tools, err := m.AgentTools() 227 tools, err := m.AgentTools()
199 c.Assert(err, IsNil) 228 c.Assert(err, IsNil)
200 if tools.URL == "" { 229 if tools.URL == "" {
201 // Machine agent hasn't started yet. 230 // Machine agent hasn't started yet.
202 continue 231 continue
203 } 232 }
204 gotTools = tools 233 gotTools = tools
205 break 234 break
206 } 235 }
207 c.Assert(gotTools, NotNil, Commentf("tools watcher died: %v", w.Err())) 236 c.Assert(gotTools, NotNil, Commentf("tools watcher died: %v", w.Err()))
208 c.Assert(gotTools.Binary, Equals, version.Current) 237 c.Assert(gotTools.Binary, Equals, version.Current)
238 return w, gotTools
239 }
209 240
241 // checkUpgrade sets the environment agent version and checks that
242 // all the provided watchers upgrade to the requested version.
243 func (t *LiveTests) checkUpgrade(c *C, conn *juju.Conn, newVersion version.Binar y, watchers ...*state.MachineWatcher) {
210 c.Logf("putting testing version of juju tools") 244 c.Logf("putting testing version of juju tools")
211
212 newVersion := version.Current
213 newVersion.Patch++
214 upgradeTools, err := environs.PutTools(t.Env.Storage(), &newVersion) 245 upgradeTools, err := environs.PutTools(t.Env.Storage(), &newVersion)
215 c.Assert(err, IsNil) 246 c.Assert(err, IsNil)
216 247
217 // Check that the put version really is the version we expect. 248 // Check that the put version really is the version we expect.
218 c.Assert(upgradeTools.Binary, Equals, newVersion) 249 c.Assert(upgradeTools.Binary, Equals, newVersion)
219 » err = setStateAgentVersion(st, newVersion.Number) 250 » err = setStateAgentVersion(conn.State, newVersion.Number)
220 c.Assert(err, IsNil) 251 c.Assert(err, IsNil)
221 252
222 » c.Logf("waiting for upgrade") 253 » for i, w := range watchers {
223 » _, ok := <-w.Changes() 254 » » c.Logf("waiting for upgrade %d", i)
224 » if !ok { 255 » » m, ok := <-w.Changes()
225 » » c.Fatalf("watcher died: %v", w.Err()) 256 » » if !c.Check(ok, Equals, true, Commentf("watcher %d died: %v", i, w.Err())) {
257 » » » continue
258 » » }
259 » » tools, err := m.AgentTools()
260 » » if !c.Check(err, IsNil) {
261 » » » continue
262 » » }
263 » » // N.B. We can't test that the URL is the same because there's
264 » » // no guarantee that it is, even though it might be referring to
265 » » // the same thing.
266 » » if c.Check(tools.Binary, DeepEquals, newVersion) {
267 » » » c.Logf("upgrade %d successful", i)
268 » » }
226 } 269 }
227 tools, err := m.AgentTools()
228 c.Assert(err, IsNil)
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)
233 c.Logf("upgrade successful!")
234 } 270 }
235 271
236 // setStateAgentVersion sets the current agent version in the state's 272 // setStateAgentVersion sets the current agent version in the state's
237 // environment configuration. 273 // environment configuration.
238 func setStateAgentVersion(st *state.State, vers version.Number) error { 274 func setStateAgentVersion(st *state.State, vers version.Number) error {
239 cfg, err := st.EnvironConfig() 275 cfg, err := st.EnvironConfig()
240 if err != nil { 276 if err != nil {
241 return err 277 return err
242 } 278 }
243 attrs := cfg.AllAttrs() 279 attrs := cfg.AllAttrs()
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 402 }
367 403
368 inst, err := t.Env.StartInstance(4, InvalidStateInfo, tools) 404 inst, err := t.Env.StartInstance(4, InvalidStateInfo, tools)
369 if inst != nil { 405 if inst != nil {
370 err := t.Env.StopInstances([]environs.Instance{inst}) 406 err := t.Env.StopInstances([]environs.Instance{inst})
371 c.Check(err, IsNil) 407 c.Check(err, IsNil)
372 } 408 }
373 c.Assert(inst, IsNil) 409 c.Assert(inst, IsNil)
374 c.Assert(err, ErrorMatches, "cannot find image.*") 410 c.Assert(err, ErrorMatches, "cannot find image.*")
375 } 411 }
OLDNEW
« no previous file with comments | « environs/ec2/live_test.go ('k') | mstate/state_test.go » ('j') | no next file with comments »

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