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

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

Issue 6347044: environs/ec2: bootstrap (Closed)
Left Patch Set: Created 11 years, 9 months ago
Right Patch Set: environs/ec2: bootstrap Created 11 years, 8 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 | « environs/ec2/local_test.go ('k') | environs/jujutest/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/state" 7 "launchpad.net/juju-core/state"
8 "time" 8 "time"
9 ) 9 )
10 10
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 t.BootstrapOnce(c) 63 t.BootstrapOnce(c)
64 64
65 // Wait for a while to let eventual consistency catch up, hopefully. 65 // Wait for a while to let eventual consistency catch up, hopefully.
66 time.Sleep(t.ConsistencyDelay) 66 time.Sleep(t.ConsistencyDelay)
67 err := t.Env.Bootstrap(false) 67 err := t.Env.Bootstrap(false)
68 c.Assert(err, ErrorMatches, "environment is already bootstrapped") 68 c.Assert(err, ErrorMatches, "environment is already bootstrapped")
69 69
70 info, err := t.Env.StateInfo() 70 info, err := t.Env.StateInfo()
71 c.Assert(err, IsNil) 71 c.Assert(err, IsNil)
72 c.Assert(info, NotNil) 72 c.Assert(info, NotNil)
73 » c.Check(info.Addrs, Not(HasLen), 0) 73 » c.Assert(info.Addrs, Not(HasLen), 0)
74 74
75 if t.CanOpenState { 75 if t.CanOpenState {
76 st, err := state.Open(info) 76 st, err := state.Open(info)
77 c.Assert(err, IsNil) 77 c.Assert(err, IsNil)
78 » » if t.HasProvisioner { 78 » » err = st.Close()
79 » » » t.testProvisioning(c, st) 79 » » c.Assert(err, IsNil)
80 » » }
81 » » st.Close()
82 } 80 }
83 81
84 c.Logf("destroy env") 82 c.Logf("destroy env")
85 t.Destroy(c) 83 t.Destroy(c)
86 84
87 // check that we can bootstrap after destroy 85 // check that we can bootstrap after destroy
88 t.BootstrapOnce(c) 86 t.BootstrapOnce(c)
89 } 87 }
90 88
91 func (t *LiveTests) testProvisioning(c *C, st *state.State) { 89 func (t *LiveTests) TestBootstrapProvisioner(c *C) {
90 » if !t.CanOpenState || !t.HasProvisioner {
91 » » c.Skip(fmt.Sprintf("skipping provisioner test, CanOpenState: %v, HasProvisioner: %v", t.CanOpenState, t.HasProvisioner))
92 » }
93 » t.BootstrapOnce(c)
94
95 » info, err := t.Env.StateInfo()
96 » c.Assert(err, IsNil)
97
98 » st, err := state.Open(info)
99 » c.Assert(err, IsNil)
100
101 » // TODO(dfc) need juju/conn.Deploy to push the secrets
102 » // into the state.
103
92 // place a new machine into the state 104 // place a new machine into the state
93 m, err := st.AddMachine() 105 m, err := st.AddMachine()
94 c.Assert(err, IsNil) 106 c.Assert(err, IsNil)
95 107
96 » t.checkStartInstance(c, m) 108 » t.assertStartInstance(c, m)
97 109
98 // now remove it 110 // now remove it
99 c.Assert(st.RemoveMachine(m.Id()), IsNil) 111 c.Assert(st.RemoveMachine(m.Id()), IsNil)
100 112
101 // TODO
102 // watch the PA remove it 113 // watch the PA remove it
103 » //s.checkStopInstance(c, instId) 114 » t.assertStopInstance(c, m)
104 » //s.checkMachineId(c, m, nil) 115 » assertInstanceId(c, m, nil)
105 } 116
106 117 » err = st.Close()
107 var agentReaction = environs.AttemptStrategy{ 118 » c.Assert(err, IsNil)
108 » Total: 1 * time.Minute, 119 }
120
121 var waitAgent = environs.AttemptStrategy{
122 » Total: 30 * time.Second,
109 Delay: 1 * time.Second, 123 Delay: 1 * time.Second,
110 } 124 }
111 125
112 func (t *LiveTests) checkStartInstance(c *C, m *state.Machine) (instId string) { 126 func (t *LiveTests) assertStartInstance(c *C, m *state.Machine) {
113 » // Wait for machine to get instance id. 127 » // Wait for machine to get an instance id.
114 » for a := agentReaction.Start(); a.Next(); { 128 » for a := waitAgent.Start(); a.Next(); {
115 » » var err error 129 » » instId, err := m.InstanceId()
116 » » instId, err = m.InstanceId() 130 » » if _, ok := err.(*state.NoInstanceIdError); ok {
117 » » c.Assert(err, IsNil) 131 » » » continue
118 » » if instId != "" { 132 » » }
119 » » » break 133 » » c.Assert(err, IsNil)
120 » » } 134 » » _, err = t.Env.Instances([]string{instId})
121 » } 135 » » c.Assert(err, IsNil)
122 » if instId == "" { 136 » » return
123 » » c.Fatalf("provisioner never failed to allocate machine after %v" , agentReaction.Total) 137 » }
124 » } 138 » c.Fatalf("provisioner failed to start machine after %v", waitAgent.Total )
125 » _, err := t.Env.Instances([]string{instId}) 139 }
126 » c.Assert(err, IsNil) 140
127 » return 141 func (t *LiveTests) assertStopInstance(c *C, m *state.Machine) {
142 » // Wait for machine id to be cleared.
143 » for a := waitAgent.Start(); a.Next(); {
144 » » if instId, err := m.InstanceId(); instId == "" {
145 » » » c.Assert(err, FitsTypeOf, &state.NoInstanceIdError{})
146 » » » return
147 » » }
148 » }
149 » c.Fatalf("provisioner failed to stop machine after %v", waitAgent.Total)
150 }
151
152 // assertInstanceId asserts that the machine has an instance id
153 // that matches that of the given instance. If the instance is nil,
154 // It asserts that the instance id is unset.
155 func assertInstanceId(c *C, m *state.Machine, inst environs.Instance) {
156 » // TODO(dfc) add machine.WatchConfig() to avoid having to poll.
157 » var instId, id string
158 » var err error
159 » if inst != nil {
160 » » instId = inst.Id()
161 » }
162 » for a := waitAgent.Start(); a.Next(); {
163 » » id, err = m.InstanceId()
164 » » _, notset := err.(*state.NoInstanceIdError)
165 » » if notset {
166 » » » if inst == nil {
167 » » » » return
168 » » » }
169 » » » continue
170 » » }
171 » » c.Assert(err, IsNil)
172 » » break
173 » }
174 » c.Assert(err, IsNil)
175 » c.Assert(id, Equals, instId)
128 } 176 }
129 177
130 // TODO check that binary data works ok? 178 // TODO check that binary data works ok?
131 var contents = []byte("hello\n") 179 var contents = []byte("hello\n")
132 var contents2 = []byte("goodbye\n\n") 180 var contents2 = []byte("goodbye\n\n")
133 181
134 func (t *LiveTests) TestFile(c *C) { 182 func (t *LiveTests) TestFile(c *C) {
135 name := fmt.Sprint("testfile", time.Now().UnixNano()) 183 name := fmt.Sprint("testfile", time.Now().UnixNano())
136 storage := t.Env.Storage() 184 storage := t.Env.Storage()
137 185
(...skipping 18 matching lines...) Expand all
156 c.Errorf("file name %q not found in file list %q", name, names) 204 c.Errorf("file name %q not found in file list %q", name, names)
157 } 205 }
158 206
159 err = storage.Remove(name) 207 err = storage.Remove(name)
160 c.Check(err, IsNil) 208 c.Check(err, IsNil)
161 checkFileDoesNotExist(c, storage, name) 209 checkFileDoesNotExist(c, storage, name)
162 // removing a file that does not exist should not be an error. 210 // removing a file that does not exist should not be an error.
163 err = storage.Remove(name) 211 err = storage.Remove(name)
164 c.Check(err, IsNil) 212 c.Check(err, IsNil)
165 } 213 }
LEFTRIGHT

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