Merge lp:~rogpeppe/juju-core/097-state-unit-id into lp:~juju/juju-core/trunk
- 097-state-unit-id
- Merge into trunk
Status: | Work in progress |
---|---|
Proposed branch: | lp:~rogpeppe/juju-core/097-state-unit-id |
Merge into: | lp:~juju/juju-core/trunk |
Diff against target: |
1020 lines (+118/-121) 26 files modified
cmd/juju/deploy_test.go (+7/-7) cmd/juju/status.go (+1/-1) cmd/jujuc/server/context.go (+1/-1) cmd/jujuc/server/context_test.go (+5/-5) cmd/jujuc/server/juju-log.go (+1/-1) cmd/jujuc/server/relation-get.go (+1/-1) cmd/jujuc/server/util_test.go (+1/-3) cmd/jujud/unit.go (+1/-1) cmd/jujud/unit_test.go (+3/-3) container/container.go (+2/-2) state/assign_test.go (+1/-1) state/life_test.go (+1/-1) state/machine.go (+1/-1) state/machine_test.go (+9/-9) state/relation.go (+5/-5) state/relation_test.go (+2/-3) state/service.go (+6/-6) state/service_test.go (+11/-10) state/unit.go (+24/-24) state/unit_test.go (+6/-6) state/watcher.go (+8/-8) worker/firewaller/firewaller.go (+7/-7) worker/machiner/machiner.go (+2/-2) worker/machiner/machiner_test.go (+2/-2) worker/uniter/relationer_test.go (+8/-9) worker/uniter/uniter.go (+2/-2) |
To merge this branch: | bzr merge lp:~rogpeppe/juju-core/097-state-unit-id |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
The Go Language Gophers | Pending | ||
Review via email: mp+127341@code.launchpad.net |
Commit message
Description of the change
state: rename Unit.Name to Unit.Id
This is a preparatory step to renaming PathKey to Name.
Also changed a couple of tests to use PathKey rather than Id.
Gustavo Niemeyer (niemeyer) wrote : | # |
I've reviewed about 80% of this with trivial comments only, and then
when I got to reviewing the service bits, I got deadlocked.
You wisely decided not to switch service.Name to mean
"service-
sane concept, wouldn't be a service name. That, in turn, means the unit
Name means something totally unlike the service Name, so we get
unit.Name() => "unit-wordpress-0", but service.Name() => "wordpress".
Also, there are public parts of the interface, such as the
JUJU_UNIT_NAME environment variable, that we can't change, so we're
introducing gratuitous inconsistencies that we can't avoid with our
renaming.
I suggest dropping our idea of replacing what the Name methods mean, and
instead doing a simpler change that introduces a Key method that returns
the equivalent of PathKey today, and dropping PathKey:
machine.Key() => "machine-0"
unit.Key() => "unit-wordpress-0"
service.Key() => "service-wordpress"
We can also have PrincipalKey in state.Info.
Unmerged revisions
- 608. By Roger Peppe
-
state: finish rename Unit.Name -> Unit.Id
- 607. By Roger Peppe
-
all: rename state.Unit.Name to state.Unit.Id
- 606. By Roger Peppe
-
state: rename Unit.Name to Unit.Id
- 605. By Roger Peppe
-
cmd/juju: implement upgrade-juju --bump-version
R=niemeyer
CC=
https://codereview. appspot. com/6593053 - 604. By Dave Cheney
-
cmd/juju: add scp subcommand
R=niemeyer
CC=
https://codereview. appspot. com/6565055 - 603. By William Reade
-
state: add CharmURL() to Service
R=niemeyer
CC=
https://codereview. appspot. com/6570064 - 602. By William Reade
-
uniter: faster tests
In each case, without regular StartSyncing, the Uniter just hangs around
waiting for events that... well, they come sooner or later, and the timeouts
are long so the tests are reliable. But I think that, in the interests of
sanity, it's better to make the environment unrealistically eager.R=niemeyer
CC=
https://codereview. appspot. com/6574061 - 601. By Gustavo Niemeyer
-
state,worker: full lifecycle machines watcher
MachinesWatcher now returns a list of ids that have had their
lifecycle changed in any way. It's up to the consumer to work
out details.R=TheMue, aram
CC=
https://codereview. appspot. com/6566066 - 600. By Roger Peppe
-
version: add Build number
This will be used to implement upgrade --bump-version.
R=niemeyer
CC=
https://codereview. appspot. com/6560066 - 599. By Roger Peppe
-
machiner: eat provisioner and firewaller for lunch
Three in one.
R=fwereade, niemeyer
CC=
https://codereview. appspot. com/6570063
Preview Diff
1 | === modified file 'cmd/juju/deploy_test.go' |
2 | --- cmd/juju/deploy_test.go 2012-09-22 23:33:31 +0000 |
3 | +++ cmd/juju/deploy_test.go 2012-10-01 17:54:22 +0000 |
4 | @@ -81,24 +81,24 @@ |
5 | } |
6 | |
7 | func (s *repoSuite) assertUnitMachines(c *C, units []*state.Unit) { |
8 | - expectUnitNames := []string{} |
9 | + expectUnitIds := []string{} |
10 | for _, u := range units { |
11 | - expectUnitNames = append(expectUnitNames, u.Name()) |
12 | + expectUnitIds = append(expectUnitIds, u.Id()) |
13 | } |
14 | - sort.Strings(expectUnitNames) |
15 | + sort.Strings(expectUnitIds) |
16 | |
17 | machines, err := s.State.AllMachines() |
18 | c.Assert(err, IsNil) |
19 | c.Assert(machines, HasLen, len(units)) |
20 | - unitNames := []string{} |
21 | + unitIds := []string{} |
22 | for _, m := range machines { |
23 | mUnits, err := m.Units() |
24 | c.Assert(err, IsNil) |
25 | c.Assert(mUnits, HasLen, 1) |
26 | - unitNames = append(unitNames, mUnits[0].Name()) |
27 | + unitIds = append(unitIds, mUnits[0].Id()) |
28 | } |
29 | - sort.Strings(unitNames) |
30 | - c.Assert(unitNames, DeepEquals, expectUnitNames) |
31 | + sort.Strings(unitIds) |
32 | + c.Assert(unitIds, DeepEquals, expectUnitIds) |
33 | } |
34 | |
35 | type DeploySuite struct { |
36 | |
37 | === modified file 'cmd/juju/status.go' |
38 | --- cmd/juju/status.go 2012-09-21 18:41:24 +0000 |
39 | +++ cmd/juju/status.go 2012-10-01 17:54:22 +0000 |
40 | @@ -194,7 +194,7 @@ |
41 | func processUnits(units []*state.Unit) (map[string]interface{}, error) { |
42 | r := m() |
43 | for _, unit := range units { |
44 | - r[unit.Name()] = checkError(processUnit(unit)) |
45 | + r[unit.Id()] = checkError(processUnit(unit)) |
46 | } |
47 | return r, nil |
48 | } |
49 | |
50 | === modified file 'cmd/jujuc/server/context.go' |
51 | --- cmd/jujuc/server/context.go 2012-09-24 11:59:53 +0000 |
52 | +++ cmd/jujuc/server/context.go 2012-10-01 17:54:22 +0000 |
53 | @@ -90,7 +90,7 @@ |
54 | "CHARM_DIR=" + charmDir, |
55 | "JUJU_CONTEXT_ID=" + ctx.Id, |
56 | "JUJU_AGENT_SOCKET=" + socketPath, |
57 | - "JUJU_UNIT_NAME=" + ctx.Unit.Name(), |
58 | + "JUJU_UNIT_NAME=" + ctx.Unit.Id(), |
59 | } |
60 | if ctx.RelationId != -1 { |
61 | vars = append(vars, "JUJU_RELATION="+ctx.envRelation()) |
62 | |
63 | === modified file 'cmd/jujuc/server/context_test.go' |
64 | --- cmd/jujuc/server/context_test.go 2012-09-24 21:19:46 +0000 |
65 | +++ cmd/jujuc/server/context_test.go 2012-10-01 17:54:22 +0000 |
66 | @@ -320,12 +320,12 @@ |
67 | node0, err = s.relctxs[0].Settings() |
68 | c.Assert(err, IsNil) |
69 | c.Assert(node0.Map(), DeepEquals, map[string]interface{}{ |
70 | - "private-address": "u-0.example.com", |
71 | + "private-address": "unit-u-0.example.com", |
72 | }) |
73 | node1, err = s.relctxs[1].Settings() |
74 | c.Assert(err, IsNil) |
75 | c.Assert(node1.Map(), DeepEquals, map[string]interface{}{ |
76 | - "private-address": "u-0.example.com", |
77 | + "private-address": "unit-u-0.example.com", |
78 | }) |
79 | |
80 | // Check that the changes have been written to state. |
81 | @@ -352,13 +352,13 @@ |
82 | node0, err = s.relctxs[0].Settings() |
83 | c.Assert(err, IsNil) |
84 | c.Assert(node0.Map(), DeepEquals, map[string]interface{}{ |
85 | - "private-address": "u-0.example.com", |
86 | + "private-address": "unit-u-0.example.com", |
87 | "baz": 3, |
88 | }) |
89 | node1, err = s.relctxs[1].Settings() |
90 | c.Assert(err, IsNil) |
91 | c.Assert(node1.Map(), DeepEquals, map[string]interface{}{ |
92 | - "private-address": "u-0.example.com", |
93 | + "private-address": "unit-u-0.example.com", |
94 | "qux": 4, |
95 | }) |
96 | |
97 | @@ -392,7 +392,7 @@ |
98 | c.Assert(err, IsNil) |
99 | unit, err := s.svc.AddUnit() |
100 | c.Assert(err, IsNil) |
101 | - unit.SetPrivateAddress("u-0.example.com") |
102 | + unit.SetPrivateAddress("unit-u-0.example.com") |
103 | c.Assert(err, IsNil) |
104 | s.ru, err = s.rel.Unit(unit) |
105 | c.Assert(err, IsNil) |
106 | |
107 | === modified file 'cmd/jujuc/server/juju-log.go' |
108 | --- cmd/jujuc/server/juju-log.go 2012-08-06 16:41:17 +0000 |
109 | +++ cmd/jujuc/server/juju-log.go 2012-10-01 17:54:22 +0000 |
110 | @@ -37,7 +37,7 @@ |
111 | } |
112 | |
113 | func (c *JujuLogCommand) Run(_ *cmd.Context) error { |
114 | - s := []string{c.Unit.Name()} |
115 | + s := []string{c.Unit.Id()} |
116 | if c.RelationId != -1 { |
117 | s = append(s, c.envRelationId()) |
118 | } |
119 | |
120 | === modified file 'cmd/jujuc/server/relation-get.go' |
121 | --- cmd/jujuc/server/relation-get.go 2012-08-07 14:22:28 +0000 |
122 | +++ cmd/jujuc/server/relation-get.go 2012-10-01 17:54:22 +0000 |
123 | @@ -65,7 +65,7 @@ |
124 | |
125 | func (c *RelationGetCommand) Run(ctx *cmd.Context) error { |
126 | var settings map[string]interface{} |
127 | - if c.UnitName == c.Unit.Name() { |
128 | + if c.UnitName == c.Unit.Id() { |
129 | node, err := c.Relations[c.RelationId].Settings() |
130 | if err != nil { |
131 | return err |
132 | |
133 | === modified file 'cmd/jujuc/server/util_test.go' |
134 | --- cmd/jujuc/server/util_test.go 2012-09-21 09:32:11 +0000 |
135 | +++ cmd/jujuc/server/util_test.go 2012-10-01 17:54:22 +0000 |
136 | @@ -10,7 +10,6 @@ |
137 | "launchpad.net/juju-core/juju/testing" |
138 | "launchpad.net/juju-core/state" |
139 | coretesting "launchpad.net/juju-core/testing" |
140 | - "strings" |
141 | stdtesting "testing" |
142 | ) |
143 | |
144 | @@ -51,8 +50,7 @@ |
145 | func (s *HookContextSuite) AddUnit(c *C) *state.Unit { |
146 | unit, err := s.service.AddUnit() |
147 | c.Assert(err, IsNil) |
148 | - name := strings.Replace(unit.Name(), "/", "-", 1) |
149 | - err = unit.SetPrivateAddress(name + ".example.com") |
150 | + err = unit.SetPrivateAddress(unit.PathKey() + ".example.com") |
151 | c.Assert(err, IsNil) |
152 | return unit |
153 | } |
154 | |
155 | === modified file 'cmd/jujud/unit.go' |
156 | --- cmd/jujud/unit.go 2012-09-28 16:10:09 +0000 |
157 | +++ cmd/jujud/unit.go 2012-10-01 17:54:22 +0000 |
158 | @@ -92,7 +92,7 @@ |
159 | return err |
160 | } |
161 | return runTasks(a.tomb.Dying(), |
162 | - uniter.NewUniter(st, unit.Name(), a.Conf.DataDir), |
163 | + uniter.NewUniter(st, unit.Id(), a.Conf.DataDir), |
164 | NewUpgrader(st, unit, a.Conf.DataDir), |
165 | ) |
166 | } |
167 | |
168 | === modified file 'cmd/jujud/unit_test.go' |
169 | --- cmd/jujud/unit_test.go 2012-09-28 15:33:46 +0000 |
170 | +++ cmd/jujud/unit_test.go 2012-10-01 17:54:22 +0000 |
171 | @@ -102,7 +102,7 @@ |
172 | |
173 | return &UnitAgent{ |
174 | Conf: AgentConf{dataDir, *s.StateInfo(c)}, |
175 | - UnitName: unit.Name(), |
176 | + UnitName: unit.Id(), |
177 | }, unit, tools |
178 | } |
179 | |
180 | @@ -132,7 +132,7 @@ |
181 | dataDir := c.MkDir() |
182 | a := &UnitAgent{ |
183 | Conf: AgentConf{dataDir, *s.StateInfo(c)}, |
184 | - UnitName: unit.Name(), |
185 | + UnitName: unit.Id(), |
186 | } |
187 | err = runWithTimeout(a) |
188 | c.Assert(err, IsNil) |
189 | @@ -142,7 +142,7 @@ |
190 | c.Assert(err, IsNil) |
191 | a = &UnitAgent{ |
192 | Conf: AgentConf{dataDir, *s.StateInfo(c)}, |
193 | - UnitName: unit.Name(), |
194 | + UnitName: unit.Id(), |
195 | } |
196 | err = runWithTimeout(a) |
197 | c.Assert(err, IsNil) |
198 | |
199 | === modified file 'container/container.go' |
200 | --- container/container.go 2012-09-21 11:53:49 +0000 |
201 | +++ container/container.go 2012-10-01 17:54:22 +0000 |
202 | @@ -67,11 +67,11 @@ |
203 | filepath.Join(toolsDir, "jujud"), |
204 | strings.Join(info.Addrs, ","), |
205 | filepath.Join("/var/log/juju", unit.PathKey()+".log"), |
206 | - unit.Name()) |
207 | + unit.Id()) |
208 | |
209 | conf := &upstart.Conf{ |
210 | Service: *c.service(unit), |
211 | - Desc: "juju unit agent for " + unit.Name(), |
212 | + Desc: "juju unit agent for " + unit.Id(), |
213 | Cmd: cmd, |
214 | } |
215 | dir := c.dirName(unit) |
216 | |
217 | === modified file 'state/assign_test.go' |
218 | --- state/assign_test.go 2012-09-28 07:21:43 +0000 |
219 | +++ state/assign_test.go 2012-10-01 17:54:22 +0000 |
220 | @@ -471,7 +471,7 @@ |
221 | units, err := m.Units() |
222 | c.Assert(err, IsNil) |
223 | c.Assert(units, HasLen, 1) |
224 | - c.Assert(units[0].Name(), Equals, unit.Name()) |
225 | + c.Assert(units[0].Id(), Equals, unit.Id()) |
226 | } |
227 | |
228 | // Remove units from alternate machines. |
229 | |
230 | === modified file 'state/life_test.go' |
231 | --- state/life_test.go 2012-09-28 07:21:43 +0000 |
232 | +++ state/life_test.go 2012-10-01 17:54:22 +0000 |
233 | @@ -108,7 +108,7 @@ |
234 | } |
235 | |
236 | func (l *unitLife) id() (coll string, id interface{}) { |
237 | - return "units", l.unit.Name() |
238 | + return "units", l.unit.Id() |
239 | } |
240 | |
241 | func (l *unitLife) setup(s *LifeSuite, c *C) state.Living { |
242 | |
243 | === modified file 'state/machine.go' |
244 | --- state/machine.go 2012-09-28 15:43:25 +0000 |
245 | +++ state/machine.go 2012-10-01 17:54:22 +0000 |
246 | @@ -186,7 +186,7 @@ |
247 | for _, pudoc := range pudocs { |
248 | units = append(units, newUnit(m.st, &pudoc)) |
249 | docs := []unitDoc{} |
250 | - err = m.st.units.Find(D{{"principal", pudoc.Name}}).All(&docs) |
251 | + err = m.st.units.Find(D{{"principal", pudoc.Id}}).All(&docs) |
252 | if err != nil { |
253 | return nil, err |
254 | } |
255 | |
256 | === modified file 'state/machine_test.go' |
257 | --- state/machine_test.go 2012-09-28 16:38:16 +0000 |
258 | +++ state/machine_test.go 2012-10-01 17:54:22 +0000 |
259 | @@ -235,18 +235,18 @@ |
260 | c.Logf("test %d", i) |
261 | got, err := a.machine.Units() |
262 | c.Assert(err, IsNil) |
263 | - expect := sortedUnitNames(append(a.units, a.subordinates...)) |
264 | - c.Assert(sortedUnitNames(got), DeepEquals, expect) |
265 | + expect := sortedUnitIds(append(a.units, a.subordinates...)) |
266 | + c.Assert(sortedUnitIds(got), DeepEquals, expect) |
267 | } |
268 | } |
269 | |
270 | -func sortedUnitNames(units []*state.Unit) []string { |
271 | - names := make([]string, len(units)) |
272 | +func sortedUnitIds(units []*state.Unit) []string { |
273 | + ids := make([]string, len(units)) |
274 | for i, u := range units { |
275 | - names[i] = u.Name() |
276 | + ids[i] = u.Id() |
277 | } |
278 | - sort.Strings(names) |
279 | - return names |
280 | + sort.Strings(ids) |
281 | + return ids |
282 | } |
283 | |
284 | type machineInfo struct { |
285 | @@ -553,12 +553,12 @@ |
286 | sort.Sort(unitSlice(change.Removed)) |
287 | var got []string |
288 | for _, g := range change.Added { |
289 | - got = append(got, g.Name()) |
290 | + got = append(got, g.Id()) |
291 | } |
292 | c.Assert(got, DeepEquals, added) |
293 | got = nil |
294 | for _, g := range change.Removed { |
295 | - got = append(got, g.Name()) |
296 | + got = append(got, g.Id()) |
297 | } |
298 | c.Assert(got, DeepEquals, removed) |
299 | } |
300 | |
301 | === modified file 'state/relation.go' |
302 | --- state/relation.go 2012-09-26 13:43:28 +0000 |
303 | +++ state/relation.go 2012-10-01 17:54:22 +0000 |
304 | @@ -192,7 +192,7 @@ |
305 | if ep.RelationScope == charm.ScopeContainer { |
306 | container := u.doc.Principal |
307 | if container == "" { |
308 | - container = u.doc.Name |
309 | + container = u.doc.Id |
310 | } |
311 | scope = append(scope, container) |
312 | } |
313 | @@ -235,7 +235,7 @@ |
314 | if err != nil { |
315 | return err |
316 | } |
317 | - key, err := ru.key(ru.unit.Name()) |
318 | + key, err := ru.key(ru.unit.Id()) |
319 | if err != nil { |
320 | return err |
321 | } |
322 | @@ -257,7 +257,7 @@ |
323 | |
324 | // LeaveScope signals that the unit has left its scope in the relation. |
325 | func (ru *RelationUnit) LeaveScope() error { |
326 | - key, err := ru.key(ru.unit.Name()) |
327 | + key, err := ru.key(ru.unit.Id()) |
328 | if err != nil { |
329 | return err |
330 | } |
331 | @@ -274,13 +274,13 @@ |
332 | func (ru *RelationUnit) WatchScope() *RelationScopeWatcher { |
333 | role := ru.endpoint.RelationRole.counterpartRole() |
334 | scope := ru.scope + "#" + string(role) |
335 | - return newRelationScopeWatcher(ru.st, scope, ru.unit.Name()) |
336 | + return newRelationScopeWatcher(ru.st, scope, ru.unit.Id()) |
337 | } |
338 | |
339 | // Settings returns a ConfigNode which allows access to the unit's settings |
340 | // within the relation. |
341 | func (ru *RelationUnit) Settings() (*ConfigNode, error) { |
342 | - key, err := ru.key(ru.unit.Name()) |
343 | + key, err := ru.key(ru.unit.Id()) |
344 | if err != nil { |
345 | return nil, err |
346 | } |
347 | |
348 | === modified file 'state/relation_test.go' |
349 | --- state/relation_test.go 2012-09-26 14:18:25 +0000 |
350 | +++ state/relation_test.go 2012-10-01 17:54:22 +0000 |
351 | @@ -6,7 +6,6 @@ |
352 | "launchpad.net/juju-core/charm" |
353 | "launchpad.net/juju-core/state" |
354 | "sort" |
355 | - "strings" |
356 | "time" |
357 | ) |
358 | |
359 | @@ -316,7 +315,7 @@ |
360 | s.assertNoScopeChange(c, w0) |
361 | node, err := pr.ru0.Settings() |
362 | c.Assert(err, IsNil) |
363 | - c.Assert(node.Map(), DeepEquals, map[string]interface{}{"private-address": "peer-0.example.com"}) |
364 | + c.Assert(node.Map(), DeepEquals, map[string]interface{}{"private-address": "unit-peer-0.example.com"}) |
365 | |
366 | // ru1 enters; check change is observed. |
367 | err = pr.ru1.EnterScope() |
368 | @@ -577,7 +576,7 @@ |
369 | u, err = svc.AddUnitSubordinateTo(principal) |
370 | } |
371 | c.Assert(err, IsNil) |
372 | - addr := fmt.Sprintf("%s.example.com", strings.Replace(u.Name(), "/", "-", 1)) |
373 | + addr := fmt.Sprintf("%s.example.com", u.PathKey()) |
374 | err = u.SetPrivateAddress(addr) |
375 | c.Assert(err, IsNil) |
376 | ru, err := rel.Unit(u) |
377 | |
378 | === modified file 'state/service.go' |
379 | --- state/service.go 2012-09-28 22:42:17 +0000 |
380 | +++ state/service.go 2012-10-01 17:54:22 +0000 |
381 | @@ -170,7 +170,7 @@ |
382 | // addUnit adds the named unit. |
383 | func (s *Service) addUnit(name string, principal *Unit) (*Unit, error) { |
384 | udoc := &unitDoc{ |
385 | - Name: name, |
386 | + Id: name, |
387 | Service: s.doc.Name, |
388 | Life: Alive, |
389 | } |
390 | @@ -186,10 +186,10 @@ |
391 | Update: D{{"$inc", D{{"unitcount", 1}}}}, |
392 | }} |
393 | if principal != nil { |
394 | - udoc.Principal = principal.Name() |
395 | + udoc.Principal = principal.Id() |
396 | ops = append(ops, txn.Op{ |
397 | C: s.st.units.Name, |
398 | - Id: principal.Name(), |
399 | + Id: principal.Id(), |
400 | Assert: isAlive, |
401 | Update: D{{"$addToSet", D{{"subordinates", name}}}}, |
402 | }) |
403 | @@ -269,7 +269,7 @@ |
404 | } |
405 | ops := []txn.Op{{ |
406 | C: s.st.units.Name, |
407 | - Id: u.doc.Name, |
408 | + Id: u.doc.Id, |
409 | Assert: D{{"life", Dead}}, |
410 | Remove: true, |
411 | }, { |
412 | @@ -283,14 +283,14 @@ |
413 | C: s.st.units.Name, |
414 | Id: u.doc.Principal, |
415 | Assert: txn.DocExists, |
416 | - Update: D{{"$pull", D{{"subordinates", u.doc.Name}}}}, |
417 | + Update: D{{"$pull", D{{"subordinates", u.Id()}}}}, |
418 | }) |
419 | } |
420 | // TODO assert that subordinates are empty before deleting |
421 | // a principal |
422 | if err = s.st.runner.Run(ops, "", nil); err != nil { |
423 | // TODO Remove this once we know the logic is right: |
424 | - if c, err := s.st.units.FindId(u.doc.Name).Count(); err != nil { |
425 | + if c, err := s.st.units.FindId(u.Id()).Count(); err != nil { |
426 | return err |
427 | } else if c > 0 { |
428 | return fmt.Errorf("cannot remove unit; something smells bad") |
429 | |
430 | === modified file 'state/service_test.go' |
431 | --- state/service_test.go 2012-09-28 16:53:40 +0000 |
432 | +++ state/service_test.go 2012-10-01 17:54:22 +0000 |
433 | @@ -140,12 +140,12 @@ |
434 | // Check that principal units can be added on their own. |
435 | unitZero, err := s.service.AddUnit() |
436 | c.Assert(err, IsNil) |
437 | - c.Assert(unitZero.Name(), Equals, "mysql/0") |
438 | + c.Assert(unitZero.Id(), Equals, "mysql/0") |
439 | principal := unitZero.IsPrincipal() |
440 | c.Assert(principal, Equals, true) |
441 | unitOne, err := s.service.AddUnit() |
442 | c.Assert(err, IsNil) |
443 | - c.Assert(unitOne.Name(), Equals, "mysql/1") |
444 | + c.Assert(unitOne.Id(), Equals, "mysql/1") |
445 | principal = unitOne.IsPrincipal() |
446 | c.Assert(principal, Equals, true) |
447 | |
448 | @@ -167,7 +167,7 @@ |
449 | // Check that subordinate units can be added to principal units |
450 | subZero, err := logging.AddUnitSubordinateTo(unitZero) |
451 | c.Assert(err, IsNil) |
452 | - c.Assert(subZero.Name(), Equals, "logging/0") |
453 | + c.Assert(subZero.Id(), Equals, "logging/0") |
454 | principal = subZero.IsPrincipal() |
455 | c.Assert(principal, Equals, false) |
456 | |
457 | @@ -201,12 +201,12 @@ |
458 | // Check that retrieving a unit from the service works correctly. |
459 | unit, err := s.service.Unit("mysql/0") |
460 | c.Assert(err, IsNil) |
461 | - c.Assert(unit.Name(), Equals, "mysql/0") |
462 | + c.Assert(unit.Id(), Equals, "mysql/0") |
463 | |
464 | // Check that retrieving a unit from state works correctly. |
465 | unit, err = s.State.Unit("mysql/0") |
466 | c.Assert(err, IsNil) |
467 | - c.Assert(unit.Name(), Equals, "mysql/0") |
468 | + c.Assert(unit.Id(), Equals, "mysql/0") |
469 | |
470 | // Check that retrieving a non-existent or an invalidly |
471 | // named unit fail nicely. |
472 | @@ -237,7 +237,7 @@ |
473 | |
474 | units, err := s.service.AllUnits() |
475 | c.Assert(err, IsNil) |
476 | - c.Assert(sortedUnitNames(units), DeepEquals, []string{"mysql/0", "mysql/1"}) |
477 | + c.Assert(sortedUnitIds(units), DeepEquals, []string{"mysql/0", "mysql/1"}) |
478 | } |
479 | |
480 | func (s *ServiceSuite) TestReadUnitWhenDying(c *C) { |
481 | @@ -287,7 +287,7 @@ |
482 | units, err := s.service.AllUnits() |
483 | c.Assert(err, IsNil) |
484 | c.Assert(units, HasLen, 1) |
485 | - c.Assert(units[0].Name(), Equals, "mysql/1") |
486 | + c.Assert(units[0].Id(), Equals, "mysql/1") |
487 | |
488 | err = s.service.RemoveUnit(unit) |
489 | c.Assert(err, IsNil) |
490 | @@ -518,7 +518,7 @@ |
491 | |
492 | func (m unitSlice) Len() int { return len(m) } |
493 | func (m unitSlice) Swap(i, j int) { m[i], m[j] = m[j], m[i] } |
494 | -func (m unitSlice) Less(i, j int) bool { return m[i].Name() < m[j].Name() } |
495 | +func (m unitSlice) Less(i, j int) bool { return m[i].Id() < m[j].Id() } |
496 | |
497 | func assertSameServiceUnits(c *C, change *state.ServiceUnitsChange, added, removed []string) { |
498 | c.Assert(change, NotNil) |
499 | @@ -528,16 +528,17 @@ |
500 | if len(removed) == 0 { |
501 | removed = nil |
502 | } |
503 | + // TODO use sortedUnitIds |
504 | sort.Sort(unitSlice(change.Added)) |
505 | sort.Sort(unitSlice(change.Removed)) |
506 | var got []string |
507 | for _, g := range change.Added { |
508 | - got = append(got, g.Name()) |
509 | + got = append(got, g.Id()) |
510 | } |
511 | c.Assert(got, DeepEquals, added) |
512 | got = nil |
513 | for _, g := range change.Removed { |
514 | - got = append(got, g.Name()) |
515 | + got = append(got, g.Id()) |
516 | } |
517 | c.Assert(got, DeepEquals, removed) |
518 | } |
519 | |
520 | === modified file 'state/unit.go' |
521 | --- state/unit.go 2012-09-28 15:43:25 +0000 |
522 | +++ state/unit.go 2012-10-01 17:54:22 +0000 |
523 | @@ -67,7 +67,7 @@ |
524 | |
525 | // unitDoc represents the internal state of a unit in MongoDB. |
526 | type unitDoc struct { |
527 | - Name string `bson:"_id"` |
528 | + Id string `bson:"_id"` |
529 | Service string |
530 | CharmURL *charm.URL |
531 | Principal string |
532 | @@ -102,17 +102,17 @@ |
533 | |
534 | // String returns the unit as string. |
535 | func (u *Unit) String() string { |
536 | - return u.doc.Name |
537 | + return u.doc.Id |
538 | } |
539 | |
540 | -// Name returns the unit name. |
541 | -func (u *Unit) Name() string { |
542 | - return u.doc.Name |
543 | +// Id returns the unit name. |
544 | +func (u *Unit) Id() string { |
545 | + return u.doc.Id |
546 | } |
547 | |
548 | // globalKey returns the global database key for the unit. |
549 | func (u *Unit) globalKey() string { |
550 | - return "u#" + u.doc.Name |
551 | + return "u#" + u.doc.Id |
552 | } |
553 | |
554 | // Life returns whether the unit is Alive, Dying or Dead. |
555 | @@ -138,7 +138,7 @@ |
556 | } |
557 | ops := []txn.Op{{ |
558 | C: u.st.units.Name, |
559 | - Id: u.doc.Name, |
560 | + Id: u.doc.Id, |
561 | Assert: notDead, |
562 | Update: D{{"$set", D{{"tools", t}}}}, |
563 | }} |
564 | @@ -153,7 +153,7 @@ |
565 | // EnsureDying sets the unit lifecycle to Dying if it is Alive. |
566 | // It does nothing otherwise. |
567 | func (u *Unit) EnsureDying() error { |
568 | - err := ensureDying(u.st, u.st.units, u.doc.Name, "unit") |
569 | + err := ensureDying(u.st, u.st.units, u.doc.Id, "unit") |
570 | if err != nil { |
571 | return err |
572 | } |
573 | @@ -164,7 +164,7 @@ |
574 | // EnsureDead sets the unit lifecycle to Dead if it is Alive or Dying. |
575 | // It does nothing otherwise. |
576 | func (u *Unit) EnsureDead() error { |
577 | - err := ensureDead(u.st, u.st.units, u.doc.Name, "unit", nil, "") |
578 | + err := ensureDead(u.st, u.st.units, u.doc.Id, "unit", nil, "") |
579 | if err != nil { |
580 | return err |
581 | } |
582 | @@ -202,7 +202,7 @@ |
583 | // Refresh refreshes the contents of the Unit from the underlying |
584 | // state. It returns a NotFoundError if the unit has been removed. |
585 | func (u *Unit) Refresh() error { |
586 | - err := u.st.units.FindId(u.doc.Name).One(&u.doc) |
587 | + err := u.st.units.FindId(u.doc.Id).One(&u.doc) |
588 | if err == mgo.ErrNotFound { |
589 | return notFound("unit %q", u) |
590 | } |
591 | @@ -268,7 +268,7 @@ |
592 | defer trivial.ErrorContextf(&err, "cannot open port %v for unit %q", port, u) |
593 | ops := []txn.Op{{ |
594 | C: u.st.units.Name, |
595 | - Id: u.doc.Name, |
596 | + Id: u.doc.Id, |
597 | Assert: notDead, |
598 | Update: D{{"$addToSet", D{{"ports", port}}}}, |
599 | }} |
600 | @@ -294,7 +294,7 @@ |
601 | defer trivial.ErrorContextf(&err, "cannot close port %v for unit %q", port, u) |
602 | ops := []txn.Op{{ |
603 | C: u.st.units.Name, |
604 | - Id: u.doc.Name, |
605 | + Id: u.doc.Id, |
606 | Assert: notDead, |
607 | Update: D{{"$pull", D{{"ports", port}}}}, |
608 | }} |
609 | @@ -331,7 +331,7 @@ |
610 | func (u *Unit) SetCharm(ch *Charm) (err error) { |
611 | ops := []txn.Op{{ |
612 | C: u.st.units.Name, |
613 | - Id: u.doc.Name, |
614 | + Id: u.doc.Id, |
615 | Assert: notDead, |
616 | Update: D{{"$set", D{{"charmurl", ch.URL()}}}}, |
617 | }} |
618 | @@ -351,7 +351,7 @@ |
619 | // file name. The returned key will be different from other |
620 | // PathKey values returned by any other entities from the same state. |
621 | func (u *Unit) PathKey() string { |
622 | - return "unit-" + strings.Replace(u.Name(), "/", "-", -1) |
623 | + return "unit-" + strings.Replace(u.Id(), "/", "-", -1) |
624 | } |
625 | |
626 | // WaitAgentAlive blocks until the respective agent is alive. |
627 | @@ -442,14 +442,14 @@ |
628 | } |
629 | ops := []txn.Op{{ |
630 | C: u.st.units.Name, |
631 | - Id: u.doc.Name, |
632 | + Id: u.doc.Id, |
633 | Assert: assert, |
634 | Update: D{{"$set", D{{"machineid", m.doc.Id}}}}, |
635 | }, { |
636 | C: u.st.machines.Name, |
637 | Id: m.doc.Id, |
638 | Assert: massert, |
639 | - Update: D{{"$addToSet", D{{"principals", u.doc.Name}}}}, |
640 | + Update: D{{"$addToSet", D{{"principals", u.doc.Id}}}}, |
641 | }} |
642 | err = u.st.runner.Run(ops, "", nil) |
643 | if err == nil { |
644 | @@ -459,7 +459,7 @@ |
645 | if err != txn.ErrAborted { |
646 | return err |
647 | } |
648 | - u0, err := u.st.Unit(u.Name()) |
649 | + u0, err := u.st.Unit(u.Id()) |
650 | if err != nil { |
651 | return err |
652 | } |
653 | @@ -518,7 +518,7 @@ |
654 | // machine id is as expected. |
655 | ops := []txn.Op{{ |
656 | C: u.st.units.Name, |
657 | - Id: u.doc.Name, |
658 | + Id: u.doc.Id, |
659 | Assert: txn.DocExists, |
660 | Update: D{{"$set", D{{"machineid", nil}}}}, |
661 | }} |
662 | @@ -527,7 +527,7 @@ |
663 | C: u.st.machines.Name, |
664 | Id: u.doc.MachineId, |
665 | Assert: txn.DocExists, |
666 | - Update: D{{"$pull", D{{"principals", u.doc.Name}}}}, |
667 | + Update: D{{"$pull", D{{"principals", u.doc.Id}}}}, |
668 | }) |
669 | } |
670 | err = u.st.runner.Run(ops, "", nil) |
671 | @@ -542,7 +542,7 @@ |
672 | func (u *Unit) SetPublicAddress(address string) (err error) { |
673 | ops := []txn.Op{{ |
674 | C: u.st.units.Name, |
675 | - Id: u.doc.Name, |
676 | + Id: u.doc.Id, |
677 | Assert: txn.DocExists, |
678 | Update: D{{"$set", D{{"publicaddress", address}}}}, |
679 | }} |
680 | @@ -557,7 +557,7 @@ |
681 | func (u *Unit) SetPrivateAddress(address string) error { |
682 | ops := []txn.Op{{ |
683 | C: u.st.units.Name, |
684 | - Id: u.doc.Name, |
685 | + Id: u.doc.Id, |
686 | Assert: txn.DocExists, |
687 | Update: D{{"$set", D{{"privateaddress", address}}}}, |
688 | }} |
689 | @@ -584,7 +584,7 @@ |
690 | assert := append(isAlive, D{{"resolved", ResolvedNone}}...) |
691 | ops := []txn.Op{{ |
692 | C: u.st.units.Name, |
693 | - Id: u.doc.Name, |
694 | + Id: u.doc.Id, |
695 | Assert: assert, |
696 | Update: D{{"$set", D{{"resolved", mode}}}}, |
697 | }} |
698 | @@ -592,7 +592,7 @@ |
699 | if err == txn.ErrAborted { |
700 | // Find which assertion failed so we can give a |
701 | // more specific error. |
702 | - u1, err := u.st.Unit(u.Name()) |
703 | + u1, err := u.st.Unit(u.Id()) |
704 | if err != nil { |
705 | return err |
706 | } |
707 | @@ -611,7 +611,7 @@ |
708 | func (u *Unit) ClearResolved() error { |
709 | ops := []txn.Op{{ |
710 | C: u.st.units.Name, |
711 | - Id: u.doc.Name, |
712 | + Id: u.doc.Id, |
713 | Assert: txn.DocExists, |
714 | Update: D{{"$set", D{{"resolved", ResolvedNone}}}}, |
715 | }} |
716 | |
717 | === modified file 'state/unit_test.go' |
718 | --- state/unit_test.go 2012-09-27 14:22:57 +0000 |
719 | +++ state/unit_test.go 2012-10-01 17:54:22 +0000 |
720 | @@ -50,7 +50,7 @@ |
721 | } |
722 | |
723 | func (s *UnitSuite) TestRefresh(c *C) { |
724 | - unit1, err := s.State.Unit(s.unit.Name()) |
725 | + unit1, err := s.State.Unit(s.unit.Id()) |
726 | c.Assert(err, IsNil) |
727 | |
728 | err = s.unit.SetPrivateAddress("example.local") |
729 | @@ -308,7 +308,7 @@ |
730 | c.Assert(err, IsNil) |
731 | |
732 | doc := make(map[string][]string) |
733 | - s.ConnSuite.units.FindId(s.unit.Name()).One(&doc) |
734 | + s.ConnSuite.units.FindId(s.unit.Id()).One(&doc) |
735 | subordinates, ok := doc["subordinates"] |
736 | if !ok { |
737 | c.Errorf(`unit document does not have a "subordinates" field`) |
738 | @@ -320,7 +320,7 @@ |
739 | err = logService.RemoveUnit(su1) |
740 | c.Assert(err, IsNil) |
741 | doc = make(map[string][]string) |
742 | - s.ConnSuite.units.FindId(s.unit.Name()).One(&doc) |
743 | + s.ConnSuite.units.FindId(s.unit.Id()).One(&doc) |
744 | subordinates, ok = doc["subordinates"] |
745 | if !ok { |
746 | c.Errorf(`unit document does not have a "subordinates" field`) |
747 | @@ -364,7 +364,7 @@ |
748 | } |
749 | |
750 | func (s *UnitSuite) TestWatchUnit(c *C) { |
751 | - altunit, err := s.State.Unit(s.unit.Name()) |
752 | + altunit, err := s.State.Unit(s.unit.Id()) |
753 | c.Assert(err, IsNil) |
754 | err = altunit.SetPublicAddress("newer-address") |
755 | c.Assert(err, IsNil) |
756 | @@ -379,7 +379,7 @@ |
757 | select { |
758 | case u, ok := <-w.Changes(): |
759 | c.Assert(ok, Equals, true) |
760 | - c.Assert(u.Name(), Equals, s.unit.Name()) |
761 | + c.Assert(u.Id(), Equals, s.unit.Id()) |
762 | addr, err := u.PublicAddress() |
763 | c.Assert(err, IsNil) |
764 | c.Assert(addr, Equals, "newer-address") |
765 | @@ -395,7 +395,7 @@ |
766 | select { |
767 | case unit, ok := <-w.Changes(): |
768 | c.Assert(ok, Equals, true) |
769 | - c.Assert(unit.Name(), Equals, s.unit.Name()) |
770 | + c.Assert(unit.Id(), Equals, s.unit.Id()) |
771 | var info unitInfo |
772 | info.Life = unit.Life() |
773 | c.Assert(err, IsNil) |
774 | |
775 | === modified file 'state/watcher.go' |
776 | --- state/watcher.go 2012-09-28 17:20:29 +0000 |
777 | +++ state/watcher.go 2012-10-01 17:54:22 +0000 |
778 | @@ -455,7 +455,7 @@ |
779 | } |
780 | for _, doc := range docs { |
781 | unit := newUnit(w.st, &doc) |
782 | - w.knownUnits[doc.Name] = unit |
783 | + w.knownUnits[doc.Id] = unit |
784 | changes.Added = append(changes.Added, unit) |
785 | } |
786 | return changes, nil |
787 | @@ -704,7 +704,7 @@ |
788 | } |
789 | for _, doc := range docs { |
790 | unit := newUnit(w.st, &doc) |
791 | - w.knownUnits[doc.Name] = unit |
792 | + w.knownUnits[doc.Id] = unit |
793 | changes.Added = append(changes.Added, unit) |
794 | } |
795 | return changes, nil |
796 | @@ -1175,13 +1175,13 @@ |
797 | } |
798 | |
799 | func (w *UnitWatcher) loop(unit *Unit) (err error) { |
800 | - name := unit.doc.Name |
801 | - if unit, err = w.st.Unit(name); err != nil { |
802 | + id := unit.doc.Id |
803 | + if unit, err = w.st.Unit(id); err != nil { |
804 | return err |
805 | } |
806 | ch := make(chan watcher.Change) |
807 | - w.st.watcher.Watch(w.st.units.Name, name, unit.doc.TxnRevno, ch) |
808 | - defer w.st.watcher.Unwatch(w.st.units.Name, name, ch) |
809 | + w.st.watcher.Watch(w.st.units.Name, id, unit.doc.TxnRevno, ch) |
810 | + defer w.st.watcher.Unwatch(w.st.units.Name, id, ch) |
811 | for { |
812 | for unit != nil { |
813 | select { |
814 | @@ -1190,7 +1190,7 @@ |
815 | case <-w.tomb.Dying(): |
816 | return tomb.ErrDying |
817 | case <-ch: |
818 | - if unit, err = w.st.Unit(name); err != nil { |
819 | + if unit, err = w.st.Unit(id); err != nil { |
820 | return err |
821 | } |
822 | case w.changeChan <- unit: |
823 | @@ -1203,7 +1203,7 @@ |
824 | case <-w.tomb.Dying(): |
825 | return tomb.ErrDying |
826 | case <-ch: |
827 | - if unit, err = w.st.Unit(name); err != nil { |
828 | + if unit, err = w.st.Unit(id); err != nil { |
829 | return err |
830 | } |
831 | } |
832 | |
833 | === modified file 'worker/firewaller/firewaller.go' |
834 | --- worker/firewaller/firewaller.go 2012-09-27 23:26:16 +0000 |
835 | +++ worker/firewaller/firewaller.go 2012-10-01 17:54:22 +0000 |
836 | @@ -75,17 +75,17 @@ |
837 | case change := <-fw.unitsChange: |
838 | changed := []*unitData{} |
839 | for _, unit := range change.Removed { |
840 | - unitd, ok := fw.unitds[unit.Name()] |
841 | + unitd, ok := fw.unitds[unit.Id()] |
842 | if !ok { |
843 | panic("trying to remove unit that was not added") |
844 | } |
845 | fw.forgetUnit(unitd) |
846 | changed = append(changed, unitd) |
847 | - log.Debugf("firewaller: stopped watching unit %s", unit.Name()) |
848 | + log.Debugf("firewaller: stopped watching unit %s", unit.Id()) |
849 | } |
850 | for _, unit := range change.Added { |
851 | unitd := newUnitData(unit, fw) |
852 | - fw.unitds[unit.Name()] = unitd |
853 | + fw.unitds[unit.Id()] = unitd |
854 | machineId, err := unit.AssignedMachineId() |
855 | if err != nil { |
856 | fw.tomb.Kill(err) |
857 | @@ -94,7 +94,7 @@ |
858 | panic("machine of added unit is not watched") |
859 | } |
860 | unitd.machined = fw.machineds[machineId] |
861 | - unitd.machined.unitds[unit.Name()] = unitd |
862 | + unitd.machined.unitds[unit.Id()] = unitd |
863 | if fw.serviceds[unit.ServiceName()] == nil { |
864 | service, err := fw.st.Service(unit.ServiceName()) |
865 | if err != nil { |
866 | @@ -103,9 +103,9 @@ |
867 | fw.serviceds[unit.ServiceName()] = newServiceData(service, fw) |
868 | } |
869 | unitd.serviced = fw.serviceds[unit.ServiceName()] |
870 | - unitd.serviced.unitds[unit.Name()] = unitd |
871 | + unitd.serviced.unitds[unit.Id()] = unitd |
872 | changed = append(changed, unitd) |
873 | - log.Debugf("firewaller: started watching unit %s", unit.Name()) |
874 | + log.Debugf("firewaller: started watching unit %s", unit.Id()) |
875 | } |
876 | if err := fw.flushUnits(changed); err != nil { |
877 | return fmt.Errorf("cannot change firewall ports: %v", err) |
878 | @@ -247,7 +247,7 @@ |
879 | |
880 | // forgetUnit cleans the unit data after the unit is removed. |
881 | func (fw *Firewaller) forgetUnit(unitd *unitData) { |
882 | - name := unitd.unit.Name() |
883 | + name := unitd.unit.Id() |
884 | serviced := unitd.serviced |
885 | machined := unitd.machined |
886 | if err := unitd.Stop(); err != nil { |
887 | |
888 | === modified file 'worker/machiner/machiner.go' |
889 | --- worker/machiner/machiner.go 2012-09-28 15:27:47 +0000 |
890 | +++ worker/machiner/machiner.go 2012-10-01 17:54:22 +0000 |
891 | @@ -63,7 +63,7 @@ |
892 | for _, u := range change.Removed { |
893 | if u.IsPrincipal() { |
894 | if err := m.localContainer.Destroy(u); err != nil { |
895 | - log.Printf("cannot destroy unit %s: %v", u.Name(), err) |
896 | + log.Printf("cannot destroy unit %s: %v", u.Id(), err) |
897 | } |
898 | } |
899 | } |
900 | @@ -71,7 +71,7 @@ |
901 | if u.IsPrincipal() { |
902 | if err := m.localContainer.Deploy(u, m.stateInfo, m.tools); err != nil { |
903 | // TODO put unit into a queue to retry the deploy. |
904 | - log.Printf("cannot deploy unit %s: %v", u.Name(), err) |
905 | + log.Printf("cannot deploy unit %s: %v", u.Id(), err) |
906 | } |
907 | } |
908 | } |
909 | |
910 | === modified file 'worker/machiner/machiner_test.go' |
911 | --- worker/machiner/machiner_test.go 2012-09-28 07:21:43 +0000 |
912 | +++ worker/machiner/machiner_test.go 2012-10-01 17:54:22 +0000 |
913 | @@ -131,12 +131,12 @@ |
914 | d.c.Check(info, Equals, d.expectedInfo) |
915 | d.c.Check(tools, DeepEquals, d.expectedTools) |
916 | |
917 | - d.action <- "+" + u.Name() |
918 | + d.action <- "+" + u.Id() |
919 | return nil |
920 | } |
921 | |
922 | func (d *dummyContainer) Destroy(u *state.Unit) error { |
923 | - d.action <- "-" + u.Name() |
924 | + d.action <- "-" + u.Id() |
925 | return nil |
926 | } |
927 | |
928 | |
929 | === modified file 'worker/uniter/relationer_test.go' |
930 | --- worker/uniter/relationer_test.go 2012-09-25 16:21:48 +0000 |
931 | +++ worker/uniter/relationer_test.go 2012-10-01 17:54:22 +0000 |
932 | @@ -8,7 +8,6 @@ |
933 | "launchpad.net/juju-core/worker/uniter" |
934 | "launchpad.net/juju-core/worker/uniter/hook" |
935 | "launchpad.net/juju-core/worker/uniter/relation" |
936 | - "strings" |
937 | "time" |
938 | ) |
939 | |
940 | @@ -39,11 +38,11 @@ |
941 | s.hooks = make(chan hook.Info) |
942 | } |
943 | |
944 | -func (s *RelationerSuite) AddRelationUnit(c *C, name string) *state.RelationUnit { |
945 | +func (s *RelationerSuite) AddRelationUnit(c *C, id string) *state.RelationUnit { |
946 | u, err := s.svc.AddUnit() |
947 | c.Assert(err, IsNil) |
948 | - c.Assert(u.Name(), Equals, name) |
949 | - err = u.SetPrivateAddress(strings.Replace(name, "/", "-", 1) + ".example.com") |
950 | + c.Assert(u.Id(), Equals, id) |
951 | + err = u.SetPrivateAddress(u.PathKey() + ".example.com") |
952 | c.Assert(err, IsNil) |
953 | ru, err := s.rel.Unit(u) |
954 | c.Assert(err, IsNil) |
955 | @@ -134,14 +133,14 @@ |
956 | Kind: hook.RelationJoined, |
957 | RemoteUnit: "u/1", |
958 | Members: map[string]map[string]interface{}{ |
959 | - "u/1": {"private-address": "u-1.example.com"}, |
960 | + "u/1": {"private-address": "unit-u-1.example.com"}, |
961 | }, |
962 | }) |
963 | s.assertHook(c, hook.Info{ |
964 | Kind: hook.RelationChanged, |
965 | RemoteUnit: "u/1", |
966 | Members: map[string]map[string]interface{}{ |
967 | - "u/1": {"private-address": "u-1.example.com"}, |
968 | + "u/1": {"private-address": "unit-u-1.example.com"}, |
969 | }, |
970 | }) |
971 | s.assertNoHook(c) |
972 | @@ -224,7 +223,7 @@ |
973 | Kind: hook.RelationJoined, |
974 | RemoteUnit: "u/1", |
975 | Members: map[string]map[string]interface{}{ |
976 | - "u/1": {"private-address": "u-1.example.com"}, |
977 | + "u/1": {"private-address": "unit-u-1.example.com"}, |
978 | }, |
979 | } |
980 | name, err := r.PrepareHook(joined) |
981 | @@ -266,7 +265,7 @@ |
982 | c.Assert(ctx.Units(), DeepEquals, []string{"u/1"}) |
983 | s1, err = ctx.ReadSettings("u/1") |
984 | c.Assert(err, IsNil) |
985 | - c.Assert(s1, DeepEquals, map[string]interface{}{"private-address": "u-1.example.com"}) |
986 | + c.Assert(s1, DeepEquals, map[string]interface{}{"private-address": "unit-u-1.example.com"}) |
987 | |
988 | // ...and commit it. |
989 | err = r.CommitHook(changed) |
990 | @@ -306,7 +305,7 @@ |
991 | Kind: hook.RelationJoined, |
992 | RemoteUnit: "u/1", |
993 | Members: map[string]map[string]interface{}{ |
994 | - "u/1": {"private-address": "u-1.example.com"}, |
995 | + "u/1": {"private-address": "unit-u-1.example.com"}, |
996 | }, |
997 | }) |
998 | |
999 | |
1000 | === modified file 'worker/uniter/uniter.go' |
1001 | --- worker/uniter/uniter.go 2012-09-28 15:27:47 +0000 |
1002 | +++ worker/uniter/uniter.go 2012-10-01 17:54:22 +0000 |
1003 | @@ -108,7 +108,7 @@ |
1004 | } |
1005 | |
1006 | func (u *Uniter) String() string { |
1007 | - return "uniter for " + u.unit.Name() |
1008 | + return "uniter for " + u.unit.Id() |
1009 | } |
1010 | |
1011 | func (u *Uniter) Dying() <-chan struct{} { |
1012 | @@ -193,7 +193,7 @@ |
1013 | panic("relation hooks are not yet supported") |
1014 | // TODO: update relation context; get hook name. |
1015 | } |
1016 | - hctxId := fmt.Sprintf("%s:%s:%d", u.unit.Name(), hookName, u.rand.Int63()) |
1017 | + hctxId := fmt.Sprintf("%s:%s:%d", u.unit.Id(), hookName, u.rand.Int63()) |
1018 | hctx := server.HookContext{ |
1019 | Service: u.service, |
1020 | Unit: u.unit, |
Reviewers: mp+127341_ code.launchpad. net,
Message:
Please take a look.
Description:
state: rename Unit.Name to Unit.Id
This is a preparatory step to renaming PathKey to Name.
Also changed a couple of tests to use PathKey rather than Id.
https:/ /code.launchpad .net/~rogpeppe/ juju-core/ 097-state- unit-id/ +merge/ 127341
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6585053/
Affected files: deploy_ test.go server/ context. go server/ context_ test.go server/ juju-log. go server/ relation- get.go server/ util_test. go unit_test. go container. go test.go test.go test.go test.go firewaller/ firewaller. go machiner/ machiner. go machiner/ machiner_ test.go uniter/ relationer_ test.go uniter/ uniter. go
A [revision details]
M cmd/juju/
M cmd/juju/status.go
M cmd/jujuc/
M cmd/jujuc/
M cmd/jujuc/
M cmd/jujuc/
M cmd/jujuc/
M cmd/jujud/unit.go
M cmd/jujud/
M container/
M state/assign_
M state/life_test.go
M state/machine.go
M state/machine_
M state/relation.go
M state/relation_
M state/service.go
M state/service_
M state/unit.go
M state/unit_test.go
M state/watcher.go
M worker/
M worker/
M worker/
M worker/
M worker/