Просмотр исходного кода

SG Integration Test refactored for checking list count after create and delete

jatin 9 лет назад
Родитель
Сommit
6dcd62fcd9

+ 7 - 2
cloudbridge/cloud/providers/azure/mock_azure_client.py

@@ -101,8 +101,13 @@ class MockAzureClient:
         self.security_groups.append(sg_create)
         return sg_create
 
-    def list_security_group(self):
-        return self.security_groups
+    # def list_security_group(self):
+    #     return self.security_groups
+
+    def list_security_group(self, filters=None):
+        security_groups= FilterList(self.security_groups)
+        security_groups.filter(filters)
+        return security_groups
 
     def delete_security_group(self, name):
         for item in self.security_groups:

+ 2 - 2
integration_test/__init__.py

@@ -32,8 +32,8 @@ from integration_test.test_integration_azure_security_group import AzureIntegrat
 from integration_test.test_integration_azure_volume_service import AzureIntegrationVolumeServiceTestCase
 
 PROVIDER_TESTS ={'azure': [
-    #AzureIntegrationObjectStoreServiceTestCase,
-    #AzureIntegrationSecurityServiceTestCase,
+    AzureIntegrationObjectStoreServiceTestCase,
+    AzureIntegrationSecurityServiceTestCase,
     AzureIntegrationVolumeServiceTestCase
 ]}
 

+ 27 - 16
integration_test/test_integration_azure_security_group.py

@@ -14,22 +14,29 @@ class AzureIntegrationSecurityServiceTestCase(ProviderTestBase):
 
     @helpers.skipIfNoService(['security.security_groups'])
     def test_azure_security_group(self):
-        sg = self.provider.security.security_groups.create(name="testCreateSecGroup", description="testCreateSecGroup", network_id="")
-        self.assertEqual("testCreateSecGroup", sg.name)
+        sg_name = '{0}'.format(uuid.uuid4())
+        print(sg_name)
 
-        list = self.provider.security.security_groups.list()
-        self.assertEqual( len(list) , 2)
+        listBeforeCreate = self.provider.security.security_groups.list()
+        print("Before create - " + str(len(listBeforeCreate)))
+        sg = self.provider.security.security_groups.create(name=sg_name, description="testCreateSecGroup", network_id="")
+        self.assertEqual(sg_name, sg.name)
 
-        get = self.provider.security.security_groups.get("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/testCreateSecGroup")
-        self.assertEqual( get.name , "testCreateSecGroup")
+        listAfterCreate = self.provider.security.security_groups.list()
+        print("After create - "+ str(len(listAfterCreate)))
+        self.assertEqual( len(listAfterCreate) , len(listBeforeCreate)+1)
 
-        get_notfound = self.provider.security.security_groups.get("testCreateSecGroup1")
+        get = self.provider.security.security_groups.get("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/"+ sg_name)
+        self.assertEqual( get.name , sg_name)
+
+        get_notfound = self.provider.security.security_groups.get("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/testCreateSecGroup1")
         self.assertEqual(get_notfound , None)
 
-        cb = list.data[0]
-        rules = cb.rules
+        cb = listAfterCreate.data[0]
+        lenBeforeCreateRule = len(cb.rules)
         cb.add_rule('*', '25', '100', '*')
-        self.assertEqual(len(rules), 3)
+        lenAfterCreateRule = len(cb.rules)
+        self.assertEqual(lenAfterCreateRule, lenBeforeCreateRule+1)
 
         get_rule = cb.get_rule('*', '*', '*', '*')
         self.assertEqual(str(get_rule), "<CBSecurityGroupRule: IP: *; from: *; to: *; grp: None>")
@@ -37,17 +44,21 @@ class AzureIntegrationSecurityServiceTestCase(ProviderTestBase):
         get_rule_notfound = cb.get_rule('*', '25', '1', '1')
         self.assertEqual(str(get_rule_notfound), 'None')
 
-        rule_json = rules[1].to_json()
+        rule_json = cb.rules[1].to_json()
         self.assertEqual(rule_json[2:9], "cidr_ip")
 
         sg_json = cb.to_json()
         self.assertEqual(sg_json[2:4], "id")
 
         with self.assertRaises(Exception):
-            rules[1].delete()
+            cb.rules[1].delete()
 
-        sg_del = self.provider.security.security_groups.delete("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/testCreateSecGroup")
-        self.assertEqual(sg_del, True)
+        listBeforeDeleteFound = self.provider.security.security_groups.list()
+        sg_del = self.provider.security.security_groups.delete("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/"+sg_name)
+        listAfterDeleteFound = self.provider.security.security_groups.list()
+        print(str(len(listBeforeDeleteFound))+"---"+str(len(listAfterDeleteFound)))
+        self.assertEqual(len(listAfterDeleteFound), len(listBeforeDeleteFound)-1)
 
-        sg_del_notfound = self.provider.security.security_groups.delete("sg5")
-        self.assertEqual(sg_del_notfound, False)
+        sg_del_notfound = self.provider.security.security_groups.delete("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/sg5")
+        listAfterDeleteNotFound = self.provider.security.security_groups.list()
+        self.assertEqual(len(listAfterDeleteNotFound), len(listAfterDeleteFound))