Merge lp:~hduran-8/goose/testservice_errors into lp:goose
- testservice_errors
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Martin Packman |
Approved revision: | 124 |
Merged at revision: | 121 |
Proposed branch: | lp:~hduran-8/goose/testservice_errors |
Merge into: | lp:goose |
Diff against target: |
681 lines (+223/-58) 5 files modified
testservices/errors.go (+137/-0) testservices/errors_test.go (+29/-0) testservices/novaservice/service.go (+21/-21) testservices/novaservice/service_test.go (+33/-33) testservices/service.go (+3/-4) |
To merge this branch: | bzr merge lp:~hduran-8/goose/testservice_errors |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+217818@code.launchpad.net |
Commit message
Added proper errortype in testservices.
Added an error type for testservers that
contains a message and an error code.
Switched novaservice to use new error type.
https:/
R=axwalk
Description of the change
Added proper errortype in testservices.
Added an error type for testservers that
contains a message and an error code.
Switched novaservice to use new error type.
Horacio Durán (hduran-8) wrote : | # |
Andrew Wilkins (axwalk) wrote : | # |
https:/
File testservices/
https:/
testservices/
Where do these values come from? I assume these are meant to match what
OpenStack returns exactly? If so, can you refer to some official
documentation?
If they're *not* meant to be identical to OpenStack, then this is
duplication of code in net/http.
https:/
testservices/
Does it perhaps make sense to expose more of goose/errors and use the
existing error types that would be returned by the real OpenStack?
https:/
testservices/
python nova code, might be wrong
XXX is not typical to Juju or related projects. Use something like
"TODO(hduran-8) this is inferred from the Python nova code and might be
wrong; validate".
For most cases, we have a common format:
TODO(nick) YYYY-MM-DD #bugid
Summary.
and file a bug.
https:/
testservices/
I would suggest a minor refactoring to simplify all of these functions:
func serverErrorf(code int, message string, args ...interface{})
*ServerError {
return &ServerError{code: code, message: fmt.Sprintf(
args...)}
}
func NewAddFlavorErr
return serverErrorf(409, "A flavor with id %q already exists", id)
}
...
https:/
testservices/
already exists", id),
Do these error messages come from OpenStack, or did you make them up? We
typically start all error messages lower-case.
https:/
File testservices/
https:/
testservices/
delete me
https:/
testservices/
delete me
Horacio Durán (hduran-8) wrote : | # |
Please take a look.
Andrew Wilkins (axwalk) wrote : | # |
LGTM with an added comment
https:/
File testservices/
https:/
testservices/
Can you please add a note about the origins of this mapping as
discussed?
Horacio Durán (hduran-8) wrote : | # |
Please take a look.
Go Bot (go-bot) wrote : | # |
The attempt to merge lp:~hduran-8/goose/testservice_errors into lp:goose failed. Below is the output from the failed tests.
ok launchpad.net/goose 0.012s
ok launchpad.
ok 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.
FAIL launchpad.
Setting GOPATH to: /home/tarmac/
Running: go fmt ./...
Running: go build ./...
Running: go test ./...
# launchpad.
tools/secgroup-
FAIL: failed running: go test ./...
Preview Diff
1 | === added file 'testservices/errors.go' |
2 | --- testservices/errors.go 1970-01-01 00:00:00 +0000 |
3 | +++ testservices/errors.go 2014-04-30 23:16:31 +0000 |
4 | @@ -0,0 +1,137 @@ |
5 | +package testservices |
6 | + |
7 | +import "fmt" |
8 | + |
9 | +// This map is copied from nova python client |
10 | +// https://github.com/openstack/nova/blob/master/nova/api/openstack/wsgi.py#L1185 |
11 | +var nameReference = map[int]string{ |
12 | + 400: "badRequest", |
13 | + 401: "unauthorized", |
14 | + 403: "forbidden", |
15 | + 404: "itemNotFound", |
16 | + 405: "badMethod", |
17 | + 409: "conflictingRequest", |
18 | + 413: "overLimit", |
19 | + 415: "badMediaType", |
20 | + 429: "overLimit", |
21 | + 501: "notImplemented", |
22 | + 503: "serviceUnavailable", |
23 | +} |
24 | + |
25 | +type ServerError struct { |
26 | + message string |
27 | + code int |
28 | +} |
29 | + |
30 | +func serverErrorf(code int, message string, args ...interface{}) *ServerError { |
31 | + return &ServerError{code: code, message: fmt.Sprintf(message, args...)} |
32 | +} |
33 | + |
34 | +func (n *ServerError) Error() string { |
35 | + return fmt.Sprintf("%s: %s", n.Name(), n.message) |
36 | +} |
37 | + |
38 | +func (n *ServerError) Name() string { |
39 | + name, ok := nameReference[n.code] |
40 | + if !ok { |
41 | + return "computeFault" |
42 | + } |
43 | + return name |
44 | +} |
45 | + |
46 | +func NewNotFoundError(message string) *ServerError { |
47 | + return serverErrorf(404, message) |
48 | +} |
49 | + |
50 | +func NewNoMoreFloatingIpsError() *ServerError { |
51 | + return serverErrorf(404, "Zero floating ips available") |
52 | +} |
53 | + |
54 | +func NewIPLimitExceededError() *ServerError { |
55 | + return serverErrorf(413, "Maximum number of floating ips exceeded") |
56 | +} |
57 | + |
58 | +func NewRateLimitExceededError() *ServerError { |
59 | + // This is an undocumented error |
60 | + return serverErrorf(413, "Retry limit exceeded") |
61 | +} |
62 | + |
63 | +func NewAddFlavorError(id string) *ServerError { |
64 | + return serverErrorf(409, "A flavor with id %q already exists", id) |
65 | +} |
66 | + |
67 | +func NewNoSuchFlavorError(id string) *ServerError { |
68 | + return serverErrorf(404, "No such flavor %q", id) |
69 | +} |
70 | + |
71 | +func NewServerByIDNotFoundError(id string) *ServerError { |
72 | + return serverErrorf(404, "No such server %q", id) |
73 | +} |
74 | + |
75 | +func NewServerByNameNotFoundError(name string) *ServerError { |
76 | + return serverErrorf(404, "No such server named %q", name) |
77 | +} |
78 | + |
79 | +func NewServerAlreadyExistsError(id string) *ServerError { |
80 | + return serverErrorf(409, "A server with id %q already exists", id) |
81 | +} |
82 | + |
83 | +func NewSecurityGroupAlreadyExistsError(id string) *ServerError { |
84 | + return serverErrorf(409, "A security group with id %s already exists", id) |
85 | +} |
86 | + |
87 | +func NewSecurityGroupByIDNotFoundError(groupId string) *ServerError { |
88 | + return serverErrorf(404, "No such security group %s", groupId) |
89 | +} |
90 | + |
91 | +func NewSecurityGroupByNameNotFoundError(name string) *ServerError { |
92 | + return serverErrorf(404, "No such security group named %q", name) |
93 | +} |
94 | + |
95 | +func NewSecurityGroupRuleAlreadyExistsError(id string) *ServerError { |
96 | + return serverErrorf(409, "A security group rule with id %s already exists", id) |
97 | +} |
98 | + |
99 | +func NewCannotAddTwiceRuleToGroupError(ruleId, groupId string) *ServerError { |
100 | + return serverErrorf(409, "Cannot add twice rule %s to security group %s", ruleId, groupId) |
101 | +} |
102 | + |
103 | +func NewUnknownSecurityGroupError(groupId string) *ServerError { |
104 | + return serverErrorf(409, "Unknown source security group %s", groupId) |
105 | +} |
106 | + |
107 | +func NewSecurityGroupRuleNotFoundError(ruleId string) *ServerError { |
108 | + return serverErrorf(404, "No such security group rule %s", ruleId) |
109 | +} |
110 | + |
111 | +func NewServerBelongsToGroupError(serverId, groupId string) *ServerError { |
112 | + return serverErrorf(409, "Server %q already belongs to group %s", serverId, groupId) |
113 | +} |
114 | + |
115 | +func NewServerDoesNotBelongToGroupsError(serverId string) *ServerError { |
116 | + return serverErrorf(400, "Server %q does not belong to any groups", serverId) |
117 | +} |
118 | + |
119 | +func NewServerDoesNotBelongToGroupError(serverId, groupId string) *ServerError { |
120 | + return serverErrorf(400, "Server %q does not belong to group %s", serverId, groupId) |
121 | +} |
122 | + |
123 | +func NewFloatingIPExistsError(ipID string) *ServerError { |
124 | + return serverErrorf(409, "A floating IP with id %s already exists", ipID) |
125 | +} |
126 | + |
127 | +func NewFloatingIPNotFoundError(address string) *ServerError { |
128 | + return serverErrorf(404, "No such floating IP %q", address) |
129 | +} |
130 | + |
131 | +func NewServerHasFloatingIPError(serverId, ipId string) *ServerError { |
132 | + return serverErrorf(409, "Server %q already has floating IP %s", serverId, ipId) |
133 | +} |
134 | + |
135 | +func NewNoFloatingIPsToRemoveError(serverId string) *ServerError { |
136 | + return serverErrorf(409, "Server %q does not have any floating IPs to remove", serverId) |
137 | +} |
138 | + |
139 | +func NewNoFloatingIPsError(serverId, ipId string) *ServerError { |
140 | + return serverErrorf(404, "Server %q does not have floating IP %s", serverId, ipId) |
141 | +} |
142 | |
143 | === added file 'testservices/errors_test.go' |
144 | --- testservices/errors_test.go 1970-01-01 00:00:00 +0000 |
145 | +++ testservices/errors_test.go 2014-04-30 23:16:31 +0000 |
146 | @@ -0,0 +1,29 @@ |
147 | +package testservices |
148 | + |
149 | +import ( |
150 | + gc "launchpad.net/gocheck" |
151 | + "testing" |
152 | +) |
153 | + |
154 | +func Test(t *testing.T) { gc.TestingT(t) } |
155 | + |
156 | +type ErrorsSuite struct { |
157 | +} |
158 | + |
159 | +var _ = gc.Suite(&ErrorsSuite{}) |
160 | + |
161 | +func (s *ErrorsSuite) TestServerErrorMessage(c *gc.C) { |
162 | + err := &ServerError{ |
163 | + message: "Instance could not be found", |
164 | + code: 404, |
165 | + } |
166 | + c.Assert(err, gc.ErrorMatches, "itemNotFound: Instance could not be found") |
167 | +} |
168 | + |
169 | +func (s *ErrorsSuite) TestServerUnknownErrcode(c *gc.C) { |
170 | + err := &ServerError{ |
171 | + message: "Impossible http code.", |
172 | + code: 999, |
173 | + } |
174 | + c.Assert(err, gc.ErrorMatches, "computeFault: Impossible http code.") |
175 | +} |
176 | |
177 | === modified file 'testservices/novaservice/service.go' |
178 | --- testservices/novaservice/service.go 2014-03-07 14:22:57 +0000 |
179 | +++ testservices/novaservice/service.go 2014-04-30 23:16:31 +0000 |
180 | @@ -139,7 +139,7 @@ |
181 | return err |
182 | } |
183 | if _, err := n.flavor(flavor.Id); err == nil { |
184 | - return fmt.Errorf("a flavor with id %q already exists", flavor.Id) |
185 | + return testservices.NewAddFlavorError(flavor.Id) |
186 | } |
187 | n.flavors[flavor.Id] = flavor |
188 | return nil |
189 | @@ -152,7 +152,7 @@ |
190 | } |
191 | flavor, ok := n.flavors[flavorId] |
192 | if !ok { |
193 | - return nil, fmt.Errorf("no such flavor %q", flavorId) |
194 | + return nil, testservices.NewNoSuchFlavorError(flavorId) |
195 | } |
196 | return &flavor, nil |
197 | } |
198 | @@ -224,7 +224,7 @@ |
199 | return err |
200 | } |
201 | if _, err := n.server(server.Id); err == nil { |
202 | - return fmt.Errorf("a server with id %q already exists", server.Id) |
203 | + return testservices.NewServerAlreadyExistsError(server.Id) |
204 | } |
205 | n.servers[server.Id] = server |
206 | return nil |
207 | @@ -237,7 +237,7 @@ |
208 | } |
209 | server, ok := n.servers[serverId] |
210 | if !ok { |
211 | - return nil, fmt.Errorf("no such server %q", serverId) |
212 | + return nil, testservices.NewServerByIDNotFoundError(serverId) |
213 | } |
214 | return &server, nil |
215 | } |
216 | @@ -252,7 +252,7 @@ |
217 | return &server, nil |
218 | } |
219 | } |
220 | - return nil, fmt.Errorf("no such server named %q", name) |
221 | + return nil, testservices.NewServerByNameNotFoundError(name) |
222 | } |
223 | |
224 | // serverAsEntity returns the stored ServerDetail as Entity. |
225 | @@ -378,7 +378,7 @@ |
226 | return err |
227 | } |
228 | if _, err := n.securityGroup(group.Id); err == nil { |
229 | - return fmt.Errorf("a security group with id %s already exists", group.Id) |
230 | + return testservices.NewSecurityGroupAlreadyExistsError(group.Id) |
231 | } |
232 | group.TenantId = n.TenantId |
233 | if group.Rules == nil { |
234 | @@ -395,7 +395,7 @@ |
235 | } |
236 | group, ok := n.groups[groupId] |
237 | if !ok { |
238 | - return nil, fmt.Errorf("no such security group %s", groupId) |
239 | + return nil, testservices.NewSecurityGroupByIDNotFoundError(groupId) |
240 | } |
241 | return &group, nil |
242 | } |
243 | @@ -410,7 +410,7 @@ |
244 | return &group, nil |
245 | } |
246 | } |
247 | - return nil, fmt.Errorf("no such security group named %q", groupName) |
248 | + return nil, testservices.NewSecurityGroupByNameNotFoundError(groupName) |
249 | } |
250 | |
251 | // allSecurityGroups returns a list of all existing groups. |
252 | @@ -442,7 +442,7 @@ |
253 | return err |
254 | } |
255 | if _, err := n.securityGroupRule(ruleId); err == nil { |
256 | - return fmt.Errorf("a security group rule with id %s already exists", ruleId) |
257 | + return testservices.NewSecurityGroupRuleAlreadyExistsError(ruleId) |
258 | } |
259 | group, err := n.securityGroup(rule.ParentGroupId) |
260 | if err != nil { |
261 | @@ -450,7 +450,7 @@ |
262 | } |
263 | for _, ru := range group.Rules { |
264 | if ru.Id == ruleId { |
265 | - return fmt.Errorf("cannot add twice rule %s to security group %s", ru.Id, group.Id) |
266 | + return testservices.NewCannotAddTwiceRuleToGroupError(ru.Id, group.Id) |
267 | } |
268 | } |
269 | var zeroSecurityGroupRef nova.SecurityGroupRef |
270 | @@ -462,7 +462,7 @@ |
271 | if rule.GroupId != nil { |
272 | sourceGroup, err := n.securityGroup(*rule.GroupId) |
273 | if err != nil { |
274 | - return fmt.Errorf("unknown source security group %s", *rule.GroupId) |
275 | + return testservices.NewUnknownSecurityGroupError(*rule.GroupId) |
276 | } |
277 | newrule.Group = nova.SecurityGroupRef{ |
278 | TenantId: sourceGroup.TenantId, |
279 | @@ -511,7 +511,7 @@ |
280 | } |
281 | rule, ok := n.rules[ruleId] |
282 | if !ok { |
283 | - return nil, fmt.Errorf("no such security group rule %s", ruleId) |
284 | + return nil, testservices.NewSecurityGroupRuleNotFoundError(ruleId) |
285 | } |
286 | return &rule, nil |
287 | } |
288 | @@ -559,7 +559,7 @@ |
289 | if ok { |
290 | for _, gid := range groups { |
291 | if gid == groupId { |
292 | - return fmt.Errorf("server %q already belongs to group %s", serverId, groupId) |
293 | + return testservices.NewServerBelongsToGroupError(serverId, groupId) |
294 | } |
295 | } |
296 | } |
297 | @@ -615,7 +615,7 @@ |
298 | } |
299 | groups, ok := n.serverGroups[serverId] |
300 | if !ok { |
301 | - return fmt.Errorf("server %q does not belong to any groups", serverId) |
302 | + return testservices.NewServerDoesNotBelongToGroupsError(serverId) |
303 | } |
304 | idx := -1 |
305 | for gi, gid := range groups { |
306 | @@ -625,7 +625,7 @@ |
307 | } |
308 | } |
309 | if idx == -1 { |
310 | - return fmt.Errorf("server %q does not belong to group %s", serverId, groupId) |
311 | + return testservices.NewServerDoesNotBelongToGroupError(serverId, groupId) |
312 | } |
313 | groups = append(groups[:idx], groups[idx+1:]...) |
314 | n.serverGroups[serverId] = groups |
315 | @@ -638,7 +638,7 @@ |
316 | return err |
317 | } |
318 | if _, err := n.floatingIP(ip.Id); err == nil { |
319 | - return fmt.Errorf("a floating IP with id %s already exists", ip.Id) |
320 | + return testservices.NewFloatingIPExistsError(ip.Id) |
321 | } |
322 | n.floatingIPs[ip.Id] = ip |
323 | return nil |
324 | @@ -664,7 +664,7 @@ |
325 | } |
326 | ip, ok := n.floatingIPs[ipId] |
327 | if !ok { |
328 | - return nil, fmt.Errorf("no such floating IP %s", ipId) |
329 | + return nil, testservices.NewFloatingIPNotFoundError(ipId) |
330 | } |
331 | return &ip, nil |
332 | } |
333 | @@ -679,7 +679,7 @@ |
334 | return &fip, nil |
335 | } |
336 | } |
337 | - return nil, fmt.Errorf("no such floating IP with address %q", address) |
338 | + return nil, testservices.NewFloatingIPNotFoundError(address) |
339 | } |
340 | |
341 | // allFloatingIPs returns a list of all created floating IPs. |
342 | @@ -723,7 +723,7 @@ |
343 | if ok { |
344 | for _, fipId := range fips { |
345 | if fipId == ipId { |
346 | - return fmt.Errorf("server %q already has floating IP %s", serverId, ipId) |
347 | + return testservices.NewServerHasFloatingIPError(serverId, ipId) |
348 | } |
349 | } |
350 | } |
351 | @@ -767,7 +767,7 @@ |
352 | } |
353 | fips, ok := n.serverIPs[serverId] |
354 | if !ok { |
355 | - return fmt.Errorf("server %q does not have any floating IPs to remove", serverId) |
356 | + return testservices.NewNoFloatingIPsToRemoveError(serverId) |
357 | } |
358 | idx := -1 |
359 | for fi, fipId := range fips { |
360 | @@ -777,7 +777,7 @@ |
361 | } |
362 | } |
363 | if idx == -1 { |
364 | - return fmt.Errorf("server %q does not have floating IP %s", serverId, ipId) |
365 | + return testservices.NewNoFloatingIPsError(serverId, ipId) |
366 | } |
367 | fips = append(fips[:idx], fips[idx+1:]...) |
368 | n.serverIPs[serverId] = fips |
369 | |
370 | === modified file 'testservices/novaservice/service_test.go' |
371 | --- testservices/novaservice/service_test.go 2014-03-07 14:24:31 +0000 |
372 | +++ testservices/novaservice/service_test.go 2014-04-30 23:16:31 +0000 |
373 | @@ -27,27 +27,27 @@ |
374 | |
375 | func (s *NovaSuite) ensureNoFlavor(c *C, flavor nova.FlavorDetail) { |
376 | _, err := s.service.flavor(flavor.Id) |
377 | - c.Assert(err, ErrorMatches, fmt.Sprintf("no such flavor %q", flavor.Id)) |
378 | + c.Assert(err, ErrorMatches, fmt.Sprintf("itemNotFound: No such flavor %q", flavor.Id)) |
379 | } |
380 | |
381 | func (s *NovaSuite) ensureNoServer(c *C, server nova.ServerDetail) { |
382 | _, err := s.service.server(server.Id) |
383 | - c.Assert(err, ErrorMatches, fmt.Sprintf("no such server %q", server.Id)) |
384 | + c.Assert(err, ErrorMatches, fmt.Sprintf("itemNotFound: No such server %q", server.Id)) |
385 | } |
386 | |
387 | func (s *NovaSuite) ensureNoGroup(c *C, group nova.SecurityGroup) { |
388 | _, err := s.service.securityGroup(group.Id) |
389 | - c.Assert(err, ErrorMatches, fmt.Sprintf("no such security group %s", group.Id)) |
390 | + c.Assert(err, ErrorMatches, fmt.Sprintf("itemNotFound: No such security group %s", group.Id)) |
391 | } |
392 | |
393 | func (s *NovaSuite) ensureNoRule(c *C, rule nova.SecurityGroupRule) { |
394 | _, err := s.service.securityGroupRule(rule.Id) |
395 | - c.Assert(err, ErrorMatches, fmt.Sprintf("no such security group rule %s", rule.Id)) |
396 | + c.Assert(err, ErrorMatches, fmt.Sprintf("itemNotFound: No such security group rule %s", rule.Id)) |
397 | } |
398 | |
399 | func (s *NovaSuite) ensureNoIP(c *C, ip nova.FloatingIP) { |
400 | _, err := s.service.floatingIP(ip.Id) |
401 | - c.Assert(err, ErrorMatches, fmt.Sprintf("no such floating IP %s", ip.Id)) |
402 | + c.Assert(err, ErrorMatches, fmt.Sprintf("itemNotFound: No such floating IP %q", ip.Id)) |
403 | } |
404 | |
405 | func (s *NovaSuite) createFlavor(c *C, flavor nova.FlavorDetail) { |
406 | @@ -142,7 +142,7 @@ |
407 | s.createFlavor(c, flavor) |
408 | defer s.deleteFlavor(c, flavor) |
409 | err := s.service.addFlavor(flavor) |
410 | - c.Assert(err, ErrorMatches, `a flavor with id "test" already exists`) |
411 | + c.Assert(err, ErrorMatches, `conflictingRequest: A flavor with id "test" already exists`) |
412 | } |
413 | |
414 | func (s *NovaSuite) TestRemoveFlavorTwiceFails(c *C) { |
415 | @@ -150,7 +150,7 @@ |
416 | s.createFlavor(c, flavor) |
417 | s.deleteFlavor(c, flavor) |
418 | err := s.service.removeFlavor(flavor.Id) |
419 | - c.Assert(err, ErrorMatches, `no such flavor "test"`) |
420 | + c.Assert(err, ErrorMatches, `itemNotFound: No such flavor "test"`) |
421 | } |
422 | |
423 | func (s *NovaSuite) TestAllFlavors(c *C) { |
424 | @@ -238,7 +238,7 @@ |
425 | s.createServer(c, server) |
426 | defer s.deleteServer(c, server) |
427 | err := s.service.addServer(server) |
428 | - c.Assert(err, ErrorMatches, `a server with id "test" already exists`) |
429 | + c.Assert(err, ErrorMatches, `conflictingRequest: A server with id "test" already exists`) |
430 | } |
431 | |
432 | // A control point can be used to change the status of the added server. |
433 | @@ -269,7 +269,7 @@ |
434 | s.createServer(c, server) |
435 | s.deleteServer(c, server) |
436 | err := s.service.removeServer(server.Id) |
437 | - c.Assert(err, ErrorMatches, `no such server "test"`) |
438 | + c.Assert(err, ErrorMatches, `itemNotFound: No such server "test"`) |
439 | } |
440 | |
441 | func (s *NovaSuite) TestAllServers(c *C) { |
442 | @@ -523,7 +523,7 @@ |
443 | |
444 | func (s *NovaSuite) TestGetServerByName(c *C) { |
445 | named, err := s.service.serverByName("test") |
446 | - c.Assert(err, ErrorMatches, `no such server named "test"`) |
447 | + c.Assert(err, ErrorMatches, `itemNotFound: No such server named "test"`) |
448 | servers := []nova.ServerDetail{ |
449 | {Id: "sr1", Name: "test"}, |
450 | {Id: "sr2", Name: "test"}, |
451 | @@ -570,7 +570,7 @@ |
452 | s.createGroup(c, group) |
453 | defer s.deleteGroup(c, group) |
454 | err := s.service.addSecurityGroup(group) |
455 | - c.Assert(err, ErrorMatches, "a security group with id 1 already exists") |
456 | + c.Assert(err, ErrorMatches, "conflictingRequest: A security group with id 1 already exists") |
457 | } |
458 | |
459 | func (s *NovaSuite) TestRemoveSecurityGroupTwiceFails(c *C) { |
460 | @@ -578,7 +578,7 @@ |
461 | s.createGroup(c, group) |
462 | s.deleteGroup(c, group) |
463 | err := s.service.removeSecurityGroup(group.Id) |
464 | - c.Assert(err, ErrorMatches, "no such security group 1") |
465 | + c.Assert(err, ErrorMatches, "itemNotFound: No such security group 1") |
466 | } |
467 | |
468 | func (s *NovaSuite) TestAllSecurityGroups(c *C) { |
469 | @@ -631,7 +631,7 @@ |
470 | } |
471 | s.ensureNoGroup(c, group) |
472 | gr, err := s.service.securityGroupByName(group.Name) |
473 | - c.Assert(err, ErrorMatches, `no such security group named "test"`) |
474 | + c.Assert(err, ErrorMatches, `itemNotFound: No such security group named "test"`) |
475 | s.createGroup(c, group) |
476 | defer s.deleteGroup(c, group) |
477 | gr, err = s.service.securityGroupByName(group.Name) |
478 | @@ -746,7 +746,7 @@ |
479 | c.Assert(err, IsNil) |
480 | defer s.deleteRule(c, rule) |
481 | err = s.service.addSecurityGroupRule(rule.Id, ri) |
482 | - c.Assert(err, ErrorMatches, "a security group rule with id 10 already exists") |
483 | + c.Assert(err, ErrorMatches, "conflictingRequest: A security group rule with id 10 already exists") |
484 | } |
485 | |
486 | func (s *NovaSuite) TestAddSecurityGroupRuleToParentTwiceFails(c *C) { |
487 | @@ -761,7 +761,7 @@ |
488 | ri := nova.RuleInfo{ParentGroupId: group.Id} |
489 | rule := nova.SecurityGroupRule{Id: "10"} |
490 | err := s.service.addSecurityGroupRule(rule.Id, ri) |
491 | - c.Assert(err, ErrorMatches, "cannot add twice rule 10 to security group 1") |
492 | + c.Assert(err, ErrorMatches, "conflictingRequest: Cannot add twice rule 10 to security group 1") |
493 | } |
494 | |
495 | func (s *NovaSuite) TestAddSecurityGroupRuleWithInvalidParentFails(c *C) { |
496 | @@ -771,7 +771,7 @@ |
497 | rule := nova.SecurityGroupRule{Id: "10"} |
498 | s.ensureNoRule(c, rule) |
499 | err := s.service.addSecurityGroupRule(rule.Id, ri) |
500 | - c.Assert(err, ErrorMatches, "no such security group 1") |
501 | + c.Assert(err, ErrorMatches, "itemNotFound: No such security group 1") |
502 | } |
503 | |
504 | func (s *NovaSuite) TestAddGroupSecurityGroupRuleWithInvalidSourceFails(c *C) { |
505 | @@ -786,7 +786,7 @@ |
506 | rule := nova.SecurityGroupRule{Id: "10"} |
507 | s.ensureNoRule(c, rule) |
508 | err := s.service.addSecurityGroupRule(rule.Id, ri) |
509 | - c.Assert(err, ErrorMatches, "unknown source security group 42") |
510 | + c.Assert(err, ErrorMatches, "conflictingRequest: Unknown source security group 42") |
511 | } |
512 | |
513 | func (s *NovaSuite) TestAddSecurityGroupRuleUpdatesParent(c *C) { |
514 | @@ -856,7 +856,7 @@ |
515 | c.Assert(err, IsNil) |
516 | s.deleteRule(c, rule) |
517 | err = s.service.removeSecurityGroupRule(rule.Id) |
518 | - c.Assert(err, ErrorMatches, "no such security group rule 10") |
519 | + c.Assert(err, ErrorMatches, "itemNotFound: No such security group rule 10") |
520 | } |
521 | |
522 | func (s *NovaSuite) TestAddHasRemoveServerSecurityGroup(c *C) { |
523 | @@ -891,7 +891,7 @@ |
524 | s.createGroup(c, group) |
525 | defer s.deleteGroup(c, group) |
526 | err := s.service.addServerSecurityGroup(server.Id, group.Id) |
527 | - c.Assert(err, ErrorMatches, `no such server "sr1"`) |
528 | + c.Assert(err, ErrorMatches, `itemNotFound: No such server "sr1"`) |
529 | } |
530 | |
531 | func (s *NovaSuite) TestAddServerSecurityGroupWithInvalidGroupFails(c *C) { |
532 | @@ -901,7 +901,7 @@ |
533 | s.createServer(c, server) |
534 | defer s.deleteServer(c, server) |
535 | err := s.service.addServerSecurityGroup(server.Id, group.Id) |
536 | - c.Assert(err, ErrorMatches, "no such security group 1") |
537 | + c.Assert(err, ErrorMatches, "itemNotFound: No such security group 1") |
538 | } |
539 | |
540 | func (s *NovaSuite) TestAddServerSecurityGroupTwiceFails(c *C) { |
541 | @@ -914,7 +914,7 @@ |
542 | err := s.service.addServerSecurityGroup(server.Id, group.Id) |
543 | c.Assert(err, IsNil) |
544 | err = s.service.addServerSecurityGroup(server.Id, group.Id) |
545 | - c.Assert(err, ErrorMatches, `server "sr1" already belongs to group 1`) |
546 | + c.Assert(err, ErrorMatches, `conflictingRequest: Server "sr1" already belongs to group 1`) |
547 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
548 | c.Assert(err, IsNil) |
549 | } |
550 | @@ -964,7 +964,7 @@ |
551 | c.Assert(err, IsNil) |
552 | s.deleteServer(c, server) |
553 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
554 | - c.Assert(err, ErrorMatches, `no such server "sr1"`) |
555 | + c.Assert(err, ErrorMatches, `itemNotFound: No such server "sr1"`) |
556 | s.createServer(c, server) |
557 | defer s.deleteServer(c, server) |
558 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
559 | @@ -981,7 +981,7 @@ |
560 | c.Assert(err, IsNil) |
561 | s.deleteGroup(c, group) |
562 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
563 | - c.Assert(err, ErrorMatches, "no such security group 1") |
564 | + c.Assert(err, ErrorMatches, "itemNotFound: No such security group 1") |
565 | s.createGroup(c, group) |
566 | defer s.deleteGroup(c, group) |
567 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
568 | @@ -1000,7 +1000,7 @@ |
569 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
570 | c.Assert(err, IsNil) |
571 | err = s.service.removeServerSecurityGroup(server.Id, group.Id) |
572 | - c.Assert(err, ErrorMatches, `server "sr1" does not belong to group 1`) |
573 | + c.Assert(err, ErrorMatches, `badRequest: Server "sr1" does not belong to group 1`) |
574 | } |
575 | |
576 | func (s *NovaSuite) TestAddHasRemoveFloatingIP(c *C) { |
577 | @@ -1023,7 +1023,7 @@ |
578 | s.createIP(c, ip) |
579 | defer s.deleteIP(c, ip) |
580 | err := s.service.addFloatingIP(ip) |
581 | - c.Assert(err, ErrorMatches, "a floating IP with id 1 already exists") |
582 | + c.Assert(err, ErrorMatches, "conflictingRequest: A floating IP with id 1 already exists") |
583 | } |
584 | |
585 | func (s *NovaSuite) TestRemoveFloatingIPTwiceFails(c *C) { |
586 | @@ -1031,7 +1031,7 @@ |
587 | s.createIP(c, ip) |
588 | s.deleteIP(c, ip) |
589 | err := s.service.removeFloatingIP(ip.Id) |
590 | - c.Assert(err, ErrorMatches, "no such floating IP 1") |
591 | + c.Assert(err, ErrorMatches, "itemNotFound: No such floating IP \"1\"") |
592 | } |
593 | |
594 | func (s *NovaSuite) TestAllFloatingIPs(c *C) { |
595 | @@ -1080,7 +1080,7 @@ |
596 | c.Assert(err, IsNil) |
597 | c.Assert(*ip, DeepEquals, fip) |
598 | _, err = s.service.floatingIPByAddr("invalid") |
599 | - c.Assert(err, ErrorMatches, `no such floating IP with address "invalid"`) |
600 | + c.Assert(err, ErrorMatches, `itemNotFound: No such floating IP "invalid"`) |
601 | } |
602 | |
603 | func (s *NovaSuite) TestAddHasRemoveServerFloatingIP(c *C) { |
604 | @@ -1115,7 +1115,7 @@ |
605 | s.createIP(c, fip) |
606 | defer s.deleteIP(c, fip) |
607 | err := s.service.addServerFloatingIP(server.Id, fip.Id) |
608 | - c.Assert(err, ErrorMatches, `no such server "sr1"`) |
609 | + c.Assert(err, ErrorMatches, `itemNotFound: No such server "sr1"`) |
610 | } |
611 | |
612 | func (s *NovaSuite) TestAddServerFloatingIPWithInvalidIPFails(c *C) { |
613 | @@ -1125,7 +1125,7 @@ |
614 | s.createServer(c, server) |
615 | defer s.deleteServer(c, server) |
616 | err := s.service.addServerFloatingIP(server.Id, fip.Id) |
617 | - c.Assert(err, ErrorMatches, "no such floating IP 1") |
618 | + c.Assert(err, ErrorMatches, "itemNotFound: No such floating IP \"1\"") |
619 | } |
620 | |
621 | func (s *NovaSuite) TestAddServerFloatingIPTwiceFails(c *C) { |
622 | @@ -1138,7 +1138,7 @@ |
623 | err := s.service.addServerFloatingIP(server.Id, fip.Id) |
624 | c.Assert(err, IsNil) |
625 | err = s.service.addServerFloatingIP(server.Id, fip.Id) |
626 | - c.Assert(err, ErrorMatches, `server "sr1" already has floating IP 1`) |
627 | + c.Assert(err, ErrorMatches, `conflictingRequest: Server "sr1" already has floating IP 1`) |
628 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
629 | c.Assert(err, IsNil) |
630 | } |
631 | @@ -1153,7 +1153,7 @@ |
632 | c.Assert(err, IsNil) |
633 | s.deleteServer(c, server) |
634 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
635 | - c.Assert(err, ErrorMatches, `no such server "sr1"`) |
636 | + c.Assert(err, ErrorMatches, `itemNotFound: No such server "sr1"`) |
637 | s.createServer(c, server) |
638 | defer s.deleteServer(c, server) |
639 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
640 | @@ -1170,7 +1170,7 @@ |
641 | c.Assert(err, IsNil) |
642 | s.deleteIP(c, fip) |
643 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
644 | - c.Assert(err, ErrorMatches, "no such floating IP 1") |
645 | + c.Assert(err, ErrorMatches, "itemNotFound: No such floating IP \"1\"") |
646 | s.createIP(c, fip) |
647 | defer s.deleteIP(c, fip) |
648 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
649 | @@ -1189,5 +1189,5 @@ |
650 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
651 | c.Assert(err, IsNil) |
652 | err = s.service.removeServerFloatingIP(server.Id, fip.Id) |
653 | - c.Assert(err, ErrorMatches, `server "sr1" does not have floating IP 1`) |
654 | + c.Assert(err, ErrorMatches, `itemNotFound: Server "sr1" does not have floating IP 1`) |
655 | } |
656 | |
657 | === modified file 'testservices/service.go' |
658 | --- testservices/service.go 2013-11-25 05:52:30 +0000 |
659 | +++ testservices/service.go 2014-04-30 23:16:31 +0000 |
660 | @@ -1,7 +1,6 @@ |
661 | package testservices |
662 | |
663 | import ( |
664 | - "errors" |
665 | "launchpad.net/goose/testservices/hook" |
666 | "launchpad.net/goose/testservices/identityservice" |
667 | "net/http" |
668 | @@ -26,10 +25,10 @@ |
669 | |
670 | // Internal Openstack errors. |
671 | |
672 | -var RateLimitExceededError = errors.New("retry limit exceeded") |
673 | +var RateLimitExceededError = NewRateLimitExceededError() |
674 | |
675 | // NoMoreFloatingIPs corresponds to "HTTP 404 Zero floating ips available." |
676 | -var NoMoreFloatingIPs = errors.New("zero floating ips available") |
677 | +var NoMoreFloatingIPs = NewNoMoreFloatingIpsError() |
678 | |
679 | // IPLimitExceeded corresponds to "HTTP 413 Maximum number of floating ips exceeded" |
680 | -var IPLimitExceeded = errors.New("maximum number of floating ips exceeded") |
681 | +var IPLimitExceeded = NewIPLimitExceededError() |
Reviewers: mp+217818_ code.launchpad. net,
Message:
Please take a look.
Description:
Added proper errortype in testservices.
Added an error type for testservers that
contains a message and an error code.
Switched novaservice to use new error type.
https:/ /code.launchpad .net/~hduran- 8/goose/ testservice_ errors/ +merge/ 217818
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/99960043/
Affected files (+295, -58 lines): errors. go errors_ test.go novaservice/ service. go novaservice/ service_ test.go service. go
A [revision details]
A testservices/
A testservices/
M testservices/
M testservices/
M testservices/