From dc081c9f6bbf10e2a4e996946a4750d08bc32a13 Mon Sep 17 00:00:00 2001 From: Girish Shilamkar Date: Thu, 31 Oct 2013 22:21:00 +0530 Subject: [PATCH] CLOUDSTACK-4256: Fixed Shared Network test cases using random private ips for shared networks --- .../component/test_shared_networks.py | 996 +++++++++--------- 1 file changed, 512 insertions(+), 484 deletions(-) diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 732e1447b50..66a9d266dac 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -18,13 +18,27 @@ """ P1 tests for shared networks """ #Import Local Modules -import marvin from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.cloudstackTestCase import cloudstackTestCase, unittest +from marvin.integration.lib.base import (Account, + Network, + NetworkOffering, + VirtualMachine, + Project, + PhysicalNetwork, + Domain, + StaticNATRule, + FireWallRule, + ServiceOffering, + PublicIPAddress) +from marvin.integration.lib.utils import (cleanup_resources, + xsplit) +from marvin.integration.lib.common import (get_domain, + get_zone, + get_template, + wait_for_cleanup) +import random + import netaddr class Services: @@ -72,20 +86,20 @@ class Services: "network": { "name": "MySharedNetwork - Test", "displaytext": "MySharedNetwork", - "gateway" :"172.16.15.1", + "gateway" :"", "netmask" :"255.255.255.0", - "startip" :"172.16.15.2", - "endip" :"172.16.15.20", + "startip" :"", + "endip" :"", "acltype" : "Domain", "scope":"all", }, "network1": { "name": "MySharedNetwork - Test1", "displaytext": "MySharedNetwork1", - "gateway" :"172.16.16.1", + "gateway" :"", "netmask" :"255.255.255.0", - "startip" :"172.16.16.21", - "endip" :"172.16.16.41", + "startip" :"", + "endip" :"", "acltype" : "Domain", "scope":"all", }, @@ -134,16 +148,16 @@ class Services: "timeout": 10, "mode": 'advanced' } - + class TestSharedNetworks(cloudstackTestCase): - + @classmethod def setUpClass(cls): cls.api_client = super( TestSharedNetworks, cls ).getClsTestClient().getApiClient() - + cls.services = Services().services # Get Zone, Domain and templates @@ -154,7 +168,7 @@ class TestSharedNetworks(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) - + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id @@ -162,7 +176,7 @@ class TestSharedNetworks(cloudstackTestCase): cls.api_client, cls.services["service_offering"] ) - + cls._cleanup = [ cls.service_offering, ] @@ -180,6 +194,19 @@ class TestSharedNetworks(cloudstackTestCase): def setUp(self): self.api_client = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() + + # Set the subnet number of shared networks randomly prior to execution + # of each test case to avoid overlapping of ip addresses + shared_network_subnet_number = random.randrange(1,254) + + self.services["network"]["gateway"] = "172.16."+str(shared_network_subnet_number)+".1" + self.services["network"]["startip"] = "172.16."+str(shared_network_subnet_number)+".2" + self.services["network"]["endip"] = "172.16."+str(shared_network_subnet_number)+".20" + + self.services["network1"]["gateway"] = "172.16."+str(shared_network_subnet_number + 1)+".1" + self.services["network1"]["startip"] = "172.16."+str(shared_network_subnet_number + 1)+".2" + self.services["network1"]["endip"] = "172.16."+str(shared_network_subnet_number + 1)+".20" + self.cleanup = [] self.cleanup_networks = [] self.cleanup_accounts = [] @@ -194,7 +221,7 @@ class TestSharedNetworks(cloudstackTestCase): cleanup_resources(self.api_client, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) - + #below components is not a part of cleanup because to mandate the order and to cleanup network try: for vm in self.cleanup_vms: @@ -204,16 +231,16 @@ class TestSharedNetworks(cloudstackTestCase): try: for project in self.cleanup_projects: - project.delete(self.api_client) + project.delete(self.api_client) except Exception as e: raise Exception("Warning: Exception during project cleanup : %s" % e) try: for account in self.cleanup_accounts: - account.delete(self.api_client) + account.delete(self.api_client) except Exception as e: raise Exception("Warning: Exception during account cleanup : %s" % e) - + #Wait till all resources created are cleaned up completely and then attempt to delete domains wait_for_cleanup(self.api_client, ["account.cleanup.interval"]) @@ -262,11 +289,11 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_sharedNetworkOffering_01(self): """ Test shared network Offering 01 """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -288,9 +315,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -314,7 +341,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.debug("Admin Type account created: %s" % self.account.name) - + #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( self.api_client, @@ -332,19 +359,19 @@ class TestSharedNetworks(cloudstackTestCase): ) physical_network = list_physical_networks_response[0] - + self.debug("Physical network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -365,14 +392,14 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -398,11 +425,11 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_sharedNetworkOffering_02(self): """ Test Shared Network Offering 02 """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -414,7 +441,7 @@ class TestSharedNetworks(cloudstackTestCase): # 1. listAccounts name=admin-XABU1, state=enabled returns your account # 2. listPhysicalNetworks should return at least one active physical network # 3. createNetworkOffering fails - vlan should be specified in advanced zone - + #Create an account self.account = Account.create( self.api_client, @@ -422,9 +449,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -446,9 +473,9 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin type account created: %s" % self.account.name) - + #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( self.api_client, @@ -464,14 +491,14 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listPhysicalNetworks should return at least one physical network." ) - + physical_network = list_physical_networks_response[0] - + self.debug("Physical network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "False" self.services["network_offering"]["specifyIpRanges"] = "False" - + try: #Create Network Offering self.shared_network_offering = NetworkOffering.create( @@ -481,16 +508,17 @@ class TestSharedNetworks(cloudstackTestCase): ) self.fail("Network offering got created with vlan as False in advance mode and shared guest type, which is invalid case.") except Exception as e: - self.debug("Network Offering creation failed with vlan as False in advance mode and shared guest type.") + self.debug("Network Offering creation failed with vlan as False in advance mode and shared guest type. Exception: %s" % + e) @attr(tags=["advanced", "advancedns"]) def test_sharedNetworkOffering_03(self): """ Test Shared Network Offering 03 """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -503,7 +531,7 @@ class TestSharedNetworks(cloudstackTestCase): # 2. listPhysicalNetworks should return at least one active physical network # 3. createNetworkOffering fails - ip ranges should be specified when creating shared network offering - + #Create an account self.account = Account.create( self.api_client, @@ -511,9 +539,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -535,9 +563,9 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin Type account created: %s" % self.account.name) - + #Verify that there should be at least one physical network present in zone. list_physical_networks_response = PhysicalNetwork.list( self.api_client, @@ -553,14 +581,14 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listPhysicalNetworks should return at least one physical network." ) - + physical_network = list_physical_networks_response[0] - + self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "False" - + try: #Create Network Offering self.shared_network_offering = NetworkOffering.create( @@ -570,16 +598,17 @@ class TestSharedNetworks(cloudstackTestCase): ) self.fail("Network offering got created with vlan as True and ip ranges as False in advance mode and with shared guest type, which is invalid case.") except Exception as e: - self.debug("Network Offering creation failed with vlan as true and ip ranges as False in advance mode and with shared guest type.") + self.debug("Network Offering creation failed with vlan as true and ip ranges as False in advance mode and with shared guest type.\ + Exception : %s" % e) @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_All(self): """ Test Shared Network ALL """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -605,7 +634,7 @@ class TestSharedNetworks(cloudstackTestCase): # 6. No checks reqd # 7. a. listVirtualMachines should show both VMs in running state in the user account and the admin account # b. VM's IPs shoud be in the range of the shared network ip ranges - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -613,9 +642,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -637,9 +666,9 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin type account created: %s" % self.admin_account.name) - + #Create an user account self.user_account = Account.create( self.api_client, @@ -647,9 +676,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=False, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.user_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -671,27 +700,27 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The user account created is not enabled." ) - + self.debug("User type account created: %s" % self.user_account.name) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.debug("Physical network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -711,17 +740,17 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -742,7 +771,7 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["acltype"] = "Domain" self.services["network"]["networkofferingid"] = self.shared_network_offering.id @@ -755,7 +784,7 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) - + self.cleanup_networks.append(self.network) list_networks_response = Network.list( @@ -777,18 +806,18 @@ class TestSharedNetworks(cloudstackTestCase): True, "The network is created with ip range but the flag is set to False." ) - + self.debug("Shared Network created for scope domain: %s" % self.network.id) - + self.admin_account_virtual_machine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], networkids=self.network.id, serviceofferingid=self.service_offering.id ) - + self.cleanup_vms.append(self.admin_account_virtual_machine) - + vms = VirtualMachine.list( self.api_client, id=self.admin_account_virtual_machine.id, @@ -804,13 +833,13 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + self.debug("Virtual Machine created: %s" % self.admin_account_virtual_machine.id) - + ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: self.fail("Virtual machine ip should be from the ip range assigned to network created.") - + self.user_account_virtual_machine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], @@ -836,7 +865,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.debug("Virtual Machine created: %s" % self.user_account_virtual_machine.id) - + ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: self.fail("Virtual machine ip should be from the ip range assigned to network created.") @@ -844,12 +873,12 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_accountSpecific(self): """ Test Shared Network with scope account """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # create a user account = user-SOPJD # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -874,7 +903,7 @@ class TestSharedNetworks(cloudstackTestCase): # 6. VM deployed in admin account should FAIL to deploy # VM should be deployed in user account only # verify VM's IP is within shared network range - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -884,7 +913,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -906,9 +935,9 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin type account created: %s" % self.admin_account.name) - + #Create an user account self.user_account = Account.create( self.api_client, @@ -916,9 +945,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=False, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.user_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -940,13 +969,13 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The user account created is not enabled." ) - + self.debug("User type account created: %s" % self.user_account.name) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" @@ -955,8 +984,8 @@ class TestSharedNetworks(cloudstackTestCase): self.api_client, self.services["network_offering"], conservemode=False - ) - + ) + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -977,16 +1006,16 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be by default disabled." ) - + self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1007,13 +1036,13 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["acltype"] = "Account" self.services["network"]["networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan - + self.network = Network.create( self.api_client, self.services["network"], @@ -1022,9 +1051,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) - + self.cleanup_networks.append(self.network) - + list_networks_response = Network.list( self.api_client, id=self.network.id @@ -1044,9 +1073,9 @@ class TestSharedNetworks(cloudstackTestCase): True, "The network is created with ip range but the flag is set to False." ) - + self.debug("Network created: %s" % self.network.id) - + try: self.admin_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1058,7 +1087,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.fail("Virtual Machine got created in admin account with network created but the network used is of scope account and for user account.") except Exception as e: - self.debug("Virtual Machine creation failed as network used have scoped only for user account.") + self.debug("Virtual Machine creation failed as network used have scoped only for user account. Exception: %s" % e) self.user_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1083,7 +1112,7 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: self.fail("Virtual machine ip should be from the ip range assigned to network created.") @@ -1091,14 +1120,14 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_domainSpecific(self): """ Test Shared Network with scope domain """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # create a domain - DOM # create a domain admin account = domadmin-SOPJD # create a user in domain - DOM # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -1123,7 +1152,7 @@ class TestSharedNetworks(cloudstackTestCase): # 6. VM should NOT be deployed in admin account # VM should be deployed in user account and domain admin account # verify VM's IP are within shared network range - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -1131,9 +1160,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -1155,21 +1184,21 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin type account created: %s" % self.admin_account.id) - + #create domain self.dom_domain = Domain.create( self.api_client, self.services["domain"], ) - + self.cleanup_domains.append(self.dom_domain) - + #verify that the account got created with state enabled list_domains_response = Domain.list( self.api_client, - id=self.dom_domain.id + id=self.dom_domain.id ) self.assertEqual( isinstance(list_domains_response, list), @@ -1181,9 +1210,9 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listDomains returned empty list." ) - + self.debug("Domain created: %s" % self.dom_domain.id) - + #Create admin account self.domain_admin_account = Account.create( self.api_client, @@ -1191,9 +1220,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.dom_domain.id ) - + self.cleanup_accounts.append(self.domain_admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -1215,9 +1244,9 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The domain admin account created is not enabled." ) - + self.debug("Domain admin account created: %s" % self.domain_admin_account.id) - + #Create an user account self.domain_user_account = Account.create( self.api_client, @@ -1225,9 +1254,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=False, domainid=self.dom_domain.id ) - + self.cleanup_accounts.append(self.domain_user_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -1249,13 +1278,13 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The domain user account created is not enabled." ) - + self.debug("Domain user account created: %s" % self.domain_user_account.id) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" @@ -1265,9 +1294,9 @@ class TestSharedNetworks(cloudstackTestCase): self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -1287,17 +1316,17 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be by default disabled." ) - + self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1318,13 +1347,13 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["acltype"] = "domain" self.services["network"]["networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan - + self.network = Network.create( self.api_client, self.services["network"], @@ -1333,9 +1362,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) - + self.cleanup_networks.append(self.network) - + list_networks_response = Network.list( self.api_client, id=self.network.id, @@ -1356,9 +1385,9 @@ class TestSharedNetworks(cloudstackTestCase): True, "The network is created with ip range but the flag is set to False." ) - + self.debug("Shared Network created: %s" % self.network.id) - + try: self.admin_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1370,7 +1399,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.fail("Virtual Machine got created in admin account with network specified but the network used is of scope domain and admin account is not part of this domain.") except Exception as e: - self.debug("Virtual Machine creation failed as network used have scoped only for DOM domain.") + self.debug("Virtual Machine creation failed as network used have scoped only for DOM domain. Exception: %s" % e) self.domain_user_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1396,11 +1425,11 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: self.fail("Virtual machine ip should be from the ip range assigned to network created.") - + self.domain_admin_account_virtual_machine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], @@ -1425,7 +1454,7 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: self.fail("Virtual machine ip should be from the ip range assigned to network created.") @@ -1433,13 +1462,13 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_projectSpecific(self): """ Test Shared Network with scope project """ - + # Steps, # 1. create an Admin Account - admin-XABU1 # create a project - proj-SADJKS # create another project - proj-SLDJK # 2. listPhysicalNetworks in available zone - # 3. createNetworkOffering: + # 3. createNetworkOffering: # - name = "MySharedOffering" # - guestiptype="shared" # - services = {Dns, Dhcp, UserData} @@ -1464,7 +1493,7 @@ class TestSharedNetworks(cloudstackTestCase): # 6. VM should NOT be deployed in admin account and user account # VM should be deployed in project account only # verify VM's IP are within shared network range - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -1472,9 +1501,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -1496,21 +1525,21 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin account created: %s" % self.admin_account.id) - + self.services["project"]["name"] = "proj-SADJKS" self.services["project"]["displaytext"] = "proj-SADJKS" - + self.project1 = Project.create( self.api_client, self.services["project"], account=self.admin_account.name, domainid=self.admin_account.domainid ) - + self.cleanup_projects.append(self.project1) - + list_projects_response = Project.list( self.api_client, id=self.project1.id, @@ -1526,21 +1555,21 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listProjects should return at least one." ) - + self.debug("Project created: %s" % self.project1.id) - + self.services["project"]["name"] = "proj-SLDJK" self.services["project"]["displaytext"] = "proj-SLDJK" - + self.project2 = Project.create( self.api_client, self.services["project"], account=self.admin_account.name, domainid=self.admin_account.domainid ) - + self.cleanup_projects.append(self.project2) - + list_projects_response = Project.list( self.api_client, id=self.project2.id, @@ -1556,26 +1585,26 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listProjects should return at least one." ) - + self.debug("Project2 created: %s" % self.project2.id) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -1595,15 +1624,15 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be by default disabled." ) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1624,15 +1653,15 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + self.debug("Shared Network found: %s" % self.shared_network_offering.id) - + #create network using the shared network offering created self.services["network"]["acltype"] = "account" self.services["network"]["networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan - + self.network = Network.create( self.api_client, self.services["network"], @@ -1642,7 +1671,7 @@ class TestSharedNetworks(cloudstackTestCase): zoneid=self.zone.id ) self.cleanup_networks.append(self.network) - + list_networks_response = Network.list( self.api_client, id=self.network.id, @@ -1664,9 +1693,9 @@ class TestSharedNetworks(cloudstackTestCase): True, "The network is created with ip range but the flag is set to False." ) - + self.debug("Shared Network created: %s" % self.network.id) - + try: self.project2_admin_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1679,7 +1708,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.fail("Virtual Machine got created in admin account with network specified but the network used is of scope project and the project2 is not assigned for the network.") except Exception as e: - self.debug("Virtual Machine creation failed as network used have scoped only for project project1.") + self.debug("Virtual Machine creation failed as network used have scoped only for project project1. Exception: %s" % e) self.project1_admin_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1705,7 +1734,7 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: self.fail("Virtual machine ip should be from the ip range assigned to network created.") @@ -1714,12 +1743,12 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_usedVlan(self): """ Test Shared Network with used vlan 01 """ - + # Steps, # 1. create an Admin account # 2. create a shared NetworkOffering # 3. enable the network offering - # 4. listPhysicalNetworks + # 4. listPhysicalNetworks # - vlan = guest VLAN range = 10-90 (say) # 5. createNetwork # - name = mysharednetwork, displaytext = mysharednetwork @@ -1733,8 +1762,8 @@ class TestSharedNetworks(cloudstackTestCase): # 2. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state # 3. listNetworkOfferings - name=mysharedoffering, should list enabled offering # 4. listPhysicalNetworks should return at least one active physical network - # 5. network creation should FAIL since VLAN is used for guest networks - + # 5. network creation should FAIL since VLAN is used for guest networks + #Create admin account self.admin_account = Account.create( self.api_client, @@ -1742,9 +1771,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -1766,23 +1795,23 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Domain admin account created: %s" % self.admin_account.id) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -1802,17 +1831,17 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1833,14 +1862,14 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["vlan"] = str.split(str(physical_network.vlan), "-")[0] self.services["network"]["acltype"] = "domain" self.services["network"]["networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan - + try: self.network = Network.create( self.api_client, @@ -1850,19 +1879,18 @@ class TestSharedNetworks(cloudstackTestCase): ) self.fail("Network created with used vlan %s id, which is invalid" % shared_vlan) except Exception as e: - self.debug("Network creation failed because the valn id being used by another network.") - + self.debug("Network creation failed because the valn id being used by another network. Exception: %s" % e) @attr(tags=["advanced", "advancedns"]) def test_createSharedNetwork_usedVlan2(self): """ Test Shared Network with used vlan 02 """ - + # Steps, # 1. create an Admin account # 2. create a shared NetworkOffering # 3. enable the network offering - # 4. listPhysicalNetworks + # 4. listPhysicalNetworks # - vlan = guest VLAN range = 10-90 (say) # 5. createNetwork # - name = mysharednetwork, displaytext = mysharednetwork @@ -1879,7 +1907,7 @@ class TestSharedNetworks(cloudstackTestCase): # 4. listPhysicalNetworks should return at least one active physical network # 5. network creation shoud PASS # 6. network creation should FAIL since VLAN is already used by previously created network - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -1888,7 +1916,7 @@ class TestSharedNetworks(cloudstackTestCase): domainid=self.domain.id ) self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -1910,25 +1938,25 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin account created: %s" % self.admin_account.id) physical_network, shared_ntwk_vlan = self.getFreeVlan(self.api_client, self.zone.id) self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -1948,17 +1976,17 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -1979,7 +2007,7 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["acltype"] = "Domain" self.services["network"]["networkofferingid"] = self.shared_network_offering.id @@ -1992,9 +2020,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) - + self.cleanup_networks.append(self.network) - + list_networks_response = Network.list( self.api_client, id=self.network.id @@ -2014,14 +2042,14 @@ class TestSharedNetworks(cloudstackTestCase): True, "The network is created with ip range but the flag is set to False." ) - + self.debug("Network created: %s" % self.network.id) - - self.services["network1"]["vlan"] = self.services["network"]["vlan"] + + self.services["network1"]["vlan"] = self.services["network"]["vlan"] self.services["network1"]["acltype"] = "domain" self.services["network1"]["networkofferingid"] = self.shared_network_offering.id self.services["network1"]["physicalnetworkid"] = physical_network.id - + try: self.network1 = Network.create( self.api_client, @@ -2032,12 +2060,12 @@ class TestSharedNetworks(cloudstackTestCase): self.cleanup_networks.append(self.network1) self.fail("Network got created with used vlan id, which is invalid") except Exception as e: - self.debug("Network creation failed because the valn id being used by another network.") + self.debug("Network creation failed because the valn id being used by another network. Exception: %s" % e) @attr(tags=["advanced", "advancedns"]) def test_deployVM_multipleSharedNetwork(self): """ Test Vm deployment with multiple shared networks """ - + # Steps, # 0. create a user account # 1. Create two shared Networks (scope=ALL, different IP ranges) @@ -2047,7 +2075,7 @@ class TestSharedNetworks(cloudstackTestCase): # 1. shared networks should be created successfully # 2. a. VM should deploy successfully # b. VM should be deployed in both networks and have IP in both the networks - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -2057,7 +2085,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -2079,25 +2107,25 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin account created: %s" % self.admin_account.id) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -2117,17 +2145,17 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2148,7 +2176,7 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["acltype"] = "domain" self.services["network"]["networkofferingid"] = self.shared_network_offering.id @@ -2161,9 +2189,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) - + self.cleanup_networks.append(self.network) - + list_networks_response = Network.list( self.api_client, id=self.network.id @@ -2183,9 +2211,9 @@ class TestSharedNetworks(cloudstackTestCase): True, "The network is created with ip range but the flag is set to False." ) - + self.debug("Shared Network created: %s" % self.network.id) - + self.services["network1"]["acltype"] = "domain" self.services["network1"]["networkofferingid"] = self.shared_network_offering.id self.services["network1"]["physicalnetworkid"] = physical_network.id @@ -2197,9 +2225,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) - + self.cleanup_networks.append(self.network1) - + list_networks_response = Network.list( self.api_client, id=self.network1.id @@ -2221,7 +2249,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.debug("Network created: %s" % self.network1.id) - + self.network_admin_account_virtual_machine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], @@ -2245,11 +2273,11 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + self.debug("Virtual Machine created: %s" % self.network_admin_account_virtual_machine.id) - + self.assertTrue(self.network_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") - + self.network1_admin_account_virtual_machine = VirtualMachine.create( self.api_client, self.services["virtual_machine"], @@ -2274,28 +2302,28 @@ class TestSharedNetworks(cloudstackTestCase): "listVirtualMachines returned empty list." ) self.debug("Virtual Machine created: %s" % self.network1_admin_account_virtual_machine.id) - + self.assertTrue(self.network1_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") @attr(tags=["advanced", "advancedns"]) def test_deployVM_isolatedAndShared(self): """ Test VM deployment in shared and isolated networks """ - + # Steps, # 0. create a user account # 1. Create one shared Network (scope=ALL, different IP ranges) - # 2. Create one Isolated Network + # 2. Create one Isolated Network # 3. deployVirtualMachine in both the above networkids within the user account # 4. apply FW rule and enable PF for port 22 for guest VM on isolated network # 5. delete the user account # Validations, # 1. shared network should be created successfully # 2. isolated network should be created successfully - # 3. + # 3. # a. VM should deploy successfully # b. VM should be deployed in both networks and have IP in both the networks # 4. FW and PF should apply successfully, ssh into the VM should work over isolated network - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -2303,9 +2331,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -2327,21 +2355,21 @@ class TestSharedNetworks(cloudstackTestCase): "enabled", "The admin account created is not enabled." ) - + self.debug("Admin type account created: %s" % self.admin_account.name) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False ) - - #Verify that the network offering got created + + #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, id=self.shared_network_offering.id @@ -2361,17 +2389,17 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2392,22 +2420,22 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + self.isolated_network_offering = NetworkOffering.create( self.api_client, self.services["isolated_network_offering"], conservemode=False ) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.isolated_network_offering, - self.api_client, - id=self.isolated_network_offering.id, - state="enabled" - ) - + NetworkOffering.update( + self.isolated_network_offering, + self.api_client, + id=self.isolated_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2428,7 +2456,7 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The isolated network offering state should get updated to Enabled." ) - + self.debug("Isolated Network Offering created: %s" % self.isolated_network_offering.id) physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) @@ -2446,9 +2474,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id ) - + self.cleanup_networks.append(self.shared_network) - + list_networks_response = Network.list( self.api_client, id=self.shared_network.id @@ -2470,7 +2498,7 @@ class TestSharedNetworks(cloudstackTestCase): ) self.debug("Shared Network created: %s" % self.shared_network.id) - + self.isolated_network = Network.create( self.api_client, self.services["isolated_network"], @@ -2479,9 +2507,9 @@ class TestSharedNetworks(cloudstackTestCase): networkofferingid=self.isolated_network_offering.id, zoneid=self.zone.id ) - - self.cleanup_networks.append(self.isolated_network) - + + self.cleanup_networks.append(self.isolated_network) + list_networks_response = Network.list( self.api_client, id=self.isolated_network.id @@ -2496,7 +2524,7 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listNetworks returned empty list." ) - + self.debug("Isolated Network created: %s" % self.isolated_network.id) self.shared_network_admin_account_virtual_machine =\ @@ -2524,7 +2552,7 @@ class TestSharedNetworks(cloudstackTestCase): "listVirtualMachines returned empty list." ) self.debug("Virtual Machine created: %s" % self.shared_network_admin_account_virtual_machine.id) - + self.assertTrue(self.shared_network_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") @@ -2552,11 +2580,11 @@ class TestSharedNetworks(cloudstackTestCase): 0, "listVirtualMachines returned empty list." ) - + self.debug("Virtual Machine created: %s" % self.isolated_network_admin_account_virtual_machine.id) - + self.assertTrue(self.isolated_network_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") - + self.debug("Associating public IP for account: %s" % self.admin_account.name) self.public_ip = PublicIPAddress.create( self.api_client, @@ -2568,7 +2596,7 @@ class TestSharedNetworks(cloudstackTestCase): self.debug("Associated %s with network %s" % (self.public_ip.ipaddress.ipaddress, self.isolated_network.id)) self.debug("Creating PF rule for IP address: %s" % self.public_ip.ipaddress.ipaddress) - + public_ip = self.public_ip.ipaddress # Enable Static NAT for VM @@ -2577,7 +2605,7 @@ class TestSharedNetworks(cloudstackTestCase): public_ip.id, self.isolated_network_admin_account_virtual_machine.id ) - + self.debug("Enabled static NAT for public IP ID: %s" % public_ip.id) #Create Firewall rule on source NAT fw_rule = FireWallRule.create( @@ -2604,8 +2632,8 @@ class TestSharedNetworks(cloudstackTestCase): len(fw_rules), 0, "Length of fw rules response should not be zero" - ) - + ) + # Should be able to SSH VM try: self.debug("SSH into VM: %s" % self.isolated_network_admin_account_virtual_machine.id) @@ -2616,12 +2644,12 @@ class TestSharedNetworks(cloudstackTestCase): @attr(tags=["advanced", "advancedns"]) def test_networkWithsubdomainaccessTrue(self): """ Test Shared Network with subdomainaccess=True """ - + # Steps, # 1. create Network using shared network offering for scope=Account and subdomainaccess=true. # Validations, # (Expected) API should fail saying that subdomainaccess cannot be given when scope is Account - + #Create admin account self.admin_account = Account.create( self.api_client, @@ -2629,9 +2657,9 @@ class TestSharedNetworks(cloudstackTestCase): admin=True, domainid=self.domain.id ) - + self.cleanup_accounts.append(self.admin_account) - + #verify that the account got created with state enabled list_accounts_response = Account.list( self.api_client, @@ -2652,153 +2680,25 @@ class TestSharedNetworks(cloudstackTestCase): list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) - + ) + self.debug("Admin type account created: %s" % self.admin_account.id) - + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - + self.debug("Physical Network found: %s" % physical_network.id) - + self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - + #Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, self.services["network_offering"], conservemode=False - ) - + ) - #Verify that the network offering got created - list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) - self.assertEqual( - isinstance(list_network_offerings_response, list), - True, - "listNetworkOfferings returned invalid object in response." - ) - self.assertNotEqual( - len(list_network_offerings_response), - 0, - "listNetworkOfferings returned empty list." - ) - self.assertEqual( - list_network_offerings_response[0].state, - "Disabled", - "The network offering created should be bydefault disabled." - ) - - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) - - #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) - #Verify that the state of the network offering is updated - list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) - self.assertEqual( - isinstance(list_network_offerings_response, list), - True, - "listNetworkOfferings returned invalid object in response." - ) - self.assertNotEqual( - len(list_network_offerings_response), - 0, - "listNetworkOfferings returned empty list." - ) - self.assertEqual( - list_network_offerings_response[0].state, - "Enabled", - "The network offering state should get updated to Enabled." - ) - - #create network using the shared network offering created - self.services["network"]["acltype"] = "Account" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan - self.services["network"]["subdomainaccess"] = "True" - - try: - self.network = Network.create( - self.api_client, - self.services["network"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) - self.fail("Network creation should fail.") - except: - self.debug("Network creation failed because subdomainaccess parameter was passed when scope was account.") - @attr(tags=["advanced", "advancedns"]) - def test_networkWithsubdomainaccessFalse(self): - """ Test shared Network with subdomainaccess=False """ - - # Steps, - # 1. create Network using shared network offering for scope=Account and subdomainaccess=false - # Validations, - # (Expected) API should fail saying that subdomainaccess cannot be given when scope is Account - - #Create admin account - self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) - - self.cleanup_accounts.append(self.admin_account) - - #verify that the account got created with state enabled - list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) - self.assertEqual( - isinstance(list_accounts_response, list), - True, - "listAccounts returned invalid object in response." - ) - self.assertNotEqual( - len(list_accounts_response), - 0, - "listAccounts returned empty list." - ) - self.assertEqual( - list_accounts_response[0].state, - "enabled", - "The admin account created is not enabled." - ) - - self.debug("Admin type account created: %s" % self.admin_account.id) - - physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) - - self.debug("Physical Network found: %s" % physical_network.id) - - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" - - #Create Network Offering - self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - #Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2819,16 +2719,16 @@ class TestSharedNetworks(cloudstackTestCase): "Disabled", "The network offering created should be bydefault disabled." ) - + self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) - + #Update network offering state from disabled to enabled. - network_offering_update_response = NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) #Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( self.api_client, @@ -2849,14 +2749,142 @@ class TestSharedNetworks(cloudstackTestCase): "Enabled", "The network offering state should get updated to Enabled." ) - + #create network using the shared network offering created self.services["network"]["acltype"] = "Account" self.services["network"]["networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan - self.services["network"]["subdomainaccess"] = "False" - + self.services["network"]["subdomainaccess"] = "True" + + try: + self.network = Network.create( + self.api_client, + self.services["network"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) + self.fail("Network creation should fail.") + except: + self.debug("Network creation failed because subdomainaccess parameter was passed when scope was account.") + + @attr(tags=["advanced", "advancedns"]) + def test_networkWithsubdomainaccessFalse(self): + """ Test shared Network with subdomainaccess=False """ + + # Steps, + # 1. create Network using shared network offering for scope=Account and subdomainaccess=false + # Validations, + # (Expected) API should fail saying that subdomainaccess cannot be given when scope is Account + + #Create admin account + self.admin_account = Account.create( + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) + + self.cleanup_accounts.append(self.admin_account) + + #verify that the account got created with state enabled + list_accounts_response = Account.list( + self.api_client, + id=self.admin_account.id, + listall=True + ) + self.assertEqual( + isinstance(list_accounts_response, list), + True, + "listAccounts returned invalid object in response." + ) + self.assertNotEqual( + len(list_accounts_response), + 0, + "listAccounts returned empty list." + ) + self.assertEqual( + list_accounts_response[0].state, + "enabled", + "The admin account created is not enabled." + ) + + self.debug("Admin type account created: %s" % self.admin_account.id) + + physical_network, shared_vlan = self.getFreeVlan(self.api_client, self.zone.id) + + self.debug("Physical Network found: %s" % physical_network.id) + + self.services["network_offering"]["specifyVlan"] = "True" + self.services["network_offering"]["specifyIpRanges"] = "True" + + #Create Network Offering + self.shared_network_offering = NetworkOffering.create( + self.api_client, + self.services["network_offering"], + conservemode=False + ) + + #Verify that the network offering got created + list_network_offerings_response = NetworkOffering.list( + self.api_client, + id=self.shared_network_offering.id + ) + self.assertEqual( + isinstance(list_network_offerings_response, list), + True, + "listNetworkOfferings returned invalid object in response." + ) + self.assertNotEqual( + len(list_network_offerings_response), + 0, + "listNetworkOfferings returned empty list." + ) + self.assertEqual( + list_network_offerings_response[0].state, + "Disabled", + "The network offering created should be bydefault disabled." + ) + + self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + + #Update network offering state from disabled to enabled. + NetworkOffering.update( + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) + #Verify that the state of the network offering is updated + list_network_offerings_response = NetworkOffering.list( + self.api_client, + id=self.shared_network_offering.id + ) + self.assertEqual( + isinstance(list_network_offerings_response, list), + True, + "listNetworkOfferings returned invalid object in response." + ) + self.assertNotEqual( + len(list_network_offerings_response), + 0, + "listNetworkOfferings returned empty list." + ) + self.assertEqual( + list_network_offerings_response[0].state, + "Enabled", + "The network offering state should get updated to Enabled." + ) + + #create network using the shared network offering created + self.services["network"]["acltype"] = "Account" + self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"]["physicalnetworkid"] = physical_network.id + self.services["network"]["vlan"] = shared_vlan + self.services["network"]["subdomainaccess"] = "False" + try: self.network = Network.create( self.api_client,