1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package jujutest
import (
"fmt"
. "launchpad.net/gocheck"
"launchpad.net/juju/go/environs"
"launchpad.net/juju/go/state"
"time"
)
// TestStartStop is similar to Tests.TestStartStop except
// that it does not assume a pristine environment.
func (t *LiveTests) TestStartStop(c *C) {
insts, err := t.Env.Instances(nil)
c.Assert(err, IsNil)
c.Check(insts, HasLen, 0)
inst, err := t.Env.StartInstance(0, InvalidStateInfo)
c.Assert(err, IsNil)
c.Assert(inst, NotNil)
id0 := inst.Id()
insts, err = t.Env.Instances([]string{id0, id0})
c.Assert(err, IsNil)
c.Assert(insts, HasLen, 2)
c.Assert(insts[0].Id(), Equals, id0)
c.Assert(insts[1].Id(), Equals, id0)
dns, err := inst.WaitDNSName()
c.Assert(err, IsNil)
c.Assert(dns, Not(Equals), "")
insts, err = t.Env.Instances([]string{id0, ""})
c.Assert(err, Equals, environs.ErrPartialInstances)
c.Assert(insts, HasLen, 2)
c.Check(insts[0].Id(), Equals, id0)
c.Check(insts[1], IsNil)
err = t.Env.StopInstances([]environs.Instance{inst})
c.Assert(err, IsNil)
// Stopping may not be noticed at first due to eventual
// consistency. Repeat a few times to ensure we get the error.
for i := 0; i < 20; i++ {
insts, err = t.Env.Instances([]string{id0})
if err != nil {
break
}
time.Sleep(0.25e9)
}
c.Assert(err, Equals, environs.ErrNoInstances)
c.Assert(insts, HasLen, 0)
}
func (t *LiveTests) TestBootstrap(c *C) {
c.Logf("initial bootstrap")
t.BootstrapOnce(c)
c.Logf("duplicate bootstrap")
// Wait for a while to let eventual consistency catch up, hopefully.
time.Sleep(t.ConsistencyDelay)
err := t.Env.Bootstrap()
c.Assert(err, ErrorMatches, "environment is already bootstrapped")
info, err := t.Env.StateInfo()
c.Assert(err, IsNil)
c.Assert(info, NotNil)
c.Check(info.Addrs, Not(HasLen), 0)
if t.CanOpenState {
c.Logf("open state")
st, err := state.Open(info)
c.Assert(err, IsNil)
st.Close()
}
c.Logf("destroy env")
t.Destroy(c)
c.Logf("bootstrap again")
// check that we can bootstrap after destroy
t.BootstrapOnce(c)
}
// TODO check that binary data works ok?
var contents = []byte("hello\n")
var contents2 = []byte("goodbye\n\n")
func (t *LiveTests) TestFile(c *C) {
name := fmt.Sprint("testfile", time.Now().UnixNano())
checkFileDoesNotExist(c, t.Env, name)
checkPutFile(c, t.Env, name, contents)
checkFileHasContents(c, t.Env, name, contents)
checkPutFile(c, t.Env, name, contents2) // check that we can overwrite the file
checkFileHasContents(c, t.Env, name, contents2)
err := t.Env.RemoveFile(name)
c.Check(err, IsNil)
checkFileDoesNotExist(c, t.Env, name)
// removing a file that does not exist should not be an error.
err = t.Env.RemoveFile(name)
c.Check(err, IsNil)
}
|