CLOUDSTACK-4453: fetch host credentials from marvin config

Tests would fetch the credentials for the host to hop into router to
check for essential services. Each test would require to put in the host
information into the test data. Instead fetch the credential information
from the marvin configuration file.

Signed-off-by: Prasanna Santhanam <tsp@apache.org>
(cherry picked from commit 4b546ce85d40098ade69c575316e76e25a422a12)
This commit is contained in:
Prasanna Santhanam 2013-08-22 20:15:16 +05:30
parent ad0fba31a3
commit b3306497fe
3 changed files with 75 additions and 40 deletions

View File

@ -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

View File

@ -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

View File

@ -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):