Skip to content

Commit b330649

Browse files
author
Prasanna Santhanam
committed
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 <[email protected]> (cherry picked from commit 4b546ce85d40098ade69c575316e76e25a422a12)
1 parent ad0fba3 commit b330649

3 files changed

Lines changed: 75 additions & 40 deletions

File tree

test/integration/component/test_routers.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from marvin.integration.lib.utils import *
2525
from marvin.integration.lib.base import *
2626
from marvin.integration.lib.common import *
27-
from marvin.remoteSSHClient import remoteSSHClient
2827

2928
#Import System modules
3029
import time
@@ -1219,20 +1218,24 @@ def test_01_RouterStopCreateFW(self):
12191218
)
12201219
host = hosts[0]
12211220
# For DNS and DHCP check 'dnsmasq' process status
1222-
result = get_process_status(
1223-
host.ipaddress,
1224-
self.services['host']["publicport"],
1225-
self.services['host']["username"],
1226-
self.services['host']["password"],
1227-
router.linklocalip,
1228-
'iptables -t nat -L'
1229-
)
1230-
self.debug("iptables -t nat -L: %s" % result)
1231-
self.debug("Public IP: %s" % public_ip.ipaddress)
1232-
res = str(result)
1233-
self.assertEqual(
1234-
res.count(str(public_ip.ipaddress)),
1235-
1,
1236-
"Check public IP address"
1237-
)
1221+
try:
1222+
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
1223+
result = get_process_status(
1224+
host.ipaddress,
1225+
22,
1226+
host.user,
1227+
host.passwd,
1228+
router.linklocalip,
1229+
'iptables -t nat -L'
1230+
)
1231+
self.debug("iptables -t nat -L: %s" % result)
1232+
self.debug("Public IP: %s" % public_ip.ipaddress)
1233+
res = str(result)
1234+
self.assertEqual(
1235+
res.count(str(public_ip.ipaddress)),
1236+
1,
1237+
"Check public IP address"
1238+
)
1239+
except KeyError:
1240+
self.skipTest("Provide a marvin config file with host credentials to run %s" % self._testMethodName)
12381241
return

test/integration/smoke/test_routers.py

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self):
4242
"cpunumber": 1,
4343
"cpuspeed": 100, # in MHz
4444
"memory": 128, # In MBs
45+
"storagetype" : "local",
4546
},
4647
"virtual_machine":
4748
{
@@ -191,11 +192,13 @@ def test_01_router_internal_basic(self):
191192
hypervisor=self.apiclient.hypervisor
192193
)
193194
else:
195+
try:
196+
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
194197
result = get_process_status(
195198
host.ipaddress,
196-
self.services['virtual_machine']["publicport"],
197-
self.vm_1.username,
198-
self.vm_1.password,
199+
22,
200+
host.user,
201+
host.passwd,
199202
router.linklocalip,
200203
"service dnsmasq status"
201204
)
@@ -207,8 +210,14 @@ def test_01_router_internal_basic(self):
207210
1,
208211
"Check dnsmasq service is running or not"
209212
)
213+
except KeyError:
214+
self.skipTest("Marvin configuration has no host credentials to check router services")
210215
return
211216

217+
218+
219+
220+
212221
@attr(tags = ["advanced", "smoke"])
213222
def test_02_router_internal_adv(self):
214223
"""Test router internal advanced zone
@@ -264,14 +273,18 @@ def test_02_router_internal_adv(self):
264273
hypervisor=self.apiclient.hypervisor
265274
)
266275
else:
267-
result = get_process_status(
268-
host.ipaddress,
269-
self.services['virtual_machine']["publicport"],
270-
self.vm_1.username,
271-
self.vm_1.password,
272-
router.linklocalip,
273-
"service dnsmasq status"
274-
)
276+
try:
277+
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
278+
result = get_process_status(
279+
host.ipaddress,
280+
22,
281+
host.user,
282+
host.passwd,
283+
router.linklocalip,
284+
"service dnsmasq status"
285+
)
286+
except KeyError:
287+
self.skipTest("Marvin configuration has no host credentials to check router services")
275288
res = str(result)
276289
self.debug("Dnsmasq process status: %s" % res)
277290

@@ -292,14 +305,18 @@ def test_02_router_internal_adv(self):
292305
hypervisor=self.apiclient.hypervisor
293306
)
294307
else:
295-
result = get_process_status(
296-
host.ipaddress,
297-
self.services['virtual_machine']["publicport"],
298-
self.vm_1.username,
299-
self.vm_1.password,
300-
router.linklocalip,
301-
"service haproxy status"
302-
)
308+
try:
309+
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
310+
result = get_process_status(
311+
host.ipaddress,
312+
22,
313+
host.user,
314+
host.passwd,
315+
router.linklocalip,
316+
"service haproxy status"
317+
)
318+
except KeyError:
319+
self.skipTest("Marvin configuration has no host credentials to check router services")
303320
res = str(result)
304321
self.assertEqual(
305322
res.count("running"),
@@ -467,14 +484,18 @@ def test_04_restart_network_wo_cleanup(self):
467484
hypervisor=self.apiclient.hypervisor
468485
)
469486
else:
470-
res = get_process_status(
487+
try:
488+
host.user, host.passwd = get_host_credentials(self.config, host.ipaddress)
489+
res = get_process_status(
471490
host.ipaddress,
472-
self.services['virtual_machine']["publicport"],
473-
self.vm_1.username,
474-
self.vm_1.password,
491+
22,
492+
host.user,
493+
host.passwd,
475494
router.linklocalip,
476495
"uptime"
477496
)
497+
except KeyError:
498+
self.skipTest("Marvin configuration has no host credentials to check router services")
478499

479500
# res = 12:37:14 up 1 min, 0 users, load average: 0.61, 0.22, 0.08
480501
# Split result to check the uptime

tools/marvin/marvin/integration/lib/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ def fetch_api_client(config_file='datacenterCfg'):
153153
)
154154
)
155155

156+
def get_host_credentials(config, hostname):
157+
"""Get login information for a host `hostname` from marvin's `config`
158+
159+
@return the tuple username, password for the host else raise keyerror"""
160+
for zone in config.zones:
161+
for pod in zone.pods:
162+
for cluster in pod.clusters:
163+
for host in cluster.hosts:
164+
if str(host.url).find(str(hostname)) > 0:
165+
return host.username, host.password
166+
raise KeyError("Please provide the marvin configuration file with credentials to your hosts")
156167

157168

158169
def get_process_status(hostip, port, username, password, linklocalip, process, hypervisor=None):

0 commit comments

Comments
 (0)