CLOUDSTACK-9511: fix test_privategw_acl.py to handle multiple physical networks
modified script to handle case where there can be multple physical networks in the zone Signed-off-by: Rohit Yadav <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/fcdc2cc5 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/fcdc2cc5 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/fcdc2cc5 Branch: refs/heads/4.8 Commit: fcdc2cc52979e74c6a67c765251c429bf354e90f Parents: 9eb8b2e Author: Murali Reddy <[email protected]> Authored: Thu Sep 29 22:41:34 2016 +0530 Committer: Rohit Yadav <[email protected]> Committed: Wed Oct 5 15:11:00 2016 +0530 ---------------------------------------------------------------------- test/integration/smoke/test_privategw_acl.py | 62 +++++++++++++++-------- 1 file changed, 41 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fcdc2cc5/test/integration/smoke/test_privategw_acl.py ---------------------------------------------------------------------- diff --git a/test/integration/smoke/test_privategw_acl.py b/test/integration/smoke/test_privategw_acl.py index d2e08f5..3b9e0a7 100644 --- a/test/integration/smoke/test_privategw_acl.py +++ b/test/integration/smoke/test_privategw_acl.py @@ -195,8 +195,9 @@ class TestPrivateGwACL(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() self.hypervisor = self.testClient.getHypervisorInfo() - + self.logger.debug("Creating Admin Account for Domain ID ==> %s" % self.domain.id) self.account = Account.create( self.apiclient, @@ -236,12 +237,16 @@ class TestPrivateGwACL(cloudstackTestCase): self.cleanup = [vpc, vpc_off, self.account] - physical_networks = get_physical_networks(self.apiclient, self.zone.id) - if not physical_networks: + physical_network = self.get_guest_traffic_physical_network(self.apiclient, self.zone.id) + if not physical_network: self.fail("No Physical Networks found!") - vlans = physical_networks[0].vlan.split('-') - vlan_1 = int(vlans[0]) + qresultset = self.dbclient.execute( + "select vnet from op_dc_vnet_alloc where physical_network_id=\ + (select id from physical_network where uuid='%s' ) and taken is NULL;" % physical_network.id + ) + vlans = qresultset + vlan_1 = int(vlans[0][0]) acl = self.createACL(vpc) self.createACLItem(acl.id) @@ -304,12 +309,16 @@ class TestPrivateGwACL(cloudstackTestCase): self.cleanup = [vpc_1, vpc_2, vpc_off, self.account] - physical_networks = get_physical_networks(self.apiclient, self.zone.id) - if not physical_networks: + physical_network = self.get_guest_traffic_physical_network(self.apiclient, self.zone.id) + if not physical_network: self.fail("No Physical Networks found!") - vlans = physical_networks[0].vlan.split('-') - vlan_1 = int(vlans[0]) + qresultset = self.dbclient.execute( + "select vnet from op_dc_vnet_alloc where physical_network_id=\ + (select id from physical_network where uuid='%s' ) and taken is NULL and reservation_id is NULL and account_id is NULL ORDER BY id DESC;" % physical_network.id + ) + vlans = qresultset + vlan_1 = int(vlans[0][0]) network_1 = self.createNetwork(vpc_1, gateway = '10.0.1.1') network_2 = self.createNetwork(vpc_2, gateway = '10.0.2.1') @@ -356,12 +365,15 @@ class TestPrivateGwACL(cloudstackTestCase): self.cleanup = [vpc_1, vpc_off, self.account] - physical_networks = get_physical_networks(self.apiclient, self.zone.id) - if not physical_networks: + physical_network = self.get_guest_traffic_physical_network(self.apiclient, self.zone.id) + if not physical_network: self.fail("No Physical Networks found!") - - vlans = physical_networks[0].vlan.split('-') - vlan_1 = int(vlans[0]) + qresultset = self.dbclient.execute( + "select vnet from op_dc_vnet_alloc where physical_network_id=\ + (select id from physical_network where uuid='%s' ) and taken is NULL;" % physical_network.id + ) + vlans = qresultset + vlan_1 = int(vlans[0][0]) net_offering_no_lb = "network_offering_no_lb" @@ -392,7 +404,7 @@ class TestPrivateGwACL(cloudstackTestCase): public_ip_1 = self.acquire_publicip(vpc_1, network_1) nat_rule_1 = self.create_natrule(vpc_1, vm1, public_ip_1, network_1) - + self.check_private_gateway_interfaces() self.check_pvt_gw_connectivity(vm1, public_ip_1, [vm2.nic[0].ipaddress, vm3.nic[0].ipaddress, vm4.nic[0].ipaddress]) @@ -573,14 +585,14 @@ class TestPrivateGwACL(cloudstackTestCase): return obj_network def createPvtGw(self, vpc, ip_address, gateway, aclId, vlan): - physical_networks = get_physical_networks(self.apiclient, self.zone.id) - if not physical_networks: + physical_network = self.get_guest_traffic_physical_network(self.apiclient, self.zone.id) + if not physical_network: self.fail("No Physical Networks found!") - self.logger.debug('::: Physical Networks ::: ==> %s' % physical_networks) + self.logger.debug('::: Physical Networks ::: ==> %s' % physical_network) createPrivateGatewayCmd = createPrivateGateway.createPrivateGatewayCmd() - createPrivateGatewayCmd.physicalnetworkid = physical_networks[0].id + createPrivateGatewayCmd.physicalnetworkid = physical_network.id createPrivateGatewayCmd.gateway = gateway createPrivateGatewayCmd.netmask = "255.255.255.0" createPrivateGatewayCmd.ipaddress = ip_address @@ -691,13 +703,13 @@ class TestPrivateGwACL(cloudstackTestCase): self.logger.debug("Ping to VM inside another Network Tier") result = str(ssh.execute(ssh_command)) - self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count("3 packets received"))) + self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count("3 received"))) except Exception as e: self.fail("SSH Access failed for %s: %s" % \ (virtual_machine, e) ) - succeeded_pings += result.count("3 packets received") + succeeded_pings += result.count("3 received") self.assertTrue(succeeded_pings >= minimum_vms_to_pass, @@ -831,3 +843,11 @@ class TestPrivateGwACL(cloudstackTestCase): if cnts[vals.index(status_to_check)] != expected_count: self.fail("Expected '%s' routers at state '%s', but found '%s'!" % (expected_count, status_to_check, cnts[vals.index(status_to_check)])) + + def get_guest_traffic_physical_network(self, apiclient, zoneid): + physical_networks = get_physical_networks(apiclient, zoneid) + if not physical_networks: + return None + for physical_network in physical_networks: + if physical_network.vlan: + return physical_network
