diff --git a/test/integration/component/test_multiple_ips_per_nic.py b/test/integration/component/test_multiple_ips_per_nic.py index 58aac9f9fa9..536c39d9904 100644 --- a/test/integration/component/test_multiple_ips_per_nic.py +++ b/test/integration/component/test_multiple_ips_per_nic.py @@ -23,15 +23,34 @@ Design Document: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Multiple+IP+address+per+NIC """ from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.lib.utils import * -from marvin.lib.base import * -from marvin.lib.common import * - +from marvin.lib.utils import (cleanup_resources, + random_gen, + validateList) +from marvin.lib.base import (Account, + VirtualMachine, + PublicIPAddress, + NATRule, + StaticNATRule, + FireWallRule, + NIC, + Network, + VPC, + ServiceOffering, + VpcOffering, + Domain, + Router) +from marvin.lib.common import (get_domain, + get_template, + get_zone, + setSharedNetworkParams, + get_free_vlan, + createEnabledNetworkOffering) from nose.plugins.attrib import attr -from marvin.codes import PASS, ISOLATED_NETWORK, VPC_NETWORK, SHARED_NETWORK, FAIL +from marvin.codes import PASS, ISOLATED_NETWORK, VPC_NETWORK, SHARED_NETWORK, FAIL, FAILED from ddt import ddt, data import time + def createNetwork(self, networkType): """Create a network of given type (isolated/shared/isolated in VPC)""" @@ -39,27 +58,36 @@ def createNetwork(self, networkType): if networkType == ISOLATED_NETWORK: try: - network = Network.create(self.apiclient,self.services["isolated_network"], - networkofferingid=self.isolated_network_offering.id, - accountid=self.account.name,domainid=self.account.domainid, - zoneid=self.zone.id) + network = Network.create( + self.apiclient, + self.services["isolated_network"], + networkofferingid=self.isolated_network_offering.id, + accountid=self.account.name, + domainid=self.account.domainid, + zoneid=self.zone.id) except Exception as e: self.fail("Isolated network creation failed because: %s" % e) elif networkType == SHARED_NETWORK: physical_network, vlan = get_free_vlan(self.api_client, self.zone.id) - #create network using the shared network offering created + # create network using the shared network offering created self.services["shared_network"]["acltype"] = "domain" self.services["shared_network"]["vlan"] = vlan - self.services["shared_network"]["networkofferingid"] = self.shared_network_offering.id - self.services["shared_network"]["physicalnetworkid"] = physical_network.id + self.services["shared_network"][ + "networkofferingid"] = self.shared_network_offering.id + self.services["shared_network"][ + "physicalnetworkid"] = physical_network.id - self.services["shared_network"] = setSharedNetworkParams(self.services["shared_network"]) + self.services["shared_network"] = setSharedNetworkParams( + self.services["shared_network"]) try: - network = Network.create(self.api_client, self.services["shared_network"], - networkofferingid=self.shared_network_offering.id, zoneid=self.zone.id) + network = Network.create( + self.api_client, + self.services["shared_network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id) self.cleanup.append(network) except Exception as e: self.fail("Shared Network creation failed because: %s" % e) @@ -67,53 +95,96 @@ def createNetwork(self, networkType): elif networkType == VPC_NETWORK: self.services["vpc"]["cidr"] = "10.1.1.1/16" self.debug("creating a VPC network in the account: %s" % - self.account.name) - vpc = VPC.create(self.apiclient, self.services["vpc"], - vpcofferingid=self.vpc_off.id, zoneid=self.zone.id, - account=self.account.name, domainid=self.account.domainid) + self.account.name) + vpc = VPC.create( + self.apiclient, + self.services["vpc"], + vpcofferingid=self.vpc_off.id, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid) vpcs = VPC.list(self.apiclient, id=vpc.id) - self.assertEqual(validateList(vpcs)[0], PASS, "VPC list validation failed, vpc list is %s" % vpcs) + self.assertEqual( + validateList(vpcs)[0], + PASS, + "VPC list validation failed, vpc list is %s" % + vpcs) - network = Network.create(self.api_client,self.services["isolated_network"], - networkofferingid=self.isolated_network_offering_vpc.id, - accountid=self.account.name,domainid=self.account.domainid, - zoneid=self.zone.id, vpcid=vpc.id, gateway="10.1.1.1", netmask="255.255.255.0") + network = Network.create( + self.api_client, + self.services["isolated_network"], + networkofferingid=self.isolated_network_offering_vpc.id, + accountid=self.account.name, + domainid=self.account.domainid, + zoneid=self.zone.id, + vpcid=vpc.id, + gateway="10.1.1.1", + netmask="255.255.255.0") return network + def CreateEnabledNetworkOffering(apiclient, networkServices): """Create network offering of given services and enable it""" result = createEnabledNetworkOffering(apiclient, networkServices) - assert result[0] == PASS, "Network offering creation/enabling failed due to %s" % result[2] + assert result[ + 0] == PASS, "Network offering creation/enabling failed due to %s" % result[2] return result[1] -def createNetworkRules(self, virtual_machine, network, vmguestip, networktype, ruletype): + +def createNetworkRules( + self, + virtual_machine, + network, + vmguestip, + networktype, + ruletype): """ Acquire public ip in the given network, open firewall if required and create NAT rule for the public ip to the given guest vm ip address""" try: - public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if networktype == VPC_NETWORK else None) + public_ip = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if networktype == VPC_NETWORK else None) if networktype != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) if ruletype == "nat": - NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip.ipaddress.id, - networkid=network.id, vmguestip = vmguestip) + NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip.ipaddress.id, + networkid=network.id, + vmguestip=vmguestip) elif ruletype == "staticnat": - StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id, network.id, vmguestip=vmguestip) - except Exception: + StaticNATRule.enable( + self.apiclient, + public_ip.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=vmguestip) + except Exception as e: + self.debug("Exception occured while creating network rules: %s" % e) return FAIL - return PASS + @ddt class TestBasicOperations(cloudstackTestCase): + """Test Basic operations (add/remove/list) IP to/from NIC """ @@ -129,34 +200,42 @@ class TestBasicOperations(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"] + ) if cls.template == FAILED: - assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + assert False, "get_template() failed to return template with description %s" % 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.services["shared_network_offering_all_services"]["specifyVlan"] = "True" - cls.services["shared_network_offering_all_services"]["specifyIpRanges"] = "True" + cls.services["shared_network_offering_all_services"][ + "specifyVlan"] = "True" + cls.services["shared_network_offering_all_services"][ + "specifyIpRanges"] = "True" - cls.shared_network_offering = CreateEnabledNetworkOffering(cls.api_client, - cls.services["shared_network_offering_all_services"]) + cls.shared_network_offering = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["shared_network_offering_all_services"]) cls._cleanup.append(cls.shared_network_offering) cls.mode = cls.zone.networktype - cls.isolated_network_offering = CreateEnabledNetworkOffering(cls.api_client, - cls.services["isolated_network_offering"]) + cls.isolated_network_offering = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["isolated_network_offering"]) cls._cleanup.append(cls.isolated_network_offering) - cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering(cls.api_client, - cls.services["nw_offering_isolated_vpc"]) + cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["nw_offering_isolated_vpc"]) cls._cleanup.append(cls.isolated_network_offering_vpc) - cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) + cls.vpc_off = VpcOffering.create( + cls.api_client, + cls.services["vpc_offering"]) cls.vpc_off.update(cls.api_client, state='Enabled') cls._cleanup.append(cls.vpc_off) return @@ -173,7 +252,7 @@ class TestBasicOperations(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.cleanup = [ ] + self.cleanup = [] return def tearDown(self): @@ -188,14 +267,24 @@ class TestBasicOperations(cloudstackTestCase): def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus): """ List public IP and verify that NAT rule status for the IP is as desired """ - publiciplist = PublicIPAddress.list(self.apiclient, id=ipaddressid, listall=True) - self.assertEqual(validateList(publiciplist)[0], PASS, "Public IP list validation failed") - self.assertEqual(publiciplist[0].isstaticnat, natrulestatus, "isstaticnat should be %s, it is %s" % - (natrulestatus, publiciplist[0].isstaticnat)) + publiciplist = PublicIPAddress.list( + self.apiclient, + id=ipaddressid, + listall=True) + self.assertEqual( + validateList(publiciplist)[0], + PASS, + "Public IP list validation failed") + self.assertEqual( + publiciplist[0].isstaticnat, + natrulestatus, + "isstaticnat should be %s, it is %s" % + (natrulestatus, + publiciplist[0].isstaticnat)) return - @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) + @data(SHARED_NETWORK) @attr(tags=["advanced"]) def test_add_ip_to_nic(self, value): """ Add secondary IP to NIC of a VM""" @@ -206,7 +295,8 @@ class TestBasicOperations(cloudstackTestCase): # 3. Add secondary IP to the default nic of VM # 4. Try to add the same IP again # 5. Try to add secondary IP providing wrong virtual machine id - # 6. Try to add secondary IP with correct virtual machine id but wrong IP address + # 6. Try to add secondary IP with correct virtual machine id but wrong + # IP address # Validations: # 1. Step 3 should succeed @@ -214,41 +304,60 @@ class TestBasicOperations(cloudstackTestCase): # 3. Step 5 should should fail # 4. Step 6 should fail - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) + + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id, + ipaddress=ipaddress_1.ipaddress) + self.debug( + "Adding already added secondary IP %s to NIC of vm %s succeeded, should have failed" % + (ipaddress_1.ipaddress, virtual_machine.id)) except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + self.debug( + "Failed while adding already added secondary IP to NIC of vm %s" % + virtual_machine.id) try: - NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id, ipaddress=ipaddress_1.ipaddress) - self.debug("Adding already added secondary IP %s to NIC of vm %s succeeded, should have failed" % - (ipaddress_1.ipaddress, virtual_machine.id)) - except Exception as e: - self.debug("Failed while adding already added secondary IP to NIC of vm %s" % virtual_machine.id) - - try: - NIC.addIp(self.apiclient, id=(virtual_machine.nic[0].id + random_gen())) - self.fail("Adding secondary IP with wrong NIC id succeded, it shoud have failed") + NIC.addIp( + self.apiclient, id=( + virtual_machine.nic[0].id + random_gen())) + self.fail( + "Adding secondary IP with wrong NIC id succeded, it shoud have failed") except Exception as e: self.debug("Failed while adding secondary IP to wrong NIC") try: - NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id, ipaddress = "255.255.255.300") - self.fail("Adding secondary IP with wrong ipaddress succeded, it should have failed") + NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id, + ipaddress="255.255.255.300") + self.fail( + "Adding secondary IP with wrong ipaddress succeded, it should have failed") except Exception as e: - self.debug("Failed while adding wrong secondary IP to NIC of VM %s" % virtual_machine.id) + self.debug( + "Failed while adding wrong secondary IP to NIC of VM %s: %s" % + (virtual_machine.id, e)) return @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @@ -267,33 +376,39 @@ class TestBasicOperations(cloudstackTestCase): # 1. Step 4 should succeed # 2. Step 5 should fail - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) + NIC.removeIp(self.apiclient, ipaddressid=ipaddress_1.id) try: - NIC.removeIp(self.apiclient, ipaddressid=ipaddress_1.id) - except Exception as e: - self.fail("Removing seondary IP %s from NIC failed as expected with Exception %s" % (ipaddress_1.id,e)) - - try: - NIC.removeIp(self.apiclient, ipaddressid=(ipaddress_1.id + random_gen())) + NIC.removeIp( + self.apiclient, + ipaddressid=( + ipaddress_1.id + + random_gen())) self.fail("Removing invalid IP address, it should have failed") except Exception as e: - self.debug("Removing invalid IP failed as expected with Exception %s" % e) + self.debug( + "Removing invalid IP failed as expected with Exception %s" % + e) return @attr(tags=["advanced"]) @@ -308,9 +423,12 @@ class TestBasicOperations(cloudstackTestCase): try: NIC.removeIp(self.apiclient, ipaddressid="") - self.fail("Removing IP address without passing IP succeeded, it should have failed") + self.fail( + "Removing IP address without passing IP succeeded, it should have failed") except Exception as e: - self.debug("Removing IP from NIC without passing ipaddressid failed as expected with Exception %s" % e) + self.debug( + "Removing IP from NIC without passing ipaddressid failed as expected with Exception %s" % + e) return @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @@ -327,7 +445,8 @@ class TestBasicOperations(cloudstackTestCase): # 6. Try to list secondary IPs by passing correct vm id and its nic id # 7. Try to list secondary IPs by passing incorrect vm id and correct nic id # 8. Try to list secondary IPs by passing correct vm id and incorrect nic id - # 9. Try to list secondary IPs by passing incorrect vm id and incorrect nic id + # 9. Try to list secondary IPs by passing incorrect vm id and incorrect + # nic id # Validations: # 1. Step 4 should fail @@ -337,58 +456,89 @@ class TestBasicOperations(cloudstackTestCase): # 5. Step 8 should fail # 6. Step 9 should fail - - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) try: nics = NIC.list(self.apiclient) - self.fail("Listing NICs without passign VM id succeeded, it should have failed, list is %s" % nics) + self.fail( + "Listing NICs without passign VM id succeeded, it should have failed, list is %s" % + nics) except Exception as e: - self.debug("Listing NICs without passing virtual machine id failed as expected") + self.debug( + "Listing NICs without passing virtual machine id failed as expected") try: NIC.list(self.apiclient, virtualmachineid=virtual_machine.id) except Exception as e: - self.fail("Listing NICs for virtual machine %s failed with Exception %s" % (virtual_machine.id, e)) + self.fail( + "Listing NICs for virtual machine %s failed with Exception %s" % + (virtual_machine.id, e)) + + NIC.list( + self.apiclient, + virtualmachineid=virtual_machine.id, + nicid=virtual_machine.nic[0].id) try: - NIC.list(self.apiclient, virtualmachineid=virtual_machine.id, nicid=virtual_machine.nic[0].id) + nics = NIC.list( + self.apiclient, + virtualmachineid=( + virtual_machine.id + + random_gen()), + nicid=virtual_machine.nic[0].id) + self.fail( + "Listing NICs with wrong virtual machine id and right nic id succeeded, should have failed") except Exception as e: - self.fail("Listing NICs for virtual machine %s and nic id %s failed with Exception %s" % - (virtual_machine.id, virtual_machine.nic[0].id, e)) + self.debug( + "Listing NICs with wrong virtual machine id and right nic failed as expected with Exception %s" % + e) try: - nics = NIC.list(self.apiclient, virtualmachineid=(virtual_machine.id + random_gen()), nicid=virtual_machine.nic[0].id) - self.fail("Listing NICs with wrong virtual machine id and right nic id succeeded, should have failed") + nics = NIC.list( + self.apiclient, + virtualmachineid=virtual_machine.id, + nicid=( + virtual_machine.nic[0].id + + random_gen())) + self.fail( + "Listing NICs with correct virtual machine id but wrong nic id succeeded, should have failed") except Exception as e: - self.debug("Listing NICs with wrong virtual machine id and right nic failed as expected with Exception %s" % e) + self.debug( + "Listing NICs with correct virtual machine id but wrong nic id failed as expected with Exception %s" % + e) try: - nics = NIC.list(self.apiclient, virtualmachineid=virtual_machine.id, nicid=(virtual_machine.nic[0].id + random_gen())) - self.fail("Listing NICs with correct virtual machine id but wrong nic id succeeded, should have failed") + nics = NIC.list( + self.apiclient, + virtualmachineid=( + virtual_machine.id + + random_gen()), + nicid=( + virtual_machine.nic[0].id + + random_gen())) + self.fail( + "Listing NICs with wrong virtual machine id and wrong nic id succeeded, should have failed") except Exception as e: - self.debug("Listing NICs with correct virtual machine id but wrong nic id failed as expected with Exception %s" % e) - - try: - nics = NIC.list(self.apiclient, virtualmachineid=(virtual_machine.id+random_gen()), nicid=(virtual_machine.nic[0].id + random_gen())) - self.fail("Listing NICs with wrong virtual machine id and wrong nic id succeeded, should have failed") - except Exception as e: - self.debug("Listing NICs with wrong virtual machine id and wrong nic id failed as expected with Exception %s" % e) + self.debug( + "Listing NICs with wrong virtual machine id and wrong nic id failed as expected with Exception %s" % + e) return @@ -409,49 +559,65 @@ class TestBasicOperations(cloudstackTestCase): # Validations: # 1. All the operations should be successful - child_domain = Domain.create(self.apiclient,services=self.services["domain"], - parentdomainid=self.domain.id) + child_domain = Domain.create( + self.apiclient, + services=self.services["domain"], + parentdomainid=self.domain.id) - self.account = Account.create(self.apiclient,self.services["account"],domainid=child_domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=child_domain.id) self.cleanup.append(self.account) self.cleanup.append(child_domain) - apiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain) + apiclient = self.testClient.getUserApiClient( + UserName=self.account.name, + DomainName=self.account.domain) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s: %s" % (virtual_machine.id, e)) + ipaddress_1 = NIC.addIp(apiclient, id=virtual_machine.nic[0].id) try: NIC.list(apiclient, virtualmachineid=virtual_machine.id) except Exception as e: - self.fail("Listing NICs for virtual machine %s failed with Exception %s" % (virtual_machine.id, e)) + self.fail( + "Listing NICs for virtual machine %s failed with Exception %s" % + (virtual_machine.id, e)) try: - NIC.list(apiclient, virtualmachineid=virtual_machine.id, nicid=virtual_machine.nic[0].id) + NIC.list( + apiclient, + virtualmachineid=virtual_machine.id, + nicid=virtual_machine.nic[0].id) except Exception as e: - self.fail("Listing NICs for virtual machine %s and nic id %s failed with Exception %s" % - (virtual_machine.id, virtual_machine.nic[0].id, e)) + self.fail( + "Listing NICs for virtual machine %s and nic id %s failed with Exception %s" % + (virtual_machine.id, virtual_machine.nic[0].id, e)) try: NIC.removeIp(apiclient, ipaddressid=ipaddress_1.id) except Exception as e: - self.fail("Removing seondary IP %s from NIC failed as expected with Exception %s" % (ipaddress_1.id,e)) + self.fail( + "Removing seondary IP %s from NIC failed as expected with Exception %s" % + (ipaddress_1.id, e)) return + @ddt class TestNetworkRules(cloudstackTestCase): + """Test PF/NAT/static nat rules with the secondary IPs """ @@ -467,32 +633,42 @@ class TestNetworkRules(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"] + ) if cls.template == FAILED: - assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + assert False, "get_template() failed to return template with description %s" % 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.services["shared_network_offering_all_services"]["specifyVlan"] = "True" - cls.services["shared_network_offering_all_services"]["specifyIpRanges"] = "True" + cls.services["shared_network_offering_all_services"][ + "specifyVlan"] = "True" + cls.services["shared_network_offering_all_services"][ + "specifyIpRanges"] = "True" - cls.shared_network_offering = CreateEnabledNetworkOffering(cls.api_client, - cls.services["shared_network_offering_all_services"]) + cls.shared_network_offering = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["shared_network_offering_all_services"]) cls._cleanup.append(cls.shared_network_offering) cls.mode = cls.zone.networktype - cls.isolated_network_offering = CreateEnabledNetworkOffering(cls.api_client, cls.services["isolated_network_offering"]) + cls.isolated_network_offering = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["isolated_network_offering"]) cls._cleanup.append(cls.isolated_network_offering) - cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering(cls.api_client, cls.services["nw_offering_isolated_vpc"]) + cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["nw_offering_isolated_vpc"]) cls._cleanup.append(cls.isolated_network_offering_vpc) - cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) + cls.vpc_off = VpcOffering.create( + cls.api_client, + cls.services["vpc_offering"]) cls.vpc_off.update(cls.api_client, state='Enabled') cls._cleanup.append(cls.vpc_off) return @@ -509,7 +685,7 @@ class TestNetworkRules(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.cleanup = [ ] + self.cleanup = [] return def tearDown(self): @@ -524,10 +700,20 @@ class TestNetworkRules(cloudstackTestCase): def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus): """ List public IP and verify that NAT rule status for the IP is as desired """ - publiciplist = PublicIPAddress.list(self.apiclient, id=ipaddressid, listall=True) - self.assertEqual(validateList(publiciplist)[0], PASS, "Public IP list validation failed") - self.assertEqual(publiciplist[0].isstaticnat, natrulestatus, "isstaticnat should be %s, it is %s" % - (natrulestatus, publiciplist[0].isstaticnat)) + publiciplist = PublicIPAddress.list( + self.apiclient, + id=ipaddressid, + listall=True) + self.assertEqual( + validateList(publiciplist)[0], + PASS, + "Public IP list validation failed") + self.assertEqual( + publiciplist[0].isstaticnat, + natrulestatus, + "isstaticnat should be %s, it is %s" % + (natrulestatus, + publiciplist[0].isstaticnat)) return @@ -552,36 +738,71 @@ class TestNetworkRules(cloudstackTestCase): # 3. Step 6 should succeed # 4. Step 7 should fail - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - try: - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="nat"), - PASS, "Failure in creating NAT rule") - self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="nat"), - PASS, "Failure in creating NAT rule") - self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_2.ipaddress, value, ruletype="nat"), - PASS, "Failure in creating NAT rule") - self.assertEqual(createNetworkRules(self, virtual_machine, network, "255.255.255.300", value, ruletype="nat"), - FAIL, "Failure in NAT rule creation") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + ipaddress_1.ipaddress, + value, + ruletype="nat"), + PASS, + "Failure in creating NAT rule") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + ipaddress_1.ipaddress, + value, + ruletype="nat"), + PASS, + "Failure in creating NAT rule") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + ipaddress_2.ipaddress, + value, + ruletype="nat"), + PASS, + "Failure in creating NAT rule") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + "255.255.255.300", + value, + ruletype="nat"), + FAIL, + "Failure in NAT rule creation") return @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @@ -602,61 +823,81 @@ class TestNetworkRules(cloudstackTestCase): # 1. Step 5 should fail # 2. Step 6 should succeed - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) firewallrule = None - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - firewallrule = FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + firewallrule = FireWallRule.create( + self.apiclient, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) # Create NAT rule - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + natrule = NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) try: NIC.removeIp(self.apiclient, ipaddressid=ipaddress_1.id) - self.fail("Removing secondary IP succeeded while it had active NAT rule on it, should have failed") + self.fail( + "Removing secondary IP succeeded while it had active NAT rule on it, should have failed") except Exception as e: - self.debug("Removing secondary IP with active NAT rule failed as expected") + self.debug( + "Removing secondary IP with active NAT rule failed as expected") if firewallrule: try: firewallrule.delete(self.apiclient) except Exception as e: - self.fail("Exception while deleting firewall rule %s: %s" % (firewallrule.id, e)) + self.fail( + "Exception while deleting firewall rule %s: %s" % + (firewallrule.id, e)) - try: - natrule.delete(self.apiclient) - except Exception as e: - self.fail("Exception while deleting nat rule %s: %s" % (natrule.id, e)) + natrule.delete(self.apiclient) return @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @attr(tags=["advanced"]) - def test_disassociate_ip_mapped_to_secondary_ip_through_PF_rule(self, value): + def test_disassociate_ip_mapped_to_secondary_ip_through_PF_rule( + self, + value): """ Add secondary IP to NIC of a VM""" - ## Steps: + # Steps: # 1. Create Account and create network in it (isoalted/ shared/ vpc) # 2. Deploy a VM in this network and account # 3. Add secondary IP to the default nic of VM @@ -667,41 +908,55 @@ class TestNetworkRules(cloudstackTestCase): # Validations: # 1. Step 5 should succeed - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) # Create NAT rule - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) - try: - public_ip.delete(self.apiclient) - except Exception as e: - self.fail("Exception while deleting nat rule %s: %s" % (natrule.id, e)) + public_ip.delete(self.apiclient) return @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @@ -727,42 +982,80 @@ class TestNetworkRules(cloudstackTestCase): # 4. Step 7 should fail # 5. Step 8 should succeed - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - try: - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="staticnat"), - PASS, "Failure in creating NAT rule") - self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="staticnat"), - FAIL, "Failure in creating NAT rule") - self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_2.ipaddress, value, ruletype="staticnat"), - PASS, "Failure in creating NAT rule") - self.assertEqual(createNetworkRules(self, virtual_machine, network, "255.255.255.300", value, ruletype="staticnat"), - FAIL, "Failure in NAT rule creation") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + ipaddress_1.ipaddress, + value, + ruletype="staticnat"), + PASS, + "Failure in creating NAT rule") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + ipaddress_1.ipaddress, + value, + ruletype="staticnat"), + FAIL, + "Failure in creating NAT rule") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + ipaddress_2.ipaddress, + value, + ruletype="staticnat"), + PASS, + "Failure in creating NAT rule") + self.assertEqual( + createNetworkRules( + self, + virtual_machine, + network, + "255.255.255.300", + value, + ruletype="staticnat"), + FAIL, + "Failure in NAT rule creation") try: NIC.removeIp(self.apiclient, ipaddress_1.id) - self.fail("Ip address should not get removed when active static NAT rule is defined for it") + self.fail( + "Ip address should not get removed when active static NAT rule is defined for it") except Exception as e: - self.debug("Exception while removing secondary ip address as expected because static nat rule is present for it") + self.debug( + "Exception while removing secondary ip address as expected\ + because static nat rule is present for it: %s" % e) return @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) @@ -779,36 +1072,54 @@ class TestNetworkRules(cloudstackTestCase): # 5. Disable the static nat rule and enable it again # Validations: - # 1. Verify step 5 by listing seconday IP and checking the appropriate flag + # 1. Verify step 5 by listing seconday IP and checking the appropriate + # flag - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) - StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_1.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_1.ipaddress) self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, True) @@ -817,16 +1128,22 @@ class TestNetworkRules(cloudstackTestCase): self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, False) - StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_1.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_1.ipaddress) self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, True) public_ip.delete(self.apiclient) return + @ddt class TestVmNetworkOperations(cloudstackTestCase): + """Test VM and Network operations with network rules created on secondary IP """ @@ -842,31 +1159,41 @@ class TestVmNetworkOperations(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"] + ) if cls.template == FAILED: - assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + assert False, "get_template() failed to return template with description %s" % 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.services["shared_network_offering_all_services"]["specifyVlan"] = "True" - cls.services["shared_network_offering_all_services"]["specifyIpRanges"] = "True" + cls.services["shared_network_offering_all_services"][ + "specifyVlan"] = "True" + cls.services["shared_network_offering_all_services"][ + "specifyIpRanges"] = "True" - cls.shared_network_offering = CreateEnabledNetworkOffering(cls.api_client, - cls.services["shared_network_offering_all_services"]) + cls.shared_network_offering = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["shared_network_offering_all_services"]) cls._cleanup.append(cls.shared_network_offering) cls.mode = cls.zone.networktype - cls.isolated_network_offering = CreateEnabledNetworkOffering(cls.api_client, cls.services["isolated_network_offering"]) + cls.isolated_network_offering = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["isolated_network_offering"]) cls._cleanup.append(cls.isolated_network_offering) - cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering(cls.api_client, cls.services["nw_offering_isolated_vpc"]) + cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering( + cls.api_client, + cls.services["nw_offering_isolated_vpc"]) cls._cleanup.append(cls.isolated_network_offering_vpc) - cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) + cls.vpc_off = VpcOffering.create( + cls.api_client, + cls.services["vpc_offering"]) cls.vpc_off.update(cls.api_client, state='Enabled') cls._cleanup.append(cls.vpc_off) return @@ -883,7 +1210,7 @@ class TestVmNetworkOperations(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.cleanup = [ ] + self.cleanup = [] return def tearDown(self): @@ -897,10 +1224,20 @@ class TestVmNetworkOperations(cloudstackTestCase): def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus): """ List public IP and verify that NAT rule status for the IP is as desired """ - publiciplist = PublicIPAddress.list(self.apiclient, id=ipaddressid, listall=True) - self.assertEqual(validateList(publiciplist)[0], PASS, "Public IP list validation failed") - self.assertEqual(publiciplist[0].isstaticnat, natrulestatus, "isstaticnat should be %s, it is %s" % - (natrulestatus, publiciplist[0].isstaticnat)) + publiciplist = PublicIPAddress.list( + self.apiclient, + id=ipaddressid, + listall=True) + self.assertEqual( + validateList(publiciplist)[0], + PASS, + "Public IP list validation failed") + self.assertEqual( + publiciplist[0].isstaticnat, + natrulestatus, + "isstaticnat should be %s, it is %s" % + (natrulestatus, + publiciplist[0].isstaticnat)) return @@ -920,49 +1257,73 @@ class TestVmNetworkOperations(cloudstackTestCase): # 7. Verify that nat rule does not exist and static nat is not enabled for # secondary IP - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) # Add secondary IPs to default NIC of VM - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) # Acquire public IP addresses in the network - try: - public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip_1 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) - public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) - except Exception as e: - self.fail("Exception while acquiring public ip address: %s" % e) + public_ip_2 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) # Create Firewall and natrule for 1st IP and static nat rule for 2nd IP if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + natrule = NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) - StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_2.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip_2.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_2.ipaddress) # Delete VM virtual_machine.delete(self.apiclient, expunge=True) @@ -1001,46 +1362,70 @@ class TestVmNetworkOperations(cloudstackTestCase): # 6. Destroy the virtual machine and recover it # 7. Verify that nat and static nat rules exist - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - try: - public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip_1 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) - public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) - except Exception as e: - self.fail("Exception while acquiring public ip address: %s" % e) + public_ip_2 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + natrule = NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) - StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_2.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip_2.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_2.ipaddress) virtual_machine.delete(self.apiclient, expunge=False) virtual_machine.recover(self.apiclient) @@ -1048,7 +1433,10 @@ class TestVmNetworkOperations(cloudstackTestCase): retriesCount = 10 while True: vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id) - self.assertEqual(validateList(vms)[0], PASS, "vms list validation failed") + self.assertEqual( + validateList(vms)[0], + PASS, + "vms list validation failed") if str(vms[0].state).lower() == "stopped": break elif retriesCount == 0: @@ -1057,7 +1445,10 @@ class TestVmNetworkOperations(cloudstackTestCase): retriesCount -= 1 natrules = NATRule.list(self.apiclient, id=natrule.id, listall=True) - self.assertEqual(validateList(natrules)[0], PASS, "nat rules validation failed") + self.assertEqual( + validateList(natrules)[0], + PASS, + "nat rules validation failed") self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) @@ -1078,51 +1469,78 @@ class TestVmNetworkOperations(cloudstackTestCase): # 6. Restart the network with cleanup option True # 7. Verify that nat and static nat rules exist after network restart - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - try: - public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip_1 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) - public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) - except Exception as e: - self.fail("Exception while acquiring public ip address: %s" % e) + public_ip_2 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + natrule = NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) - StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_2.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip_2.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_2.ipaddress) network.restart(self.apiclient, cleanup=True) natrulelist = NATRule.list(self.apiclient, id=natrule.id, listall=True) - self.assertEqual(validateList(natrulelist)[0], PASS, "nat rules list validation failed") + self.assertEqual( + validateList(natrulelist)[0], + PASS, + "nat rules list validation failed") self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) return @@ -1142,51 +1560,78 @@ class TestVmNetworkOperations(cloudstackTestCase): # 6. Restart the network with cleanup option False # 7. Verify that nat and static nat rules exist after network restart - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - try: - public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip_1 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) - public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) - except Exception as e: - self.fail("Exception while acquiring public ip address: %s" % e) + public_ip_2 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + natrule = NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) - StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_2.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip_2.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_2.ipaddress) network.restart(self.apiclient, cleanup=False) natrulelist = NATRule.list(self.apiclient, id=natrule.id, listall=True) - self.assertEqual(validateList(natrulelist)[0], PASS, "nat rules list validation failed") + self.assertEqual( + validateList(natrulelist)[0], + PASS, + "nat rules list validation failed") self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) return @@ -1206,54 +1651,87 @@ class TestVmNetworkOperations(cloudstackTestCase): # 6. Reboot router VM # 7. Verify that nat and static nat rules exist after router restart - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id) self.cleanup.append(self.account) network = createNetwork(self, value) - try: - virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - networkids=[network.id],serviceofferingid=self.service_offering.id, - accountid=self.account.name,domainid=self.account.domainid) - except Exception as e: - self.fail("vm creation failed: %s" % e) + virtual_machine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + networkids=[ + network.id], + serviceofferingid=self.service_offering.id, + accountid=self.account.name, + domainid=self.account.domainid) - try: - ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) - except Exception as e: - self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + ipaddress_1 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp( + self.apiclient, + id=virtual_machine.nic[0].id) - try: - public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + public_ip_1 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) - public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, - zoneid=self.zone.id,domainid=self.account.domainid, - networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) - except Exception as e: - self.fail("Exception while acquiring public ip address: %s" % e) + public_ip_2 = PublicIPAddress.create( + self.api_client, + accountid=self.account.name, + zoneid=self.zone.id, + domainid=self.account.domainid, + networkid=network.id, + vpcid=network.vpcid if value == VPC_NETWORK else None) if value != VPC_NETWORK: - FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, - protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], - startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + FireWallRule.create( + self.apiclient, + ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', + cidrlist=[ + self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"], + endport=self.services["fwrule"]["endport"]) - natrule = NATRule.create(self.api_client, virtual_machine, - self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, - networkid=network.id, vmguestip = ipaddress_1.ipaddress) + natrule = NATRule.create( + self.api_client, + virtual_machine, + self.services["natrule"], + ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, + vmguestip=ipaddress_1.ipaddress) - StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, - network.id, vmguestip=ipaddress_2.ipaddress) + StaticNATRule.enable( + self.apiclient, + public_ip_2.ipaddress.id, + virtual_machine.id, + network.id, + vmguestip=ipaddress_2.ipaddress) - routers = Router.list(self.apiclient, networkid=network.id, listall=True) - self.assertEqual(validateList(routers)[0], PASS, "routers list validation failed") + routers = Router.list( + self.apiclient, + networkid=network.id, + listall=True) + self.assertEqual( + validateList(routers)[0], + PASS, + "routers list validation failed") Router.reboot(self.apiclient, id=routers[0].id) natrulelist = NATRule.list(self.apiclient, id=natrule.id, listall=True) - self.assertEqual(validateList(natrulelist)[0], PASS, "nat rules list validation failed") + self.assertEqual( + validateList(natrulelist)[0], + PASS, + "nat rules list validation failed") self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) return diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 4d71ed3755c..4492a3e65b0 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -17,139 +17,140 @@ """ P1 tests for shared networks """ -# Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.lib.base import (Account, - Network, - NetworkOffering, - VirtualMachine, - Project, - PhysicalNetwork, - Domain, - StaticNATRule, - FireWallRule, - ServiceOffering, - PublicIPAddress) + Network, + NetworkOffering, + VirtualMachine, + Project, + PhysicalNetwork, + Domain, + StaticNATRule, + FireWallRule, + ServiceOffering, + PublicIPAddress) from marvin.lib.utils import (cleanup_resources, - validateList, - xsplit) + validateList) from marvin.lib.common import (get_domain, - get_zone, - get_template, - wait_for_cleanup, - get_free_vlan) -from marvin.codes import * + get_zone, + get_template, + wait_for_cleanup, + get_free_vlan) +from marvin.codes import PASS 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' - } + "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' + } + class TestSharedNetworks(cloudstackTestCase): @@ -163,22 +164,22 @@ class TestSharedNetworks(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 @@ -198,13 +199,19 @@ class TestSharedNetworks(cloudstackTestCase): # of each test case to avoid overlapping of ip addresses shared_network_subnet_number = random.randrange(1, 254) - self.services["network"]["gateway"] = "172.16." + str(shared_network_subnet_number) + ".1" - self.services["network"]["startip"] = "172.16." + str(shared_network_subnet_number) + ".2" - self.services["network"]["endip"] = "172.16." + str(shared_network_subnet_number) + ".20" + self.services["network"]["gateway"] = "172.16." + \ + str(shared_network_subnet_number) + ".1" + self.services["network"]["startip"] = "172.16." + \ + str(shared_network_subnet_number) + ".2" + self.services["network"]["endip"] = "172.16." + \ + str(shared_network_subnet_number) + ".20" - self.services["network1"]["gateway"] = "172.16." + str(shared_network_subnet_number + 1) + ".1" - self.services["network1"]["startip"] = "172.16." + str(shared_network_subnet_number + 1) + ".2" - self.services["network1"]["endip"] = "172.16." + str(shared_network_subnet_number + 1) + ".20" + self.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 = [] @@ -221,26 +228,34 @@ class TestSharedNetworks(cloudstackTestCase): except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) - # below components is not a part of cleanup because to mandate the order and to cleanup network + # below components is not a part of cleanup because to mandate the + # order and to cleanup network try: for vm in self.cleanup_vms: - vm.delete(self.api_client) + vm.delete(self.api_client) except Exception as e: - raise Exception("Warning: Exception during virtual machines cleanup : %s" % e) + raise Exception( + "Warning: Exception during virtual machines cleanup : %s" % + e) try: for project in self.cleanup_projects: - project.delete(self.api_client) + project.delete(self.api_client) except Exception as e: - raise Exception("Warning: Exception during project cleanup : %s" % e) + raise Exception( + "Warning: Exception during project cleanup : %s" % + e) try: for account in self.cleanup_accounts: account.delete(self.api_client) except Exception as e: - raise Exception("Warning: Exception during account cleanup : %s" % e) + raise Exception( + "Warning: Exception during account cleanup : %s" % + e) - # Wait till all resources created are cleaned up completely and then attempt to delete domains + # Wait till all resources created are cleaned up completely and then + # attempt to delete domains wait_for_cleanup(self.api_client, ["account.cleanup.interval"]) try: @@ -254,7 +269,9 @@ class TestSharedNetworks(cloudstackTestCase): for domain in self.cleanup_domains: domain.delete(self.api_client) except Exception as e: - raise Exception("Warning: Exception during domain cleanup : %s" % e) + raise Exception( + "Warning: Exception during domain cleanup : %s" % + e) return @@ -278,57 +295,59 @@ class TestSharedNetworks(cloudstackTestCase): # 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 + # 4. listNetworkOfferings - name=mysharedoffering, should list enabled + # offering # Create an account self.account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.account.id, - listall=True - ) + self.api_client, + id=self.account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin Type account created: %s" % self.account.name) - # Verify that there should be at least one physical network present in zone. + # Verify that there should be at least one physical network present in + # zone. list_physical_networks_response = PhysicalNetwork.list( - self.api_client, - zoneid=self.zone.id - ) + self.api_client, + zoneid=self.zone.id + ) self.assertEqual( isinstance(list_physical_networks_response, list), True, "listPhysicalNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_physical_networks_response), 0, "listPhysicalNetworks should return at least one physical network." - ) + ) physical_network = list_physical_networks_response[0] @@ -339,60 +358,62 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) - self.debug("NetworkOffering created and enabled: %s" % self.shared_network_offering.id) + ) + self.debug( + "NetworkOffering created and enabled: %s" % + self.shared_network_offering.id) @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_sharedNetworkOffering_02(self): @@ -412,57 +433,59 @@ class TestSharedNetworks(cloudstackTestCase): # 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 + # 3. createNetworkOffering fails - vlan should be specified in advanced + # zone # Create an account self.account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.account.id, - listall=True - ) + self.api_client, + id=self.account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.account.name) - # Verify that there should be at least one physical network present in zone. + # Verify that there should be at least one physical network present in + # zone. list_physical_networks_response = PhysicalNetwork.list( - self.api_client, - zoneid=self.zone.id - ) + self.api_client, + zoneid=self.zone.id + ) self.assertEqual( isinstance(list_physical_networks_response, list), True, "listPhysicalNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_physical_networks_response), 0, "listPhysicalNetworks should return at least one physical network." - ) + ) physical_network = list_physical_networks_response[0] @@ -474,14 +497,16 @@ class TestSharedNetworks(cloudstackTestCase): try: # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - self.fail("Network offering got created with vlan as False in advance mode and shared guest type, which is invalid case.") + self.api_client, + self.services["network_offering"], + conservemode=False + ) + self.fail( + "Network offering got created with vlan as False in advance mode and shared guest type, which is invalid case.") except Exception as e: - self.debug("Network Offering creation failed with vlan as False in advance mode and shared guest type. Exception: %s" % - e) + self.debug( + "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") def test_sharedNetworkOffering_03(self): @@ -501,58 +526,59 @@ class TestSharedNetworks(cloudstackTestCase): # 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 - + # 3. createNetworkOffering fails - ip ranges should be specified when + # creating shared network offering # Create an account self.account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.account.id, - listall=True - ) + self.api_client, + id=self.account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin Type account created: %s" % self.account.name) - # Verify that there should be at least one physical network present in zone. + # Verify that there should be at least one physical network present in + # zone. list_physical_networks_response = PhysicalNetwork.list( - self.api_client, - zoneid=self.zone.id - ) + self.api_client, + zoneid=self.zone.id + ) self.assertEqual( isinstance(list_physical_networks_response, list), True, "listPhysicalNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_physical_networks_response), 0, "listPhysicalNetworks should return at least one physical network." - ) + ) physical_network = list_physical_networks_response[0] @@ -564,14 +590,17 @@ class TestSharedNetworks(cloudstackTestCase): try: # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - 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.") + self.api_client, + self.services["network_offering"], + 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.") 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) + self.debug( + "Network Offering creation failed with vlan as true and ip ranges as False in advance mode and with shared guest type.\ + Exception : %s" % + e) @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_createSharedNetwork_All(self): @@ -609,73 +638,74 @@ class TestSharedNetworks(cloudstackTestCase): # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.name) # Create an user account self.user_account = Account.create( - self.api_client, - self.services["account"], - admin=False, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=False, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.user_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.user_account.id, - listall=True - ) + self.api_client, + id=self.user_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The user account created is not enabled." - ) + ) self.debug("User type account created: %s" % self.user_account.name) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -684,165 +714,180 @@ class TestSharedNetworks(cloudstackTestCase): self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "Domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.network = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id - ) + self.api_client, + id=self.network.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) + self.debug( + "Shared Network created for scope domain: %s" % + self.network.id) self.admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - networkids=self.network.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + networkids=self.network.id, + serviceofferingid=self.service_offering.id + ) self.cleanup_vms.append(self.admin_account_virtual_machine) vms = VirtualMachine.list( - self.api_client, - id=self.admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - self.debug("Virtual Machine created: %s" % self.admin_account_virtual_machine.id) + self.debug( + "Virtual Machine created: %s" % + self.admin_account_virtual_machine.id) - ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) + ip_range = list( + netaddr.iter_iprange( + unicode( + self.services["network"]["startip"]), unicode( + self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: - self.fail("Virtual machine ip should be from the ip range assigned to network created.") + self.fail( + "Virtual machine ip should be from the ip range assigned to network created.") self.user_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.user_account.name, - domainid=self.user_account.domainid, - serviceofferingid=self.service_offering.id, - networkids=self.network.id - ) + self.api_client, + self.services["virtual_machine"], + accountid=self.user_account.name, + domainid=self.user_account.domainid, + serviceofferingid=self.service_offering.id, + networkids=self.network.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.user_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.user_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - self.debug("Virtual Machine created: %s" % self.user_account_virtual_machine.id) + self.debug( + "Virtual Machine created: %s" % + self.user_account_virtual_machine.id) - ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) + ip_range = list( + netaddr.iter_iprange( + unicode( + self.services["network"]["startip"]), unicode( + self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: - self.fail("Virtual machine ip should be from the ip range assigned to network created.") + self.fail( + "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): @@ -880,73 +925,74 @@ class TestSharedNetworks(cloudstackTestCase): # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.name) # Create an user account self.user_account = Account.create( - self.api_client, - self.services["account"], - admin=False, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=False, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.user_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.user_account.id, - listall=True - ) + self.api_client, + id=self.user_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The user account created is not enabled." - ) + ) self.debug("User type account created: %s" % self.user_account.name) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -957,141 +1003,151 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be by default disabled." - ) + ) - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network Offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "Account" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.network = Network.create( - self.api_client, - self.services["network"], - accountid=self.user_account.name, - domainid=self.user_account.domainid, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["network"], + accountid=self.user_account.name, + domainid=self.user_account.domainid, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id - ) + self.api_client, + id=self.network.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) try: self.admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.network.id, - 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.") + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.network.id, + 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.") except Exception as e: - self.debug("Virtual Machine creation failed as network used have scoped only for user account. Exception: %s" % e) + self.debug( + "Virtual Machine creation failed as network used have scoped only for user account. Exception: %s" % + e) self.user_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.user_account.name, - domainid=self.user_account.domainid, - networkids=self.network.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + accountid=self.user_account.name, + domainid=self.user_account.domainid, + networkids=self.network.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.user_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.user_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) + ip_range = list( + netaddr.iter_iprange( + unicode( + self.services["network"]["startip"]), unicode( + self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: - self.fail("Virtual machine ip should be from the ip range assigned to network created.") + self.fail( + "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): @@ -1131,133 +1187,138 @@ class TestSharedNetworks(cloudstackTestCase): # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.id) # create domain self.dom_domain = Domain.create( - self.api_client, - self.services["domain"], - ) + self.api_client, + self.services["domain"], + ) self.cleanup_domains.append(self.dom_domain) # verify that the account got created with state enabled list_domains_response = Domain.list( - self.api_client, - id=self.dom_domain.id - ) + self.api_client, + id=self.dom_domain.id + ) self.assertEqual( isinstance(list_domains_response, list), True, "listDomains returned invalid object in response." - ) + ) self.assertNotEqual( len(list_domains_response), 0, "listDomains returned empty list." - ) + ) self.debug("Domain created: %s" % self.dom_domain.id) # Create admin account self.domain_admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.dom_domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.dom_domain.id + ) self.cleanup_accounts.append(self.domain_admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.domain_admin_account.id, - listall=True - ) + self.api_client, + id=self.domain_admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The domain admin account created is not enabled." - ) + ) - self.debug("Domain admin account created: %s" % self.domain_admin_account.id) + self.debug( + "Domain admin account created: %s" % + self.domain_admin_account.id) # Create an user account self.domain_user_account = Account.create( - self.api_client, - self.services["account"], - admin=False, - domainid=self.dom_domain.id - ) + self.api_client, + self.services["account"], + admin=False, + domainid=self.dom_domain.id + ) self.cleanup_accounts.append(self.domain_user_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.domain_user_account.id, - listall=True - ) + self.api_client, + id=self.domain_user_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The domain user account created is not enabled." - ) + ) - self.debug("Domain user account created: %s" % self.domain_user_account.id) + self.debug( + "Domain user account created: %s" % + self.domain_user_account.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -1268,174 +1329,188 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be by default disabled." - ) + ) - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network Offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.network = Network.create( - self.api_client, - self.services["network"], - accountid=self.domain_admin_account.name, - domainid=self.dom_domain.id, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["network"], + accountid=self.domain_admin_account.name, + domainid=self.dom_domain.id, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id, - listall=True - ) + self.api_client, + id=self.network.id, + listall=True + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) try: self.admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.network.id, - 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.") + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.network.id, + 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.") except Exception as e: - self.debug("Virtual Machine creation failed as network used have scoped only for DOM domain. Exception: %s" % e) + self.debug( + "Virtual Machine creation failed as network used have scoped only for DOM domain. Exception: %s" % + e) self.domain_user_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.domain_user_account.name, - domainid=self.domain_user_account.domainid, - networkids=self.network.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + accountid=self.domain_user_account.name, + domainid=self.domain_user_account.domainid, + networkids=self.network.id, + serviceofferingid=self.service_offering.id + ) self.cleanup_vms.append(self.domain_user_account_virtual_machine) vms = VirtualMachine.list( - self.api_client, - id=self.domain_user_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.domain_user_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) + ip_range = list( + netaddr.iter_iprange( + unicode( + self.services["network"]["startip"]), unicode( + self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: - self.fail("Virtual machine ip should be from the ip range assigned to network created.") + self.fail( + "Virtual machine ip should be from the ip range assigned to network created.") self.domain_admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.domain_admin_account.name, - domainid=self.domain_admin_account.domainid, - networkids=self.network.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + accountid=self.domain_admin_account.name, + domainid=self.domain_admin_account.domainid, + networkids=self.network.id, + serviceofferingid=self.service_offering.id + ) self.cleanup_vms.append(self.domain_admin_account_virtual_machine) vms = VirtualMachine.list( - self.api_client, - id=self.domain_admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.domain_admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) + ip_range = list( + netaddr.iter_iprange( + unicode( + self.services["network"]["startip"]), unicode( + self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: - self.fail("Virtual machine ip should be from the ip range assigned to network created.") + self.fail( + "Virtual machine ip should be from the ip range assigned to network created.") @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_createSharedNetwork_projectSpecific(self): @@ -1474,35 +1549,35 @@ class TestSharedNetworks(cloudstackTestCase): # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin account created: %s" % self.admin_account.id) @@ -1510,29 +1585,29 @@ class TestSharedNetworks(cloudstackTestCase): self.services["project"]["displaytext"] = "proj-SADJKS" self.project1 = Project.create( - self.api_client, - self.services["project"], - account=self.admin_account.name, - domainid=self.admin_account.domainid - ) + self.api_client, + self.services["project"], + account=self.admin_account.name, + domainid=self.admin_account.domainid + ) self.cleanup_projects.append(self.project1) list_projects_response = Project.list( - self.api_client, - id=self.project1.id, - listall=True - ) + self.api_client, + id=self.project1.id, + listall=True + ) self.assertEqual( isinstance(list_projects_response, list), True, "listProjects returned invalid object in response." - ) + ) self.assertNotEqual( len(list_projects_response), 0, "listProjects should return at least one." - ) + ) self.debug("Project created: %s" % self.project1.id) @@ -1540,33 +1615,34 @@ class TestSharedNetworks(cloudstackTestCase): self.services["project"]["displaytext"] = "proj-SLDJK" self.project2 = Project.create( - self.api_client, - self.services["project"], - account=self.admin_account.name, - domainid=self.admin_account.domainid - ) + self.api_client, + self.services["project"], + account=self.admin_account.name, + domainid=self.admin_account.domainid + ) self.cleanup_projects.append(self.project2) list_projects_response = Project.list( - self.api_client, - id=self.project2.id, - listall=True - ) + self.api_client, + id=self.project2.id, + listall=True + ) self.assertEqual( isinstance(list_projects_response, list), True, "listProjects returned invalid object in response." - ) + ) self.assertNotEqual( len(list_projects_response), 0, "listProjects should return at least one." - ) + ) self.debug("Project2 created: %s" % self.project2.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -1575,145 +1651,150 @@ class TestSharedNetworks(cloudstackTestCase): self.services["network_offering"]["specifyVlan"] = "True" self.services["network_offering"]["specifyIpRanges"] = "True" - # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be by default disabled." - ) + ) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) - self.debug("Shared Network found: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network found: %s" % + self.shared_network_offering.id) # create network using the shared network offering created self.services["network"]["acltype"] = "account" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.network = Network.create( - self.api_client, - self.services["network"], - projectid=self.project1.id, - domainid=self.admin_account.domainid, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["network"], + projectid=self.project1.id, + domainid=self.admin_account.domainid, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id, - projectid=self.project1.id, - listall=True - ) + self.api_client, + id=self.network.id, + projectid=self.project1.id, + listall=True + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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.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( - self.api_client, - self.services["virtual_machine"], - networkids=self.network.id, - projectid=self.project1.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + networkids=self.network.id, + projectid=self.project1.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.project1_admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.project1_admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - ip_range = list(netaddr.iter_iprange(unicode(self.services["network"]["startip"]), unicode(self.services["network"]["endip"]))) + ip_range = list( + netaddr.iter_iprange( + unicode( + self.services["network"]["startip"]), unicode( + self.services["network"]["endip"]))) if netaddr.IPAddress(unicode(vms[0].nic[0].ipaddress)) not in ip_range: - self.fail("Virtual machine ip should be from the ip range assigned to network created.") + self.fail( + "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 ") + @unittest.skip( + "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 """ @@ -1736,43 +1817,44 @@ class TestSharedNetworks(cloudstackTestCase): # 2. listNetworkOfferings - name=mysharedoffering , should list offering in disabled state # 3. listNetworkOfferings - name=mysharedoffering, should list enabled offering # 4. listPhysicalNetworks should return at least one active physical network - # 5. network creation should FAIL since VLAN is used for guest networks + # 5. network creation should FAIL since VLAN is used for guest networks # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Domain admin account created: %s" % self.admin_account.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -1781,82 +1863,88 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network Offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created - self.services["network"]["vlan"] = str.split(str(physical_network.vlan), "-")[0] + self.services["network"]["vlan"] = str.split( + str(physical_network.vlan), "-")[0] self.services["network"]["acltype"] = "domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan try: self.network = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) - self.fail("Network created with used vlan %s id, which is invalid" % shared_vlan) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) + self.fail( + "Network created with used vlan %s id, which is invalid" % + shared_vlan) except Exception as e: - self.debug("Network creation failed because the valn id being used by another network. Exception: %s" % e) - + self.debug( + "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): @@ -1882,42 +1970,44 @@ class TestSharedNetworks(cloudstackTestCase): # 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( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin account created: %s" % self.admin_account.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -1928,117 +2018,124 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network Offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "Domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan - self.debug("Creating a shared network in non-cloudstack VLAN %s" % 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"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id - ) + self.api_client, + id=self.network.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) self.services["network1"]["vlan"] = self.services["network"]["vlan"] self.services["network1"]["acltype"] = "domain" - self.services["network1"]["networkofferingid"] = self.shared_network_offering.id + self.services["network1"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network1"]["physicalnetworkid"] = physical_network.id try: self.network1 = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network1) - self.fail("Network got created with used vlan id, which is invalid") + self.fail( + "Network got created with used vlan id, which is invalid") except Exception as e: - self.debug("Network creation failed because the valn id being used by another network. Exception: %s" % e) + self.debug( + "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): @@ -2052,43 +2149,45 @@ class TestSharedNetworks(cloudstackTestCase): # Validations, # 1. shared networks should be created successfully # 2. a. VM should deploy successfully - # b. VM should be deployed in both networks and have IP in both the networks + # b. VM should be deployed in both networks and have IP in both the + # networks # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin account created: %s" % self.admin_account.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -2099,103 +2198,105 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.network = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id - ) + self.api_client, + id=self.network.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) self.services["network1"]["acltype"] = "domain" - self.services["network1"]["networkofferingid"] = self.shared_network_offering.id + self.services["network1"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network1"]["physicalnetworkid"] = physical_network.id shared_vlan = get_free_vlan(self.api_client, self.zone.id)[1] @@ -2205,90 +2306,97 @@ class TestSharedNetworks(cloudstackTestCase): self.services["network1"]["vlan"] = shared_vlan self.network1 = Network.create( - self.api_client, - self.services["network1"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network1"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network1) list_networks_response = Network.list( - self.api_client, - id=self.network1.id - ) + self.api_client, + id=self.network1.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) self.network_admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.network.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.network.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.network_admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.network_admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - self.debug("Virtual Machine created: %s" % self.network_admin_account_virtual_machine.id) + self.debug( + "Virtual Machine created: %s" % + self.network_admin_account_virtual_machine.id) - self.assertTrue(self.network_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") + self.assertTrue( + self.network_admin_account_virtual_machine.nic[0].ipaddress is not None, + "ip should be assigned to running virtual machine") self.network1_admin_account_virtual_machine = VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.network1.id, - serviceofferingid=self.service_offering.id - ) + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.network1.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.network1_admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.network1_admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) - self.debug("Virtual Machine created: %s" % self.network1_admin_account_virtual_machine.id) + ) + self.debug( + "Virtual Machine created: %s" % + self.network1_admin_account_virtual_machine.id) - self.assertTrue(self.network1_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") + self.assertTrue( + self.network1_admin_account_virtual_machine.nic[0].ipaddress is not None, + "ip should be assigned to running virtual machine") @attr(tags=["advanced", "advancedns"], required_hardware="true") def test_deployVM_isolatedAndShared(self): @@ -2307,39 +2415,40 @@ class TestSharedNetworks(cloudstackTestCase): # 3. # a. VM should deploy successfully # b. VM should be deployed in both networks and have IP in both the networks - # 4. FW and PF should apply successfully, ssh into the VM should work over isolated network + # 4. FW and PF should apply successfully, ssh into the VM should work + # over isolated network # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.name) @@ -2348,286 +2457,306 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) self.isolated_network_offering = NetworkOffering.create( - self.api_client, - self.services["isolated_network_offering"], - conservemode=False - ) - + self.api_client, + self.services["isolated_network_offering"], + conservemode=False + ) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.isolated_network_offering, - self.api_client, - id=self.isolated_network_offering.id, - state="enabled" - ) + self.isolated_network_offering, + self.api_client, + id=self.isolated_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.isolated_network_offering.id - ) + self.api_client, + id=self.isolated_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", - "The 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" % self.isolated_network_offering.id) + self.debug( + "Isolated Network Offering created: %s" % + self.isolated_network_offering.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") # create network using the shared network offering created self.services["network"]["acltype"] = "domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.shared_network = Network.create( - self.api_client, - self.services["network"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["network"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) self.cleanup_networks.append(self.shared_network) list_networks_response = Network.list( - self.api_client, - id=self.shared_network.id - ) + self.api_client, + id=self.shared_network.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) 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) self.isolated_network = Network.create( - self.api_client, - self.services["isolated_network"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkofferingid=self.isolated_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["isolated_network"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkofferingid=self.isolated_network_offering.id, + zoneid=self.zone.id + ) self.cleanup_networks.append(self.isolated_network) list_networks_response = Network.list( - self.api_client, - id=self.isolated_network.id - ) + self.api_client, + id=self.isolated_network.id + ) self.assertEqual( isinstance(list_networks_response, list), True, "listNetworks returned invalid object in response." - ) + ) self.assertNotEqual( len(list_networks_response), 0, "listNetworks returned empty list." - ) + ) self.debug("Isolated Network created: %s" % self.isolated_network.id) self.shared_network_admin_account_virtual_machine = \ - VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.shared_network.id, - serviceofferingid=self.service_offering.id - ) + VirtualMachine.create( + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.shared_network.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.shared_network_admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.shared_network_admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) - self.debug("Virtual Machine created: %s" % self.shared_network_admin_account_virtual_machine.id) + ) + self.debug( + "Virtual Machine created: %s" % + self.shared_network_admin_account_virtual_machine.id) - self.assertTrue(self.shared_network_admin_account_virtual_machine.nic[0].ipaddress is not None, + self.assertTrue( + 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 = \ - VirtualMachine.create( - self.api_client, - self.services["virtual_machine"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkids=self.isolated_network.id, - serviceofferingid=self.service_offering.id - ) + VirtualMachine.create( + self.api_client, + self.services["virtual_machine"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkids=self.isolated_network.id, + serviceofferingid=self.service_offering.id + ) vms = VirtualMachine.list( - self.api_client, - id=self.isolated_network_admin_account_virtual_machine.id, - listall=True - ) + self.api_client, + id=self.isolated_network_admin_account_virtual_machine.id, + listall=True + ) self.assertEqual( isinstance(vms, list), True, "listVirtualMachines returned invalid object in response." - ) + ) self.assertNotEqual( len(vms), 0, "listVirtualMachines returned empty list." - ) + ) - self.debug("Virtual Machine created: %s" % self.isolated_network_admin_account_virtual_machine.id) + self.debug( + "Virtual Machine created: %s" % + self.isolated_network_admin_account_virtual_machine.id) - self.assertTrue(self.isolated_network_admin_account_virtual_machine.nic[0].ipaddress is not None, "ip should be assigned to running virtual machine") + self.assertTrue( + self.isolated_network_admin_account_virtual_machine.nic[0].ipaddress is not None, + "ip should be assigned to running virtual machine") - self.debug("Associating public IP for account: %s" % self.admin_account.name) + self.debug( + "Associating public IP for account: %s" % + self.admin_account.name) self.public_ip = PublicIPAddress.create( - self.api_client, - accountid=self.admin_account.name, - zoneid=self.zone.id, - domainid=self.admin_account.domainid, - networkid=self.isolated_network.id - ) + self.api_client, + accountid=self.admin_account.name, + zoneid=self.zone.id, + domainid=self.admin_account.domainid, + networkid=self.isolated_network.id + ) - self.debug("Associated %s with network %s" % (self.public_ip.ipaddress.ipaddress, self.isolated_network.id)) - self.debug("Creating PF rule for IP address: %s" % self.public_ip.ipaddress.ipaddress) + self.debug( + "Associated %s with network %s" % + (self.public_ip.ipaddress.ipaddress, self.isolated_network.id)) + self.debug( + "Creating PF rule for IP address: %s" % + self.public_ip.ipaddress.ipaddress) public_ip = self.public_ip.ipaddress # Enable Static NAT for VM StaticNATRule.enable( - self.api_client, - public_ip.id, - self.isolated_network_admin_account_virtual_machine.id - ) + self.api_client, + public_ip.id, + self.isolated_network_admin_account_virtual_machine.id + ) self.debug("Enabled static NAT for public IP ID: %s" % public_ip.id) # Create Firewall rule on source NAT fw_rule = FireWallRule.create( - 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"] - ) + 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"] + ) self.debug("Created firewall rule: %s" % fw_rule.id) fw_rules = FireWallRule.list( - self.api_client, - id=fw_rule.id - ) + self.api_client, + id=fw_rule.id + ) self.assertEqual( - isinstance(fw_rules, list), - True, - "List fw rules should return a valid firewall rules" - ) + isinstance(fw_rules, list), + True, + "List fw rules should return a valid firewall rules" + ) self.assertNotEqual( - len(fw_rules), - 0, - "Length of fw rules response should not be zero" - ) + len(fw_rules), + 0, + "Length of fw rules response should not be zero" + ) # Should be able to SSH VM try: - self.debug("SSH into VM: %s" % self.isolated_network_admin_account_virtual_machine.id) - ssh = self.isolated_network_admin_account_virtual_machine.get_ssh_client(ipaddress=self.public_ip.ipaddress.ipaddress) + self.debug( + "SSH into VM: %s" % + self.isolated_network_admin_account_virtual_machine.id) + self.isolated_network_admin_account_virtual_machine.get_ssh_client( + ipaddress=self.public_ip.ipaddress.ipaddress) except Exception as e: - self.fail("SSH Access failed for %s: %s" % (self.isolated_network_admin_account_virtual_machine.ipaddress, e)) + self.fail( + "SSH Access failed for %s: %s" % + (self.isolated_network_admin_account_virtual_machine.ipaddress, e)) @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_networkWithsubdomainaccessTrue(self): @@ -2640,39 +2769,40 @@ class TestSharedNetworks(cloudstackTestCase): # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -2683,82 +2813,85 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) - + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network Offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "Account" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.services["network"]["subdomainaccess"] = "True" try: self.network = Network.create( - self.api_client, - self.services["network"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["network"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) self.fail("Network creation should fail.") except: - self.debug("Network creation failed because subdomainaccess parameter was passed when scope was account.") + self.debug( + "Network creation failed because subdomainaccess parameter was passed when scope was account.") @attr(tags=["advanced", "advancedns"], required_hardware="false") def test_networkWithsubdomainaccessFalse(self): @@ -2771,39 +2904,40 @@ class TestSharedNetworks(cloudstackTestCase): # Create admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) self.assertEqual( isinstance(list_accounts_response, list), True, "listAccounts returned invalid object in response." - ) + ) self.assertNotEqual( len(list_accounts_response), 0, "listAccounts returned empty list." - ) + ) self.assertEqual( list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.id) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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") @@ -2814,81 +2948,85 @@ class TestSharedNetworks(cloudstackTestCase): # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) + ) - self.debug("Shared Network Offering created: %s" % self.shared_network_offering.id) + self.debug( + "Shared Network Offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) self.assertEqual( isinstance(list_network_offerings_response, list), True, "listNetworkOfferings returned invalid object in response." - ) + ) self.assertNotEqual( len(list_network_offerings_response), 0, "listNetworkOfferings returned empty list." - ) + ) self.assertEqual( list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "Account" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.services["network"]["subdomainaccess"] = "False" try: self.network = Network.create( - self.api_client, - self.services["network"], - accountid=self.admin_account.name, - domainid=self.admin_account.domainid, - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id - ) + self.api_client, + self.services["network"], + accountid=self.admin_account.name, + domainid=self.admin_account.domainid, + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id + ) self.fail("Network creation should fail.") except: - self.debug("Network creation failed because subdomainaccess parameter was passed when scope was account.") + self.debug( + "Network creation failed because subdomainaccess parameter was passed when scope was account.") @attr(tags=["advanced"], required_hardware="false") def test_escalation_ES1621(self): @@ -2910,18 +3048,18 @@ class TestSharedNetworks(cloudstackTestCase): """ # Creating Admin account self.admin_account = Account.create( - self.api_client, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.api_client, + self.services["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup_accounts.append(self.admin_account) # verify that the account got created with state enabled list_accounts_response = Account.list( - self.api_client, - id=self.admin_account.id, - listall=True - ) + self.api_client, + id=self.admin_account.id, + listall=True + ) status = validateList(list_accounts_response) self.assertEqual( PASS, @@ -2932,9 +3070,10 @@ class TestSharedNetworks(cloudstackTestCase): list_accounts_response[0].state, "enabled", "The admin account created is not enabled." - ) + ) self.debug("Admin type account created: %s" % self.admin_account.name) - physical_network, shared_vlan = get_free_vlan(self.api_client, self.zone.id) + 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) @@ -2942,15 +3081,15 @@ class TestSharedNetworks(cloudstackTestCase): self.services["network_offering"]["specifyIpRanges"] = "True" # Create Network Offering self.shared_network_offering = NetworkOffering.create( - self.api_client, - self.services["network_offering"], - conservemode=False - ) + self.api_client, + self.services["network_offering"], + conservemode=False + ) # Verify that the network offering got created list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) status = validateList(list_network_offerings_response) self.assertEquals( PASS, @@ -2961,20 +3100,22 @@ class TestSharedNetworks(cloudstackTestCase): list_network_offerings_response[0].state, "Disabled", "The network offering created should be bydefault disabled." - ) - self.debug("Shared Network offering created: %s" % self.shared_network_offering.id) + ) + self.debug( + "Shared Network offering created: %s" % + self.shared_network_offering.id) # Update network offering state from disabled to enabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="enabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="enabled" + ) # Verify that the state of the network offering is updated list_network_offerings_response = NetworkOffering.list( - self.api_client, - id=self.shared_network_offering.id - ) + self.api_client, + id=self.shared_network_offering.id + ) status = validateList(list_network_offerings_response) self.assertEquals( PASS, @@ -2985,23 +3126,24 @@ class TestSharedNetworks(cloudstackTestCase): list_network_offerings_response[0].state, "Enabled", "The network offering state should get updated to Enabled." - ) + ) # create network using the shared network offering created self.services["network"]["acltype"] = "Domain" - self.services["network"]["networkofferingid"] = self.shared_network_offering.id + self.services["network"][ + "networkofferingid"] = self.shared_network_offering.id self.services["network"]["physicalnetworkid"] = physical_network.id self.services["network"]["vlan"] = shared_vlan self.network = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network) list_networks_response = Network.list( - self.api_client, - id=self.network.id - ) + self.api_client, + id=self.network.id + ) status = validateList(list_accounts_response) self.assertEquals( PASS, @@ -3011,37 +3153,41 @@ class TestSharedNetworks(cloudstackTestCase): self.assertEqual( list_networks_response[0].specifyipranges, True, - "The network is created with ip range but the flag is set to False." - ) - self.debug("Shared Network created for scope domain: %s" % self.network.id) + "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) # Create another network with same ip range and vlan. It should fail try: self.network1 = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) 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") + self.fail( + "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 vlan - physical_network, shared_vlan1 = get_free_vlan(self.api_client, self.zone.id) + # Create another shared network with overlapped ip range but different + # vlan + physical_network, shared_vlan1 = get_free_vlan( + 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.network2 = Network.create( - self.api_client, - self.services["network"], - networkofferingid=self.shared_network_offering.id, - zoneid=self.zone.id, - ) + self.api_client, + self.services["network"], + networkofferingid=self.shared_network_offering.id, + zoneid=self.zone.id, + ) self.cleanup_networks.append(self.network2) list_networks_response = Network.list( - self.api_client, - id=self.network2.id - ) + self.api_client, + id=self.network2.id + ) status = validateList(list_networks_response) self.assertEquals( PASS, @@ -3052,17 +3198,16 @@ class TestSharedNetworks(cloudstackTestCase): 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." - ) - self.debug("Shared Network created for scope domain: %s" % self.network2.id) + ) + self.debug( + "Shared Network created for scope domain: %s" % + self.network2.id) # Update network offering state from enabled to disabled. NetworkOffering.update( - self.shared_network_offering, - self.api_client, - id=self.shared_network_offering.id, - state="disabled" - ) + self.shared_network_offering, + self.api_client, + id=self.shared_network_offering.id, + state="disabled" + ) self.cleanup_networks.append(self.shared_network_offering) return - - -