diff --git a/test/integration/component/test_vpc_offerings.py b/test/integration/component/test_vpc_offerings.py index 5424cbeaba5..e763e515cd4 100644 --- a/test/integration/component/test_vpc_offerings.py +++ b/test/integration/component/test_vpc_offerings.py @@ -14,150 +14,148 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -import unittest """ Component tests for inter VLAN functionality """ -#Import Local Modules -import marvin -from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * + +# Import Local Modules from marvin.cloudstackAPI import * -from marvin.lib.utils import * +from marvin.cloudstackTestCase import * from marvin.lib.base import * from marvin.lib.common import * -from marvin.sshClient import SshClient -import datetime +from marvin.lib.utils import * +from nose.plugins.attrib import attr import logging + class Services: """Test inter VLAN services """ def __init__(self): self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 128, - }, - "network_offering": { - "name": 'VPC Network offering', - "displaytext": 'VPC Network off', - "guestiptype": 'Isolated', - "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', - "traffictype": 'GUEST', - "availability": 'Optional', - "useVpc": 'on', - "serviceProviderList": { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - }, - "vpc_offering": { - "name": 'VPC off', - "displaytext": 'VPC off', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', - }, - "redundant_vpc_offering": { - "name": 'Redundant VPC off', - "displaytext": 'Redundant VPC off', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', - "serviceProviderList": { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - }, - "serviceCapabilityList": { - "SourceNat": { - "RedundantRouter": 'true' - } - }, - }, - "vpc": { - "name": "TestVPC", - "displaytext": "TestVPC", - "cidr": '10.0.0.1/24' - }, - "redundant_vpc": { - "name": "TestRedundantVPC", - "displaytext": "TestRedundantVPC", - "cidr": '10.0.0.1/24' - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - "netmask": '255.255.255.0' - }, - "lbrule": { - "name": "SSH", - "alg": "leastconn", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - "openfirewall": False, - "startport": 2222, - "endport": 2222, - "cidrlist": '0.0.0.0/0', - "protocol": 'TCP' - }, - "natrule": { - "privateport": 22, - "publicport": 22, - "startport": 22, - "endport": 22, - "protocol": "TCP", - "cidrlist": '0.0.0.0/0', - }, - "fw_rule": { - "startport": 1, - "endport": 6000, - "cidr": '0.0.0.0/0', - # Any network (For creating FW rule) - "protocol": "TCP" - }, - "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) - "sleep": 60, - "timeout": 10, + "account": { + "email": "test@test.com", + "firstname": "Test", + "lastname": "User", + "username": "test", + # Random characters are appended for unique + # username + "password": "password", + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + }, + "network_offering": { + "name": 'VPC Network offering', + "displaytext": 'VPC Network off', + "guestiptype": 'Isolated', + "supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "useVpc": 'on', + "serviceProviderList": { + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + }, + "vpc_offering": { + "name": 'VPC off', + "displaytext": 'VPC off', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', + }, + "redundant_vpc_offering": { + "name": 'Redundant VPC off', + "displaytext": 'Redundant VPC off', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat', + "serviceProviderList": { + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + "serviceCapabilityList": { + "SourceNat": { + "RedundantRouter": 'true' } + }, + }, + "vpc": { + "name": "TestVPC", + "displaytext": "TestVPC", + "cidr": '10.0.0.1/24' + }, + "redundant_vpc": { + "name": "TestRedundantVPC", + "displaytext": "TestRedundantVPC", + "cidr": '10.0.0.1/24' + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + "netmask": '255.255.255.0' + }, + "lbrule": { + "name": "SSH", + "alg": "leastconn", + # Algorithm used for load balancing + "privateport": 22, + "publicport": 2222, + "openfirewall": False, + "startport": 2222, + "endport": 2222, + "cidrlist": '0.0.0.0/0', + "protocol": 'TCP' + }, + "natrule": { + "privateport": 22, + "publicport": 22, + "startport": 22, + "endport": 22, + "protocol": "TCP", + "cidrlist": '0.0.0.0/0', + }, + "fw_rule": { + "startport": 1, + "endport": 6000, + "cidr": '0.0.0.0/0', + # Any network (For creating FW rule) + "protocol": "TCP" + }, + "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) + "sleep": 60, + "timeout": 10, + } class TestVPCOffering(cloudstackTestCase): @@ -178,74 +176,65 @@ class TestVPCOffering(cloudstackTestCase): 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.api_client, + cls.zone.id, + cls.services["ostype"] + ) cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.services["service_offering"] + ) cls._cleanup = [ - cls.service_offering, - ] + cls.service_offering, + ] return @classmethod def tearDownClass(cls): - try: - #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestVPCOffering,cls).tearDownClass() def setUp(self): self.logger.debug("test_vpc_offering#setUp") self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [] - self.cleanup.insert(0, self.account) + self.cleanup.append(self.account) return def tearDown(self): self.logger.debug("test_vpc_offering#tearDown") - try: - cleanup_resources(self.apiclient, self.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestVPCOffering,self).tearDown() def validate_vpc_offering(self, vpc_offering): """Validates the VPC offering""" self.logger.debug("Check if the VPC offering is created successfully?") vpc_offs = VpcOffering.list( - self.apiclient, - id=vpc_offering.id - ) + self.apiclient, + id=vpc_offering.id + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings should return a valid list" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings should return a valid list" + ) self.assertEqual( - vpc_offering.name, - vpc_offs[0].name, - "Name of the VPC offering should match with listVPCOff data" - ) + vpc_offering.name, + vpc_offs[0].name, + "Name of the VPC offering should match with listVPCOff data" + ) self.logger.debug( - "VPC offering is created successfully - %s" % - vpc_offering.name) + "VPC offering is created successfully - %s" % + vpc_offering.name) return def validate_vpc_network(self, network): @@ -253,19 +242,19 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Check if the VPC network is created successfully?") vpc_networks = VPC.list( - self.apiclient, - id=network.id - ) + self.apiclient, + id=network.id + ) self.assertEqual( - isinstance(vpc_networks, list), - True, - "List VPC network should return a valid list" - ) + isinstance(vpc_networks, list), + True, + "List VPC network should return a valid list" + ) self.assertEqual( - network.name, - vpc_networks[0].name, - "Name of the VPC network should match with listVPC data" - ) + network.name, + vpc_networks[0].name, + "Name of the VPC network should match with listVPC data" + ) self.logger.debug("VPC network created successfully - %s" % network.name) return @@ -280,9 +269,9 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Creating inter VPC offering") vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.logger.debug("Check if the VPC offering is created successfully?") self.cleanup.append(vpc_off) @@ -308,9 +297,9 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Creating a VPC offering..") vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.validate_vpc_offering(vpc_off) @@ -318,22 +307,22 @@ class TestVPCOffering(cloudstackTestCase): vpc_off.update(self.apiclient, state='Enabled') self.logger.debug("creating a VPC network in the account: %s" % - self.account.name) + self.account.name) vpc = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.validate_vpc_network(vpc) self.network_offering = NetworkOffering.create( - self.apiclient, - self.services["network_offering"], - conservemode=False - ) + self.apiclient, + self.services["network_offering"], + conservemode=False + ) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') @@ -344,150 +333,150 @@ class TestVPCOffering(cloudstackTestCase): # Creating network using the network offering created self.logger.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id, - gateway=gateway, - vpcid=vpc.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id, + gateway=gateway, + vpcid=vpc.id + ) self.logger.debug("Created network with ID: %s" % network.id) # Spawn an instance in that network virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(network.id)] + ) self.logger.debug("Deployed VM in network: %s" % network.id) self.logger.debug("Associating public IP for network: %s" % network.name) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Associated %s with network %s" % ( - public_ip.ipaddress.ipaddress, - network.id - )) + public_ip.ipaddress.ipaddress, + network.id + )) self.logger.debug("Creating LB rule for IP address: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) lb_rule = LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip.ipaddress.id, - accountid=self.account.name, - networkid=network.id, - vpcid=vpc.id, - domainid=self.account.domainid - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.name, + networkid=network.id, + vpcid=vpc.id, + domainid=self.account.domainid + ) self.logger.debug("Associating public IP for network: %s" % vpc.name) public_ip_2 = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Associated %s with network %s" % ( - public_ip_2.ipaddress.ipaddress, - network.id - )) + public_ip_2.ipaddress.ipaddress, + network.id + )) nat_rule = NATRule.create( - self.apiclient, - virtual_machine, - self.services["natrule"], - ipaddressid=public_ip_2.ipaddress.id, - openfirewall=False, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip_2.ipaddress.id, + openfirewall=False, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Adding NetwrokACl rules to make PF and LB accessible") networkacl_1 = NetworkACL.create( - self.apiclient, - networkid=network.id, - services=self.services["natrule"], - traffictype='Ingress' - ) + self.apiclient, + networkid=network.id, + services=self.services["natrule"], + traffictype='Ingress' + ) networkacl_2 = NetworkACL.create( - self.apiclient, - networkid=network.id, - services=self.services["lbrule"], - traffictype='Ingress' - ) + self.apiclient, + networkid=network.id, + services=self.services["lbrule"], + traffictype='Ingress' + ) self.logger.debug("Checking if we can SSH into VM?") try: virtual_machine.get_ssh_client( ipaddress=public_ip_2.ipaddress.ipaddress, - ) + ) self.logger.debug("SSH into VM is successfully") except Exception as e: self.fail("Failed to SSH into VM - %s, %s" % - (public_ip_2.ipaddress.ipaddress, e)) + (public_ip_2.ipaddress.ipaddress, e)) self.logger.debug("Associating public IP for network: %s" % network.name) public_ip_3 = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Associated %s with network %s" % ( - public_ip_3.ipaddress.ipaddress, - network.id - )) + public_ip_3.ipaddress.ipaddress, + network.id + )) self.logger.debug("Enabling static NAT for IP: %s" % - public_ip_3.ipaddress.ipaddress) + public_ip_3.ipaddress.ipaddress) try: StaticNATRule.enable( - self.apiclient, - ipaddressid=public_ip_3.ipaddress.id, - virtualmachineid=virtual_machine.id, - networkid=network.id - ) + self.apiclient, + ipaddressid=public_ip_3.ipaddress.id, + virtualmachineid=virtual_machine.id, + networkid=network.id + ) self.logger.debug("Static NAT enabled for IP: %s" % - public_ip_3.ipaddress.ipaddress) + public_ip_3.ipaddress.ipaddress) except Exception as e: self.fail("Failed to enable static NAT on IP: %s - %s" % ( - public_ip_3.ipaddress.ipaddress, e)) + public_ip_3.ipaddress.ipaddress, e)) public_ips = PublicIPAddress.list( - self.apiclient, - networkid=network.id, - listall=True, - isstaticnat=True, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + networkid=network.id, + listall=True, + isstaticnat=True, + account=self.account.name, + domainid=self.account.domainid + ) self.assertEqual( - isinstance(public_ips, list), - True, - "List public Ip for network should list the Ip addr" - ) + isinstance(public_ips, list), + True, + "List public Ip for network should list the Ip addr" + ) self.assertEqual( - public_ips[0].ipaddress, - public_ip_3.ipaddress.ipaddress, - "List public Ip for network should list the Ip addr" - ) + public_ips[0].ipaddress, + public_ip_3.ipaddress.ipaddress, + "List public Ip for network should list the Ip addr" + ) # TODO: Remote Access VPN is not yet supported in VPC return @@ -504,56 +493,56 @@ class TestVPCOffering(cloudstackTestCase): # 5. Try to create a LB rule for this VM. LB creation should fail self.logger.debug( - "Creating a VPC offering with Vpn,dhcpdns,UserData," + - " SourceNat,Static NAT and PF services" - ) + "Creating a VPC offering with Vpn,dhcpdns,UserData," + + " SourceNat,Static NAT and PF services" + ) self.services["vpc_offering"]["supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL' self.services["network_offering"]["supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL' self.services["network_offering"]["serviceProviderList"] = { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - } + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + } self.network_offering = NetworkOffering.create( - self.apiclient, - self.services["network_offering"], - conservemode=False - ) + self.apiclient, + self.services["network_offering"], + conservemode=False + ) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') - self.cleanup.insert(0, self.network_offering) + self.cleanup.append(self.network_offering) vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.validate_vpc_offering(vpc_off) self.logger.debug("Enabling the VPC offering created") vpc_off.update(self.apiclient, state='Enabled') - - self.cleanup.insert(0, vpc_off) + + self.cleanup.append(vpc_off) self.logger.debug("creating a VPC network in the account: %s" % - self.account.name) + self.account.name) vpc = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.validate_vpc_network(vpc) - self.cleanup.insert(0, vpc) + self.cleanup.append(vpc) gateway = vpc.cidr.split('/')[0] # Split the cidr to retrieve gateway @@ -562,58 +551,58 @@ class TestVPCOffering(cloudstackTestCase): # Creating network using the network offering created self.logger.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id, - gateway=gateway, - vpcid=vpc.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id, + gateway=gateway, + vpcid=vpc.id + ) self.logger.debug("Created network with ID: %s" % network.id) - self.cleanup.insert(0, network) + self.cleanup.append(network) self.logger.debug("Deploying virtual machines in network: %s" % vpc.name) # Spawn an instance in that network virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(network.id)] + ) self.logger.debug("Deployed VM in network: %s" % network.id) - self.cleanup.insert(0, virtual_machine) + self.cleanup.append(virtual_machine) self.logger.debug("Associating public IP for network: %s" % network.name) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Associated %s with network %s" % ( - public_ip.ipaddress.ipaddress, - vpc.id - )) + public_ip.ipaddress.ipaddress, + vpc.id + )) self.logger.debug("Trying to LB rule for IP address: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) with self.assertRaises(Exception): LoadBalancerRule.create( - self.apiclient, - self.services["lbrule"], - ipaddressid=public_ip.ipaddress.id, - accountid=self.account.name, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + self.services["lbrule"], + ipaddressid=public_ip.ipaddress.id, + accountid=self.account.name, + networkid=network.id, + vpcid=vpc.id + ) return @attr(tags=["advanced", "intervlan"], required_hardware="false") @@ -629,53 +618,53 @@ class TestVPCOffering(cloudstackTestCase): # 5. Try to create NAT rule for this VMStatic NAT creation should fail self.logger.debug("Creating a VPC offering with Vpn,dhcpdns,UserData," + - "SourceNat,lb and PF services") + "SourceNat,lb and PF services") self.services["vpc_offering"]["supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,Lb,UserData,PortForwarding,NetworkACL' self.services["network_offering"]["supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,Lb,UserData,PortForwarding,NetworkACL' self.services["network_offering"]["serviceProviderList"] = { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "PortForwarding": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - } + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + } self.network_offering = NetworkOffering.create( - self.apiclient, - self.services["network_offering"], - conservemode=False - ) + self.apiclient, + self.services["network_offering"], + conservemode=False + ) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') - self.cleanup.insert(0, self.network_offering) + self.cleanup.append(self.network_offering) vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.validate_vpc_offering(vpc_off) self.logger.debug("Enabling the VPC offering created") vpc_off.update(self.apiclient, state='Enabled') - self.cleanup.insert(0, vpc_off) + self.cleanup.append(vpc_off) self.logger.debug("creating a VPC network in the account: %s" % - self.account.name) + self.account.name) vpc = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.validate_vpc_network(vpc) - self.cleanup.insert(0, vpc) + self.cleanup.append(vpc) gateway = vpc.cidr.split('/')[0] # Split the cidr to retrieve gateway @@ -684,58 +673,58 @@ class TestVPCOffering(cloudstackTestCase): # Creating network using the network offering created self.logger.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id, - gateway=gateway, - vpcid=vpc.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id, + gateway=gateway, + vpcid=vpc.id + ) self.logger.debug("Created network with ID: %s" % network.id) - self.cleanup.insert(0, network) + self.cleanup.append(network) self.logger.debug("Deploying virtual machines in network: %s" % vpc.name) # Spawn an instance in that network virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(network.id)] + ) self.logger.debug("Deployed VM in network: %s" % network.id) - self.cleanup.insert(0, virtual_machine) + self.cleanup.append(virtual_machine) self.logger.debug("Associating public IP for network: %s" % network.name) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Associated %s with network %s" % ( - public_ip.ipaddress.ipaddress, - network.id - )) + public_ip.ipaddress.ipaddress, + network.id + )) with self.assertRaises(Exception): static_nat = StaticNATRule.create( - self.apiclient, - self.services["fw_rule"], - ipaddressid=public_ip.ipaddress.id - ) + self.apiclient, + self.services["fw_rule"], + ipaddressid=public_ip.ipaddress.id + ) static_nat.enable( - self.apiclient, - ipaddressid=public_ip.ipaddress.id, - virtualmachineid=virtual_machine.id - ) + self.apiclient, + ipaddressid=public_ip.ipaddress.id, + virtualmachineid=virtual_machine.id + ) return @attr(tags=["advanced", "intervlan"], required_hardware="false") @@ -751,55 +740,55 @@ class TestVPCOffering(cloudstackTestCase): # 5. Try to create a PF rule for this VM. PF creation should fail self.logger.debug( - "Creating a VPC offering with Vpn,dhcpdns,UserData," + - "SourceNat,Static NAT and lb services" - ) + "Creating a VPC offering with Vpn,dhcpdns,UserData," + + "SourceNat,Static NAT and lb services" + ) self.services["vpc_offering"]["supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,Lb,UserData,StaticNat,NetworkACL' self.services["network_offering"]["supportedservices"] = 'Vpn,Dhcp,Dns,SourceNat,Lb,UserData,StaticNat,NetworkACL' self.services["network_offering"]["serviceProviderList"] = { - "Vpn": 'VpcVirtualRouter', - "Dhcp": 'VpcVirtualRouter', - "Dns": 'VpcVirtualRouter', - "SourceNat": 'VpcVirtualRouter', - "Lb": 'VpcVirtualRouter', - "UserData": 'VpcVirtualRouter', - "StaticNat": 'VpcVirtualRouter', - "NetworkACL": 'VpcVirtualRouter' - } + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "Lb": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + } self.network_offering = NetworkOffering.create( - self.apiclient, - self.services["network_offering"], - conservemode=False - ) + self.apiclient, + self.services["network_offering"], + conservemode=False + ) # Enable Network offering self.network_offering.update(self.apiclient, state='Enabled') - self.cleanup.insert(0, self.network_offering) + self.cleanup.append(self.network_offering) vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.validate_vpc_offering(vpc_off) self.logger.debug("Enabling the VPC offering created") vpc_off.update(self.apiclient, state='Enabled') - self.cleanup.insert(0, vpc_off) + self.cleanup.append(vpc_off) self.logger.debug("creating a VPC network in the account: %s" % - self.account.name) + self.account.name) vpc = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.validate_vpc_network(vpc) - self.cleanup.insert(0, vpc) + self.cleanup.append(vpc) gateway = vpc.cidr.split('/')[0] # Split the cidr to retrieve gateway @@ -808,56 +797,56 @@ class TestVPCOffering(cloudstackTestCase): # Creating network using the network offering created self.logger.debug("Creating network with network offering: %s" % - self.network_offering.id) + self.network_offering.id) network = Network.create( - self.apiclient, - self.services["network"], - accountid=self.account.name, - domainid=self.account.domainid, - networkofferingid=self.network_offering.id, - zoneid=self.zone.id, - gateway=gateway, - vpcid=vpc.id - ) + self.apiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.account.domainid, + networkofferingid=self.network_offering.id, + zoneid=self.zone.id, + gateway=gateway, + vpcid=vpc.id + ) self.logger.debug("Deploying virtual machines in network: %s" % vpc.name) - self.cleanup.insert(0, network) + self.cleanup.append(network) # Spawn an instance in that network virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - networkids=[str(network.id)] - ) + self.apiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + networkids=[str(network.id)] + ) self.logger.debug("Deployed VM in network: %s" % network.id) - self.cleanup.insert(0, virtual_machine) + self.cleanup.append(virtual_machine) self.logger.debug("Associating public IP for network: %s" % network.name) public_ip = PublicIPAddress.create( - self.apiclient, - accountid=self.account.name, - zoneid=self.zone.id, - domainid=self.account.domainid, - networkid=network.id, - vpcid=vpc.id - ) + self.apiclient, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=vpc.id + ) self.logger.debug("Associated %s with network %s" % ( - public_ip.ipaddress.ipaddress, - network.id - )) + public_ip.ipaddress.ipaddress, + network.id + )) self.logger.debug("Trying to create NAT rule for the IP: %s" % - public_ip.ipaddress.ipaddress) + public_ip.ipaddress.ipaddress) with self.assertRaises(Exception): NATRule.create( - self.apiclient, - virtual_machine, - self.services["natrule"], - ipaddressid=public_ip.ipaddress.id, - openfirewall=True - ) + self.apiclient, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip.ipaddress.id, + openfirewall=True + ) return @attr(tags=["advanced", "intervlan"], required_hardware="false") @@ -873,18 +862,18 @@ class TestVPCOffering(cloudstackTestCase): with self.assertRaises(Exception): VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.logger.debug("Creating a VPC offering with only sourceNAT service") self.services["vpc_offering"]["supportedservices"] = 'SourceNat' try: vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.validate_vpc_offering(vpc_off) # Appending to cleanup to delete after test self.cleanup.append(vpc_off) @@ -907,9 +896,9 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Creating a VPC offering..") vpc_off = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.cleanup.append(vpc_off) self.validate_vpc_offering(vpc_off) @@ -918,30 +907,30 @@ class TestVPCOffering(cloudstackTestCase): vpc_off.update(self.apiclient, state='Disabled') self.logger.debug("creating a VPC network in the account: %s" % - self.account.name) + self.account.name) with self.assertRaises(Exception): VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.logger.debug("VPC network creation failed! (Test succeeded)") self.logger.debug("Enabling the VPC offering created") vpc_off.update(self.apiclient, state='Enabled') self.logger.debug("creating a VPC network in the account: %s" % - self.account.name) + self.account.name) vpc = VPC.create( - self.apiclient, - self.services["vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.validate_vpc_network(vpc) self.logger.debug("Updating name & display text of the vpc offering created") @@ -950,35 +939,35 @@ class TestVPCOffering(cloudstackTestCase): try: vpc_off.update( - self.apiclient, - name=new_name, - displaytext=new_displaytext - ) + self.apiclient, + name=new_name, + displaytext=new_displaytext + ) except Exception as e: self.fail("Failed to update VPC offering- %s" % e) self.logger.debug("Cheking if the changes are reflected to listVPC call?") vpc_offs = vpc_off.list( - self.apiclient, - id=vpc_off.id, - listall=True - ) + self.apiclient, + id=vpc_off.id, + listall=True + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings shall return a valid list" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings shall return a valid list" + ) list_reposnse_vpc = vpc_offs[0] self.assertEqual( - list_reposnse_vpc.name, - new_name, - "VPC off Name should be updated with new one" - ) + list_reposnse_vpc.name, + new_name, + "VPC off Name should be updated with new one" + ) self.assertEqual( - list_reposnse_vpc.displaytext, - new_displaytext, - "VPC off display text should be updated with new one" - ) + list_reposnse_vpc.displaytext, + new_displaytext, + "VPC off display text should be updated with new one" + ) return @attr(tags=["advanced", "intervlan"], required_hardware="false") @@ -1004,18 +993,18 @@ class TestVPCOffering(cloudstackTestCase): self.services["vpc_offering"]["supportedservices"] = 'SourceNat' vpc_off_1 = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.cleanup.append(vpc_off_1) self.validate_vpc_offering(vpc_off_1) self.logger.debug("Disabling the VPC offering created") vpc_off_1.update(self.apiclient, state='Disabled') vpc_off_2 = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.cleanup.append(vpc_off_2) self.validate_vpc_offering(vpc_off_2) @@ -1023,9 +1012,9 @@ class TestVPCOffering(cloudstackTestCase): vpc_off_2.update(self.apiclient, state='Enabled') vpc_off_3 = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.cleanup.append(vpc_off_3) self.validate_vpc_offering(vpc_off_3) @@ -1033,9 +1022,9 @@ class TestVPCOffering(cloudstackTestCase): vpc_off_3.update(self.apiclient, state='Enabled') vpc_off_4 = VpcOffering.create( - self.apiclient, - self.services["vpc_offering"] - ) + self.apiclient, + self.services["vpc_offering"] + ) self.logger.debug("Enabling the VPC offering created") vpc_off_4.update(self.apiclient, state='Enabled') @@ -1044,110 +1033,110 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Cheking if listVPCOff return the deleted VPC off") vpc_offs = VpcOffering.list( - self.apiclient, - id=vpc_off_4.id, - listall=True - ) + self.apiclient, + id=vpc_off_4.id, + listall=True + ) self.assertEqual( - vpc_offs, - None, - "List VPC offerings should nt return any response for deleted offering" - ) + vpc_offs, + None, + "List VPC offerings should nt return any response for deleted offering" + ) self.logger.debug("Validating the listVPCOfferings repsonse by ids") self.validate_vpc_offering(vpc_off_3) self.logger.debug("ListVPCOfferings by displaytext & verifying the response") vpc_offs = VpcOffering.list( - self.apiclient, - displaytext=vpc_off_3.displaytext, - listall=True - ) + self.apiclient, + displaytext=vpc_off_3.displaytext, + listall=True + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings shall return a valid response" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings shall return a valid response" + ) list_vpc_off_response = vpc_offs[0] self.assertIn( - vpc_off_3.id, - [vpc.id for vpc in vpc_offs], - "ListVPC Off with displaytext should return same VPC off" - ) + vpc_off_3.id, + [vpc.id for vpc in vpc_offs], + "ListVPC Off with displaytext should return same VPC off" + ) self.logger.debug("ListVPCOfferings by name and verifying the response") vpc_offs = VpcOffering.list( - self.apiclient, - name=vpc_off_2.name, - listall=True - ) + self.apiclient, + name=vpc_off_2.name, + listall=True + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings shall return a valid response" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings shall return a valid response" + ) list_vpc_off_response = vpc_offs[0] self.assertEqual( - list_vpc_off_response.id, - vpc_off_2.id, - "ListVPC Off with name should return same VPC off" - ) + list_vpc_off_response.id, + vpc_off_2.id, + "ListVPC Off with name should return same VPC off" + ) self.logger.debug( "ListVPCOfferings by supported services & verifying the response") vpc_offs = VpcOffering.list( - self.apiclient, - supportedservices='SourceNat', - listall=True - ) + self.apiclient, + supportedservices='SourceNat', + listall=True + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings shall return a valid response" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings shall return a valid response" + ) for vpc_off in vpc_offs: self.logger.debug(vpc_off) self.assertEqual( - 'SourceNat' in str(vpc_off), - True, - "ListVPC Off with name should return same VPC off" - ) + 'SourceNat' in str(vpc_off), + True, + "ListVPC Off with name should return same VPC off" + ) self.logger.debug("ListVPCOfferings by state & verifying the response") vpc_offs = VpcOffering.list( - self.apiclient, - state='Enabled', - listall=True - ) + self.apiclient, + state='Enabled', + listall=True + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings shall return a valid response" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings shall return a valid response" + ) for vpc_off in vpc_offs: self.assertEqual( - vpc_off.state, - 'Enabled', - "List VPC offering should return only offerings that are enabled" - ) + vpc_off.state, + 'Enabled', + "List VPC offering should return only offerings that are enabled" + ) self.logger.debug("ListVPCOfferings by state & verifying the response") vpc_offs = VpcOffering.list( - self.apiclient, - state='Disabled', - listall=True - ) + self.apiclient, + state='Disabled', + listall=True + ) self.assertEqual( - isinstance(vpc_offs, list), - True, - "List VPC offerings shall return a valid response" - ) + isinstance(vpc_offs, list), + True, + "List VPC offerings shall return a valid response" + ) for vpc_off in vpc_offs: self.assertEqual( - vpc_off.state, - 'Disabled', - "List VPC offering should return only offerings that are disabled" - ) + vpc_off.state, + 'Disabled', + "List VPC offering should return only offerings that are disabled" + ) return @attr(tags=["advanced", "redundancy"], required_hardware="false") @@ -1155,9 +1144,9 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Creating Redundant VPC offering") vpc_off = VpcOffering.create( - self.apiclient, - self.services["redundant_vpc_offering"] - ) + self.apiclient, + self.services["redundant_vpc_offering"] + ) self.cleanup.append(vpc_off) self.logger.debug("Check if the Redundant VPC offering is created successfully?") @@ -1166,17 +1155,16 @@ class TestVPCOffering(cloudstackTestCase): self.logger.debug("Enabling the created Redundant VPC offering") vpc_off.update(self.apiclient, state='Enabled') - self.logger.debug("Creating a Redundant VPC network in the account: %s" % - self.account.name) + self.account.name) vpc = VPC.create( - self.apiclient, - self.services["redundant_vpc"], - vpcofferingid=vpc_off.id, - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.services["redundant_vpc"], + vpcofferingid=vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.logger.debug("Validating Redundant VPC Nw creation") self.validate_vpc_network(vpc) @@ -1195,9 +1183,9 @@ class TestVPCOffering(cloudstackTestCase): break self.assertEqual( - redundant, - True, - "Didn't create any Redundant Vpc" - ) + redundant, + True, + "Didn't create any Redundant Vpc" + ) return diff --git a/test/integration/component/test_vpc_routers.py b/test/integration/component/test_vpc_routers.py index fe9dc5d5520..7314b69baee 100644 --- a/test/integration/component/test_vpc_routers.py +++ b/test/integration/component/test_vpc_routers.py @@ -17,39 +17,42 @@ """ Component tests for VPC - Router Operations """ -# Import Local Modules -from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.cloudstackAPI import (startRouter, - stopRouter, - rebootRouter, - migrateSystemVm) -from marvin.lib.utils import cleanup_resources -from marvin.lib.base import (Account, - Router, - ServiceOffering, - VirtualMachine, - Host, - PublicIPAddress, - VPC, - VpcOffering, - StaticRoute, - Network, - NetworkOffering, - PrivateGateway, - NATRule, - NetworkACL, - StaticNATRule, - LoadBalancerRule) -from marvin.lib.common import (get_domain, - get_zone, - list_routers, - get_template) import time +from nose.plugins.attrib import attr + +# Import Local Modules +from marvin.cloudstackAPI import ( + startRouter, + stopRouter, + rebootRouter, + migrateSystemVm) +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.base import ( + Account, + Router, + ServiceOffering, + VirtualMachine, + Host, + PublicIPAddress, + VPC, + VpcOffering, + StaticRoute, + Network, + NetworkOffering, + PrivateGateway, + NATRule, + NetworkACL, + StaticNATRule, + LoadBalancerRule) +from marvin.lib.common import ( + get_domain, + get_zone, + list_routers, + get_template) +from marvin.lib.utils import cleanup_resources class Services: - """Test VPC Router services """ @@ -228,11 +231,8 @@ class TestVPCRoutersBasic(cloudstackTestCase): ) cls._cleanup = [cls.account] cls._cleanup.append(cls.vpc_off) - #cls.debug("Enabling the VPC offering created") cls.vpc_off.update(cls.api_client, state='Enabled') - # cls.debug("creating a VPC network in the account: %s" % - # cls.account.name) cls.services["vpc"]["cidr"] = '10.1.1.1/16' cls.vpc = VPC.create( cls.api_client, @@ -248,12 +248,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): @classmethod def tearDownClass(cls): - try: - # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestVPCRoutersBasic, cls).tearDownClass() def setUp(self): self.api_client = self.testClient.getApiClient() @@ -262,6 +257,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): return def tearDown(self): + super(TestVPCRoutersBasic, self).tearDown() return def validate_vpc_offering(self, vpc_offering): @@ -368,8 +364,8 @@ class TestVPCRoutersBasic(cloudstackTestCase): router.hostid = router_response[0].hostid self.assertEqual( router.hostid, host.id, "Migration to host %s failed. The router host is" - " still %s" % - (host.id, router.hostid)) + " still %s" % + (host.id, router.hostid)) return @attr(tags=["advanced", "intervlan"], required_hardware="false") @@ -498,7 +494,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"], required_hardware="true") + @attr(tags=["advanced", "intervlan", "bla"], required_hardware="true") def test_03_migrate_router_after_creating_vpc(self): """ Test migration of router to another host after creating VPC """ self.hypervisor = self.testClient.getHypervisorInfo() @@ -638,7 +634,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): cls._cleanup = [] if cls.hypervisor.lower() == 'hyperv': cls.vpcSupported = False - return + return cls.services = Services().services # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) @@ -669,7 +665,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): admin=True, domainid=cls.domain.id ) - cls._cleanup.insert(0, cls.account) + cls._cleanup.append(cls.account) cls.services["vpc"]["cidr"] = '10.1.1.1/16' cls.vpc = VPC.create( @@ -852,12 +848,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): @classmethod def tearDownClass(cls): - try: - # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - return + super(TestVPCRouterOneNetwork, cls).tearDownClass() def setUp(self): self.api_client = self.testClient.getApiClient() @@ -867,12 +858,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): return def tearDown(self): - try: - # Clean up, terminate the created network offerings - cleanup_resources(self.api_client, self.cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - + super(TestVPCRouterOneNetwork, self).tearDown() return def validate_vpc_offering(self, vpc_offering): @@ -1020,8 +1006,8 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): router.hostid = router_response[0].hostid self.assertEqual( router.hostid, host.id, "Migration to host %s failed. The router host is" - "still %s" % - (host.id, router.hostid)) + "still %s" % + (host.id, router.hostid)) return @attr(tags=["advanced", "intervlan", "provisioining"]) @@ -1188,7 +1174,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"], required_hardware="true") + @attr(tags=["advanced", "intervlan", "bla"], required_hardware="true") def test_03_migrate_router_after_addition_of_one_guest_network(self): """ Test migrate of router after addition of one guest network """ @@ -1316,7 +1302,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) return - @attr(tags=["advanced", "intervlan"], required_hardware="false") + @attr(tags=["advanced", "intervlan", "bla"], required_hardware="false") def test_05_destroy_router_after_addition_of_one_guest_network(self): """ Test destroy of router after addition of one guest network """