LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011, 2012, 2013 Canonical Ltd. | 1 // Copyright 2011, 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 jujutest | 4 package jujutest |
5 | 5 |
6 import ( | 6 import ( |
7 "bytes" | 7 "bytes" |
8 "fmt" | 8 "fmt" |
9 "io" | 9 "io" |
10 "io/ioutil" | 10 "io/ioutil" |
11 . "launchpad.net/gocheck" | 11 . "launchpad.net/gocheck" |
12 "launchpad.net/juju-core/charm" | 12 "launchpad.net/juju-core/charm" |
13 "launchpad.net/juju-core/constraints" | 13 "launchpad.net/juju-core/constraints" |
14 "launchpad.net/juju-core/environs" | 14 "launchpad.net/juju-core/environs" |
15 "launchpad.net/juju-core/environs/config" | 15 "launchpad.net/juju-core/environs/config" |
16 "launchpad.net/juju-core/environs/tools" | 16 "launchpad.net/juju-core/environs/tools" |
17 "launchpad.net/juju-core/errors" | 17 "launchpad.net/juju-core/errors" |
18 "launchpad.net/juju-core/instance" | 18 "launchpad.net/juju-core/instance" |
19 "launchpad.net/juju-core/juju" | 19 "launchpad.net/juju-core/juju" |
20 "launchpad.net/juju-core/juju/testing" | 20 "launchpad.net/juju-core/juju/testing" |
21 "launchpad.net/juju-core/state" | 21 "launchpad.net/juju-core/state" |
22 "launchpad.net/juju-core/state/api" | 22 "launchpad.net/juju-core/state/api" |
23 coretesting "launchpad.net/juju-core/testing" | 23 coretesting "launchpad.net/juju-core/testing" |
| 24 . "launchpad.net/juju-core/testing/checkers" |
24 "launchpad.net/juju-core/utils" | 25 "launchpad.net/juju-core/utils" |
25 "launchpad.net/juju-core/version" | 26 "launchpad.net/juju-core/version" |
26 "time" | 27 "time" |
27 ) | 28 ) |
28 | 29 |
29 // LiveTests contains tests that are designed to run against a live server | 30 // LiveTests contains tests that are designed to run against a live server |
30 // (e.g. Amazon EC2). The Environ is opened once only for all the tests | 31 // (e.g. Amazon EC2). The Environ is opened once only for all the tests |
31 // in the suite, stored in Env, and Destroyed after the suite has completed. | 32 // in the suite, stored in Env, and Destroyed after the suite has completed. |
32 type LiveTests struct { | 33 type LiveTests struct { |
33 coretesting.LoggingSuite | 34 coretesting.LoggingSuite |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 // Check that the constraints have been set in the environment. | 351 // Check that the constraints have been set in the environment. |
351 cons, err := conn.State.EnvironConstraints() | 352 cons, err := conn.State.EnvironConstraints() |
352 c.Assert(err, IsNil) | 353 c.Assert(err, IsNil) |
353 c.Assert(cons.String(), Equals, "mem=2048M") | 354 c.Assert(cons.String(), Equals, "mem=2048M") |
354 | 355 |
355 // Wait for machine agent to come up on the bootstrap | 356 // Wait for machine agent to come up on the bootstrap |
356 // machine and find the deployed series from that. | 357 // machine and find the deployed series from that. |
357 m0, err := conn.State.Machine("0") | 358 m0, err := conn.State.Machine("0") |
358 c.Assert(err, IsNil) | 359 c.Assert(err, IsNil) |
359 | 360 |
360 » instId0, ok := m0.InstanceId() | 361 » instId0, err := m0.InstanceId() |
361 » c.Assert(ok, Equals, true) | 362 » c.Assert(err, IsNil) |
362 | 363 |
363 // Check that the API connection is working. | 364 // Check that the API connection is working. |
364 status, err := apiConn.State.Client().Status() | 365 status, err := apiConn.State.Client().Status() |
365 c.Assert(err, IsNil) | 366 c.Assert(err, IsNil) |
366 c.Assert(status.Machines["0"].InstanceId, Equals, string(instId0)) | 367 c.Assert(status.Machines["0"].InstanceId, Equals, string(instId0)) |
367 | 368 |
368 mw0 := newMachineToolWaiter(m0) | 369 mw0 := newMachineToolWaiter(m0) |
369 defer mw0.Stop() | 370 defer mw0.Stop() |
370 | 371 |
371 // If the series has not been specified, we expect the most recent Ubunt
u LTS release to be used. | 372 // If the series has not been specified, we expect the most recent Ubunt
u LTS release to be used. |
(...skipping 20 matching lines...) Expand all Loading... |
392 mid1, err := unit.AssignedMachineId() | 393 mid1, err := unit.AssignedMachineId() |
393 c.Assert(err, IsNil) | 394 c.Assert(err, IsNil) |
394 m1, err := conn.State.Machine(mid1) | 395 m1, err := conn.State.Machine(mid1) |
395 c.Assert(err, IsNil) | 396 c.Assert(err, IsNil) |
396 mw1 := newMachineToolWaiter(m1) | 397 mw1 := newMachineToolWaiter(m1) |
397 defer mw1.Stop() | 398 defer mw1.Stop() |
398 waitAgentTools(c, mw1, mtools0.Binary) | 399 waitAgentTools(c, mw1, mtools0.Binary) |
399 | 400 |
400 err = m1.Refresh() | 401 err = m1.Refresh() |
401 c.Assert(err, IsNil) | 402 c.Assert(err, IsNil) |
402 » instId1, ok := m1.InstanceId() | 403 » instId1, err := m1.InstanceId() |
403 » c.Assert(ok, Equals, true) | 404 » c.Assert(err, IsNil) |
404 uw := newUnitToolWaiter(unit) | 405 uw := newUnitToolWaiter(unit) |
405 defer uw.Stop() | 406 defer uw.Stop() |
406 utools := waitAgentTools(c, uw, expectedVersion) | 407 utools := waitAgentTools(c, uw, expectedVersion) |
407 | 408 |
408 // Check that we can upgrade the environment. | 409 // Check that we can upgrade the environment. |
409 newVersion := utools.Binary | 410 newVersion := utools.Binary |
410 newVersion.Patch++ | 411 newVersion.Patch++ |
411 t.checkUpgrade(c, conn, newVersion, mw0, mw1, uw) | 412 t.checkUpgrade(c, conn, newVersion, mw0, mw1, uw) |
412 | 413 |
413 // BUG(niemeyer): Logic below is very much wrong. Must be: | 414 // BUG(niemeyer): Logic below is very much wrong. Must be: |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 var waitAgent = utils.AttemptStrategy{ | 611 var waitAgent = utils.AttemptStrategy{ |
611 Total: 30 * time.Second, | 612 Total: 30 * time.Second, |
612 Delay: 1 * time.Second, | 613 Delay: 1 * time.Second, |
613 } | 614 } |
614 | 615 |
615 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) { | 616 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) { |
616 // Wait for machine to get an instance id. | 617 // Wait for machine to get an instance id. |
617 for a := waitAgent.Start(); a.Next(); { | 618 for a := waitAgent.Start(); a.Next(); { |
618 err := m.Refresh() | 619 err := m.Refresh() |
619 c.Assert(err, IsNil) | 620 c.Assert(err, IsNil) |
620 » » instId, ok := m.InstanceId() | 621 » » instId, err := m.InstanceId() |
621 » » if !ok { | 622 » » if err != nil { |
| 623 » » » c.Assert(state.IsNotProvisionedError(err), IsTrue) |
622 continue | 624 continue |
623 } | 625 } |
624 _, err = t.Env.Instances([]instance.Id{instId}) | 626 _, err = t.Env.Instances([]instance.Id{instId}) |
625 c.Assert(err, IsNil) | 627 c.Assert(err, IsNil) |
626 return | 628 return |
627 } | 629 } |
628 c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total
) | 630 c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total
) |
629 } | 631 } |
630 | 632 |
631 func (t *LiveTests) assertStopInstance(c *C, env environs.Environ, instId instan
ce.Id) { | 633 func (t *LiveTests) assertStopInstance(c *C, env environs.Environ, instId instan
ce.Id) { |
(...skipping 16 matching lines...) Expand all Loading... |
648 // It asserts that the instance id is unset. | 650 // It asserts that the instance id is unset. |
649 func assertInstanceId(c *C, m *state.Machine, inst instance.Instance) { | 651 func assertInstanceId(c *C, m *state.Machine, inst instance.Instance) { |
650 var wantId, gotId instance.Id | 652 var wantId, gotId instance.Id |
651 var err error | 653 var err error |
652 if inst != nil { | 654 if inst != nil { |
653 wantId = inst.Id() | 655 wantId = inst.Id() |
654 } | 656 } |
655 for a := waitAgent.Start(); a.Next(); { | 657 for a := waitAgent.Start(); a.Next(); { |
656 err := m.Refresh() | 658 err := m.Refresh() |
657 c.Assert(err, IsNil) | 659 c.Assert(err, IsNil) |
658 » » var ok bool | 660 » » gotId, err = m.InstanceId() |
659 » » gotId, ok = m.InstanceId() | 661 » » if err != nil { |
660 » » if !ok { | 662 » » » c.Assert(state.IsNotProvisionedError(err), IsTrue) |
661 if inst == nil { | 663 if inst == nil { |
662 return | 664 return |
663 } | 665 } |
664 continue | 666 continue |
665 } | 667 } |
666 break | 668 break |
667 } | 669 } |
668 c.Assert(err, IsNil) | 670 c.Assert(err, IsNil) |
669 c.Assert(gotId, Equals, wantId) | 671 c.Assert(gotId, Equals, wantId) |
670 } | 672 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 return err | 814 return err |
813 } | 815 } |
814 var buf bytes.Buffer | 816 var buf bytes.Buffer |
815 _, err = io.Copy(&buf, rc) | 817 _, err = io.Copy(&buf, rc) |
816 rc.Close() | 818 rc.Close() |
817 if err != nil { | 819 if err != nil { |
818 return err | 820 return err |
819 } | 821 } |
820 return target.Put(targetPath, &buf, int64(buf.Len())) | 822 return target.Put(targetPath, &buf, int64(buf.Len())) |
821 } | 823 } |
LEFT | RIGHT |