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

Side by Side Diff: state/state_test.go

Issue 5671055: Implementation of the charm state. (Closed)
Patch Set: Implementation of the charm state. Created 13 years, 1 month 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 | « state/state.go ('k') | state/util.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 // launchpad.net/juju/go/state 1 // launchpad.net/juju/go/state
2 // 2 //
3 // Copyright (c) 2011-2012 Canonical Ltd. 3 // Copyright (c) 2011-2012 Canonical Ltd.
4
5 package state_test 4 package state_test
6 5
7 import ( 6 import (
8 "fmt" 7 "fmt"
9 . "launchpad.net/gocheck" 8 . "launchpad.net/gocheck"
10 "launchpad.net/gozk/zookeeper" 9 "launchpad.net/gozk/zookeeper"
11 "launchpad.net/juju/go/charm" 10 "launchpad.net/juju/go/charm"
12 "launchpad.net/juju/go/state" 11 "launchpad.net/juju/go/state"
12 "net/url"
13 "path/filepath"
13 "testing" 14 "testing"
14 ) 15 )
15 16
16 // zkCreate is a simple helper to create a node with a value based 17 // TestPackage integrates the tests into gotest.
17 // on the path. It uses standard parameters for ZooKeeper and the 18 func TestPackage(t *testing.T) {
18 // test fails when the node can't be created. 19 » srv, dir := state.ZkSetUpEnvironment(t)
19 func zkCreate(c *C, zk *zookeeper.Conn, path, value string) { 20 » defer state.ZkTearDownEnvironment(t, srv, dir)
20 » if _, err := zk.Create(path, value, 0, zookeeper.WorldACL(zookeeper.PERM _ALL)); err != nil { 21
21 » » c.Fatal("Cannot set path '"+path+"' in ZooKeeper: ", err) 22 » TestingT(t)
22 » }
23 } 23 }
24 24
25 // TestPackage integrates the tests into gotest. 25 // charmDir returns a directory containing the given test charm.
26 func TestPackage(t *testing.T) { 26 func charmDir(name string) string {
27 » TestingT(t) 27 » return filepath.Join("..", "charm", "testrepo", "series", name)
28 }
29
30 // readCharm returns a test charm by its name.
31 func readCharm(c *C, name string) charm.Charm {
32 » ch, err := charm.ReadDir(charmDir(name))
33 » c.Assert(err, IsNil)
34 » return ch
35 }
36
37 // localCharmURL returns the local URL of a charm.
38 func localCharmURL(ch charm.Charm) *charm.URL {
39 » url := fmt.Sprintf("local:series/%s-%d", ch.Meta().Name, ch.Revision())
40 » return charm.MustParseURL(url)
41 }
42
43 // addDummyCharm adds the 'dummy' charm state to st.
44 func addDummyCharm(c *C, st *state.State) (*state.Charm, *charm.URL) {
45 » ch := readCharm(c, "dummy")
46 » curl := localCharmURL(ch)
47 » bundleURL, err := url.Parse("http://bundle.url")
48 » c.Assert(err, IsNil)
49 » dummy, err := st.AddCharm(ch, curl, bundleURL)
50 » c.Assert(err, IsNil)
51 » return dummy, curl
28 } 52 }
29 53
30 type StateSuite struct { 54 type StateSuite struct {
31 zkServer *zookeeper.Server 55 zkServer *zookeeper.Server
32 zkTestRoot string 56 zkTestRoot string
33 zkTestPort int 57 zkTestPort int
34 zkAddr string 58 zkAddr string
35 zkConn *zookeeper.Conn 59 zkConn *zookeeper.Conn
36 st *state.State 60 st *state.State
37 } 61 }
38 62
39 var _ = Suite(&StateSuite{}) 63 var _ = Suite(&StateSuite{})
40 64
41 func (s *StateSuite) SetUpSuite(c *C) { 65 func (s *StateSuite) SetUpTest(c *C) {
42 var err error 66 var err error
43 » s.zkTestRoot = c.MkDir() + "/zookeeper" 67 » s.st, err = state.Open(&state.Info{
44 » s.zkTestPort = 21812 68 » » Addrs: []string{state.ZkAddr},
45 » s.zkAddr = fmt.Sprint("localhost:", s.zkTestPort) 69 » })
46
47 » s.zkServer, err = zookeeper.CreateServer(s.zkTestPort, s.zkTestRoot, "")
48 » if err != nil {
49 » » c.Fatal("Cannot set up ZooKeeper server environment: ", err)
50 » }
51 » err = s.zkServer.Start()
52 » if err != nil {
53 » » c.Fatal("Cannot start ZooKeeper server: ", err)
54 » }
55 }
56
57 func (s *StateSuite) TearDownSuite(c *C) {
58 » if s.zkServer != nil {
59 » » s.zkServer.Destroy()
60 » }
61 }
62
63 func (s *StateSuite) SetUpTest(c *C) {
64 » s.st, s.zkConn = state.OpenAddr(c, s.zkAddr)
65 » err := s.st.Initialize()
66 c.Assert(err, IsNil) 70 c.Assert(err, IsNil)
71 err = s.st.Initialize()
72 c.Assert(err, IsNil)
73 s.zkConn = state.ZkConn(s.st)
67 } 74 }
68 75
69 func (s *StateSuite) TearDownTest(c *C) { 76 func (s *StateSuite) TearDownTest(c *C) {
70 // Delete possible nodes, ignore errors. 77 // Delete possible nodes, ignore errors.
71 zkRemoveTree(s.zkConn, "/topology") 78 zkRemoveTree(s.zkConn, "/topology")
72 zkRemoveTree(s.zkConn, "/charms") 79 zkRemoveTree(s.zkConn, "/charms")
73 zkRemoveTree(s.zkConn, "/services") 80 zkRemoveTree(s.zkConn, "/services")
74 zkRemoveTree(s.zkConn, "/machines") 81 zkRemoveTree(s.zkConn, "/machines")
75 zkRemoveTree(s.zkConn, "/units") 82 zkRemoveTree(s.zkConn, "/units")
76 zkRemoveTree(s.zkConn, "/relations") 83 zkRemoveTree(s.zkConn, "/relations")
77 zkRemoveTree(s.zkConn, "/initialized") 84 zkRemoveTree(s.zkConn, "/initialized")
78 s.zkConn.Close() 85 s.zkConn.Close()
79 } 86 }
80 87
88 func (s StateSuite) TestAddCharm(c *C) {
89 // Check that adding charms works correctly.
90 dummyCharm := readCharm(c, "dummy")
91 curl := localCharmURL(dummyCharm)
92 bundleURL, err := url.Parse("http://bundle.url")
93 c.Assert(err, IsNil)
94 dummy, err := s.st.AddCharm(dummyCharm, curl, bundleURL)
95 c.Assert(err, IsNil)
96 c.Assert(dummy.URL().String(), Equals, curl.String())
97 _, _, err = s.zkConn.Children("/charms")
98 c.Assert(err, IsNil)
99 }
100
101 func (s StateSuite) TestCharm(c *C) {
102 // Check that reading a previously added charm works correctly.
103 _, curl := addDummyCharm(c, s.st)
104
105 _, err := s.st.Charm(curl)
106 c.Assert(err, IsNil)
107 }
108
109 func (s StateSuite) TestCharmAttributes(c *C) {
110 // Check that the basic (invariant) fields of the charm
111 // are correctly in place.
112 _, curl := addDummyCharm(c, s.st)
113
114 dummy, err := s.st.Charm(curl)
115 c.Assert(err, IsNil)
116 c.Assert(dummy.URL().String(), Equals, curl.String())
117 c.Assert(dummy.Revision(), Equals, 1)
118 bundleURL, err := url.Parse("http://bundle.url")
119 c.Assert(err, IsNil)
120 c.Assert(dummy.BundleURL(), DeepEquals, bundleURL)
121 meta := dummy.Meta()
122 c.Assert(meta.Name, Equals, "dummy")
123 config := dummy.Config()
124 c.Assert(config.Options["title"], Equals,
125 charm.Option{
126 Default: "My Title",
127 Description: "A descriptive title used for the service." ,
128 Type: "string",
129 },
130 )
131 }
132
133 func (s StateSuite) TestNonExistentCharmPriorToInitialization(c *C) {
134 // Check that getting a charm before any other charm has been added fail s nicely.
135 curl, err := charm.ParseURL("local:series/dummy-1")
136 c.Assert(err, IsNil)
137 _, err = s.st.Charm(curl)
138 c.Assert(err, ErrorMatches, `charm not found: "local:series/dummy-1"`)
139 }
140
141 func (s StateSuite) TestGetNonExistentCharm(c *C) {
142 // Check that getting a non-existent charm fails nicely.
143 addDummyCharm(c, s.st)
144
145 curl := charm.MustParseURL("local:anotherseries/dummy-1")
146 _, err := s.st.Charm(curl)
147 c.Assert(err, ErrorMatches, `charm not found: "local:anotherseries/dummy -1"`)
148 }
149
81 func (s StateSuite) TestAddService(c *C) { 150 func (s StateSuite) TestAddService(c *C) {
82 // Check that adding services works correctly. 151 // Check that adding services works correctly.
83 » charm := state.CharmMock("local:myseries/mytest-1") 152 » dummy, curl := addDummyCharm(c, s.st)
84 » wordpress, err := s.st.AddService("wordpress", charm) 153 » wordpress, err := s.st.AddService("wordpress", dummy)
85 c.Assert(err, IsNil) 154 c.Assert(err, IsNil)
86 c.Assert(wordpress.Name(), Equals, "wordpress") 155 c.Assert(wordpress.Name(), Equals, "wordpress")
87 » mysql, err := s.st.AddService("mysql", charm) 156 » mysql, err := s.st.AddService("mysql", dummy)
88 c.Assert(err, IsNil) 157 c.Assert(err, IsNil)
89 c.Assert(mysql.Name(), Equals, "mysql") 158 c.Assert(mysql.Name(), Equals, "mysql")
90 159
91 // Check that retrieving the new created services works correctly. 160 // Check that retrieving the new created services works correctly.
92 wordpress, err = s.st.Service("wordpress") 161 wordpress, err = s.st.Service("wordpress")
93 c.Assert(err, IsNil) 162 c.Assert(err, IsNil)
94 c.Assert(wordpress.Name(), Equals, "wordpress") 163 c.Assert(wordpress.Name(), Equals, "wordpress")
95 url, err := wordpress.CharmURL() 164 url, err := wordpress.CharmURL()
96 c.Assert(err, IsNil) 165 c.Assert(err, IsNil)
97 » c.Assert(url.String(), Equals, "local:myseries/mytest-1") 166 » c.Assert(url.String(), Equals, curl.String())
98 mysql, err = s.st.Service("mysql") 167 mysql, err = s.st.Service("mysql")
99 c.Assert(err, IsNil) 168 c.Assert(err, IsNil)
100 c.Assert(mysql.Name(), Equals, "mysql") 169 c.Assert(mysql.Name(), Equals, "mysql")
101 url, err = mysql.CharmURL() 170 url, err = mysql.CharmURL()
102 c.Assert(err, IsNil) 171 c.Assert(err, IsNil)
103 » c.Assert(url.String(), Equals, "local:myseries/mytest-1") 172 » c.Assert(url.String(), Equals, curl.String())
104 } 173 }
105 174
106 func (s StateSuite) TestRemoveService(c *C) { 175 func (s StateSuite) TestRemoveService(c *C) {
107 » service, err := s.st.AddService("wordpress", state.CharmMock("local:myse ries/mytest-1")) 176 » dummy, _ := addDummyCharm(c, s.st)
177 » service, err := s.st.AddService("wordpress", dummy)
108 c.Assert(err, IsNil) 178 c.Assert(err, IsNil)
109 179
110 // Check that removing the service works correctly. 180 // Check that removing the service works correctly.
111 err = s.st.RemoveService(service) 181 err = s.st.RemoveService(service)
112 c.Assert(err, IsNil) 182 c.Assert(err, IsNil)
113 service, err = s.st.Service("wordpress") 183 service, err = s.st.Service("wordpress")
114 c.Assert(err, ErrorMatches, `service with name "wordpress" not found`) 184 c.Assert(err, ErrorMatches, `service with name "wordpress" not found`)
115 } 185 }
116 186
117 func (s StateSuite) TestReadNonExistentService(c *C) { 187 func (s StateSuite) TestReadNonExistentService(c *C) {
118 _, err := s.st.Service("pressword") 188 _, err := s.st.Service("pressword")
119 c.Assert(err, ErrorMatches, `service with name "pressword" not found`) 189 c.Assert(err, ErrorMatches, `service with name "pressword" not found`)
120 } 190 }
121 191
122 func (s StateSuite) TestAllServices(c *C) { 192 func (s StateSuite) TestAllServices(c *C) {
123 // Check without existing services. 193 // Check without existing services.
124 services, err := s.st.AllServices() 194 services, err := s.st.AllServices()
125 c.Assert(err, IsNil) 195 c.Assert(err, IsNil)
126 c.Assert(len(services), Equals, 0) 196 c.Assert(len(services), Equals, 0)
127 197
128 // Check that after adding services the result is ok. 198 // Check that after adding services the result is ok.
129 » charm := state.CharmMock("local:myseries/mytest-1") 199 » dummy, _ := addDummyCharm(c, s.st)
130 » _, err = s.st.AddService("wordpress", charm) 200 » _, err = s.st.AddService("wordpress", dummy)
131 c.Assert(err, IsNil) 201 c.Assert(err, IsNil)
132 services, err = s.st.AllServices() 202 services, err = s.st.AllServices()
133 c.Assert(err, IsNil) 203 c.Assert(err, IsNil)
134 c.Assert(len(services), Equals, 1) 204 c.Assert(len(services), Equals, 1)
135 205
136 » _, err = s.st.AddService("mysql", charm) 206 » _, err = s.st.AddService("mysql", dummy)
137 c.Assert(err, IsNil) 207 c.Assert(err, IsNil)
138 services, err = s.st.AllServices() 208 services, err = s.st.AllServices()
139 c.Assert(err, IsNil) 209 c.Assert(err, IsNil)
140 c.Assert(len(services), Equals, 2) 210 c.Assert(len(services), Equals, 2)
141 211
142 // Check the returned service, order is defined by sorted keys. 212 // Check the returned service, order is defined by sorted keys.
143 c.Assert(services[0].Name(), Equals, "wordpress") 213 c.Assert(services[0].Name(), Equals, "wordpress")
144 c.Assert(services[1].Name(), Equals, "mysql") 214 c.Assert(services[1].Name(), Equals, "mysql")
145 } 215 }
146 216
147 func (s StateSuite) TestServiceCharm(c *C) { 217 func (s StateSuite) TestServiceCharm(c *C) {
148 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 218 » dummy, curl := addDummyCharm(c, s.st)
219 » wordpress, err := s.st.AddService("wordpress", dummy)
149 c.Assert(err, IsNil) 220 c.Assert(err, IsNil)
150 221
151 // Check that getting and setting the service charm URL works correctly. 222 // Check that getting and setting the service charm URL works correctly.
152 » url, err := wordpress.CharmURL() 223 » testcurl, err := wordpress.CharmURL()
153 c.Assert(err, IsNil) 224 c.Assert(err, IsNil)
154 » c.Assert(url.String(), Equals, "local:myseries/mytest-1") 225 » c.Assert(testcurl.String(), Equals, curl.String())
155 » url, err = charm.ParseURL("local:myseries/myprod-1") 226 » testcurl, err = charm.ParseURL("local:myseries/mydummy-1")
156 c.Assert(err, IsNil) 227 c.Assert(err, IsNil)
157 » err = wordpress.SetCharmURL(url) 228 » err = wordpress.SetCharmURL(testcurl)
158 c.Assert(err, IsNil) 229 c.Assert(err, IsNil)
159 » url, err = wordpress.CharmURL() 230 » testcurl, err = wordpress.CharmURL()
160 c.Assert(err, IsNil) 231 c.Assert(err, IsNil)
161 » c.Assert(url.String(), Equals, "local:myseries/myprod-1") 232 » c.Assert(testcurl.String(), Equals, "local:myseries/mydummy-1")
162 } 233 }
163 234
164 func (s StateSuite) TestServiceExposed(c *C) { 235 func (s StateSuite) TestServiceExposed(c *C) {
165 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 236 » dummy, _ := addDummyCharm(c, s.st)
237 » wordpress, err := s.st.AddService("wordpress", dummy)
166 c.Assert(err, IsNil) 238 c.Assert(err, IsNil)
167 239
168 // Check that querying for the exposed flag works correctly. 240 // Check that querying for the exposed flag works correctly.
169 exposed, err := wordpress.IsExposed() 241 exposed, err := wordpress.IsExposed()
170 c.Assert(err, IsNil) 242 c.Assert(err, IsNil)
171 c.Assert(exposed, Equals, false) 243 c.Assert(exposed, Equals, false)
172 244
173 // Check that setting and clearing the exposed flag works correctly. 245 // Check that setting and clearing the exposed flag works correctly.
174 err = wordpress.SetExposed() 246 err = wordpress.SetExposed()
175 c.Assert(err, IsNil) 247 c.Assert(err, IsNil)
(...skipping 17 matching lines...) Expand all
193 c.Assert(err, IsNil) 265 c.Assert(err, IsNil)
194 266
195 // Check that setting and clearing the exposed flag on removed services also doesn't fail. 267 // Check that setting and clearing the exposed flag on removed services also doesn't fail.
196 err = s.st.RemoveService(wordpress) 268 err = s.st.RemoveService(wordpress)
197 c.Assert(err, IsNil) 269 c.Assert(err, IsNil)
198 err = wordpress.ClearExposed() 270 err = wordpress.ClearExposed()
199 c.Assert(err, IsNil) 271 c.Assert(err, IsNil)
200 } 272 }
201 273
202 func (s StateSuite) TestAddUnit(c *C) { 274 func (s StateSuite) TestAddUnit(c *C) {
203 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 275 » dummy, _ := addDummyCharm(c, s.st)
276 » wordpress, err := s.st.AddService("wordpress", dummy)
204 c.Assert(err, IsNil) 277 c.Assert(err, IsNil)
205 278
206 // Check that adding units works. 279 // Check that adding units works.
207 unitZero, err := wordpress.AddUnit() 280 unitZero, err := wordpress.AddUnit()
208 c.Assert(err, IsNil) 281 c.Assert(err, IsNil)
209 c.Assert(unitZero.Name(), Equals, "wordpress/0") 282 c.Assert(unitZero.Name(), Equals, "wordpress/0")
210 unitOne, err := wordpress.AddUnit() 283 unitOne, err := wordpress.AddUnit()
211 c.Assert(err, IsNil) 284 c.Assert(err, IsNil)
212 c.Assert(unitOne.Name(), Equals, "wordpress/1") 285 c.Assert(unitOne.Name(), Equals, "wordpress/1")
213 } 286 }
214 287
215 func (s StateSuite) TestReadUnit(c *C) { 288 func (s StateSuite) TestReadUnit(c *C) {
216 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 289 » dummy, _ := addDummyCharm(c, s.st)
290 » wordpress, err := s.st.AddService("wordpress", dummy)
217 c.Assert(err, IsNil) 291 c.Assert(err, IsNil)
218 _, err = wordpress.AddUnit() 292 _, err = wordpress.AddUnit()
219 c.Assert(err, IsNil) 293 c.Assert(err, IsNil)
220 _, err = wordpress.AddUnit() 294 _, err = wordpress.AddUnit()
221 c.Assert(err, IsNil) 295 c.Assert(err, IsNil)
222 » mysql, err := s.st.AddService("mysql", state.CharmMock("local:myseries/m ytest-1")) 296 » mysql, err := s.st.AddService("mysql", dummy)
223 c.Assert(err, IsNil) 297 c.Assert(err, IsNil)
224 _, err = mysql.AddUnit() 298 _, err = mysql.AddUnit()
225 c.Assert(err, IsNil) 299 c.Assert(err, IsNil)
226 300
227 // Check that retrieving a unit works correctly. 301 // Check that retrieving a unit works correctly.
228 unit, err := wordpress.Unit("wordpress/0") 302 unit, err := wordpress.Unit("wordpress/0")
229 c.Assert(err, IsNil) 303 c.Assert(err, IsNil)
230 c.Assert(unit.Name(), Equals, "wordpress/0") 304 c.Assert(unit.Name(), Equals, "wordpress/0")
231 305
232 // Check that retrieving a non-existent or an invalidly 306 // Check that retrieving a non-existent or an invalidly
233 // named unit fail nicely. 307 // named unit fail nicely.
234 unit, err = wordpress.Unit("wordpress") 308 unit, err = wordpress.Unit("wordpress")
235 c.Assert(err, ErrorMatches, `"wordpress" is not a valid unit name`) 309 c.Assert(err, ErrorMatches, `"wordpress" is not a valid unit name`)
236 unit, err = wordpress.Unit("wordpress/0/0") 310 unit, err = wordpress.Unit("wordpress/0/0")
237 c.Assert(err, ErrorMatches, `"wordpress/0/0" is not a valid unit name`) 311 c.Assert(err, ErrorMatches, `"wordpress/0/0" is not a valid unit name`)
238 unit, err = wordpress.Unit("pressword/0") 312 unit, err = wordpress.Unit("pressword/0")
239 c.Assert(err, ErrorMatches, `can't find unit "pressword/0" on service "w ordpress"`) 313 c.Assert(err, ErrorMatches, `can't find unit "pressword/0" on service "w ordpress"`)
240 unit, err = wordpress.Unit("mysql/0") 314 unit, err = wordpress.Unit("mysql/0")
241 c.Assert(err, ErrorMatches, `can't find unit "mysql/0" on service "wordp ress"`) 315 c.Assert(err, ErrorMatches, `can't find unit "mysql/0" on service "wordp ress"`)
242 316
243 // Check that retrieving unit names works. 317 // Check that retrieving unit names works.
244 unitNames, err := wordpress.UnitNames() 318 unitNames, err := wordpress.UnitNames()
245 c.Assert(err, IsNil) 319 c.Assert(err, IsNil)
246 » c.Assert(unitNames, Equals, []string{"wordpress/0", "wordpress/1"}) 320 » c.Assert(unitNames, DeepEquals, []string{"wordpress/0", "wordpress/1"})
247 321
248 // Check that retrieving all units works. 322 // Check that retrieving all units works.
249 units, err := wordpress.AllUnits() 323 units, err := wordpress.AllUnits()
250 c.Assert(err, IsNil) 324 c.Assert(err, IsNil)
251 c.Assert(len(units), Equals, 2) 325 c.Assert(len(units), Equals, 2)
252 c.Assert(units[0].Name(), Equals, "wordpress/0") 326 c.Assert(units[0].Name(), Equals, "wordpress/0")
253 c.Assert(units[1].Name(), Equals, "wordpress/1") 327 c.Assert(units[1].Name(), Equals, "wordpress/1")
254 } 328 }
255 329
256 func (s StateSuite) TestReadUnitWithChangingState(c *C) { 330 func (s StateSuite) TestReadUnitWithChangingState(c *C) {
257 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 331 » dummy, _ := addDummyCharm(c, s.st)
332 » wordpress, err := s.st.AddService("wordpress", dummy)
258 c.Assert(err, IsNil) 333 c.Assert(err, IsNil)
259 334
260 // Check that reading a unit after removing the service 335 // Check that reading a unit after removing the service
261 // fails nicely. 336 // fails nicely.
262 err = s.st.RemoveService(wordpress) 337 err = s.st.RemoveService(wordpress)
263 c.Assert(err, IsNil) 338 c.Assert(err, IsNil)
264 _, err = s.st.Unit("wordpress/0") 339 _, err = s.st.Unit("wordpress/0")
265 c.Assert(err, ErrorMatches, `service with name "wordpress" not found`) 340 c.Assert(err, ErrorMatches, `service with name "wordpress" not found`)
266 } 341 }
267 342
268 func (s StateSuite) TestRemoveUnit(c *C) { 343 func (s StateSuite) TestRemoveUnit(c *C) {
269 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 344 » dummy, _ := addDummyCharm(c, s.st)
345 » wordpress, err := s.st.AddService("wordpress", dummy)
270 c.Assert(err, IsNil) 346 c.Assert(err, IsNil)
271 _, err = wordpress.AddUnit() 347 _, err = wordpress.AddUnit()
272 c.Assert(err, IsNil) 348 c.Assert(err, IsNil)
273 _, err = wordpress.AddUnit() 349 _, err = wordpress.AddUnit()
274 c.Assert(err, IsNil) 350 c.Assert(err, IsNil)
275 351
276 // Check that removing a unit works. 352 // Check that removing a unit works.
277 unit, err := wordpress.Unit("wordpress/0") 353 unit, err := wordpress.Unit("wordpress/0")
278 c.Assert(err, IsNil) 354 c.Assert(err, IsNil)
279 err = wordpress.RemoveUnit(unit) 355 err = wordpress.RemoveUnit(unit)
280 c.Assert(err, IsNil) 356 c.Assert(err, IsNil)
281 unitNames, err := wordpress.UnitNames() 357 unitNames, err := wordpress.UnitNames()
282 c.Assert(err, IsNil) 358 c.Assert(err, IsNil)
283 » c.Assert(unitNames, Equals, []string{"wordpress/1"}) 359 » c.Assert(unitNames, DeepEquals, []string{"wordpress/1"})
284 360
285 // Check that removing a non-existent unit fails nicely. 361 // Check that removing a non-existent unit fails nicely.
286 err = wordpress.RemoveUnit(unit) 362 err = wordpress.RemoveUnit(unit)
287 c.Assert(err, ErrorMatches, "environment state has changed") 363 c.Assert(err, ErrorMatches, "environment state has changed")
288 } 364 }
289 365
290 func (s StateSuite) TestGetSetPublicAddress(c *C) { 366 func (s StateSuite) TestGetSetPublicAddress(c *C) {
291 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 367 » dummy, _ := addDummyCharm(c, s.st)
368 » wordpress, err := s.st.AddService("wordpress", dummy)
292 c.Assert(err, IsNil) 369 c.Assert(err, IsNil)
293 unit, err := wordpress.AddUnit() 370 unit, err := wordpress.AddUnit()
294 c.Assert(err, IsNil) 371 c.Assert(err, IsNil)
295 372
296 // Check that retrieving and setting of a public address works. 373 // Check that retrieving and setting of a public address works.
297 address, err := unit.PublicAddress() 374 address, err := unit.PublicAddress()
298 c.Assert(err, ErrorMatches, "unit has no public address") 375 c.Assert(err, ErrorMatches, "unit has no public address")
299 err = unit.SetPublicAddress("example.foobar.com") 376 err = unit.SetPublicAddress("example.foobar.com")
300 c.Assert(err, IsNil) 377 c.Assert(err, IsNil)
301 address, err = unit.PublicAddress() 378 address, err = unit.PublicAddress()
302 c.Assert(err, IsNil) 379 c.Assert(err, IsNil)
303 c.Assert(address, Equals, "example.foobar.com") 380 c.Assert(address, Equals, "example.foobar.com")
304 } 381 }
305 382
306 func (s StateSuite) TestGetSetPrivateAddress(c *C) { 383 func (s StateSuite) TestGetSetPrivateAddress(c *C) {
307 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 384 » dummy, _ := addDummyCharm(c, s.st)
385 » wordpress, err := s.st.AddService("wordpress", dummy)
308 c.Assert(err, IsNil) 386 c.Assert(err, IsNil)
309 unit, err := wordpress.AddUnit() 387 unit, err := wordpress.AddUnit()
310 c.Assert(err, IsNil) 388 c.Assert(err, IsNil)
311 389
312 // Check that retrieving and setting of a private address works. 390 // Check that retrieving and setting of a private address works.
313 address, err := unit.PrivateAddress() 391 address, err := unit.PrivateAddress()
314 c.Assert(err, ErrorMatches, "unit has no private address") 392 c.Assert(err, ErrorMatches, "unit has no private address")
315 err = unit.SetPrivateAddress("example.local") 393 err = unit.SetPrivateAddress("example.local")
316 c.Assert(err, IsNil) 394 c.Assert(err, IsNil)
317 address, err = unit.PrivateAddress() 395 address, err = unit.PrivateAddress()
318 c.Assert(err, IsNil) 396 c.Assert(err, IsNil)
319 c.Assert(address, Equals, "example.local") 397 c.Assert(address, Equals, "example.local")
320 } 398 }
321 399
322 func (s StateSuite) TestUnitCharm(c *C) { 400 func (s StateSuite) TestUnitCharm(c *C) {
323 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 401 » dummy, curl := addDummyCharm(c, s.st)
402 » wordpress, err := s.st.AddService("wordpress", dummy)
324 c.Assert(err, IsNil) 403 c.Assert(err, IsNil)
325 unit, err := wordpress.AddUnit() 404 unit, err := wordpress.AddUnit()
326 c.Assert(err, IsNil) 405 c.Assert(err, IsNil)
327 406
328 // Check that getting and setting the unit charm URL works correctly. 407 // Check that getting and setting the unit charm URL works correctly.
329 » url, err := unit.CharmURL() 408 » testcurl, err := unit.CharmURL()
330 c.Assert(err, IsNil) 409 c.Assert(err, IsNil)
331 » c.Assert(url.String(), Equals, "local:myseries/mytest-1") 410 » c.Assert(testcurl.String(), Equals, curl.String())
332 » url, err = charm.ParseURL("local:myseries/myprod-1") 411 » testcurl, err = charm.ParseURL("local:myseries/mydummy-1")
333 c.Assert(err, IsNil) 412 c.Assert(err, IsNil)
334 » err = unit.SetCharmURL(url) 413 » err = unit.SetCharmURL(testcurl)
335 c.Assert(err, IsNil) 414 c.Assert(err, IsNil)
336 » url, err = unit.CharmURL() 415 » testcurl, err = unit.CharmURL()
337 c.Assert(err, IsNil) 416 c.Assert(err, IsNil)
338 » c.Assert(url.String(), Equals, "local:myseries/myprod-1") 417 » c.Assert(testcurl.String(), Equals, "local:myseries/mydummy-1")
339 } 418 }
340 419
341 func (s StateSuite) TestUnassignUnitFromMachineWithoutBeingAssigned(c *C) { 420 func (s StateSuite) TestUnassignUnitFromMachineWithoutBeingAssigned(c *C) {
342 // When unassigning a machine from a unit, it is possible that 421 // When unassigning a machine from a unit, it is possible that
343 // the machine has not been previously assigned, or that it 422 // the machine has not been previously assigned, or that it
344 // was assigned but the state changed beneath us. In either 423 // was assigned but the state changed beneath us. In either
345 // case, the end state is the intended state, so we simply 424 // case, the end state is the intended state, so we simply
346 // move forward without any errors here, to avoid having to 425 // move forward without any errors here, to avoid having to
347 // handle the extra complexity of dealing with the concurrency 426 // handle the extra complexity of dealing with the concurrency
348 // problems. 427 // problems.
349 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 428 » dummy, _ := addDummyCharm(c, s.st)
429 » wordpress, err := s.st.AddService("wordpress", dummy)
350 c.Assert(err, IsNil) 430 c.Assert(err, IsNil)
351 unit, err := wordpress.AddUnit() 431 unit, err := wordpress.AddUnit()
352 c.Assert(err, IsNil) 432 c.Assert(err, IsNil)
353 433
354 err = unit.UnassignFromMachine() 434 err = unit.UnassignFromMachine()
355 c.Assert(err, IsNil) 435 c.Assert(err, IsNil)
356 436
357 // Check that the unit has no machine assigned. 437 // Check that the unit has no machine assigned.
358 wordpress, err = s.st.Service("wordpress") 438 wordpress, err = s.st.Service("wordpress")
359 c.Assert(err, IsNil) 439 c.Assert(err, IsNil)
360 units, err := wordpress.AllUnits() 440 units, err := wordpress.AllUnits()
361 c.Assert(err, IsNil) 441 c.Assert(err, IsNil)
362 unit = units[0] 442 unit = units[0]
363 _, err = unit.AssignedMachineId() 443 _, err = unit.AssignedMachineId()
364 c.Assert(err, ErrorMatches, `unit not assigned to machine`) 444 c.Assert(err, ErrorMatches, `unit not assigned to machine`)
365 } 445 }
366 446
367 func (s StateSuite) TestAssignUnitToMachineAgainFails(c *C) { 447 func (s StateSuite) TestAssignUnitToMachineAgainFails(c *C) {
368 // Check that assigning an already assigned unit to 448 // Check that assigning an already assigned unit to
369 // a machine fails if it isn't precisely the same 449 // a machine fails if it isn't precisely the same
370 // machine.· 450 // machine.·
371 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 451 » dummy, _ := addDummyCharm(c, s.st)
452 » wordpress, err := s.st.AddService("wordpress", dummy)
372 c.Assert(err, IsNil) 453 c.Assert(err, IsNil)
373 unit, err := wordpress.AddUnit() 454 unit, err := wordpress.AddUnit()
374 c.Assert(err, IsNil) 455 c.Assert(err, IsNil)
375 machineOne, err := s.st.AddMachine() 456 machineOne, err := s.st.AddMachine()
376 c.Assert(err, IsNil) 457 c.Assert(err, IsNil)
377 machineTwo, err := s.st.AddMachine() 458 machineTwo, err := s.st.AddMachine()
378 c.Assert(err, IsNil) 459 c.Assert(err, IsNil)
379 460
380 err = unit.AssignToMachine(machineOne) 461 err = unit.AssignToMachine(machineOne)
381 c.Assert(err, IsNil) 462 c.Assert(err, IsNil)
382 463
383 // Assigning the unit to the same machine should return no error. 464 // Assigning the unit to the same machine should return no error.
384 err = unit.AssignToMachine(machineOne) 465 err = unit.AssignToMachine(machineOne)
385 c.Assert(err, IsNil) 466 c.Assert(err, IsNil)
386 467
387 // Assigning the unit to a different machine should fail. 468 // Assigning the unit to a different machine should fail.
388 err = unit.AssignToMachine(machineTwo) 469 err = unit.AssignToMachine(machineTwo)
389 c.Assert(err, ErrorMatches, `unit "wordpress/0" already assigned to mach ine 0`) 470 c.Assert(err, ErrorMatches, `unit "wordpress/0" already assigned to mach ine 0`)
390 471
391 machineId, err := unit.AssignedMachineId() 472 machineId, err := unit.AssignedMachineId()
392 c.Assert(err, IsNil) 473 c.Assert(err, IsNil)
393 c.Assert(machineId, Equals, 0) 474 c.Assert(machineId, Equals, 0)
394 } 475 }
395 476
396 func (s StateSuite) TestUnassignUnitFromMachineWithChangingState(c *C) { 477 func (s StateSuite) TestUnassignUnitFromMachineWithChangingState(c *C) {
397 » // Check 478 » // Check that unassigning while the state changes fails nicely.
398 » wordpress, err := s.st.AddService("wordpress", state.CharmMock("local:my series/mytest-1")) 479 » dummy, _ := addDummyCharm(c, s.st)
480 » wordpress, err := s.st.AddService("wordpress", dummy)
399 c.Assert(err, IsNil) 481 c.Assert(err, IsNil)
400 unit, err := wordpress.AddUnit() 482 unit, err := wordpress.AddUnit()
401 c.Assert(err, IsNil) 483 c.Assert(err, IsNil)
402 484
403 // Remove the unit for the tests. 485 // Remove the unit for the tests.
404 wordpress, err = s.st.Service("wordpress") 486 wordpress, err = s.st.Service("wordpress")
405 c.Assert(err, IsNil) 487 c.Assert(err, IsNil)
406 units, err := wordpress.AllUnits() 488 units, err := wordpress.AllUnits()
407 c.Assert(err, IsNil) 489 c.Assert(err, IsNil)
408 unit = units[0] 490 unit = units[0]
(...skipping 12 matching lines...) Expand all
421 c.Assert(err, ErrorMatches, "environment state has changed") 503 c.Assert(err, ErrorMatches, "environment state has changed")
422 _, err = unit.AssignedMachineId() 504 _, err = unit.AssignedMachineId()
423 c.Assert(err, ErrorMatches, "environment state has changed") 505 c.Assert(err, ErrorMatches, "environment state has changed")
424 } 506 }
425 507
426 func (s StateSuite) TestAssignUnitToUnusedMachine(c *C) { 508 func (s StateSuite) TestAssignUnitToUnusedMachine(c *C) {
427 // Create root machine that shouldn't be useds. 509 // Create root machine that shouldn't be useds.
428 _, err := s.st.AddMachine() 510 _, err := s.st.AddMachine()
429 c.Assert(err, IsNil) 511 c.Assert(err, IsNil)
430 // Check that a unit can be assigned to an unused machine. 512 // Check that a unit can be assigned to an unused machine.
431 » mysqlService, err := s.st.AddService("mysql", state.CharmMock("local:mys eries/mytest-1")) 513 » dummy, _ := addDummyCharm(c, s.st)
514 » mysqlService, err := s.st.AddService("mysql", dummy)
432 c.Assert(err, IsNil) 515 c.Assert(err, IsNil)
433 mysqlUnit, err := mysqlService.AddUnit() 516 mysqlUnit, err := mysqlService.AddUnit()
434 c.Assert(err, IsNil) 517 c.Assert(err, IsNil)
435 mysqlMachine, err := s.st.AddMachine() 518 mysqlMachine, err := s.st.AddMachine()
436 c.Assert(err, IsNil) 519 c.Assert(err, IsNil)
437 err = mysqlUnit.AssignToMachine(mysqlMachine) 520 err = mysqlUnit.AssignToMachine(mysqlMachine)
438 c.Assert(err, IsNil) 521 c.Assert(err, IsNil)
439 err = s.st.RemoveService(mysqlService) 522 err = s.st.RemoveService(mysqlService)
440 c.Assert(err, IsNil) 523 c.Assert(err, IsNil)
441 524
442 » wordpressService, err := s.st.AddService("wordpress", state.CharmMock("l ocal:myseries/mytest-1")) 525 » wordpressService, err := s.st.AddService("wordpress", dummy)
443 c.Assert(err, IsNil) 526 c.Assert(err, IsNil)
444 wordpressUnit, err := wordpressService.AddUnit() 527 wordpressUnit, err := wordpressService.AddUnit()
445 c.Assert(err, IsNil) 528 c.Assert(err, IsNil)
446 wordpressMachine, err := wordpressUnit.AssignToUnusedMachine() 529 wordpressMachine, err := wordpressUnit.AssignToUnusedMachine()
447 c.Assert(err, IsNil) 530 c.Assert(err, IsNil)
448 531
449 c.Assert(wordpressMachine.Id(), Equals, mysqlMachine.Id()) 532 c.Assert(wordpressMachine.Id(), Equals, mysqlMachine.Id())
450 } 533 }
451 534
452 func (s StateSuite) TestAssignUnitToUnusedMachineWithChangingService(c *C) { 535 func (s StateSuite) TestAssignUnitToUnusedMachineWithChangingService(c *C) {
453 // Create root machine that shouldn't be useds. 536 // Create root machine that shouldn't be useds.
454 _, err := s.st.AddMachine() 537 _, err := s.st.AddMachine()
455 c.Assert(err, IsNil) 538 c.Assert(err, IsNil)
456 // Check for a 'state changed' error if a service is manipulated 539 // Check for a 'state changed' error if a service is manipulated
457 // during reuse. 540 // during reuse.
458 » mysqlService, err := s.st.AddService("mysql", state.CharmMock("local:mys eries/mytest-1")) 541 » dummy, _ := addDummyCharm(c, s.st)
542 » mysqlService, err := s.st.AddService("mysql", dummy)
459 c.Assert(err, IsNil) 543 c.Assert(err, IsNil)
460 mysqlUnit, err := mysqlService.AddUnit() 544 mysqlUnit, err := mysqlService.AddUnit()
461 c.Assert(err, IsNil) 545 c.Assert(err, IsNil)
462 mysqlMachine, err := s.st.AddMachine() 546 mysqlMachine, err := s.st.AddMachine()
463 c.Assert(err, IsNil) 547 c.Assert(err, IsNil)
464 err = mysqlUnit.AssignToMachine(mysqlMachine) 548 err = mysqlUnit.AssignToMachine(mysqlMachine)
465 c.Assert(err, IsNil) 549 c.Assert(err, IsNil)
466 err = s.st.RemoveService(mysqlService) 550 err = s.st.RemoveService(mysqlService)
467 c.Assert(err, IsNil) 551 c.Assert(err, IsNil)
468 552
469 » wordpressService, err := s.st.AddService("wordpress", state.CharmMock("l ocal:myseries/mytest-1")) 553 » wordpressService, err := s.st.AddService("wordpress", dummy)
470 c.Assert(err, IsNil) 554 c.Assert(err, IsNil)
471 wordpressUnit, err := wordpressService.AddUnit() 555 wordpressUnit, err := wordpressService.AddUnit()
472 c.Assert(err, IsNil) 556 c.Assert(err, IsNil)
473 err = s.st.RemoveService(wordpressService) 557 err = s.st.RemoveService(wordpressService)
474 c.Assert(err, IsNil) 558 c.Assert(err, IsNil)
475 559
476 _, err = wordpressUnit.AssignToUnusedMachine() 560 _, err = wordpressUnit.AssignToUnusedMachine()
477 c.Assert(err, ErrorMatches, "environment state has changed") 561 c.Assert(err, ErrorMatches, "environment state has changed")
478 } 562 }
479 563
480 func (s StateSuite) TestAssignUniToUnusedMachineWithChangingUnit(c *C) { 564 func (s StateSuite) TestAssignUnitToUnusedMachineWithChangingUnit(c *C) {
481 // Create root machine that shouldn't be useds. 565 // Create root machine that shouldn't be useds.
482 _, err := s.st.AddMachine() 566 _, err := s.st.AddMachine()
483 c.Assert(err, IsNil) 567 c.Assert(err, IsNil)
484 // Check for a 'state changed' error if a unit is manipulated 568 // Check for a 'state changed' error if a unit is manipulated
485 // during reuse. 569 // during reuse.
486 » mysqlService, err := s.st.AddService("mysql", state.CharmMock("local:mys eries/mytest-1")) 570 » dummy, _ := addDummyCharm(c, s.st)
571 » mysqlService, err := s.st.AddService("mysql", dummy)
487 c.Assert(err, IsNil) 572 c.Assert(err, IsNil)
488 mysqlUnit, err := mysqlService.AddUnit() 573 mysqlUnit, err := mysqlService.AddUnit()
489 c.Assert(err, IsNil) 574 c.Assert(err, IsNil)
490 mysqlMachine, err := s.st.AddMachine() 575 mysqlMachine, err := s.st.AddMachine()
491 c.Assert(err, IsNil) 576 c.Assert(err, IsNil)
492 err = mysqlUnit.AssignToMachine(mysqlMachine) 577 err = mysqlUnit.AssignToMachine(mysqlMachine)
493 c.Assert(err, IsNil) 578 c.Assert(err, IsNil)
494 err = s.st.RemoveService(mysqlService) 579 err = s.st.RemoveService(mysqlService)
495 c.Assert(err, IsNil) 580 c.Assert(err, IsNil)
496 581
497 » wordpressService, err := s.st.AddService("wordpress", state.CharmMock("l ocal:myseries/mytest-1")) 582 » wordpressService, err := s.st.AddService("wordpress", dummy)
498 c.Assert(err, IsNil) 583 c.Assert(err, IsNil)
499 wordpressUnit, err := wordpressService.AddUnit() 584 wordpressUnit, err := wordpressService.AddUnit()
500 c.Assert(err, IsNil) 585 c.Assert(err, IsNil)
501 err = wordpressService.RemoveUnit(wordpressUnit) 586 err = wordpressService.RemoveUnit(wordpressUnit)
502 c.Assert(err, IsNil) 587 c.Assert(err, IsNil)
503 588
504 _, err = wordpressUnit.AssignToUnusedMachine() 589 _, err = wordpressUnit.AssignToUnusedMachine()
505 c.Assert(err, ErrorMatches, "environment state has changed") 590 c.Assert(err, ErrorMatches, "environment state has changed")
506 } 591 }
507 592
508 func (s StateSuite) TestAssignUnitToUnusedMachineOnlyZero(c *C) { 593 func (s StateSuite) TestAssignUnitToUnusedMachineOnlyZero(c *C) {
509 // Create root machine that shouldn't be useds. 594 // Create root machine that shouldn't be useds.
510 _, err := s.st.AddMachine() 595 _, err := s.st.AddMachine()
511 c.Assert(err, IsNil) 596 c.Assert(err, IsNil)
512 // Check that the unit can't be assigned to machine zero. 597 // Check that the unit can't be assigned to machine zero.
513 » wordpressService, err := s.st.AddService("wordpress", state.CharmMock("l ocal:myseries/mytest-1")) 598 » dummy, _ := addDummyCharm(c, s.st)
599 » wordpressService, err := s.st.AddService("wordpress", dummy)
514 c.Assert(err, IsNil) 600 c.Assert(err, IsNil)
515 wordpressUnit, err := wordpressService.AddUnit() 601 wordpressUnit, err := wordpressService.AddUnit()
516 c.Assert(err, IsNil) 602 c.Assert(err, IsNil)
517 603
518 _, err = wordpressUnit.AssignToUnusedMachine() 604 _, err = wordpressUnit.AssignToUnusedMachine()
519 c.Assert(err, ErrorMatches, "no unused machine found") 605 c.Assert(err, ErrorMatches, "no unused machine found")
520 } 606 }
521 607
522 func (s StateSuite) TestAssignUnitToUnusedMachineNoneAvailable(c *C) { 608 func (s StateSuite) TestAssignUnitToUnusedMachineNoneAvailable(c *C) {
523 // Create machine 0, that shouldn't be used. 609 // Create machine 0, that shouldn't be used.
524 _, err := s.st.AddMachine() 610 _, err := s.st.AddMachine()
525 c.Assert(err, IsNil) 611 c.Assert(err, IsNil)
526 // Check that assigning without unused machine fails.··· 612 // Check that assigning without unused machine fails.···
527 » mysqlService, err := s.st.AddService("mysql", state.CharmMock("local:mys eries/mytest-1")) 613 » dummy, _ := addDummyCharm(c, s.st)
614 » mysqlService, err := s.st.AddService("mysql", dummy)
528 c.Assert(err, IsNil) 615 c.Assert(err, IsNil)
529 mysqlUnit, err := mysqlService.AddUnit() 616 mysqlUnit, err := mysqlService.AddUnit()
530 c.Assert(err, IsNil) 617 c.Assert(err, IsNil)
531 mysqlMachine, err := s.st.AddMachine() 618 mysqlMachine, err := s.st.AddMachine()
532 c.Assert(err, IsNil) 619 c.Assert(err, IsNil)
533 err = mysqlUnit.AssignToMachine(mysqlMachine) 620 err = mysqlUnit.AssignToMachine(mysqlMachine)
534 c.Assert(err, IsNil) 621 c.Assert(err, IsNil)
535 622
536 » wordpressService, err := s.st.AddService("wordpress", state.CharmMock("l ocal:myseries/mytest-1")) 623 » wordpressService, err := s.st.AddService("wordpress", dummy)
537 c.Assert(err, IsNil) 624 c.Assert(err, IsNil)
538 wordpressUnit, err := wordpressService.AddUnit() 625 wordpressUnit, err := wordpressService.AddUnit()
539 c.Assert(err, IsNil) 626 c.Assert(err, IsNil)
540 627
541 _, err = wordpressUnit.AssignToUnusedMachine() 628 _, err = wordpressUnit.AssignToUnusedMachine()
542 c.Assert(err, ErrorMatches, "no unused machine found") 629 c.Assert(err, ErrorMatches, "no unused machine found")
543 } 630 }
544 631
545 // zkRemoveTree recursively removes a tree. 632 // zkRemoveTree recursively removes a tree.
546 func zkRemoveTree(zk *zookeeper.Conn, path string) error { 633 func zkRemoveTree(zk *zookeeper.Conn, path string) error {
547 // First recursively delete the children. 634 // First recursively delete the children.
548 children, _, err := zk.Children(path) 635 children, _, err := zk.Children(path)
549 if err != nil { 636 if err != nil {
550 return err 637 return err
551 } 638 }
552 for _, child := range children { 639 for _, child := range children {
553 if err = zkRemoveTree(zk, fmt.Sprintf("%s/%s", path, child)); er r != nil { 640 if err = zkRemoveTree(zk, fmt.Sprintf("%s/%s", path, child)); er r != nil {
554 return err 641 return err
555 } 642 }
556 } 643 }
557 // Now delete the path itself. 644 // Now delete the path itself.
558 return zk.Delete(path, -1) 645 return zk.Delete(path, -1)
559 } 646 }
OLDNEW
« no previous file with comments | « state/state.go ('k') | state/util.go » ('j') | no next file with comments »

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