CLOUDSTACK-8915 - Improve routers tests

- Add egress tests in order to check if VMs can reach the outside world
   - Increase the wait when testing redundant routers: they fight to become master
   - Make sure the clean up is done properly
This commit is contained in:
Wilder Rodrigues 2015-09-30 10:29:46 +02:00
parent 260ff836b6
commit 7c7c0149b2
2 changed files with 100 additions and 20 deletions

View File

@ -236,7 +236,7 @@ class TestVPCRedundancy(cloudstackTestCase):
admin=True,
domainid=self.domain.id)
self.cleanup = [self.account]
self._cleanup = [self.account]
self.debug("Creating a VPC offering..")
self.vpc_off = VpcOffering.create(
self.apiclient,
@ -256,13 +256,6 @@ class TestVPCRedundancy(cloudstackTestCase):
domainid=self.account.domainid)
return
def tearDown(self):
try:
cleanup_resources(self.apiclient, self.cleanup)
except Exception as e:
self.debug("Warning: Exception during cleanup : %s" % e)
return
def query_routers(self, count=2, showall=False):
self.routers = list_routers(self.apiclient,
account=self.account.name,
@ -318,7 +311,6 @@ class TestVPCRedundancy(cloudstackTestCase):
conservemode=False)
nw_off.update(self.apiclient, state='Enabled')
self._cleanup.append(nw_off)
self.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
@ -333,6 +325,7 @@ class TestVPCRedundancy(cloudstackTestCase):
gateway=gateway,
vpcid=vpc.id if vpc else self.vpc.id
)
self.debug("Created network with ID: %s" % obj_network.id)
except Exception, e:
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
@ -419,16 +412,16 @@ class TestVPCRedundancy(cloudstackTestCase):
self.fail("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress))
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_01a_create_redundant_VPC(self):
""" Create a redundant vpc with two networks with two vms in each network """
self.debug("Starting est 1a")
def test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL(self):
""" Create a redundant VPC with two networks with two VMs in each network """
self.debug("Starting test_01_create_redundant_VPC_2tiers_4VMs_4IPs_4PF_ACL")
self.query_routers()
self.networks.append(self.create_network(self.services["network_offering"], "10.1.1.1"))
self.networks.append(self.create_network(self.services["network_offering_no_lb"], "10.1.2.1"))
time.sleep(30)
self.check_master_status(2)
self.add_nat_rules()
self.do_vpc_test(False)
time.sleep(15)
self.stop_router("MASTER")
# wait for the backup router to transit to master state
@ -437,15 +430,29 @@ class TestVPCRedundancy(cloudstackTestCase):
self.do_vpc_test(False)
self.delete_nat_rules()
time.sleep(45)
self.check_master_status(1)
self.do_vpc_test(True)
self.start_router()
self.add_nat_rules()
time.sleep(15)
time.sleep(45)
self.check_master_status(2)
self.do_vpc_test(False)
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_02_redundant_VPC_default_routes(self):
""" Create a redundant VPC with two networks with two VMs in each network and check default routes"""
self.debug("Starting test_02_redundant_VPC_default_routes")
self.query_routers()
self.networks.append(self.create_network(self.services["network_offering"], "10.1.1.1"))
self.networks.append(self.create_network(self.services["network_offering_no_lb"], "10.1.2.1"))
time.sleep(30)
self.check_master_status(2)
self.add_nat_rules()
self.test_default_routes()
def delete_nat_rules(self):
for o in self.networks:
for vm in o.get_vms():
@ -470,6 +477,35 @@ class TestVPCRedundancy(cloudstackTestCase):
for vm in o.get_vms():
self.check_ssh_into_vm(vm.get_vm(), vm.get_ip(), expectFail=expectFail, retries=retries)
def test_default_routes(self):
for o in self.networks:
for vmObj in o.get_vms():
ssh_command = "ping -c 3 8.8.8.8"
# Should be able to SSH VM
result = 'failed'
try:
vm = vmObj.get_vm()
public_ip = vmObj.get_ip()
self.debug("SSH into VM: %s" % public_ip.ipaddress.ipaddress)
ssh = vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
self.debug("Ping to google.com from VM")
result = ssh.execute(ssh_command)
self.debug("SSH result: %s" % str(result))
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
(vmObj.get_ip(), e)
)
self.assertEqual(
result.count("0% packet loss"),
1,
"Ping to outside world from VM should be successful"
)
class networkO(object):
def __init__(self, net):

