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

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

Issue 6347044: environs/ec2: bootstrap (Closed)
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:
View unified diff | Download patch
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/state" 7 "launchpad.net/juju-core/state"
8 "time" 8 "time"
9 ) 9 )
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.Check(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 » » st.Close() 78 » » // TODO(dfc) need juju/conn.Deploy to push the secrets
79 » » // into the state.
80 » » if t.HasProvisioner {
81 » » » t.testProvisioning(c, st)
82 » » }
83 » » err = st.Close()
84 » » c.Assert(err, IsNil)
79 } 85 }
80 86
81 c.Logf("destroy env") 87 c.Logf("destroy env")
82 t.Destroy(c) 88 t.Destroy(c)
83 89
84 // check that we can bootstrap after destroy 90 // check that we can bootstrap after destroy
85 t.BootstrapOnce(c) 91 t.BootstrapOnce(c)
86 } 92 }
87 93
94 func (t *LiveTests) testProvisioning(c *C, st *state.State) {
niemeyer 2012/07/06 19:44:56 This should be in a test by itself. Note that Test
dfc 2012/07/09 00:52:58 Done.
niemeyer 2012/07/09 22:59:37 Apparently not?
dfc 2012/07/10 00:13:19 I think you reviewed an old version of this file,
rog 2012/07/10 08:07:56 The reason I put this inside TestBootstrap was tha
niemeyer 2012/07/10 13:10:16 The only purpose of BootstrapOnce is to not have t
95 // place a new machine into the state
96 m, err := st.AddMachine()
97 c.Assert(err, IsNil)
98
99 t.checkStartInstance(c, m)
100
101 // now remove it
102 c.Assert(st.RemoveMachine(m.Id()), IsNil)
103
104 // watch the PA remove it
105 t.checkStopInstance(c, m)
106 checkMachineId(c, m, nil)
107 }
108
109 var agentReaction = environs.AttemptStrategy{
niemeyer 2012/07/06 19:44:56 s/agentReaction/waitAgent/; agentReaction.Start re
dfc 2012/07/09 00:52:58 Done.
110 Total: 30 * time.Second,
111 Delay: 1 * time.Second,
112 }
113
114 func (t *LiveTests) checkStartInstance(c *C, m *state.Machine) (instId string) {
115 // Wait for machine to get instance id.
116 for a := agentReaction.Start(); a.Next(); {
117 var err error
118 instId, err = m.InstanceId()
119 if _, ok := err.(*state.NoInstanceIdError); ok {
120 continue
121 }
122 c.Assert(err, IsNil)
123 if instId != "" {
niemeyer 2012/07/06 19:44:56 Argh. We have to fix InstanceId to never return ""
dfc 2012/07/09 00:52:58 This isn't actually testing that instId is "", it'
124 break
125 }
126 }
127 if instId == "" {
128 c.Fatalf("provisioner failed to start machine after %v", agentRe action.Total)
129 }
130 _, err := t.Env.Instances([]string{instId})
131 c.Assert(err, IsNil)
132 return
133 }
134
135 func (t *LiveTests) checkStopInstance(c *C, m *state.Machine) {
136 // Wait for machine to get instance id.
niemeyer 2012/07/06 19:44:56 Comment is wrong.
dfc 2012/07/09 00:52:58 Done.
137 for a := agentReaction.Start(); a.Next(); {
138 if instId, err := m.InstanceId(); instId == "" {
139 c.Assert(err, FitsTypeOf, &state.NoInstanceIdError{})
140 return
141 }
142 }
143 c.Fatalf("provisioner failed to stop machine after %v", agentReaction.To tal)
144 }
145
146 // checkMachineIdSet checks that the machine has an instance id
147 // that matches that of the given instance. If the instance is nil,
148 // It checks that the instance id is unset.
149 func checkMachineId(c *C, m *state.Machine, inst environs.Instance) {
niemeyer 2012/07/06 19:44:56 s/MachineId/InstanceId/; in the documentation too.
dfc 2012/07/09 00:52:58 Done.
150 // TODO(dfc) add machine.WatchConfig() to avoid having to poll.
151 instId := ""
152 if inst != nil {
153 instId = inst.Id()
154 }
155 for a := agentReaction.Start(); a.Next(); {
156 _, err := m.InstanceId()
157 _, notset := err.(*state.NoInstanceIdError)
158 if notset {
159 if inst == nil {
160 return
161 } else {
162 continue
163 }
164 }
165 c.Assert(err, IsNil)
166 break
167 }
168 id, err := m.InstanceId()
169 c.Assert(err, IsNil)
170 c.Assert(id, Equals, instId)
171 }
172
88 // TODO check that binary data works ok? 173 // TODO check that binary data works ok?
89 var contents = []byte("hello\n") 174 var contents = []byte("hello\n")
90 var contents2 = []byte("goodbye\n\n") 175 var contents2 = []byte("goodbye\n\n")
91 176
92 func (t *LiveTests) TestFile(c *C) { 177 func (t *LiveTests) TestFile(c *C) {
93 name := fmt.Sprint("testfile", time.Now().UnixNano()) 178 name := fmt.Sprint("testfile", time.Now().UnixNano())
94 storage := t.Env.Storage() 179 storage := t.Env.Storage()
95 180
96 checkFileDoesNotExist(c, storage, name) 181 checkFileDoesNotExist(c, storage, name)
97 checkPutFile(c, storage, name, contents) 182 checkPutFile(c, storage, name, contents)
(...skipping 16 matching lines...) Expand all
114 c.Errorf("file name %q not found in file list %q", name, names) 199 c.Errorf("file name %q not found in file list %q", name, names)
115 } 200 }
116 201
117 err = storage.Remove(name) 202 err = storage.Remove(name)
118 c.Check(err, IsNil) 203 c.Check(err, IsNil)
119 checkFileDoesNotExist(c, storage, name) 204 checkFileDoesNotExist(c, storage, name)
120 // removing a file that does not exist should not be an error. 205 // removing a file that does not exist should not be an error.
121 err = storage.Remove(name) 206 err = storage.Remove(name)
122 c.Check(err, IsNil) 207 c.Check(err, IsNil)
123 } 208 }
OLDNEW

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