From a3d08aebb70bff102cb898d8c979f14cecc275cd Mon Sep 17 00:00:00 2001 From: Gaurav Aradhye Date: Thu, 6 Nov 2014 18:23:08 +0530 Subject: [PATCH] CLOUDSTACK-7856: test_vpc_network_pf_rules.py - Check if httpd service is running or not, if not, start it Signed-off-by: SrikanteswaraRao Talluri --- .../component/test_vpc_network_pfrules.py | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index c3a81614c18..e49642b427c 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -18,7 +18,7 @@ """ Component tests for VPC network functionality - Port Forwarding Rules. """ from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase, unittest +from marvin.cloudstackTestCase import cloudstackTestCase from marvin.lib.base import (stopRouter, startRouter, Account, @@ -327,20 +327,31 @@ class TestVPCNetworkPFRules(cloudstackTestCase): else: self.debug("Failed to SSH into VM - %s" % (public_ip.ipaddress.ipaddress)) - def check_wget_from_vm(self, vm, public_ip, testnegative=False): + def check_wget_from_vm(self, vm, public_ip, network=None, testnegative=False, isVmAccessible=True): import urllib self.debug("Checking if we can wget from a VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) try: + if not isVmAccessible: + self.create_natrule(vm, public_ip, network) + # Start httpd service on VM first + sshClient = vm.get_ssh_client() + sshClient.execute("service httpd start") + time.sleep(5) + ssh_response = str(sshClient.execute("service httpd status")).lower() + self.debug("httpd service status is: %s" % ssh_response) + if not "running" in ssh_response: + raise Exception("Failed to start httpd service") + urllib.urlretrieve("http://%s/test.html" % public_ip.ipaddress.ipaddress, filename="test.html") if not testnegative: self.debug("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) else: self.fail("Successesfull to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) - except: + except Exception as e: if not testnegative: - self.fail("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) + self.fail("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e)) else: - self.debug("Failed to wget from VM=%s http server on public_ip=%s" % (vm.name, public_ip.ipaddress.ipaddress)) + self.debug("Failed to wget from VM=%s http server on public_ip=%s: %s" % (vm.name, public_ip.ipaddress.ipaddress, e)) def create_natrule(self, vm, public_ip, network, services=None): self.debug("Creating NAT rule in network for vm with public IP") @@ -687,7 +698,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): nat_rule.delete(self.apiclient) self.start_vpcrouter(router) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) return @attr(tags=["advanced", "intervlan"], required_hardware="true") @@ -717,7 +729,8 @@ class TestVPCNetworkPFRules(cloudstackTestCase): http_rule.delete(self.apiclient) nat_rule.delete(self.apiclient) self.check_ssh_into_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) return @attr(tags=["advanced", "intervlan"], required_hardware="true") @@ -781,10 +794,14 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True) - self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True) - self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True, + isVmAccessible=False, network=network_2) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True, + isVmAccessible=False, network=network_2) return @attr(tags=["advanced", "intervlan"], required_hardware="true") @@ -843,8 +860,12 @@ class TestVPCNetworkPFRules(cloudstackTestCase): self.check_ssh_into_vm(vm_2, public_ip_2, testnegative=True) self.check_ssh_into_vm(vm_3, public_ip_3, testnegative=True) self.check_ssh_into_vm(vm_4, public_ip_4, testnegative=True) - self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True) - self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True) - self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True) - self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True) + self.check_wget_from_vm(vm_1, public_ip_1, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_2, public_ip_2, testnegative=True, + isVmAccessible=False, network=network_1) + self.check_wget_from_vm(vm_3, public_ip_3, testnegative=True, + isVmAccessible=False, network=network_2) + self.check_wget_from_vm(vm_4, public_ip_4, testnegative=True, + isVmAccessible=False, network=network_2) return