Merge lp:~wallyworld/juju-core/add-machine-panic into lp:~go-bot/juju-core/trunk
- add-machine-panic
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Ian Booth |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1591 |
Proposed branch: | lp:~wallyworld/juju-core/add-machine-panic |
Merge into: | lp:~go-bot/juju-core/trunk |
Diff against target: |
351 lines (+93/-135) 9 files modified
cmd/juju/addmachine.go (+1/-1) cmd/juju/addmachine_test.go (+8/-4) cmd/juju/addunit.go (+1/-2) cmd/names.go (+25/-0) cmd/names_test.go (+36/-0) names/machine.go (+3/-13) names/machine_test.go (+3/-32) names/service_test.go (+16/-1) state/state_test.go (+0/-82) |
To merge this branch: | bzr merge lp:~wallyworld/juju-core/add-machine-panic |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email:
|
Commit message
Remove panic for bad arg to add-machine
If add-machine is invoked with a machine id as the
argument, it no longer panics.
The recently refactored IsMachineOrNewC
method was moved from the names package to cmd
since it's only used there. Plus there were left
over tests in state which were duplicated in names
and some of the tests were missing so I fix that
as well.
Description of the change
Remove panic for bad arg to add-machine
If add-machine is invoked with a machine id as the
argument, it no longer panics.
The recently refactored IsMachineOrNewC
method was moved from the names package to cmd
since it's only used there. Plus there were left
over tests in state which were duplicated in names
and some of the tests were missing so I fix that
as well.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ian Booth (wallyworld) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Tim Penhey (thumper) wrote : | # |
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Dimiter Naydenov (dimitern) wrote : | # |
LGTM minus some suggestions below
https:/
File cmd/names.go (right):
https:/
cmd/names.go:8: "regexp"
"regexp"
"...names"
https:/
File cmd/names_test.go (right):
https:/
cmd/names_
s/NamesSuite/
https:/
File names/machine.go (right):
https:/
names/machine.
var validMachine = ...
https:/
File names/service_
https:/
names/service_
d
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ian Booth (wallyworld) wrote : | # |
https:/
File cmd/names.go (right):
https:/
cmd/names.go:8: "regexp"
On 2013/08/02 08:51:03, dimitern wrote:
> "regexp"
> "...names"
Done.
https:/
File cmd/names_test.go (right):
https:/
cmd/names_
On 2013/08/02 08:51:03, dimitern wrote:
> s/NamesSuite/
Done.
https:/
File names/machine.go (right):
https:/
names/machine.
On 2013/08/02 08:51:03, dimitern wrote:
> var validMachine = ...
Done.
https:/
File names/service_
https:/
names/service_
On 2013/08/02 08:51:03, dimitern wrote:
> d
Done.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~wallyworld/juju-core/add-machine-panic into lp:juju-core failed. Below is the output from the failed tests.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
? launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
FAIL launchpad.
? launchpad.
ok launchpad.
? launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
ok launchpad.
Preview Diff
1 | === modified file 'cmd/juju/addmachine.go' | |||
2 | --- cmd/juju/addmachine.go 2013-07-30 23:46:30 +0000 | |||
3 | +++ cmd/juju/addmachine.go 2013-08-02 22:26:24 +0000 | |||
4 | @@ -57,7 +57,7 @@ | |||
5 | 57 | } | 57 | } |
6 | 58 | // container arg can either be 'type:machine' or 'type' | 58 | // container arg can either be 'type:machine' or 'type' |
7 | 59 | if c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec); err != nil { | 59 | if c.ContainerType, err = instance.ParseSupportedContainerType(containerSpec); err != nil { |
9 | 60 | if !names.IsMachineOrNewContainer(containerSpec) { | 60 | if names.IsMachine(containerSpec) || !cmd.IsMachineOrNewContainer(containerSpec) { |
10 | 61 | return fmt.Errorf("malformed container argument %q", containerSpec) | 61 | return fmt.Errorf("malformed container argument %q", containerSpec) |
11 | 62 | } | 62 | } |
12 | 63 | sep := strings.Index(containerSpec, ":") | 63 | sep := strings.Index(containerSpec, ":") |
13 | 64 | 64 | ||
14 | === modified file 'cmd/juju/addmachine_test.go' | |||
15 | --- cmd/juju/addmachine_test.go 2013-07-16 00:47:26 +0000 | |||
16 | +++ cmd/juju/addmachine_test.go 2013-08-02 22:26:24 +0000 | |||
17 | @@ -92,10 +92,14 @@ | |||
18 | 92 | } | 92 | } |
19 | 93 | 93 | ||
20 | 94 | func (s *AddMachineSuite) TestAddMachineErrors(c *C) { | 94 | func (s *AddMachineSuite) TestAddMachineErrors(c *C) { |
25 | 95 | err := runAddMachine(c, ":foo") | 95 | err := runAddMachine(c, ":lxc") |
26 | 96 | c.Assert(err, ErrorMatches, `malformed container argument ":foo"`) | 96 | c.Assert(err, ErrorMatches, `malformed container argument ":lxc"`) |
27 | 97 | err = runAddMachine(c, "foo:") | 97 | err = runAddMachine(c, "lxc:") |
28 | 98 | c.Assert(err, ErrorMatches, `malformed container argument "foo:"`) | 98 | c.Assert(err, ErrorMatches, `malformed container argument "lxc:"`) |
29 | 99 | err = runAddMachine(c, "2") | ||
30 | 100 | c.Assert(err, ErrorMatches, `malformed container argument "2"`) | ||
31 | 101 | err = runAddMachine(c, "foo") | ||
32 | 102 | c.Assert(err, ErrorMatches, `malformed container argument "foo"`) | ||
33 | 99 | err = runAddMachine(c, "lxc", "--constraints", "container=lxc") | 103 | err = runAddMachine(c, "lxc", "--constraints", "container=lxc") |
34 | 100 | c.Assert(err, ErrorMatches, `container constraint "lxc" not allowed when adding a machine`) | 104 | c.Assert(err, ErrorMatches, `container constraint "lxc" not allowed when adding a machine`) |
35 | 101 | } | 105 | } |
36 | 102 | 106 | ||
37 | === modified file 'cmd/juju/addunit.go' | |||
38 | --- cmd/juju/addunit.go 2013-07-30 23:46:30 +0000 | |||
39 | +++ cmd/juju/addunit.go 2013-08-02 22:26:24 +0000 | |||
40 | @@ -11,7 +11,6 @@ | |||
41 | 11 | 11 | ||
42 | 12 | "launchpad.net/juju-core/cmd" | 12 | "launchpad.net/juju-core/cmd" |
43 | 13 | "launchpad.net/juju-core/juju" | 13 | "launchpad.net/juju-core/juju" |
44 | 14 | "launchpad.net/juju-core/names" | ||
45 | 15 | "launchpad.net/juju-core/state/api/params" | 14 | "launchpad.net/juju-core/state/api/params" |
46 | 16 | "launchpad.net/juju-core/state/statecmd" | 15 | "launchpad.net/juju-core/state/statecmd" |
47 | 17 | ) | 16 | ) |
48 | @@ -36,7 +35,7 @@ | |||
49 | 36 | if c.NumUnits > 1 { | 35 | if c.NumUnits > 1 { |
50 | 37 | return errors.New("cannot use --num-units > 1 with --to") | 36 | return errors.New("cannot use --num-units > 1 with --to") |
51 | 38 | } | 37 | } |
53 | 39 | if !names.IsMachineOrNewContainer(c.ToMachineSpec) { | 38 | if !cmd.IsMachineOrNewContainer(c.ToMachineSpec) { |
54 | 40 | return fmt.Errorf("invalid --to parameter %q", c.ToMachineSpec) | 39 | return fmt.Errorf("invalid --to parameter %q", c.ToMachineSpec) |
55 | 41 | } | 40 | } |
56 | 42 | } | 41 | } |
57 | 43 | 42 | ||
58 | === added file 'cmd/names.go' | |||
59 | --- cmd/names.go 1970-01-01 00:00:00 +0000 | |||
60 | +++ cmd/names.go 2013-08-02 22:26:24 +0000 | |||
61 | @@ -0,0 +1,25 @@ | |||
62 | 1 | // Copyright 2012, 2013 Canonical Ltd. | ||
63 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | ||
64 | 3 | |||
65 | 4 | package cmd | ||
66 | 5 | |||
67 | 6 | import ( | ||
68 | 7 | "regexp" | ||
69 | 8 | |||
70 | 9 | "launchpad.net/juju-core/names" | ||
71 | 10 | ) | ||
72 | 11 | |||
73 | 12 | const ( | ||
74 | 13 | ContainerSnippet = "(/[a-z]+/" + names.NumberSnippet + ")" | ||
75 | 14 | ContainerSpecSnippet = "([a-z]+:)?" | ||
76 | 15 | ) | ||
77 | 16 | |||
78 | 17 | var ( | ||
79 | 18 | validMachineOrNewContainer = regexp.MustCompile("^" + ContainerSpecSnippet + names.MachineSnippet + "$") | ||
80 | 19 | ) | ||
81 | 20 | |||
82 | 21 | // IsMachineOrNewContainer returns whether spec is a valid machine id | ||
83 | 22 | // or new container definition. | ||
84 | 23 | func IsMachineOrNewContainer(spec string) bool { | ||
85 | 24 | return validMachineOrNewContainer.MatchString(spec) | ||
86 | 25 | } | ||
87 | 0 | 26 | ||
88 | === added file 'cmd/names_test.go' | |||
89 | --- cmd/names_test.go 1970-01-01 00:00:00 +0000 | |||
90 | +++ cmd/names_test.go 2013-08-02 22:26:24 +0000 | |||
91 | @@ -0,0 +1,36 @@ | |||
92 | 1 | // Copyright 2012, 2013 Canonical Ltd. | ||
93 | 2 | // Licensed under the AGPLv3, see LICENCE file for details. | ||
94 | 3 | |||
95 | 4 | package cmd_test | ||
96 | 5 | |||
97 | 6 | import ( | ||
98 | 7 | gc "launchpad.net/gocheck" | ||
99 | 8 | |||
100 | 9 | "launchpad.net/juju-core/cmd" | ||
101 | 10 | ) | ||
102 | 11 | |||
103 | 12 | type namesSuite struct { | ||
104 | 13 | } | ||
105 | 14 | |||
106 | 15 | var _ = gc.Suite(&namesSuite{}) | ||
107 | 16 | |||
108 | 17 | func (*namesSuite) TestNameChecks(c *gc.C) { | ||
109 | 18 | assertMachineOrNewContainer := func(s string, expect bool) { | ||
110 | 19 | c.Assert(cmd.IsMachineOrNewContainer(s), gc.Equals, expect) | ||
111 | 20 | } | ||
112 | 21 | assertMachineOrNewContainer("0", true) | ||
113 | 22 | assertMachineOrNewContainer("00", false) | ||
114 | 23 | assertMachineOrNewContainer("1", true) | ||
115 | 24 | assertMachineOrNewContainer("0/lxc/0", true) | ||
116 | 25 | assertMachineOrNewContainer("lxc:0", true) | ||
117 | 26 | assertMachineOrNewContainer("lxc:lxc:0", false) | ||
118 | 27 | assertMachineOrNewContainer("kvm:0/lxc/1", true) | ||
119 | 28 | assertMachineOrNewContainer("lxc:", false) | ||
120 | 29 | assertMachineOrNewContainer(":lxc", false) | ||
121 | 30 | assertMachineOrNewContainer("0/lxc/", false) | ||
122 | 31 | assertMachineOrNewContainer("0/lxc", false) | ||
123 | 32 | assertMachineOrNewContainer("kvm:0/lxc", false) | ||
124 | 33 | assertMachineOrNewContainer("0/lxc/01", false) | ||
125 | 34 | assertMachineOrNewContainer("0/lxc/10", true) | ||
126 | 35 | assertMachineOrNewContainer("0/kvm/4", true) | ||
127 | 36 | } | ||
128 | 0 | 37 | ||
129 | === modified file 'names/machine.go' | |||
130 | --- names/machine.go 2013-07-30 18:27:04 +0000 | |||
131 | +++ names/machine.go 2013-08-02 22:26:24 +0000 | |||
132 | @@ -7,27 +7,17 @@ | |||
133 | 7 | ) | 7 | ) |
134 | 8 | 8 | ||
135 | 9 | const ( | 9 | const ( |
139 | 10 | ContainerSnippet = "(/[a-z]+/" + NumberSnippet + ")" | 10 | ContainerSnippet = "(/[a-z]+/" + NumberSnippet + ")" |
140 | 11 | MachineSnippet = NumberSnippet + ContainerSnippet + "*" | 11 | MachineSnippet = NumberSnippet + ContainerSnippet + "*" |
138 | 12 | ContainerSpecSnippet = "([a-z]+:)?" | ||
141 | 13 | ) | 12 | ) |
142 | 14 | 13 | ||
147 | 15 | var ( | 14 | var validMachine = regexp.MustCompile("^" + MachineSnippet + "$") |
144 | 16 | validMachine = regexp.MustCompile("^" + MachineSnippet + "$") | ||
145 | 17 | validMachineOrNewContainer = regexp.MustCompile("^" + ContainerSpecSnippet + MachineSnippet + "$") | ||
146 | 18 | ) | ||
148 | 19 | 15 | ||
149 | 20 | // IsMachine returns whether id is a valid machine id. | 16 | // IsMachine returns whether id is a valid machine id. |
150 | 21 | func IsMachine(id string) bool { | 17 | func IsMachine(id string) bool { |
151 | 22 | return validMachine.MatchString(id) | 18 | return validMachine.MatchString(id) |
152 | 23 | } | 19 | } |
153 | 24 | 20 | ||
154 | 25 | // IsMachineOrNewContainer returns whether spec is a valid machine id | ||
155 | 26 | // or new container definition. | ||
156 | 27 | func IsMachineOrNewContainer(spec string) bool { | ||
157 | 28 | return validMachineOrNewContainer.MatchString(spec) | ||
158 | 29 | } | ||
159 | 30 | |||
160 | 31 | // MachineTag returns the tag for the machine with the given id. | 21 | // MachineTag returns the tag for the machine with the given id. |
161 | 32 | func MachineTag(id string) string { | 22 | func MachineTag(id string) string { |
162 | 33 | tag := makeTag(MachineTagKind, id) | 23 | tag := makeTag(MachineTagKind, id) |
163 | 34 | 24 | ||
164 | === modified file 'names/machine_test.go' | |||
165 | --- names/machine_test.go 2013-07-31 14:21:38 +0000 | |||
166 | +++ names/machine_test.go 2013-08-02 22:26:24 +0000 | |||
167 | @@ -64,6 +64,9 @@ | |||
168 | 64 | {pattern: "1/foo", valid: false}, | 64 | {pattern: "1/foo", valid: false}, |
169 | 65 | {pattern: "2/foo/", valid: false}, | 65 | {pattern: "2/foo/", valid: false}, |
170 | 66 | {pattern: "3/lxc/42", valid: true}, | 66 | {pattern: "3/lxc/42", valid: true}, |
171 | 67 | {pattern: "3/lxc-nodash/42", valid: false}, | ||
172 | 68 | {pattern: "0/lxc/00", valid: false}, | ||
173 | 69 | {pattern: "0/lxc/0/", valid: false}, | ||
174 | 67 | {pattern: "03/lxc/42", valid: false}, | 70 | {pattern: "03/lxc/42", valid: false}, |
175 | 68 | {pattern: "3/lxc/042", valid: false}, | 71 | {pattern: "3/lxc/042", valid: false}, |
176 | 69 | {pattern: "4/foo/bar", valid: false}, | 72 | {pattern: "4/foo/bar", valid: false}, |
177 | @@ -81,35 +84,3 @@ | |||
178 | 81 | c.Assert(names.IsMachine(test.pattern), gc.Equals, test.valid) | 84 | c.Assert(names.IsMachine(test.pattern), gc.Equals, test.valid) |
179 | 82 | } | 85 | } |
180 | 83 | } | 86 | } |
181 | 84 | |||
182 | 85 | var machineOrNewContainerTests = []struct { | ||
183 | 86 | pattern string | ||
184 | 87 | valid bool | ||
185 | 88 | }{ | ||
186 | 89 | {pattern: "42", valid: true}, | ||
187 | 90 | {pattern: "0", valid: true}, | ||
188 | 91 | {pattern: "042", valid: false}, | ||
189 | 92 | {pattern: ":42", valid: false}, | ||
190 | 93 | {pattern: "lxc:42", valid: true}, | ||
191 | 94 | {pattern: "lxc:042", valid: false}, | ||
192 | 95 | {pattern: "lxc:0", valid: true}, | ||
193 | 96 | {pattern: "foo42", valid: false}, | ||
194 | 97 | {pattern: "foo", valid: false}, | ||
195 | 98 | {pattern: "foo:3/", valid: false}, | ||
196 | 99 | {pattern: "kvm:3/foo", valid: false}, | ||
197 | 100 | {pattern: "kvm:3/foo/", valid: false}, | ||
198 | 101 | {pattern: "lxc:42/kvm/0", valid: true}, | ||
199 | 102 | {pattern: "lxc:042/kvm/0", valid: false}, | ||
200 | 103 | {pattern: "lxc:42/kvm/00", valid: false}, | ||
201 | 104 | {pattern: "lxc:42/kvm/56/lxc/0", valid: true}, | ||
202 | 105 | {pattern: "lxc:042/kvm/56/lxc/0", valid: false}, | ||
203 | 106 | {pattern: "lxc:42/kvm/056/lxc/0", valid: false}, | ||
204 | 107 | {pattern: "lxc:42/kvm/56/lxc/00", valid: false}, | ||
205 | 108 | } | ||
206 | 109 | |||
207 | 110 | func (s *machineSuite) TestMachineOrNewContainerFormats(c *gc.C) { | ||
208 | 111 | for i, test := range machineOrNewContainerTests { | ||
209 | 112 | c.Logf("test %d: %q", i, test.pattern) | ||
210 | 113 | c.Assert(names.IsMachineOrNewContainer(test.pattern), gc.Equals, test.valid) | ||
211 | 114 | } | ||
212 | 115 | } | ||
213 | 116 | 87 | ||
214 | === modified file 'names/service_test.go' | |||
215 | --- names/service_test.go 2013-07-31 14:21:38 +0000 | |||
216 | +++ names/service_test.go 2013-08-02 22:26:24 +0000 | |||
217 | @@ -17,6 +17,7 @@ | |||
218 | 17 | pattern string | 17 | pattern string |
219 | 18 | valid bool | 18 | valid bool |
220 | 19 | }{ | 19 | }{ |
221 | 20 | {pattern: "", valid: false}, | ||
222 | 20 | {pattern: "wordpress", valid: true}, | 21 | {pattern: "wordpress", valid: true}, |
223 | 21 | {pattern: "foo42", valid: true}, | 22 | {pattern: "foo42", valid: true}, |
224 | 22 | {pattern: "doing55in54", valid: true}, | 23 | {pattern: "doing55in54", valid: true}, |
225 | @@ -27,11 +28,25 @@ | |||
226 | 27 | {pattern: "foo/42", valid: false}, | 28 | {pattern: "foo/42", valid: false}, |
227 | 28 | {pattern: "is-it-", valid: false}, | 29 | {pattern: "is-it-", valid: false}, |
228 | 29 | {pattern: "broken2-", valid: false}, | 30 | {pattern: "broken2-", valid: false}, |
229 | 31 | {pattern: "foo2", valid: true}, | ||
230 | 32 | {pattern: "foo-2", valid: false}, | ||
231 | 30 | } | 33 | } |
232 | 31 | 34 | ||
233 | 32 | func (s *serviceSuite) TestServiceNameFormats(c *gc.C) { | 35 | func (s *serviceSuite) TestServiceNameFormats(c *gc.C) { |
234 | 36 | assertService := func(s string, expect bool) { | ||
235 | 37 | c.Assert(names.IsService(s), gc.Equals, expect) | ||
236 | 38 | // Check that anything that is considered a valid service name | ||
237 | 39 | // is also (in)valid if a(n) (in)valid unit designator is added | ||
238 | 40 | // to it. | ||
239 | 41 | c.Assert(names.IsUnit(s+"/0"), gc.Equals, expect) | ||
240 | 42 | c.Assert(names.IsUnit(s+"/99"), gc.Equals, expect) | ||
241 | 43 | c.Assert(names.IsUnit(s+"/-1"), gc.Equals, false) | ||
242 | 44 | c.Assert(names.IsUnit(s+"/blah"), gc.Equals, false) | ||
243 | 45 | c.Assert(names.IsUnit(s+"/"), gc.Equals, false) | ||
244 | 46 | } | ||
245 | 47 | |||
246 | 33 | for i, test := range serviceNameTests { | 48 | for i, test := range serviceNameTests { |
247 | 34 | c.Logf("test %d: %q", i, test.pattern) | 49 | c.Logf("test %d: %q", i, test.pattern) |
249 | 35 | c.Assert(names.IsService(test.pattern), gc.Equals, test.valid) | 50 | assertService(test.pattern, test.valid) |
250 | 36 | } | 51 | } |
251 | 37 | } | 52 | } |
252 | 38 | 53 | ||
253 | === modified file 'state/state_test.go' | |||
254 | --- state/state_test.go 2013-08-01 15:41:09 +0000 | |||
255 | +++ state/state_test.go 2013-08-02 22:26:24 +0000 | |||
256 | @@ -19,7 +19,6 @@ | |||
257 | 19 | "launchpad.net/juju-core/environs/config" | 19 | "launchpad.net/juju-core/environs/config" |
258 | 20 | "launchpad.net/juju-core/errors" | 20 | "launchpad.net/juju-core/errors" |
259 | 21 | "launchpad.net/juju-core/instance" | 21 | "launchpad.net/juju-core/instance" |
260 | 22 | "launchpad.net/juju-core/names" | ||
261 | 23 | "launchpad.net/juju-core/state" | 22 | "launchpad.net/juju-core/state" |
262 | 24 | "launchpad.net/juju-core/state/api/params" | 23 | "launchpad.net/juju-core/state/api/params" |
263 | 25 | statetesting "launchpad.net/juju-core/state/testing" | 24 | statetesting "launchpad.net/juju-core/state/testing" |
264 | @@ -1046,87 +1045,6 @@ | |||
265 | 1046 | } | 1045 | } |
266 | 1047 | } | 1046 | } |
267 | 1048 | 1047 | ||
268 | 1049 | func (*StateSuite) TestNameChecks(c *gc.C) { | ||
269 | 1050 | assertService := func(s string, expect bool) { | ||
270 | 1051 | c.Assert(names.IsService(s), gc.Equals, expect) | ||
271 | 1052 | // Check that anything that is considered a valid service name | ||
272 | 1053 | // is also (in)valid if a(n) (in)valid unit designator is added | ||
273 | 1054 | // to it. | ||
274 | 1055 | c.Assert(names.IsUnit(s+"/0"), gc.Equals, expect) | ||
275 | 1056 | c.Assert(names.IsUnit(s+"/99"), gc.Equals, expect) | ||
276 | 1057 | c.Assert(names.IsUnit(s+"/-1"), gc.Equals, false) | ||
277 | 1058 | c.Assert(names.IsUnit(s+"/blah"), gc.Equals, false) | ||
278 | 1059 | c.Assert(names.IsUnit(s+"/"), gc.Equals, false) | ||
279 | 1060 | } | ||
280 | 1061 | // Service names must be non-empty... | ||
281 | 1062 | assertService("", false) | ||
282 | 1063 | // must not consist entirely of numbers | ||
283 | 1064 | assertService("33", false) | ||
284 | 1065 | // may consist of a single word | ||
285 | 1066 | assertService("wordpress", true) | ||
286 | 1067 | // may contain hyphen-seperated words... | ||
287 | 1068 | assertService("super-duper-wordpress", true) | ||
288 | 1069 | // ...but those words must have at least one letter in them | ||
289 | 1070 | assertService("super-1234-wordpress", false) | ||
290 | 1071 | // may contain internal numbers. | ||
291 | 1072 | assertService("w0rd-pre55", true) | ||
292 | 1073 | // must not begin with a number | ||
293 | 1074 | assertService("3wordpress", false) | ||
294 | 1075 | // but internal, hyphen-sperated words can begin with numbers | ||
295 | 1076 | assertService("foo-2foo", true) | ||
296 | 1077 | // and may end with a number... | ||
297 | 1078 | assertService("foo2", true) | ||
298 | 1079 | // ...unless that number is all by itself | ||
299 | 1080 | assertService("foo-2", false) | ||
300 | 1081 | |||
301 | 1082 | assertMachine := func(s string, expect bool) { | ||
302 | 1083 | c.Assert(names.IsMachine(s), gc.Equals, expect) | ||
303 | 1084 | } | ||
304 | 1085 | assertMachine("0", true) | ||
305 | 1086 | assertMachine("00", false) | ||
306 | 1087 | assertMachine("1", true) | ||
307 | 1088 | assertMachine("1000001", true) | ||
308 | 1089 | assertMachine("01", false) | ||
309 | 1090 | assertMachine("-1", false) | ||
310 | 1091 | assertMachine("", false) | ||
311 | 1092 | assertMachine("cantankerous", false) | ||
312 | 1093 | // And container specs | ||
313 | 1094 | assertMachine("0/", false) | ||
314 | 1095 | assertMachine("0/0", false) | ||
315 | 1096 | assertMachine("0/lxc", false) | ||
316 | 1097 | assertMachine("0/lxc/", false) | ||
317 | 1098 | assertMachine("0/lxc/0", true) | ||
318 | 1099 | assertMachine("0/lxc/0/", false) | ||
319 | 1100 | assertMachine("0/lxc/00", false) | ||
320 | 1101 | assertMachine("0/lxc/01", false) | ||
321 | 1102 | assertMachine("0/lxc/10", true) | ||
322 | 1103 | assertMachine("0/kvm/4", true) | ||
323 | 1104 | assertMachine("0/no-dash/0", false) | ||
324 | 1105 | assertMachine("0/lxc/1/embedded/2", true) | ||
325 | 1106 | |||
326 | 1107 | assertMachineOrNewContainer := func(s string, expect bool) { | ||
327 | 1108 | c.Assert(names.IsMachineOrNewContainer(s), gc.Equals, expect) | ||
328 | 1109 | } | ||
329 | 1110 | assertMachineOrNewContainer("0", true) | ||
330 | 1111 | assertMachineOrNewContainer("00", false) | ||
331 | 1112 | assertMachineOrNewContainer("1", true) | ||
332 | 1113 | assertMachineOrNewContainer("0/lxc/0", true) | ||
333 | 1114 | assertMachineOrNewContainer("lxc:0", true) | ||
334 | 1115 | assertMachineOrNewContainer("lxc:lxc:0", false) | ||
335 | 1116 | assertMachineOrNewContainer("kvm:0/lxc/1", true) | ||
336 | 1117 | assertMachineOrNewContainer("lxc:", false) | ||
337 | 1118 | assertMachineOrNewContainer(":lxc", false) | ||
338 | 1119 | assertMachineOrNewContainer("0/lxc/", false) | ||
339 | 1120 | assertMachineOrNewContainer("0/lxc", false) | ||
340 | 1121 | assertMachineOrNewContainer("kvm:0/lxc", false) | ||
341 | 1122 | assertMachine("0/lxc/00", false) | ||
342 | 1123 | assertMachine("0/lxc/01", false) | ||
343 | 1124 | assertMachineOrNewContainer("0/lxc/01", false) | ||
344 | 1125 | assertMachineOrNewContainer("0/lxc/10", true) | ||
345 | 1126 | assertMachineOrNewContainer("0/kvm/4", true) | ||
346 | 1127 | assertMachine("0/lxc/1/embedded/2", true) | ||
347 | 1128 | } | ||
348 | 1129 | |||
349 | 1130 | type attrs map[string]interface{} | 1048 | type attrs map[string]interface{} |
350 | 1131 | 1049 | ||
351 | 1132 | func (s *StateSuite) TestWatchEnvironConfig(c *gc.C) { | 1050 | func (s *StateSuite) TestWatchEnvironConfig(c *gc.C) { |
Reviewers: mp+178185_ code.launchpad. net,
Message:
Please take a look.
Description:
Remove panic for bad arg to add-machine
If add-machine is invoked with a machine id as the
argument, it no longer panics.
The recently refactored IsMachineOrNewC ontainer
method was moved from the names package to cmd
since it's only used there. Plus there were left
over tests in state which were duplicated in names
and some of the tests were missing so I fix that
as well.
https:/ /code.launchpad .net/~wallyworl d/juju- core/add- machine- panic/+ merge/178185
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/12309043/
Affected files: addmachine. go addmachine_ test.go test.go test.go
A [revision details]
M cmd/juju/
M cmd/juju/
M cmd/juju/addunit.go
A cmd/names.go
A cmd/names_test.go
M names/machine.go
M names/machine_
M names/service_
M state/state_test.go