View File

@ -279,7 +279,6 @@ class TestVPCNics(cloudstackTestCase):
conservemode=False)
nw_off.update(self.apiclient, state='Enabled')
self._cleanup.append(nw_off)
self.debug('Created and Enabled NetworkOffering')
self.services["network"]["name"] = "NETWORK-" + str(gateway)
@ -294,6 +293,7 @@ class TestVPCNics(cloudstackTestCase):
gateway=gateway,
vpcid=vpc.id if vpc else self.vpc.id
)
self.debug("Created network with ID: %s" % obj_network.id)
except Exception, e:
self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
@ -369,8 +369,8 @@ class TestVPCNics(cloudstackTestCase):
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_01_VPC_nics_after_destroy(self):
""" Create a vpc with two networks with two vms in each network """
self.debug("Starting test 1")
""" Create a VPC with two networks with one VM in each network and test nics after destroy"""
self.debug("Starting test_01_VPC_nics_after_destroy")
self.query_routers()
net1 = self.create_network(self.services["network_offering"], "10.1.1.1")
@ -380,7 +380,7 @@ class TestVPCNics(cloudstackTestCase):
self.networks.append(net2)
self.add_nat_rules()
self.do_vpc_test()
self.test_ssh_to_vm()
self.stop_router()
self.destroy_router()
@ -388,7 +388,22 @@ class TestVPCNics(cloudstackTestCase):
net1.add_vm(self.deployvm_in_network(net1.get_net()))
self.add_nat_rules()
self.do_vpc_test()
self.test_ssh_to_vm()
@attr(tags=["advanced", "intervlan"], required_hardware="true")
def test_02_VPC_default_routes(self):
""" Create a VPC with two networks with one VM in each network and test default routes"""
self.debug("Starting test_02_VPC_default_routes")
self.query_routers()
net1 = self.create_network(self.services["network_offering"], "10.1.1.1")
net2 = self.create_network(self.services["network_offering_no_lb"], "10.1.2.1")
self.networks.append(net1)
self.networks.append(net2)
self.add_nat_rules()
self.test_default_routes()
def delete_nat_rules(self):
for o in self.networks:
@ -406,11 +421,40 @@ class TestVPCNics(cloudstackTestCase):
vm.set_nat(self.create_natrule(vm.get_vm(), vm.get_ip(), o.get_net()))
time.sleep(5)
def do_vpc_test(self):
def test_ssh_to_vm(self):
for o in self.networks:
for vm in o.get_vms():
self.check_ssh_into_vm(vm.get_vm(), vm.get_ip())
def test_default_routes(self):
for o in self.networks:
for vmObj in o.get_vms():
ssh_command = "ping -c 3 8.8.8.8"
# Should be able to SSH VM
result = 'failed'
try:
vm = vmObj.get_vm()
public_ip = vmObj.get_ip()
self.debug("SSH into VM: %s" % public_ip.ipaddress.ipaddress)
ssh = vm.get_ssh_client(ipaddress=public_ip.ipaddress.ipaddress)
self.debug("Ping to google.com from VM")
result = ssh.execute(ssh_command)
self.debug("SSH result: %s" % str(result))
except Exception as e:
self.fail("SSH Access failed for %s: %s" % \
(vmObj.get_ip(), e)
)
self.assertEqual(
result.count("0% packet loss"),
1,
"Ping to outside world from VM should be successful"
)
class networkO(object):
def __init__(self, net):