Procházet zdrojové kódy

Add tests for security group rules

Enis Afgan před 10 roky
rodič
revize
6880b78729
1 změnil soubory, kde provedl 29 přidání a 1 odebrání
  1. 29 1
      test/test_provider_security_service.py

+ 29 - 1
test/test_provider_security_service.py

@@ -86,6 +86,7 @@ class ProviderSecurityServiceTestCase(ProviderTestBase):
                 .format(name))
                 .format(name))
 
 
     def test_security_group(self):
     def test_security_group(self):
+        """Test for proper creation of a security group."""
         name = 'cbtestsecuritygroupB-{0}'.format(uuid.uuid4())
         name = 'cbtestsecuritygroupB-{0}'.format(uuid.uuid4())
         sg = self.provider.security.security_groups.create(
         sg = self.provider.security.security_groups.create(
             name=name, description=name)
             name=name, description=name)
@@ -93,7 +94,8 @@ class ProviderSecurityServiceTestCase(ProviderTestBase):
             lambda:
             lambda:
                 self.provider.security.security_groups.delete(group_id=sg.id)
                 self.provider.security.security_groups.delete(group_id=sg.id)
         ):
         ):
-            sg.add_rule('tcp', 1111, 1111, '0.0.0.0/0')
+            sg.add_rule(ip_protocol='tcp', from_port=1111, to_port=1111,
+                        cidr_ip='0.0.0.0/0')
             found_rules = [rule for rule in sg.rules if
             found_rules = [rule for rule in sg.rules if
                            rule.cidr_ip == '0.0.0.0/0' and
                            rule.cidr_ip == '0.0.0.0/0' and
                            rule.ip_protocol == 'tcp' and
                            rule.ip_protocol == 'tcp' and
@@ -117,3 +119,29 @@ class ProviderSecurityServiceTestCase(ProviderTestBase):
                 len(found_sg) == 0,
                 len(found_sg) == 0,
                 "Security group {0} should have been deleted but still exists."
                 "Security group {0} should have been deleted but still exists."
                 .format(name))
                 .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.exception_action(
+            lambda:
+                self.provider.security.security_groups.delete(group_id=sg.id)
+        ):
+            self.assertTrue(
+                len(sg.rules) == 0,
+                "Expected no security group group rule. Got {0}."
+                .format(sg.rules))
+            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))
+            sg.delete()
+            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))