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

« back to all changes in this revision

Viewing changes to testservices/novaservice/service_http_test.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:
322
322
                },
323
323
                {
324
324
                        method: "GET",
325
 
                        url:    "/os-security-groups/invalid",
326
 
                        expect: errBadRequestSG,
327
 
                },
328
 
                {
329
 
                        method: "GET",
330
325
                        url:    "/os-security-groups/42",
331
326
                        expect: errNotFoundJSONSG,
332
327
                },
357
352
                },
358
353
                {
359
354
                        method: "DELETE",
360
 
                        url:    "/os-security-groups/invalid",
361
 
                        expect: errBadRequestSG,
362
 
                },
363
 
                {
364
 
                        method: "DELETE",
365
355
                        url:    "/os-security-groups/42",
366
356
                        expect: errNotFoundJSONSG,
367
357
                },
404
394
                        method: "DELETE",
405
395
                        url:    "/os-security-group-rules",
406
396
                        expect: errNotFound,
407
 
                },
408
 
                {
409
 
                        method: "DELETE",
410
 
                        url:    "/os-security-group-rules/invalid",
411
 
                        expect: errBadRequestSG, // sic; should've been rule-specific
412
397
                },
413
398
                {
414
399
                        method: "DELETE",
676
661
                {"name": "group1"},
677
662
                {"name": "group2"},
678
663
        }
679
 
        err = s.service.addSecurityGroup(nova.SecurityGroup{Id: 1, Name: "group1"})
680
 
        c.Assert(err, IsNil)
681
 
        defer s.service.removeSecurityGroup(1)
682
 
        err = s.service.addSecurityGroup(nova.SecurityGroup{Id: 2, Name: "group2"})
683
 
        c.Assert(err, IsNil)
684
 
        defer s.service.removeSecurityGroup(2)
 
664
        err = s.service.addSecurityGroup(nova.SecurityGroup{Id: "1", Name: "group1"})
 
665
        c.Assert(err, IsNil)
 
666
        defer s.service.removeSecurityGroup("1")
 
667
        err = s.service.addSecurityGroup(nova.SecurityGroup{Id: "2", Name: "group2"})
 
668
        c.Assert(err, IsNil)
 
669
        defer s.service.removeSecurityGroup("2")
685
670
        resp, err = s.jsonRequest("POST", "/servers", req, nil)
686
671
        c.Assert(err, IsNil)
687
672
        c.Assert(resp.StatusCode, Equals, http.StatusAccepted)
689
674
        c.Assert(expected.Server.SecurityGroups, DeepEquals, req.Server.SecurityGroups)
690
675
        srv, err = s.service.server(expected.Server.Id)
691
676
        c.Assert(err, IsNil)
692
 
        ok := s.service.hasServerSecurityGroup(srv.Id, 1)
693
 
        c.Assert(ok, Equals, true)
694
 
        ok = s.service.hasServerSecurityGroup(srv.Id, 2)
695
 
        c.Assert(ok, Equals, true)
696
 
        s.service.removeServerSecurityGroup(srv.Id, 1)
697
 
        s.service.removeServerSecurityGroup(srv.Id, 2)
 
677
        ok := s.service.hasServerSecurityGroup(srv.Id, "1")
 
678
        c.Assert(ok, Equals, true)
 
679
        ok = s.service.hasServerSecurityGroup(srv.Id, "2")
 
680
        c.Assert(ok, Equals, true)
 
681
        s.service.removeServerSecurityGroup(srv.Id, "1")
 
682
        s.service.removeServerSecurityGroup(srv.Id, "2")
698
683
        s.service.removeServer(srv.Id)
699
684
}
700
685
 
794
779
        c.Assert(expected.Groups, HasLen, 1)
