~bigkevmcd/goose/fix-for-swift-headers

« back to all changes in this revision

Viewing changes to testservices/novaservice/service_http.go

[r=wallyworld],[bug=1188815] Support string id for SecurityGroup et al

Openstack with Quantum/Grizzly uses string ids for SecurityGroup
and other similar data structures. Goose was written for deployments
that use int ids. This branch fixes that issue using the pattern
already in palce to deal with HP Cloud vs Canonistack for
ServerDetail et al ids.

https://codereview.appspot.com/10527043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
                nil,
115
115
                nil,
116
116
        }
117
 
        errBadRequestSG = &errorResponse{
118
 
                http.StatusBadRequest,
119
 
                `{"badRequest": {"message": "Security group id should be integer", "code": 400}}`,
120
 
                "application/json; charset=UTF-8",
121
 
                "bad security group id type",
122
 
                nil,
123
 
                nil,
124
 
        }
125
117
        errNotFound = &errorResponse{
126
118
                http.StatusNotFound,
127
119
                `404 Not Found
567
559
        if err != nil {
568
560
                return err
569
561
        }
570
 
        var groups []int
 
562
        var groups []string
571
563
        if len(req.Server.SecurityGroups) > 0 {
572
564
                for _, group := range req.Server.SecurityGroups {
573
565
                        groupName := group["name"]
772
764
// If there was no group id specified in the path, it returns errNoGroupId
773
765
func (n *Nova) processGroupId(w http.ResponseWriter, r *http.Request) (*nova.SecurityGroup, error) {
774
766
        if groupId := path.Base(r.URL.Path); groupId != "os-security-groups" {
775
 
                id, err := strconv.Atoi(groupId)
776
 
                if err != nil {
777
 
                        return nil, errBadRequestSG
778
 
                }
779
 
                group, err := n.securityGroup(id)
 
767
                group, err := n.securityGroup(groupId)
780
768
                if err != nil {
781
769
                        return nil, errNotFoundJSONSG
782
770
                }
829
817
                                return errBadRequestDuplicateValue
830
818
                        }
831
819
                        n.nextGroupId++
832
 
                        nextId := n.nextGroupId
 
820
                        nextId := strconv.Itoa(n.nextGroupId)
833
821
                        err = n.addSecurityGroup(nova.SecurityGroup{
834
822
                                Id:          nextId,
835
823
                                Name:        req.Group.Name,
912
900
                        }
913
901
                }
914
902
                n.nextRuleId++
915
 
                nextId := n.nextRuleId
 
903
                nextId := strconv.Itoa(n.nextRuleId)
916
904
                err = n.addSecurityGroupRule(nextId, req.Rule)
917
905
                if err != nil {
918
906
                        return err
933
921
                return errNotFound
934
922
        case "DELETE":
935
923
                if ruleId := path.Base(r.URL.Path); ruleId != "os-security-group-rules" {
936
 
                        id, err := strconv.Atoi(ruleId)
937
 
                        if err != nil {
938
 
                                // weird, but this is how nova responds
939
 
                                return errBadRequestSG
940
 
                        }
941
 
                        if _, err = n.securityGroupRule(id); err != nil {
 
924
                        if _, err := n.securityGroupRule(ruleId); err != nil {
942
925
                                return errNotFoundJSONSGR
943
926
                        }
944
 
                        if err = n.removeSecurityGroupRule(id); err != nil {
 
927
                        if err := n.removeSecurityGroupRule(ruleId); err != nil {
945
928
                                return err
946
929
                        }
947
930
                        writeResponse(w, http.StatusAccepted, nil)
957
940
        switch r.Method {
958
941
        case "GET":
959
942
                if ipId := path.Base(r.URL.Path); ipId != "os-floating-ips" {
960
 
                        nId, err := strconv.Atoi(ipId)
961
 
                        if err != nil {
962
 
                                return errNotFoundJSON
963
 
                        }
964
 
                        fip, err := n.floatingIP(nId)
 
943
                        fip, err := n.floatingIP(ipId)
965
944
                        if err != nil {
966
945
                                return errNotFoundJSON
967
946
                        }
983
962
                        return errNotFound
984
963
                }
985
964
                n.nextIPId++
986
 
                nextId := n.nextIPId
987
 
                addr := fmt.Sprintf("10.0.0.%d", nextId)
 
965
                addr := fmt.Sprintf("10.0.0.%d", n.nextIPId)
 
966
                nextId := strconv.Itoa(n.nextIPId)
988
967
                fip := nova.FloatingIP{Id: nextId, IP: addr, Pool: "nova"}
989
968
                err := n.addFloatingIP(fip)
990
969
                if err != nil {
1001
980
                return errNotFound
1002
981
        case "DELETE":
1003
982
                if ipId := path.Base(r.URL.Path); ipId != "os-floating-ips" {
1004
 
                        if nId, err := strconv.Atoi(ipId); err == nil {
1005
 
                                if err := n.removeFloatingIP(nId); err == nil {
1006
 
                                        writeResponse(w, http.StatusAccepted, nil)
1007
 
                                        return nil
1008
 
                                }
 
983
                        if err := n.removeFloatingIP(ipId); err == nil {
 
984
                                writeResponse(w, http.StatusAccepted, nil)
 
985
                                return nil
1009
986
                        }
1010
987
                        return errNotFoundJSON
1011
988
                }