From 5b9c889eabc7b37d4d2d7d6b11bd176e0eb71bc1 Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Thu, 19 Mar 2015 17:38:40 +0530 Subject: [PATCH 1/2] CLOUDSTACK-8336: Adding test for shared network restart, with and without cleanup --- .../component/test_shared_networks.py | 446 +++++++++++++----- 1 file changed, 327 insertions(+), 119 deletions(-) diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 4492a3e65b02..86df2fb2cf9b 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -29,15 +29,17 @@ StaticNATRule, FireWallRule, ServiceOffering, - PublicIPAddress) + PublicIPAddress, + Router) from marvin.lib.utils import (cleanup_resources, validateList) from marvin.lib.common import (get_domain, get_zone, get_template, - wait_for_cleanup, - get_free_vlan) + get_free_vlan, + wait_for_cleanup) from marvin.codes import PASS +from ddt import ddt, data import random import netaddr @@ -152,6 +154,7 @@ def __init__(self): } +@ddt class TestSharedNetworks(cloudstackTestCase): @classmethod @@ -293,10 +296,12 @@ def test_sharedNetworkOffering_01(self): # 5. delete the admin account # Validations, # 1. listAccounts name=admin-XABU1, state=enabled returns your account - # 2. listPhysicalNetworks should return at least one active physical network - # 3. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state - # 4. listNetworkOfferings - name=mysharedoffering, should list enabled - # offering + # 2. listPhysicalNetworks should return at least one active physical + # network + # 3. listNetworkOfferings - name=mysharedoffering , should list + # offering in disabled state + # 4. listNetworkOfferings - name=mysharedoffering, should list + # enabled offering # Create an account self.account = Account.create( @@ -432,9 +437,10 @@ def test_sharedNetworkOffering_02(self): # 4. delete the admin account # Validations, # 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 + # 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( @@ -502,10 +508,12 @@ def test_sharedNetworkOffering_02(self): conservemode=False ) self.fail( - "Network offering got created with vlan as False in advance mode and shared guest type, which is invalid case.") + "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. Exception: %s" % + "Network Offering creation failed with vlan as False\ + in advance mode and shared guest type. Exception: %s" % e) @attr(tags=["advanced", "advancedns"], required_hardware="false") @@ -525,9 +533,10 @@ def test_sharedNetworkOffering_03(self): # 4. delete the admin account # Validations, # 1. listAccounts name=admin-XABU1, state=enabled returns your account - # 2. listPhysicalNetworks should return at least one active physical network - # 3. createNetworkOffering fails - ip ranges should be specified when - # creating shared network offering + # 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( @@ -595,12 +604,14 @@ def test_sharedNetworkOffering_03(self): conservemode=False ) 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.") + "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.\ - Exception : %s" % - e) + "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"], required_hardware="false") def test_createSharedNetwork_All(self): @@ -621,19 +632,27 @@ def test_createSharedNetwork_All(self): # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = 123 (say) # - networkofferingid = - # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200, netmask=255.255.255.0 + # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200 + # - netmask=255.255.255.0 # - scope = all # 6. create User account - user-ASJDK - # 7. deployVirtualMachine in this account and in admin account & within networkid = + # 7. deployVirtualMachine in this account and in admin account & + # within networkid = # 8. delete the admin account and the user account # Validations, - # 1. listAccounts name=admin-XABU1, state=enabled returns your account - # 2. listPhysicalNetworks should return at least one active physical network - # 3. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state - # 4. listNetworkOfferings - name=mysharedoffering, should list enabled offering - # 5. listNetworks - name = mysharednetwork should list the successfully created network, verify the guestIp ranges and CIDR are as given in the createNetwork call + # 1. listAccounts name=admin-XABU1, state=enabled returns account + # 2. listPhysicalNetworks should return at least one active + # physical network + # 3. listNetworkOfferings - name=mysharedoffering , should list + # offering in disabled state + # 4. listNetworkOfferings - name=mysharedoffering, should list + # enabled offering + # 5. listNetworks - name = mysharednetwork should list the + # successfully created network, verify the guestIp ranges and + # CIDR are as given in the createNetwork call # 6. No checks reqd - # 7. a. listVirtualMachines should show both VMs in running state in the user account and the admin account + # 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 @@ -808,7 +827,8 @@ def test_createSharedNetwork_All(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug( "Shared Network created for scope domain: %s" % @@ -850,7 +870,8 @@ def test_createSharedNetwork_All(self): 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.") + "Virtual machine ip should be from the ip range assigned to\ + network created.") self.user_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -887,7 +908,8 @@ def test_createSharedNetwork_All(self): 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.") + "Virtual machine ip should be from the ip range assigned to\ + network created.") @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_createSharedNetwork_accountSpecific(self): @@ -909,16 +931,24 @@ def test_createSharedNetwork_accountSpecific(self): # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = 123 (say) # - networkofferingid = - # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200, netmask=255.255.255.0 + # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200 + # - netmask=255.255.255.0 # - scope = account, account = user-SOPJD, domain = ROOT - # 6. deployVirtualMachine in this account and in admin account & within networkid = + # 6. deployVirtualMachine in this account and in admin account + # & within networkid = # 7. delete the admin account and the user account # Validations, - # 1. listAccounts name=admin-XABU1 and user-SOPJD, state=enabled returns your account - # 2. listPhysicalNetworks should return at least one active physical network - # 3. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state - # 4. listNetworkOfferings - name=mysharedoffering, should list enabled offering - # 5. listNetworks - name = mysharednetwork should list the successfully created network, verify the guestIp ranges and CIDR are as given in the createNetwork call + # 1. listAccounts name=admin-XABU1 and user-SOPJD, state=enabled + # returns your account + # 2. listPhysicalNetworks should return at least one active + # physical network + # 3. listNetworkOfferings - name=mysharedoffering , should list + # offering in disabled state + # 4. listNetworkOfferings - name=mysharedoffering, should list + # enabled offering + # 5. listNetworks - name = mysharednetwork should list the + # successfully created network, verify the guestIp ranges and CIDR + # are as given in the createNetwork call # 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 @@ -1096,7 +1126,8 @@ def test_createSharedNetwork_accountSpecific(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug("Network created: %s" % self.network.id) @@ -1110,11 +1141,13 @@ def test_createSharedNetwork_accountSpecific(self): serviceofferingid=self.service_offering.id ) self.fail( - "Virtual Machine got created in admin account with network created but the network used is of scope account and for user account.") + "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. Exception: %s" % - e) + "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, @@ -1147,7 +1180,8 @@ def test_createSharedNetwork_accountSpecific(self): 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.") + "Virtual machine ip should be from the ip range assigned\ + to network created.") @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_createSharedNetwork_domainSpecific(self): @@ -1171,16 +1205,24 @@ def test_createSharedNetwork_domainSpecific(self): # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = 123 (say) # - networkofferingid = - # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200, netmask=255.255.255.0 + # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200 + # - netmask=255.255.255.0 # - scope = domain, domain = DOM - # 6. deployVirtualMachine in this admin, domainadmin and user account & within networkid = + # 6. deployVirtualMachine in this admin, domainadmin and user account + # & within networkid = # 7. delete all the accounts # Validations, - # 1. listAccounts state=enabled returns your accounts, listDomains - DOM should be created - # 2. listPhysicalNetworks should return at least one active physical network - # 3. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state - # 4. listNetworkOfferings - name=mysharedoffering, should list enabled offering - # 5. listNetworks - name = mysharednetwork should list the successfully created network, verify the guestIp ranges and CIDR are as given in the createNetwork call + # 1. listAccounts state=enabled returns your accounts, + # listDomains - DOM should be created + # 2. listPhysicalNetworks should return at least one + # active physical network + # 3. listNetworkOfferings - name=mysharedoffering , should list + # offering in disabled state + # 4. listNetworkOfferings - name=mysharedoffering, should list + # enabled offering + # 5. listNetworks - name = mysharednetwork should list the + # successfully created network, verify the guestIp ranges and + # CIDR are as given in the createNetwork call # 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 @@ -1424,7 +1466,8 @@ def test_createSharedNetwork_domainSpecific(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug("Shared Network created: %s" % self.network.id) @@ -1438,11 +1481,13 @@ def test_createSharedNetwork_domainSpecific(self): serviceofferingid=self.service_offering.id ) 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.") + "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. Exception: %s" % - e) + "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, @@ -1476,7 +1521,8 @@ def test_createSharedNetwork_domainSpecific(self): 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.") + "Virtual machine ip should be from the ip range\ + assigned to network created.") self.domain_admin_account_virtual_machine = VirtualMachine.create( self.api_client, @@ -1510,7 +1556,8 @@ def test_createSharedNetwork_domainSpecific(self): 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.") + "Virtual machine ip should be from the ip range assigne\ + to network created.") @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_createSharedNetwork_projectSpecific(self): @@ -1533,16 +1580,24 @@ def test_createSharedNetwork_projectSpecific(self): # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = 123 (say) # - networkofferingid = - # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200, netmask=255.255.255.0 + # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200 + # - netmask=255.255.255.0 # - scope = project, project = proj-SLDJK - # 6. deployVirtualMachine in admin, project and user account & within networkid = + # 6. deployVirtualMachine in admin, project and user account & within + # networkid = # 7. delete all the accounts # Validations, - # 1. listAccounts state=enabled returns your accounts, listDomains - DOM should be created - # 2. listPhysicalNetworks should return at least one active physical network - # 3. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state - # 4. listNetworkOfferings - name=mysharedoffering, should list enabled offering - # 5. listNetworks - name = mysharednetwork should list the successfully created network, verify the guestIp ranges and CIDR are as given in the createNetwork call + # 1. listAccounts state=enabled returns your accounts, listDomains + # - DOM should be created + # 2. listPhysicalNetworks should return at least one active physical + # network + # 3. listNetworkOfferings - name=mysharedoffering , should list + # offering in disabled state + # 4. listNetworkOfferings - name=mysharedoffering, should list + # enabled offering + # 5. listNetworks - name = mysharednetwork should list the + # successfully created network, verify the guestIp ranges + # and CIDR are as given in the createNetwork call # 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 @@ -1748,17 +1803,19 @@ def test_createSharedNetwork_projectSpecific(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False") self.debug("Shared Network created: %s" % self.network.id) with self.assertRaises(Exception): - self.project2_admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - networkids=self.network.id, - projectid=self.project2.id, - serviceofferingid=self.service_offering.id) + self.project2_admin_account_virtual_machine =\ + VirtualMachine.create( + self.api_client, + self.services["virtual_machine"], + networkids=self.network.id, + projectid=self.project2.id, + serviceofferingid=self.service_offering.id) self.debug("Deploying a vm to project other than the one in which \ network is created raised an Exception as expected") self.project1_admin_account_virtual_machine = VirtualMachine.create( @@ -1791,10 +1848,12 @@ def test_createSharedNetwork_projectSpecific(self): 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.") + "Virtual machine ip should be from the ip range assigned\ + to network created.") @unittest.skip( - "skipped - This is a redundant case and also this is causing issue for rest fo the cases ") + "skipped - This is a redundant case and also this\ + is causing issue for rest fo the cases ") @attr(tags=["advanced", "advancedns", "NA"]) def test_createSharedNetwork_usedVlan(self): """ Test Shared Network with used vlan 01 """ @@ -1809,15 +1868,20 @@ def test_createSharedNetwork_usedVlan(self): # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = any vlan between 10-90 # - networkofferingid = - # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200, netmask=255.255.255.0 + # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200 + # - netmask=255.255.255.0 # - scope = all # 6. delete admin account # Validations, # 1. listAccounts state=enabled returns your account - # 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 + # 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 # Create admin account self.admin_account = Account.create( @@ -1943,8 +2007,8 @@ def test_createSharedNetwork_usedVlan(self): shared_vlan) except Exception as e: self.debug( - "Network creation failed because the valn id being used by another network. Exception: %s" % - e) + "Network creation failed because the valn id being used by\ + another network. Exception: %s" % e) @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_createSharedNetwork_usedVlan2(self): @@ -1960,18 +2024,23 @@ def test_createSharedNetwork_usedVlan2(self): # - name = mysharednetwork, displaytext = mysharednetwork # - vlan = any vlan beyond 10-90 (123 for eg) # - networkofferingid = - # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200, netmask=255.255.255.0 + # - gw = 172.16.15.1, startip = 172.16.15.2 , endip = 172.16.15.200 + # - netmask=255.255.255.0 # - scope = all - # 6. createNetwork again with same VLAN but different IP ranges and gw + # 6. createNetwork again with same VLAN but different IP ranges and + # gateway # 7. delete admin account # Validations, # 1. listAccounts state=enabled returns your account - # 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 + # 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 shoud PASS - # 6. network creation should FAIL since VLAN is already used by - # previously created network + # 6. network creation should FAIL since VLAN is already used by + # previously created network # Create admin account self.admin_account = Account.create( @@ -2112,7 +2181,8 @@ def test_createSharedNetwork_usedVlan2(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug("Network created: %s" % self.network.id) @@ -2134,8 +2204,8 @@ def test_createSharedNetwork_usedVlan2(self): "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. Exception: %s" % - e) + "Network creation failed because the valn id being used by\ + another network. Exception: %s" % e) @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_deployVM_multipleSharedNetwork(self): @@ -2144,7 +2214,8 @@ def test_deployVM_multipleSharedNetwork(self): # Steps, # 0. create a user account # 1. Create two shared Networks (scope=ALL, different IP ranges) - # 2. deployVirtualMachine in both the above networkids within the user account + # 2. deployVirtualMachine in both the above networkids within the + # user account # 3. delete the user account # Validations, # 1. shared networks should be created successfully @@ -2290,7 +2361,8 @@ def test_deployVM_multipleSharedNetwork(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug("Shared Network created: %s" % self.network.id) @@ -2331,7 +2403,8 @@ def test_deployVM_multipleSharedNetwork(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug("Network created: %s" % self.network1.id) @@ -2364,7 +2437,8 @@ def test_deployVM_multipleSharedNetwork(self): self.network_admin_account_virtual_machine.id) self.assertTrue( - self.network_admin_account_virtual_machine.nic[0].ipaddress is not None, + 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( @@ -2395,7 +2469,8 @@ def test_deployVM_multipleSharedNetwork(self): self.network1_admin_account_virtual_machine.id) self.assertTrue( - self.network1_admin_account_virtual_machine.nic[0].ipaddress is not None, + self.network1_admin_account_virtual_machine.nic[0].ipaddress + is not None, "ip should be assigned to running virtual machine") @attr(tags=["advanced", "advancedns"], required_hardware="true") @@ -2406,15 +2481,18 @@ def test_deployVM_isolatedAndShared(self): # 0. create a user account # 1. Create one shared Network (scope=ALL, different IP ranges) # 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 + # 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. # a. VM should deploy successfully - # b. VM should be deployed in both networks and have IP in both the networks + # 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 @@ -2548,7 +2626,8 @@ def test_deployVM_isolatedAndShared(self): self.assertEqual( list_network_offerings_response[0].state, "Enabled", - "The isolated network offering state should get updated to Enabled.") + "The isolated network offering state should get\ + updated to Enabled.") self.debug( "Isolated Network Offering created: %s" % @@ -2594,7 +2673,8 @@ def test_deployVM_isolatedAndShared(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "The network is created with ip range but the flag is\ + set to False.") self.debug("Shared Network created: %s" % self.shared_network.id) @@ -2655,7 +2735,8 @@ def test_deployVM_isolatedAndShared(self): self.shared_network_admin_account_virtual_machine.id) self.assertTrue( - self.shared_network_admin_account_virtual_machine.nic[0].ipaddress is not None, + self.shared_network_admin_account_virtual_machine.nic[0].ipaddress + is not None, "ip should be assigned to running virtual machine") self.isolated_network_admin_account_virtual_machine = \ @@ -2688,7 +2769,8 @@ def test_deployVM_isolatedAndShared(self): self.isolated_network_admin_account_virtual_machine.id) self.assertTrue( - self.isolated_network_admin_account_virtual_machine.nic[0].ipaddress is not None, + self.isolated_network_admin_account_virtual_machine.nic[0].ipaddress + is not None, "ip should be assigned to running virtual machine") self.debug( @@ -2756,16 +2838,19 @@ def test_deployVM_isolatedAndShared(self): except Exception as e: self.fail( "SSH Access failed for %s: %s" % - (self.isolated_network_admin_account_virtual_machine.ipaddress, e)) + (self.isolated_network_admin_account_virtual_machine.ipaddress, + e)) @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_networkWithsubdomainaccessTrue(self): """ Test Shared Network with subdomainaccess=True """ # Steps, - # 1. create Network using shared network offering for scope=Account and subdomainaccess=true. + # 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 + # (Expected) API should fail saying that subdomainaccess cannot be + # given when scope is Account # Create admin account self.admin_account = Account.create( @@ -2891,16 +2976,19 @@ def test_networkWithsubdomainaccessTrue(self): self.fail("Network creation should fail.") except: self.debug( - "Network creation failed because subdomainaccess parameter was passed when scope was account.") + "Network creation failed because subdomainaccess parameter was\ + passed when scope was account.") @attr(tags=["advanced", "advancedns"], required_hardware="false") 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 + # 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( @@ -3026,7 +3114,8 @@ def test_networkWithsubdomainaccessFalse(self): self.fail("Network creation should fail.") except: self.debug( - "Network creation failed because subdomainaccess parameter was passed when scope was account.") + "Network creation failed because subdomainaccess parameter\ + was passed when scope was account.") @attr(tags=["advanced"], required_hardware="false") def test_escalation_ES1621(self): @@ -3039,12 +3128,17 @@ def test_escalation_ES1621(self): Step3: Update the network offering to Enabled state Step4: list network offering Step5: Create network with above offering - Step6: List netwokrs and verify the network created in step5 in the response - Step7: Create another network with offering,vlan and ip range same as in step6 + Step6: List netwokrs and verify the network created in + step5 in the response + Step7: Create another network with offering,vlan and ip range + same as in step6 Step8: Verify that network creationin Step7 should fail - Step9: Repeat step6 with diff vlan but same ip range and network offering - Step10: List netwokrs and verify the network created in step9 in the response - Step11: Dislable network offering for the cleanup to delete at the end of the test + Step9: Repeat step6 with diff vlan but same ip range and network + offering + Step10: List netwokrs and verify the network created in step9 + in the response + Step11: Dislable network offering for the cleanup to delete at + the end of the test """ # Creating Admin account self.admin_account = Account.create( @@ -3120,7 +3214,8 @@ def test_escalation_ES1621(self): self.assertEquals( PASS, status[0], - "listNetworkOfferings returned invalid object in response after enabling it." + "listNetworkOfferings returned invalid object in\ + response after enabling it." ) self.assertEqual( list_network_offerings_response[0].state, @@ -3153,7 +3248,8 @@ def test_escalation_ES1621(self): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False.") + "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) @@ -3167,7 +3263,8 @@ def test_escalation_ES1621(self): ) self.cleanup_networks.append(self.network1) self.fail( - "CS is allowing to create shared network with ip range and vlan same as used by another shared network") + "CS is allowing to create shared network with ip range and\ + vlan same as used by another shared network") except Exception as e: self.debug("Network Creation Exception Raised: %s" % e) # Create another shared network with overlapped ip range but different @@ -3192,13 +3289,14 @@ def test_escalation_ES1621(self): self.assertEquals( PASS, status[0], - "listNetworks returned invalid object in response after creating with overlapped ip range in diff vlan." + "listNetworks returned invalid object in response after\ + creating with overlapped ip range in diff vlan." ) self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False after creating with overlapped ip range in diff vlan." - ) + "The network is created with ip range but the flag is set to\ + False after creating with overlapped ip range in diff vlan") self.debug( "Shared Network created for scope domain: %s" % self.network2.id) @@ -3211,3 +3309,113 @@ def test_escalation_ES1621(self): ) self.cleanup_networks.append(self.shared_network_offering) return + + @data(True, False) + @attr(tags=["advanced", "advancedns", "dvs"], required_hardware="false") + def test_restart_network(self, cleanup): + """ Test restart shared Network + + # Steps + # 1. Create a shared network in an account + # 2. Deploy a VM in the network + # 3. Restart the network with cleanup true and false + # 4. List the router for the network and verify that publicip of + the router remain the same + """ + + # Create admin account + account = Account.create( + self.api_client, + self.services["account"], + domainid=self.domain.id + ) + self.cleanup_accounts.append(account) + + physical_network, shared_vlan = get_free_vlan( + self.api_client, self.zone.id) + if shared_vlan is None: + self.fail("Failed to get free vlan id for shared network") + + self.debug("Physical network found: %s" % physical_network.id) + + self.services["network_offering"]["specifyVlan"] = "True" + self.services["network_offering"]["specifyIpRanges"] = "True" + + # Create Network Offering + shared_network_offering = NetworkOffering.create( + self.api_client, + self.services["network_offering"], + conservemode=False + ) + + # Update network offering state from disabled to enabled. + NetworkOffering.update( + shared_network_offering, + self.api_client, + id=shared_network_offering.id, + state="enabled" + ) + #self._cleanup.append(shared_network_offering) + + # create network using the shared network offering created + self.services["network"]["acltype"] = "Domain" + self.services["network"][ + "networkofferingid"] = shared_network_offering.id + self.services["network"]["physicalnetworkid"] = physical_network.id + self.services["network"]["vlan"] = shared_vlan + + shared_network = Network.create( + self.api_client, + self.services["network"], + networkofferingid=shared_network_offering.id, + zoneid=self.zone.id, + ) + + self.cleanup_networks.append(shared_network) + + self.debug( + "Shared Network created for scope domain: %s" % + shared_network.id) + + VirtualMachine.create( + self.api_client, + self.services["virtual_machine"], + networkids=shared_network.id, + serviceofferingid=self.service_offering.id + ) + + list_router_response = Router.list( + self.api_client, + networkid=shared_network.id, + listall=True + ) + self.assertEqual( + validateList(list_router_response)[0], + PASS, + "Router list validation failed" + ) + router = list_router_response[0] + # Store old values before restart + old_publicip = router.publicip + + shared_network.restart(self.api_client, cleanup=cleanup) + + # Get router details after restart + list_router_response = Router.list( + self.api_client, + networkid=shared_network.id, + listall=True + ) + self.assertEqual( + validateList(list_router_response)[0], + PASS, + "Router list validation failed" + ) + router = list_router_response[0] + + self.assertEqual( + router.publicip, + old_publicip, + "Public IP of the router should remain same after network restart" + ) + return From d50414031a0a586202db6a12e8ff2676f79f8957 Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Fri, 20 Mar 2015 14:36:54 +0530 Subject: [PATCH 2/2] Adding more test case for shared network --- .../component/test_shared_networks.py | 901 +++++++++++------- tools/marvin/marvin/lib/common.py | 32 +- 2 files changed, 604 insertions(+), 329 deletions(-) diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 86df2fb2cf9b..dde5983b8734 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -19,6 +19,7 @@ """ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest +from marvin.cloudstackAPI import rebootRouter, stopRouter, startRouter from marvin.lib.base import (Account, Network, NetworkOffering, @@ -30,130 +31,24 @@ FireWallRule, ServiceOffering, PublicIPAddress, - Router) + Router, + NATRule) from marvin.lib.utils import (cleanup_resources, validateList) from marvin.lib.common import (get_domain, get_zone, get_template, get_free_vlan, - wait_for_cleanup) + wait_for_cleanup, + verifyRouterState) +from marvin.sshClient import SshClient from marvin.codes import PASS from ddt import ddt, data +import time import random import netaddr -class Services: - - """ Test shared networks """ - - def __init__(self): - self.services = { - "domain": { - "name": "DOM", - }, - "project": { - "name": "Project", - "displaytext": "Test project", - }, - "account": { - "email": "admin-XABU1@test.com", - "firstname": "admin-XABU1", - "lastname": "admin-XABU1", - "username": "admin-XABU1", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "network_offering": { - "name": 'MySharedOffering', - "displaytext": 'MySharedOffering', - "guestiptype": 'Shared', - "supportedservices": 'Dhcp,Dns,UserData', - "specifyVlan": "False", - "specifyIpRanges": "False", - "traffictype": 'GUEST', - "serviceProviderList": { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "UserData": 'VirtualRouter' - }, - }, - "network": { - "name": "MySharedNetwork - Test", - "displaytext": "MySharedNetwork", - "gateway": "", - "netmask": "255.255.255.0", - "startip": "", - "endip": "", - "acltype": "Domain", - "scope": "all", - }, - "network1": { - "name": "MySharedNetwork - Test1", - "displaytext": "MySharedNetwork1", - "gateway": "", - "netmask": "255.255.255.0", - "startip": "", - "endip": "", - "acltype": "Domain", - "scope": "all", - }, - "isolated_network_offering": { - "name": 'Network offering-VR services', - "displaytext": 'Network offering-VR services', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList": { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - "Vpn": 'VirtualRouter', - "Firewall": 'VirtualRouter', - "Lb": 'VirtualRouter', - "UserData": 'VirtualRouter', - "StaticNat": 'VirtualRouter', - }, - }, - "isolated_network": { - "name": "Isolated Network", - "displaytext": "Isolated Network", - }, - "fw_rule": { - "startport": 22, - "endport": 22, - "cidr": '0.0.0.0/0', - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - # Hypervisor type should be same as - # hypervisor type of cluster - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - # Cent OS 5.3 (64 bit) - "timeout": 10, - "mode": 'advanced' - } - - @ddt class TestSharedNetworks(cloudstackTestCase): @@ -162,26 +57,58 @@ def setUpClass(cls): cls.testClient = super(TestSharedNetworks, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + cls.testdata = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, - cls.services["ostype"] + cls.testdata["ostype"] ) - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id + cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id + cls.testdata["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( cls.api_client, - cls.services["service_offering"] + cls.testdata["service_offering"] + ) + + cls.testdata["shared_network_offering"]["specifyVlan"] = "True" + cls.testdata["shared_network_offering"]["specifyIpRanges"] = "True" + + cls.shared_network_offering = NetworkOffering.create( + cls.api_client, + cls.testdata["shared_network_offering"], + conservemode=False + ) + + NetworkOffering.update( + cls.shared_network_offering, + cls.api_client, + id=cls.shared_network_offering.id, + state="enabled" + ) + + cls.testdata["shared_network_offering_all_services"]["specifyVlan"] = "True" + cls.testdata["shared_network_offering_all_services"]["specifyIpRanges"] = "True" + + cls.shared_network_offering_all_services = NetworkOffering.create( + cls.api_client, + cls.testdata["shared_network_offering_all_services"], + conservemode=False + ) + + NetworkOffering.update( + cls.shared_network_offering_all_services, + cls.api_client, + id=cls.shared_network_offering_all_services.id, + state="enabled" ) cls._cleanup = [ - cls.service_offering, + cls.service_offering ] return @@ -202,20 +129,14 @@ def setUp(self): # of each test case to avoid overlapping of ip addresses shared_network_subnet_number = random.randrange(1, 254) - self.services["network"]["gateway"] = "172.16." + \ + self.testdata["shared_network"]["netmask"] = "255.255.255.0" + self.testdata["shared_network"]["gateway"] = "172.16." + \ str(shared_network_subnet_number) + ".1" - self.services["network"]["startip"] = "172.16." + \ + self.testdata["shared_network"]["startip"] = "172.16." + \ str(shared_network_subnet_number) + ".2" - self.services["network"]["endip"] = "172.16." + \ + self.testdata["shared_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 = [] @@ -278,6 +199,13 @@ def tearDown(self): return + def verifyRouterResponse(self, router_response, ip): + if (router_response) and (isinstance(router_response, list)) and \ + (router_response[0].state == "Running") and \ + (router_response[0].publicip == ip): + return True + return False + @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_sharedNetworkOffering_01(self): """ Test shared network Offering 01 """ @@ -306,7 +234,7 @@ def test_sharedNetworkOffering_01(self): # Create an account self.account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -358,13 +286,13 @@ def test_sharedNetworkOffering_01(self): self.debug("Physical network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -445,7 +373,7 @@ def test_sharedNetworkOffering_02(self): # Create an account self.account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -497,14 +425,14 @@ def test_sharedNetworkOffering_02(self): self.debug("Physical network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "False" - self.services["network_offering"]["specifyIpRanges"] = "False" + self.testdata["shared_network_offering"]["specifyVlan"] = "False" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "False" try: # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) self.fail( @@ -541,7 +469,7 @@ def test_sharedNetworkOffering_03(self): # Create an account self.account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -593,14 +521,14 @@ def test_sharedNetworkOffering_03(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "False" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "False" try: # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) self.fail( @@ -658,7 +586,7 @@ def test_createSharedNetwork_All(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -692,7 +620,7 @@ def test_createSharedNetwork_All(self): # Create an user account self.user_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=False, domainid=self.domain.id ) @@ -730,13 +658,13 @@ def test_createSharedNetwork_All(self): self.debug("Physical network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -795,15 +723,16 @@ def test_createSharedNetwork_All(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "Domain" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -836,7 +765,7 @@ def test_createSharedNetwork_All(self): self.admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], networkids=self.network.id, serviceofferingid=self.service_offering.id ) @@ -866,8 +795,8 @@ def test_createSharedNetwork_All(self): ip_range = list( netaddr.iter_iprange( unicode( - self.services["network"]["startip"]), unicode( - self.services["network"]["endip"]))) + self.testdata["shared_network"]["startip"]), unicode( + self.testdata["shared_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\ @@ -875,7 +804,7 @@ def test_createSharedNetwork_All(self): self.user_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.user_account.name, domainid=self.user_account.domainid, serviceofferingid=self.service_offering.id, @@ -904,8 +833,8 @@ def test_createSharedNetwork_All(self): ip_range = list( netaddr.iter_iprange( unicode( - self.services["network"]["startip"]), unicode( - self.services["network"]["endip"]))) + self.testdata["shared_network"]["startip"]), unicode( + self.testdata["shared_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\ @@ -956,7 +885,7 @@ def test_createSharedNetwork_accountSpecific(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -990,7 +919,7 @@ def test_createSharedNetwork_accountSpecific(self): # Create an user account self.user_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=False, domainid=self.domain.id ) @@ -1028,13 +957,13 @@ def test_createSharedNetwork_accountSpecific(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -1092,15 +1021,16 @@ def test_createSharedNetwork_accountSpecific(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "Account" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "Account" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], accountid=self.user_account.name, domainid=self.user_account.domainid, networkofferingid=self.shared_network_offering.id, @@ -1134,7 +1064,7 @@ def test_createSharedNetwork_accountSpecific(self): try: self.admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkids=self.network.id, @@ -1151,7 +1081,7 @@ def test_createSharedNetwork_accountSpecific(self): self.user_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.user_account.name, domainid=self.user_account.domainid, networkids=self.network.id, @@ -1176,8 +1106,8 @@ def test_createSharedNetwork_accountSpecific(self): ip_range = list( netaddr.iter_iprange( unicode( - self.services["network"]["startip"]), unicode( - self.services["network"]["endip"]))) + self.testdata["shared_network"]["startip"]), unicode( + self.testdata["shared_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\ @@ -1230,7 +1160,7 @@ def test_createSharedNetwork_domainSpecific(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -1264,7 +1194,7 @@ def test_createSharedNetwork_domainSpecific(self): # create domain self.dom_domain = Domain.create( self.api_client, - self.services["domain"], + self.testdata["domain"], ) self.cleanup_domains.append(self.dom_domain) @@ -1290,7 +1220,7 @@ def test_createSharedNetwork_domainSpecific(self): # Create admin account self.domain_admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.dom_domain.id ) @@ -1326,7 +1256,7 @@ def test_createSharedNetwork_domainSpecific(self): # Create an user account self.domain_user_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=False, domainid=self.dom_domain.id ) @@ -1366,13 +1296,13 @@ def test_createSharedNetwork_domainSpecific(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -1431,15 +1361,16 @@ def test_createSharedNetwork_domainSpecific(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "domain" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], accountid=self.domain_admin_account.name, domainid=self.dom_domain.id, networkofferingid=self.shared_network_offering.id, @@ -1474,7 +1405,7 @@ def test_createSharedNetwork_domainSpecific(self): try: self.admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkids=self.network.id, @@ -1491,7 +1422,7 @@ def test_createSharedNetwork_domainSpecific(self): self.domain_user_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.domain_user_account.name, domainid=self.domain_user_account.domainid, networkids=self.network.id, @@ -1517,8 +1448,8 @@ def test_createSharedNetwork_domainSpecific(self): ip_range = list( netaddr.iter_iprange( unicode( - self.services["network"]["startip"]), unicode( - self.services["network"]["endip"]))) + self.testdata["shared_network"]["startip"]), unicode( + self.testdata["shared_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\ @@ -1526,7 +1457,7 @@ def test_createSharedNetwork_domainSpecific(self): self.domain_admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.domain_admin_account.name, domainid=self.domain_admin_account.domainid, networkids=self.network.id, @@ -1552,8 +1483,8 @@ def test_createSharedNetwork_domainSpecific(self): ip_range = list( netaddr.iter_iprange( unicode( - self.services["network"]["startip"]), unicode( - self.services["network"]["endip"]))) + self.testdata["shared_network"]["startip"]), unicode( + self.testdata["shared_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 assigne\ @@ -1605,7 +1536,7 @@ def test_createSharedNetwork_projectSpecific(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -1636,12 +1567,12 @@ def test_createSharedNetwork_projectSpecific(self): self.debug("Admin account created: %s" % self.admin_account.id) - self.services["project"]["name"] = "proj-SADJKS" - self.services["project"]["displaytext"] = "proj-SADJKS" + self.testdata["project"]["name"] = "proj-SADJKS" + self.testdata["project"]["displaytext"] = "proj-SADJKS" self.project1 = Project.create( self.api_client, - self.services["project"], + self.testdata["project"], account=self.admin_account.name, domainid=self.admin_account.domainid ) @@ -1666,12 +1597,12 @@ def test_createSharedNetwork_projectSpecific(self): self.debug("Project created: %s" % self.project1.id) - self.services["project"]["name"] = "proj-SLDJK" - self.services["project"]["displaytext"] = "proj-SLDJK" + self.testdata["project"]["name"] = "proj-SLDJK" + self.testdata["project"]["displaytext"] = "proj-SLDJK" self.project2 = Project.create( self.api_client, - self.services["project"], + self.testdata["project"], account=self.admin_account.name, domainid=self.admin_account.domainid ) @@ -1703,13 +1634,13 @@ def test_createSharedNetwork_projectSpecific(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -1768,15 +1699,16 @@ def test_createSharedNetwork_projectSpecific(self): self.shared_network_offering.id) # create network using the shared network offering created - self.services["network"]["acltype"] = "account" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "account" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], projectid=self.project1.id, domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, @@ -1812,7 +1744,7 @@ def test_createSharedNetwork_projectSpecific(self): self.project2_admin_account_virtual_machine =\ VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], networkids=self.network.id, projectid=self.project2.id, serviceofferingid=self.service_offering.id) @@ -1820,7 +1752,7 @@ def test_createSharedNetwork_projectSpecific(self): network is created raised an Exception as expected") self.project1_admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], networkids=self.network.id, projectid=self.project1.id, serviceofferingid=self.service_offering.id @@ -1844,8 +1776,8 @@ def test_createSharedNetwork_projectSpecific(self): ip_range = list( netaddr.iter_iprange( unicode( - self.services["network"]["startip"]), unicode( - self.services["network"]["endip"]))) + self.testdata["shared_network"]["startip"]), unicode( + self.testdata["shared_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\ @@ -1886,7 +1818,7 @@ def test_createSharedNetwork_usedVlan(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -1922,13 +1854,13 @@ def test_createSharedNetwork_usedVlan(self): if shared_vlan is None: self.fail("Failed to get free vlan id for shared network") - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -1987,18 +1919,19 @@ def test_createSharedNetwork_usedVlan(self): ) # create network using the shared network offering created - self.services["network"]["vlan"] = str.split( + self.testdata["shared_network"]["vlan"] = str.split( str(physical_network.vlan), "-")[0] - self.services["network"]["acltype"] = "domain" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan try: self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -2045,7 +1978,7 @@ def test_createSharedNetwork_usedVlan2(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -2082,13 +2015,13 @@ def test_createSharedNetwork_usedVlan2(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -2147,17 +2080,18 @@ def test_createSharedNetwork_usedVlan2(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "Domain" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.debug( "Creating a shared network in non-cloudstack VLAN %s" % shared_vlan) self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -2186,16 +2120,25 @@ def test_createSharedNetwork_usedVlan2(self): self.debug("Network created: %s" % self.network.id) - self.services["network1"]["vlan"] = self.services["network"]["vlan"] - self.services["network1"]["acltype"] = "domain" - self.services["network1"][ + shared_network_subnet_number = random.randrange(1, 254) + + self.testdata["shared_network"]["gateway"] = "172.16." + \ + str(shared_network_subnet_number) + ".1" + self.testdata["shared_network"]["startip"] = "172.16." + \ + str(shared_network_subnet_number) + ".2" + self.testdata["shared_network"]["endip"] = "172.16." + \ + str(shared_network_subnet_number) + ".20" + + self.testdata["shared_network"]["acltype"] = "domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network1"]["physicalnetworkid"] = physical_network.id + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id try: self.network1 = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -2226,7 +2169,7 @@ def test_deployVM_multipleSharedNetwork(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -2264,13 +2207,13 @@ def test_deployVM_multipleSharedNetwork(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -2329,15 +2272,16 @@ def test_deployVM_multipleSharedNetwork(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "domain" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -2366,20 +2310,30 @@ def test_deployVM_multipleSharedNetwork(self): self.debug("Shared Network created: %s" % self.network.id) - self.services["network1"]["acltype"] = "domain" - self.services["network1"][ + shared_network_subnet_number = random.randrange(1, 254) + + self.testdata["shared_network"]["gateway"] = "172.16." + \ + str(shared_network_subnet_number) + ".1" + self.testdata["shared_network"]["startip"] = "172.16." + \ + str(shared_network_subnet_number) + ".2" + self.testdata["shared_network"]["endip"] = "172.16." + \ + str(shared_network_subnet_number) + ".20" + + self.testdata["shared_network"]["acltype"] = "domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network1"]["physicalnetworkid"] = physical_network.id + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id shared_vlan = get_free_vlan(self.api_client, self.zone.id)[1] if shared_vlan is None: self.fail("Failed to get free vlan id for shared network") - self.services["network1"]["vlan"] = shared_vlan + self.testdata["shared_network"]["vlan"] = shared_vlan self.network1 = Network.create( self.api_client, - self.services["network1"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -2410,7 +2364,7 @@ def test_deployVM_multipleSharedNetwork(self): self.network_admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkids=self.network.id, @@ -2443,7 +2397,7 @@ def test_deployVM_multipleSharedNetwork(self): self.network1_admin_account_virtual_machine = VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkids=self.network1.id, @@ -2499,7 +2453,7 @@ def test_deployVM_isolatedAndShared(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -2530,13 +2484,13 @@ def test_deployVM_isolatedAndShared(self): self.debug("Admin type account created: %s" % self.admin_account.name) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -2596,7 +2550,7 @@ def test_deployVM_isolatedAndShared(self): self.isolated_network_offering = NetworkOffering.create( self.api_client, - self.services["isolated_network_offering"], + self.testdata["isolated_network_offering"], conservemode=False ) @@ -2639,15 +2593,16 @@ def test_deployVM_isolatedAndShared(self): self.fail("Failed to get free vlan id for shared network") # create network using the shared network offering created - self.services["network"]["acltype"] = "domain" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.shared_network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, @@ -2680,7 +2635,7 @@ def test_deployVM_isolatedAndShared(self): self.isolated_network = Network.create( self.api_client, - self.services["isolated_network"], + self.testdata["isolated_network"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkofferingid=self.isolated_network_offering.id, @@ -2709,7 +2664,7 @@ def test_deployVM_isolatedAndShared(self): self.shared_network_admin_account_virtual_machine = \ VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkids=self.shared_network.id, @@ -2742,7 +2697,7 @@ def test_deployVM_isolatedAndShared(self): self.isolated_network_admin_account_virtual_machine = \ VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkids=self.isolated_network.id, @@ -2806,9 +2761,9 @@ def test_deployVM_isolatedAndShared(self): self.api_client, ipaddressid=self.public_ip.ipaddress.id, protocol='TCP', - cidrlist=[self.services["fw_rule"]["cidr"]], - startport=self.services["fw_rule"]["startport"], - endport=self.services["fw_rule"]["endport"] + cidrlist=[self.testdata["fwrule"]["cidr"]], + startport=self.testdata["fwrule"]["startport"], + endport=self.testdata["fwrule"]["endport"] ) self.debug("Created firewall rule: %s" % fw_rule.id) @@ -2855,7 +2810,7 @@ def test_networkWithsubdomainaccessTrue(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -2893,13 +2848,13 @@ def test_networkWithsubdomainaccessTrue(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -2957,17 +2912,18 @@ def test_networkWithsubdomainaccessTrue(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "Account" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "Account" + self.testdata["shared_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" + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan + self.testdata["shared_network"]["subdomainaccess"] = "True" try: self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, @@ -2993,7 +2949,7 @@ def test_networkWithsubdomainaccessFalse(self): # Create admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -3031,13 +2987,13 @@ def test_networkWithsubdomainaccessFalse(self): self.debug("Physical Network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) @@ -3095,17 +3051,18 @@ def test_networkWithsubdomainaccessFalse(self): ) # create network using the shared network offering created - self.services["network"]["acltype"] = "Account" - self.services["network"][ + self.testdata["shared_network"]["acltype"] = "Account" + self.testdata["shared_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.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan + self.testdata["shared_network"]["subdomainaccess"] = "False" try: self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], accountid=self.admin_account.name, domainid=self.admin_account.domainid, networkofferingid=self.shared_network_offering.id, @@ -3143,7 +3100,7 @@ def test_escalation_ES1621(self): # Creating Admin account self.admin_account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], admin=True, domainid=self.domain.id ) @@ -3171,12 +3128,12 @@ def test_escalation_ES1621(self): if shared_vlan is None: self.fail("Failed to get free vlan id for shared network") self.debug("Physical network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" + self.testdata["shared_network_offering"]["specifyVlan"] = "True" + self.testdata["shared_network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( self.api_client, - self.services["network_offering"], + self.testdata["shared_network_offering"], conservemode=False ) # Verify that the network offering got created @@ -3223,14 +3180,15 @@ def test_escalation_ES1621(self): "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"][ + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ "networkofferingid"] = self.shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan self.network = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -3257,7 +3215,7 @@ def test_escalation_ES1621(self): try: self.network1 = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -3273,10 +3231,10 @@ def test_escalation_ES1621(self): self.api_client, self.zone.id) if shared_vlan1 is None: self.fail("Failed to get free vlan id for shared network") - self.services["network"]["vlan"] = shared_vlan1 + self.testdata["shared_network"]["vlan"] = shared_vlan1 self.network2 = Network.create( self.api_client, - self.services["network"], + self.testdata["shared_network"], networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -3326,7 +3284,7 @@ def test_restart_network(self, cleanup): # Create admin account account = Account.create( self.api_client, - self.services["account"], + self.testdata["account"], domainid=self.domain.id ) self.cleanup_accounts.append(account) @@ -3338,36 +3296,18 @@ def test_restart_network(self, cleanup): self.debug("Physical network found: %s" % physical_network.id) - self.services["network_offering"]["specifyVlan"] = "True" - self.services["network_offering"]["specifyIpRanges"] = "True" - - # Create Network Offering - shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - - # Update network offering state from disabled to enabled. - NetworkOffering.update( - shared_network_offering, - self.api_client, - id=shared_network_offering.id, - state="enabled" - ) - #self._cleanup.append(shared_network_offering) - # create network using the shared network offering created - self.services["network"]["acltype"] = "Domain" - self.services["network"][ - "networkofferingid"] = shared_network_offering.id - self.services["network"]["physicalnetworkid"] = physical_network.id - self.services["network"]["vlan"] = shared_vlan + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ + "networkofferingid"] = self.shared_network_offering.id + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan shared_network = Network.create( self.api_client, - self.services["network"], - networkofferingid=shared_network_offering.id, + self.testdata["shared_network"], + networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id, ) @@ -3379,7 +3319,7 @@ def test_restart_network(self, cleanup): VirtualMachine.create( self.api_client, - self.services["virtual_machine"], + self.testdata["virtual_machine"], networkids=shared_network.id, serviceofferingid=self.service_offering.id ) @@ -3419,3 +3359,316 @@ def test_restart_network(self, cleanup): "Public IP of the router should remain same after network restart" ) return + + @attr(tags=["advanced", "advancedns", "dvs"], required_hardware="false") + def test_reboot_router(self): + """Test reboot router + + # Steps + # 1. Create a shared network in an account + # 2. Deploy a VM in the network + # 3. Restart the router related to shared network + # 4. List the router for the network and verify that publicip of + the router remain the same + """ + + # Create admin account + account = Account.create( + self.api_client, + self.testdata["account"], + domainid=self.domain.id + ) + self.cleanup_accounts.append(account) + + physical_network, shared_vlan = get_free_vlan( + self.api_client, self.zone.id) + if shared_vlan is None: + self.fail("Failed to get free vlan id for shared network") + + self.debug("Physical network found: %s" % physical_network.id) + + # create network using the shared network offering created + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ + "networkofferingid"] = self.shared_network_offering.id + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan + + shared_network = Network.create( + self.api_client, + self.testdata["shared_network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) + + self.cleanup_networks.append(shared_network) + + self.debug( + "Shared Network created for scope domain: %s" % + shared_network.id) + + vm = VirtualMachine.create( + self.api_client, + self.testdata["virtual_machine"], + networkids=shared_network.id, + serviceofferingid=self.service_offering.id + ) + self.cleanup_vms.append(vm) + + list_router_response = Router.list( + self.api_client, + networkid=shared_network.id, + listall=True + ) + self.assertEqual( + validateList(list_router_response)[0], + PASS, + "Router list validation failed" + ) + router = list_router_response[0] + # Store old values before restart + public_ip = router.publicip + + self.debug("Rebooting the router with ID: %s" % router.id) + # Stop the router + cmd = rebootRouter.rebootRouterCmd() + cmd.id = router.id + self.api_client.rebootRouter(cmd) + + isRouterRunningSuccessfully = False + + # List routers to check state of router + retries_cnt = 6 + while retries_cnt >= 0: + router_response = Router.list( + self.api_client, + id=router.id + ) + if self.verifyRouterResponse(router_response, public_ip): + isRouterRunningSuccessfully = True + break + time.sleep(10) + retries_cnt = retries_cnt - 1 + + if not isRouterRunningSuccessfully: + self.fail( + "Router response after reboot is either is invalid\ + or in stopped state") + return + + @attr(tags=["advanced", "advancedns", "dvs"], required_hardware="false") + def test_stop_start_router(self): + """Test stop and start router + + # Steps + # 1. Create a shared network in an account + # 2. Deploy a VM in the network + # 3. Stop the router related to shared network and start it again + # 4. List the router for the network and verify that publicip of + the router remain the same + """ + + # Create admin account + account = Account.create( + self.api_client, + self.testdata["account"], + domainid=self.domain.id + ) + self.cleanup_accounts.append(account) + + physical_network, shared_vlan = get_free_vlan( + self.api_client, self.zone.id) + if shared_vlan is None: + self.fail("Failed to get free vlan id for shared network") + + self.debug("Physical network found: %s" % physical_network.id) + + # create network using the shared network offering created + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ + "networkofferingid"] = self.shared_network_offering.id + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan + + shared_network = Network.create( + self.api_client, + self.testdata["shared_network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) + + self.cleanup_networks.append(shared_network) + + self.debug( + "Shared Network created for scope domain: %s" % + shared_network.id) + + vm = VirtualMachine.create( + self.api_client, + self.testdata["virtual_machine"], + networkids=shared_network.id, + serviceofferingid=self.service_offering.id + ) + self.cleanup_vms.append(vm) + + list_router_response = Router.list( + self.api_client, + networkid=shared_network.id, + listall=True + ) + self.assertEqual( + validateList(list_router_response)[0], + PASS, + "Router list validation failed" + ) + router = list_router_response[0] + + self.debug("Stopping the router with ID: %s" % router.id) + # Reboot the router + cmd = stopRouter.stopRouterCmd() + cmd.id = router.id + self.api_client.stopRouter(cmd) + + response = verifyRouterState(self.api_client, router.id, "stopped") + exceptionOccured = response[0] + isNetworkInDesiredState = response[1] + exceptionMessage = response[2] + + if (exceptionOccured or (not isNetworkInDesiredState)): + self.fail(exceptionMessage) + + self.debug("Starting the router with ID: %s" % router.id) + # Reboot the router + cmd = startRouter.startRouterCmd() + cmd.id = router.id + self.api_client.startRouter(cmd) + + response = verifyRouterState(self.api_client, router.id, "running") + exceptionOccured = response[0] + isNetworkInDesiredState = response[1] + exceptionMessage = response[2] + + if (exceptionOccured or (not isNetworkInDesiredState)): + self.fail(exceptionMessage) + return + + @attr(tags=["advanced", "advancedns", "dvs"], required_hardware="false") + def test_acquire_ip(self): + """Test acquire IP in shared network + + # Steps + # 1. Create a shared network in an account + # 2. Deploy a VM in the network + # 3. Acquire a public IP in the network + # 4. List the public IP by passing the id, it should be listed properly + # 5. Create Firewall and NAT rules for the public IP and verify that + ssh to vm works using the public IP + # 6. Disassociate the public IP and try to list the public IP + # 7. The list should be empty + """ + + # Create admin account + account = Account.create( + self.api_client, + self.testdata["account"], + domainid=self.domain.id + ) + self.cleanup_accounts.append(account) + + physical_network, shared_vlan = get_free_vlan( + self.api_client, self.zone.id) + if shared_vlan is None: + self.fail("Failed to get free vlan id for shared network") + + self.debug("Physical network found: %s" % physical_network.id) + + # create network using the shared network offering created + self.testdata["shared_network"]["acltype"] = "Domain" + self.testdata["shared_network"][ + "networkofferingid"] = self.shared_network_offering_all_services.id + self.testdata["shared_network"][ + "physicalnetworkid"] = physical_network.id + self.testdata["shared_network"]["vlan"] = shared_vlan + + shared_network = Network.create( + self.api_client, + self.testdata["shared_network"], + networkofferingid=self.shared_network_offering_all_services.id, + zoneid=self.zone.id, + ) + + self.cleanup_networks.append(shared_network) + + self.debug( + "Shared Network created for scope domain: %s" % + shared_network.id) + + vm = VirtualMachine.create( + self.api_client, + self.testdata["virtual_machine"], + networkids=shared_network.id, + serviceofferingid=self.service_offering.id + ) + self.cleanup_vms.append(vm) + + public_ip = PublicIPAddress.create( + self.api_client, + accountid=account.name, + zoneid=self.zone.id, + domainid=account.domainid, + networkid=shared_network.id) + + # listPublicIpAddresses should return newly created public IP + list_pub_ip_addr_resp = PublicIPAddress.list( + self.api_client, + id=public_ip.ipaddress.id + ) + self.assertEqual( + validateList(list_pub_ip_addr_resp)[0], + PASS, + "IP address list validation failed" + ) + self.assertEqual( + list_pub_ip_addr_resp[0].id, + public_ip.ipaddress.id, + "Check Correct IP Address is returned in the List Call" + ) + + FireWallRule.create( + self.api_client, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.testdata["fwrule"]["cidr"]], + startport=self.testdata["fwrule"]["startport"], + endport=self.testdata["fwrule"]["endport"]) + + NATRule.create( + self.api_client, + vm, + self.testdata["natrule"], + ipaddressid=public_ip.ipaddress.id, + networkid=shared_network.id) + + SshClient( + public_ip.ipaddress.ipaddress, + vm.ssh_port, + vm.username, + vm.password + ) + + public_ip.delete(self.api_client) + + list_pub_ip_addr_resp = PublicIPAddress.list( + self.api_client, + id=public_ip.ipaddress.id + ) + + self.assertEqual( + list_pub_ip_addr_resp, + None, + "Check if disassociated IP Address is no longer available" + ) + return diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py index de6f14676e7f..fdbf1532e8ce 100644 --- a/tools/marvin/marvin/lib/common.py +++ b/tools/marvin/marvin/lib/common.py @@ -57,10 +57,6 @@ listNetworkOfferings, listResourceLimits, listVPCOfferings) - - - - from marvin.sshClient import SshClient from marvin.codes import (PASS, FAILED, ISOLATED_NETWORK, VPC_NETWORK, BASIC_ZONE, FAIL, NAT_RULE, STATIC_NAT_RULE, @@ -83,7 +79,8 @@ Network, Host, Resources, - Configurations) + Configurations, + Router) import random @@ -1395,3 +1392,28 @@ def isNetworkDeleted(apiclient, networkid, timeout=600): time.sleep(60) #end while return networkDeleted + +def verifyRouterState(apiclient, routerid, state, listall=True): + """List router and check if the router state matches the given state""" + retriesCount = 10 + isRouterInDesiredState = False + exceptionOccured = False + exceptionMessage = "" + try: + while retriesCount >= 0: + routers = Router.list(apiclient, id=routerid, listall=listall) + assert validateList( + routers)[0] == PASS, "Routers list validation failed" + if str(routers[0].state).lower() == state: + isRouterInDesiredState = True + break + retriesCount -= 1 + time.sleep(60) + if not isRouterInDesiredState: + exceptionMessage = "Router state should be %s, it is %s" %\ + (state, routers[0].state) + except Exception as e: + exceptionOccured = True + exceptionMessage = e + return [exceptionOccured, isRouterInDesiredState, exceptionMessage] + return [exceptionOccured, isRouterInDesiredState, exceptionMessage]