795
780
        groups = []nova.SecurityGroup{
796
781
                {
797
 
                        Id:       1,
 
782
                        Id:       "1",
798
783
                        Name:     "group 1",
799
784
                        TenantId: s.service.TenantId,
800
785
                        Rules:    []nova.SecurityGroupRule{},
801
786
                },
802
787
                {
803
 
                        Id:       2,
 
788
                        Id:       "2",
804
789
                        Name:     "group 2",
805
790
                        TenantId: s.service.TenantId,
806
791
                        Rules:    []nova.SecurityGroupRule{},
829
814
 
830
815
func (s *NovaHTTPSuite) TestAddSecurityGroup(c *C) {
831
816
        group := nova.SecurityGroup{
832
 
                Id:          1,
 
817
                Id:          "1",
833
818
                Name:        "group 1",
834
819
                Description: "desc",
835
820
                TenantId:    s.service.TenantId,
858
843
}
859
844
 
860
845
func (s *NovaHTTPSuite) TestDeleteSecurityGroup(c *C) {
861
 
        group := nova.SecurityGroup{Id: 1, Name: "group 1"}
 
846
        group := nova.SecurityGroup{Id: "1", Name: "group 1"}
862
847
        _, err := s.service.securityGroup(group.Id)
863
848
        c.Assert(err, NotNil)
864
849
        err = s.service.addSecurityGroup(group)
872
857
}
873
858
 
874
859
func (s *NovaHTTPSuite) TestAddSecurityGroupRule(c *C) {
875
 
        group1 := nova.SecurityGroup{Id: 1, Name: "src"}
876
 
        group2 := nova.SecurityGroup{Id: 2, Name: "tgt"}
 
860
        group1 := nova.SecurityGroup{Id: "1", Name: "src"}
 
861
        group2 := nova.SecurityGroup{Id: "2", Name: "tgt"}
877
862
        err := s.service.addSecurityGroup(group1)
878
863
        c.Assert(err, IsNil)
879
864
        defer s.service.removeSecurityGroup(group1.Id)
881
866
        c.Assert(err, IsNil)
882
867
        defer s.service.removeSecurityGroup(group2.Id)
883
868
        riIngress := nova.RuleInfo{
884
 
                ParentGroupId: 1,
 
869
                ParentGroupId: "1",
885
870
                FromPort:      1234,
886
871
                ToPort:        4321,
887
872
                IPProtocol:    "tcp",
894
879
        iprange := make(map[string]string)
895
880
        iprange["cidr"] = riIngress.Cidr
896
881
        rule1 := nova.SecurityGroupRule{
897
 
                Id:            1,
 
882
                Id:            "1",
898
883
                ParentGroupId: group1.Id,
899
884
                FromPort:      &riIngress.FromPort,
900
885
                ToPort:        &riIngress.ToPort,
902
887
                IPRange:       iprange,
903
888
        }
904
889
        rule2 := nova.SecurityGroupRule{
905
 
                Id:            2,
 
890
                Id:            "2",
906
891
                ParentGroupId: group2.Id,
907
892
                Group: nova.SecurityGroupRef{
908
893
                        Name:     group1.Name,
945
930
}
946
931
 
947
932
func (s *NovaHTTPSuite) TestDeleteSecurityGroupRule(c *C) {
948
 
        group1 := nova.SecurityGroup{Id: 1, Name: "src"}
949
 
        group2 := nova.SecurityGroup{Id: 2, Name: "tgt"}
 
933
        group1 := nova.SecurityGroup{Id: "1", Name: "src"}
 
934
        group2 := nova.SecurityGroup{Id: "2", Name: "tgt"}
950
935
        err := s.service.addSecurityGroup(group1)
951
936
        c.Assert(err, IsNil)
952
937
        defer s.service.removeSecurityGroup(group1.Id)
958
943
                GroupId:       &group1.Id,
959
944
        }
960
945
        rule := nova.SecurityGroupRule{
961
 
                Id:            1,
 
946
                Id:            "1",
962
947
                ParentGroupId: group2.Id,
963
948
                Group: nova.SecurityGroupRef{
964
949
                        Name:     group1.Name,
975
960
}
976
961
 
977
962
func (s *NovaHTTPSuite) TestAddServerSecurityGroup(c *C) {
978
 
        group := nova.SecurityGroup{Id: 1, Name: "group"}
 
963
        group := nova.SecurityGroup{Id: "1", Name: "group"}
979
964
        err := s.service.addSecurityGroup(group)
980
965
        c.Assert(err, IsNil)
981
966
        defer s.service.removeSecurityGroup(group.Id)
1004
989
        server := nova.ServerDetail{Id: "sr1"}
1005
990
        groups := []nova.SecurityGroup{
1006
991
                {
1007
 
                        Id:       1,
 
992
                        Id:       "1",
1008
993
                        Name:     "group1",
1009
994
                        TenantId: s.service.TenantId,
1010
995
                        Rules:    []nova.SecurityGroupRule{},
1011
996
                },
1012
997
                {
1013
 
                        Id:       2,
 
998
                        Id:       "2",
1014
999
                        Name:     "group2",
1015
1000
                        TenantId: s.service.TenantId,
1016
1001
                        Rules:    []nova.SecurityGroupRule{},
1040
1025
}
1041
1026
 
1042
1027
func (s *NovaHTTPSuite) TestDeleteServerSecurityGroup(c *C) {
1043
 
        group := nova.SecurityGroup{Id: 1, Name: "group"}
 
1028
        group := nova.SecurityGroup{Id: "1", Name: "group"}
1044
1029
        err := s.service.addSecurityGroup(group)
1045
1030
        c.Assert(err, IsNil)
1046
1031
        defer s.service.removeSecurityGroup(group.Id)
1066
1051
}
1067
1052
 
1068
1053
func (s *NovaHTTPSuite) TestPostFloatingIP(c *C) {
1069
 
        fip := nova.FloatingIP{Id: 1, IP: "10.0.0.1", Pool: "nova"}
 
1054
        fip := nova.FloatingIP{Id: "1", IP: "10.0.0.1", Pool: "nova"}
1070
1055
        c.Assert(s.service.allFloatingIPs(), HasLen, 0)
1071
1056
        var expected struct {
1072
1057
                IP nova.FloatingIP `json:"floating_ip"`
1091
1076
        assertJSON(c, resp, &expected)
1092
1077
        c.Assert(expected.IPs, HasLen, 0)
1093
1078
        fips := []nova.FloatingIP{
1094
 
                {Id: 1, IP: "1.2.3.4", Pool: "nova"},
1095
 
                {Id: 2, IP: "4.3.2.1", Pool: "nova"},
 
1079
                {Id: "1", IP: "1.2.3.4", Pool: "nova"},
 
1080
                {Id: "2", IP: "4.3.2.1", Pool: "nova"},
1096
1081
        }
1097
1082
        for _, fip := range fips {
1098
1083
                err := s.service.addFloatingIP(fip)
1118
1103
}
1119
1104
 
1120
1105
func (s *NovaHTTPSuite) TestDeleteFloatingIP(c *C) {
1121
 
        fip := nova.FloatingIP{Id: 1, IP: "10.0.0.1", Pool: "nova"}
 
1106
        fip := nova.FloatingIP{Id: "1", IP: "10.0.0.1", Pool: "nova"}
1122
1107
        err := s.service.addFloatingIP(fip)
1123
1108
        c.Assert(err, IsNil)
1124
1109
        defer s.service.removeFloatingIP(fip.Id)
1130
1115
}
1131
1116
 
1132
1117
func (s *NovaHTTPSuite) TestAddServerFloatingIP(c *C) {
1133
 
        fip := nova.FloatingIP{Id: 1, IP: "1.2.3.4"}
 
1118
        fip := nova.FloatingIP{Id: "1", IP: "1.2.3.4"}
1134
1119
        server := nova.ServerDetail{Id: "sr1"}
1135
1120
        err := s.service.addFloatingIP(fip)
1136
1121
        c.Assert(err, IsNil)
1154
1139
}
1155
1140
 
1156
1141
func (s *NovaHTTPSuite) TestRemoveServerFloatingIP(c *C) {
1157
 
        fip := nova.FloatingIP{Id: 1, IP: "1.2.3.4"}
 
1142
        fip := nova.FloatingIP{Id: "1", IP: "1.2.3.4"}
1158
1143
        server := nova.ServerDetail{Id: "sr1"}
1159
1144
        err := s.service.addFloatingIP(fip)
1160
1145
        c.Assert(err, IsNil)