Преглед изворни кода

Fix security group group test

Enis Afgan пре 10 година
родитељ
комит
44e3395e75
2 измењених фајлова са 28 додато и 33 уклоњено
  1. 0 3
      cloudbridge/cloud/providers/aws/resources.py
  2. 28 30
      test/test_security_service.py

+ 0 - 3
cloudbridge/cloud/providers/aws/resources.py

@@ -599,9 +599,6 @@ class AWSSecurityGroup(BaseSecurityGroup):
 
     @property
     def rules(self):
-        # Refresh the local object; otherwise get stale rules
-        self._security_group = self._provider.ec2_conn.get_all_security_groups(
-            group_ids=[self.id])[0]
         return [AWSSecurityGroupRule(self._provider, r, self)
                 for r in self._security_group.rules]
 

+ 28 - 30
test/test_security_service.py

@@ -201,33 +201,31 @@ class CloudSecurityServiceTestCase(ProviderTestBase):
             "Security group {0} should have been deleted but still exists."
             .format(name))
 
-    # FIXME
-    # def test_security_group_group_role(self):
-    #     """Test for proper creation of a security group rule."""
-    #     name = 'cbtestsecuritygroupC-{0}'.format(uuid.uuid4())
-    #     sg = self.provider.security.security_groups.create(
-    #         name=name, description=name)
-    #     with helpers.cleanup_action(lambda: sg.delete()):
-    #         self.assertTrue(
-    #             len(sg.rules) == 0,
-    #             "Expected no security group group rule. Got {0}."
-    #             .format(sg.rules))
-    #         rule = sg.add_rule(src_group=sg)
-    #         self.assertTrue(
-    #             sg.rules[0].group.name == name,
-    #             "Expected security group rule name {0}. Got {1}."
-    #             .format(name, sg.rules[0].group.name))
-    #         # On OpenStack, each group rule is an independent rule;
-    #         # On AWS, each group rule is a group and gets deleted at once
-    #         for rule in sg.rules:
-    #             rule.delete()
-    #         self.assertTrue(
-    #             len(sg.rules) == 0,
-    #             "Deleting SecurityGroupRule should delete it: {0}".format(
-    #                 sg.rules))
-    #     sgl = self.provider.security.security_groups.list()
-    #     found_sg = [g for g in sgl if g.name == name]
-    #     self.assertTrue(
-    #         len(found_sg) == 0,
-    #         "Security group {0} should have been deleted but still exists."
-    #         .format(name))
+    def test_security_group_group_role(self):
+        """Test for proper creation of a security group rule."""
+        name = 'cbtestsecuritygroupC-{0}'.format(uuid.uuid4())
+        sg = self.provider.security.security_groups.create(
+            name=name, description=name)
+        with helpers.cleanup_action(lambda: sg.delete()):
+            self.assertTrue(
+                len(sg.rules) == 0,
+                "Expected no security group group rule. Got {0}."
+                .format(sg.rules))
+            rule = sg.add_rule(src_group=sg)
+            self.assertTrue(
+                rule.group.name == name,
+                "Expected security group rule name {0}. Got {1}."
+                .format(name, rule.group.name))
+            for r in sg.rules:
+                r.delete()
+            sg = self.provider.security.security_groups.get(sg.id)  # update
+            self.assertTrue(
+                len(sg.rules) == 0,
+                "Deleting SecurityGroupRule should delete it: {0}".format(
+                    sg.rules))
+        sgl = self.provider.security.security_groups.list()
+        found_sg = [g for g in sgl if g.name == name]
+        self.assertTrue(
+            len(found_sg) == 0,
+            "Security group {0} should have been deleted but still exists."
+            .format(name))