Merge lp://staging/~gz/goose/nts_duplicate_secgroup_rules into lp://staging/goose
Status: | Merged |
---|---|
Approved by: | Martin Packman |
Approved revision: | 68 |
Merged at revision: | 75 |
Proposed branch: | lp://staging/~gz/goose/nts_duplicate_secgroup_rules |
Merge into: | lp://staging/goose |
Diff against target: |
65 lines (+38/-17) 1 file modified
testservices/novaservice/service_http.go (+38/-17) |
To merge this branch: | bzr merge lp://staging/~gz/goose/nts_duplicate_secgroup_rules |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
The Go Language Gophers | Pending | ||
Review via email: mp+147222@code.staging.launchpad.net |
Commit message
Error on existing secgroup rules in test service
Juju has a test that relies on being able to tell the EC2 to reopen
the same port and ignore the error. To share that test we need some
of the existing rule checking behaviour from nova in the test service.
Description of the change
Error on existing secgroup rules in test service
Juju has a test that relies on being able to tell the EC2 to reopen
the same port and ignore the error. To share that test we need some
of the existing rule checking behaviour from nova in the test service.
Most of the diff is just dedent, but this is none of it pretty.
Actually using this for anything useful is harder without stronger
handling of errors from the api.
Reviewers: mp+147222_ code.launchpad. net,
Message:
Please take a look.
Description:
Error on existing secgroup rules in test service
Juju has a test that relies on being able to tell the EC2 to reopen
the same port and ignore the error. To share that test we need some
of the existing rule checking behaviour from nova in the test service.
Most of the diff is just dedent, but this is none of it pretty.
Actually using this for anything useful is harder without stronger
handling of errors from the api.
https:/ /code.launchpad .net/~gz/ goose/nts_ duplicate_ secgroup_ rules/+ merge/147222
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/7301061/
Affected files: novaservice/ service_ http.go
A [revision details]
M testservices/
Index: [revision details] 20130207052913- e5vfzm0pg3786t9 i
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-
+New revision: <email address hidden>
Index: testservices/ novaservice/ service_ http.go novaservice/ service_ http.go' novaservice/ service_ http.go 2013-02-04 15:53:04 +0000 novaservice/ service_ http.go 2013-02-07 20:32:29 +0000 body, &req); err != nil { oupRule( nextId, req.Rule) Rule(nextId) oupRule `json:" security_ group_rule" ` http.StatusOK, resp, w, r) (inrule. ParentGroupId) equest, `{"badRequest" : {"message": "This rule already exists in oupRule( nextId, req.Rule) Rule(nextId) oupRule `json:" security_ group_rule" ` http.StatusOK, resp, w, r) r.URL.Path) ; ruleId != "os-security- group-rules" {
=== modified file 'testservices/
--- testservices/
+++ testservices/
@@ -879,23 +879,44 @@
}
if err = json.Unmarshal(
return err
- } else {
- n.nextRuleId++
- nextId := n.nextRuleId
- err = n.addSecurityGr
- if err != nil {
- return err
- }
- rule, err := n.securityGroup
- if err != nil {
- return err
- }
- var resp struct {
- Rule nova.SecurityGr
- }
- resp.Rule = *rule
- return sendJSON(
- }
+ }
+ inrule := req.Rule
+ group, err := n.securityGroup
+ if err != nil {
+ return err // TODO: should be a 4XX error with details
+ }
+ for _, r := range group.Rules {
+ // TODO: this logic is actually wrong, not what nova does at all
+ // why are we reimplementing half of nova/api/openstack in go again?
+ if r.IPProtocol != nil && *r.IPProtocol == inrule.IPProtocol &&
+ r.FromPort != nil && *r.FromPort == inrule.FromPort &&
+ r.ToPort != nil && *r.ToPort == inrule.ToPort {
+ // TODO: Use a proper helper and sane error type
+ return &errorResponse{
+ http.StatusBadR
+ fmt.Sprintf(
group %d", "code": 400}}`, group.Id),
+ "application/json; charset=UTF-8",
+ "rule already exists",
+ nil,
+ nil,
+ }
+ }
+ }
+ n.nextRuleId++
+ nextId := n.nextRuleId
+ err = n.addSecurityGr
+ if err != nil {
+ return err
+ }
+ rule, err := n.securityGroup
+ if err != nil {
+ return err
+ }
+ var resp struct {
+ Rule nova.SecurityGr
+ }
+ resp.Rule = *rule
+ return sendJSON(
case "PUT":
if ruleId := path.Base(
return errNotFoundJSON
...