Pārlūkot izejas kodu

Integration test for SG modified

jatin 9 gadi atpakaļ
vecāks
revīzija
569bb2172d

+ 23 - 12
integration_test/test_integration_azure_security_group.py

@@ -15,28 +15,34 @@ class AzureIntegrationSecurityServiceTestCase(ProviderTestBase):
     @helpers.skipIfNoService(['security.security_groups'])
     @helpers.skipIfNoService(['security.security_groups'])
     def test_azure_security_group(self):
     def test_azure_security_group(self):
         sg_name = '{0}'.format(uuid.uuid4())
         sg_name = '{0}'.format(uuid.uuid4())
-        print(sg_name)
+        print("SG guid - " + sg_name)
 
 
         listBeforeCreate = self.provider.security.security_groups.list()
         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="")
+        print("Length Before create - " + str(len(listBeforeCreate)))
+        netId = "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/CloudBridge-Azure/providers/Microsoft.Network/virtualNetworks/SampleNetwork"
+        sg = self.provider.security.security_groups.create(name=sg_name, description="testCreateSecGroup",
+                                                           network_id=netId)
         self.assertEqual(sg_name, sg.name)
         self.assertEqual(sg_name, sg.name)
 
 
         listAfterCreate = self.provider.security.security_groups.list()
         listAfterCreate = self.provider.security.security_groups.list()
-        print("After create - "+ str(len(listAfterCreate)))
+        print("Length After create - " + str(len(listAfterCreate)))
         self.assertEqual( len(listAfterCreate) , len(listBeforeCreate)+1)
         self.assertEqual( len(listAfterCreate) , len(listBeforeCreate)+1)
 
 
-        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 = self.provider.security.security_groups.get(
+            "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/CloudBridge-Azure/providers/Microsoft.Network/networkSecurityGroups/sampleSG")
+        print("Get SG - " + str(get))
+        print(str(get.rules))
+        self.assertEqual(get.name, "sampleSG")
 
 
-        get_notfound = self.provider.security.security_groups.get("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/testCreateSecGroup1")
+        get_notfound = self.provider.security.security_groups.get(
+            "/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/SecgrupDontFindMe")
         self.assertEqual(get_notfound , None)
         self.assertEqual(get_notfound , None)
 
 
         find_exists_list = self.provider.security.security_groups.find(sg_name)
         find_exists_list = self.provider.security.security_groups.find(sg_name)
         for sg in find_exists_list:
         for sg in find_exists_list:
             self.assertTrue(sg_name in sg.name)
             self.assertTrue(sg_name in sg.name)
         print("Find - " + str(find_exists_list))
         print("Find - " + str(find_exists_list))
-        print("Find - " + str(find_exists_list.total_results))
+        print("Find Total Results- " + str(find_exists_list.total_results))
         self.assertTrue(find_exists_list.total_results > 0)
         self.assertTrue(find_exists_list.total_results > 0)
 
 
         find_not_exists_list = self.provider.security.security_groups.find('dontfindme')
         find_not_exists_list = self.provider.security.security_groups.find('dontfindme')
@@ -44,20 +50,24 @@ class AzureIntegrationSecurityServiceTestCase(ProviderTestBase):
 
 
         cb = listAfterCreate.data[0]
         cb = listAfterCreate.data[0]
         lenBeforeCreateRule = len(cb.rules)
         lenBeforeCreateRule = len(cb.rules)
-        cb.add_rule('*', '25', '100', '*')
+        cb.add_rule('tcp', '1111', '2222', '0.0.0.0/0')
         lenAfterCreateRule = len(cb.rules)
         lenAfterCreateRule = len(cb.rules)
         self.assertEqual(lenAfterCreateRule, lenBeforeCreateRule+1)
         self.assertEqual(lenAfterCreateRule, lenBeforeCreateRule+1)
 
 
-        get_rule = cb.get_rule('*', '*', '*', '*')
-        self.assertEqual(str(get_rule), "<CBSecurityGroupRule: IP: *; from: *; to: *; grp: None>")
+        print(str(cb.rules))
+        get_rule = cb.get_rule('tcp', '1111', '2222', '0.0.0.0/0')
+        print("Get Rule - " + str(get_rule))
+        self.assertEqual(str(get_rule), "<CBSecurityGroupRule: IP: tcp; from: 1111; to: 2222; grp: None>")
 
 
         get_rule_notfound = cb.get_rule('*', '25', '1', '1')
         get_rule_notfound = cb.get_rule('*', '25', '1', '1')
         self.assertEqual(str(get_rule_notfound), 'None')
         self.assertEqual(str(get_rule_notfound), 'None')
 
 
         rule_json = cb.rules[1].to_json()
         rule_json = cb.rules[1].to_json()
+        print("Rule json - " + str(rule_json))
         self.assertEqual(rule_json[2:9], "cidr_ip")
         self.assertEqual(rule_json[2:9], "cidr_ip")
 
 
         sg_json = cb.to_json()
         sg_json = cb.to_json()
+        print("SG json - " + str(sg_json))
         self.assertEqual(sg_json[2:4], "id")
         self.assertEqual(sg_json[2:4], "id")
 
 
         with self.assertRaises(Exception):
         with self.assertRaises(Exception):
@@ -66,7 +76,8 @@ class AzureIntegrationSecurityServiceTestCase(ProviderTestBase):
         listBeforeDeleteFound = self.provider.security.security_groups.list()
         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)
         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()
         listAfterDeleteFound = self.provider.security.security_groups.list()
-        print(str(len(listBeforeDeleteFound))+"---"+str(len(listAfterDeleteFound)))
+        print("Length before delete - " + str(len(listBeforeDeleteFound)))
+        print("Length after delete - " + str(len(listAfterDeleteFound)))
         self.assertEqual(len(listAfterDeleteFound), len(listBeforeDeleteFound)-1)
         self.assertEqual(len(listAfterDeleteFound), len(listBeforeDeleteFound)-1)
 
 
         sg_del_notfound = self.provider.security.security_groups.delete("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/sg5")
         sg_del_notfound = self.provider.security.security_groups.delete("/subscriptions/7904d702-e01c-4826-8519-f5a25c866a96/resourceGroups/cloudbridge-azure/providers/Microsoft.Network/networkSecurityGroups/sg5")