diff --git a/test/integration/component/test_routers.py b/test/integration/component/test_routers.py index e0d90d6ed92..888302fa7c2 100644 --- a/test/integration/component/test_routers.py +++ b/test/integration/component/test_routers.py @@ -24,7 +24,6 @@ from marvin.cloudstackAPI import * from marvin.integration.lib.utils import * from marvin.integration.lib.base import * from marvin.integration.lib.common import * -from marvin.remoteSSHClient import remoteSSHClient #Import System modules import time @@ -1219,20 +1218,24 @@ class TestRouterStopCreateFW(cloudstackTestCase): ) host = hosts[0] # For DNS and DHCP check 'dnsmasq' process status - result = get_process_status( - host.ipaddress, - self.services['host']["publicport"], - self.services['host']["username"], - self.services['host']["password"], - router.linklocalip, - 'iptables -t nat -L' - ) - self.debug("iptables -t nat -L: %s" % result) - self.debug("Public IP: %s" % public_ip.ipaddress) - res = str(result) - self.assertEqual( - res.count(str(public_ip.ipaddress)), - 1, - "Check public IP address" - ) + try: + host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) + result = get_process_status( + host.ipaddress, + 22, + host.user, + host.passwd, + router.linklocalip, + 'iptables -t nat -L' + ) + self.debug("iptables -t nat -L: %s" % result) + self.debug("Public IP: %s" % public_ip.ipaddress) + res = str(result) + self.assertEqual( + res.count(str(public_ip.ipaddress)), + 1, + "Check public IP address" + ) + except KeyError: + self.skipTest("Provide a marvin config file with host credentials to run %s" % self._testMethodName) return diff --git a/test/integration/smoke/test_routers.py b/test/integration/smoke/test_routers.py index 49c4969adf0..bd53dcafaf2 100644 --- a/test/integration/smoke/test_routers.py +++ b/test/integration/smoke/test_routers.py @@ -42,6 +42,7 @@ class Services: "cpunumber": 1, "cpuspeed": 100, # in MHz "memory": 128, # In MBs + "storagetype" : "local", }, "virtual_machine": { @@ -191,11 +192,13 @@ class TestRouterServices(cloudstackTestCase): hypervisor=self.apiclient.hypervisor ) else: + try: + host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) result = get_process_status( host.ipaddress, - self.services['virtual_machine']["publicport"], - self.vm_1.username, - self.vm_1.password, + 22, + host.user, + host.passwd, router.linklocalip, "service dnsmasq status" ) @@ -207,8 +210,14 @@ class TestRouterServices(cloudstackTestCase): 1, "Check dnsmasq service is running or not" ) + except KeyError: + self.skipTest("Marvin configuration has no host credentials to check router services") return + + + + @attr(tags = ["advanced", "smoke"]) def test_02_router_internal_adv(self): """Test router internal advanced zone @@ -264,14 +273,18 @@ class TestRouterServices(cloudstackTestCase): hypervisor=self.apiclient.hypervisor ) else: - result = get_process_status( - host.ipaddress, - self.services['virtual_machine']["publicport"], - self.vm_1.username, - self.vm_1.password, - router.linklocalip, - "service dnsmasq status" - ) + try: + host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) + result = get_process_status( + host.ipaddress, + 22, + host.user, + host.passwd, + router.linklocalip, + "service dnsmasq status" + ) + except KeyError: + self.skipTest("Marvin configuration has no host credentials to check router services") res = str(result) self.debug("Dnsmasq process status: %s" % res) @@ -292,14 +305,18 @@ class TestRouterServices(cloudstackTestCase): hypervisor=self.apiclient.hypervisor ) else: - result = get_process_status( - host.ipaddress, - self.services['virtual_machine']["publicport"], - self.vm_1.username, - self.vm_1.password, - router.linklocalip, - "service haproxy status" - ) + try: + host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) + result = get_process_status( + host.ipaddress, + 22, + host.user, + host.passwd, + router.linklocalip, + "service haproxy status" + ) + except KeyError: + self.skipTest("Marvin configuration has no host credentials to check router services") res = str(result) self.assertEqual( res.count("running"), @@ -467,14 +484,18 @@ class TestRouterServices(cloudstackTestCase): hypervisor=self.apiclient.hypervisor ) else: - res = get_process_status( + try: + host.user, host.passwd = get_host_credentials(self.config, host.ipaddress) + res = get_process_status( host.ipaddress, - self.services['virtual_machine']["publicport"], - self.vm_1.username, - self.vm_1.password, + 22, + host.user, + host.passwd, router.linklocalip, "uptime" ) + except KeyError: + self.skipTest("Marvin configuration has no host credentials to check router services") # res = 12:37:14 up 1 min, 0 users, load average: 0.61, 0.22, 0.08 # Split result to check the uptime diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index 7863bfb8d94..7c4c7045a2f 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -153,6 +153,17 @@ def fetch_api_client(config_file='datacenterCfg'): ) ) +def get_host_credentials(config, hostname): + """Get login information for a host `hostname` from marvin's `config` + + @return the tuple username, password for the host else raise keyerror""" + for zone in config.zones: + for pod in zone.pods: + for cluster in pod.clusters: + for host in cluster.hosts: + if str(host.url).find(str(hostname)) > 0: + return host.username, host.password + raise KeyError("Please provide the marvin configuration file with credentials to your hosts") def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None):