From 433d5839a196dd4a8ecc49abc192c580d79c175d Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Mon, 9 Sep 2013 11:41:13 +0530 Subject: [PATCH] CLOUDSTACK-4608: Resolve the hostname to fqdn from marvin config In case the marvin configuration does not contain fqdn information fetch and compare the fqdns of hostip from `cloud`.`host` with the fqdn available on the client. Signed-off-by: Prasanna Santhanam --- tools/marvin/marvin/integration/lib/utils.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/integration/lib/utils.py index c2403d4fb0a..a6abe0665eb 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/integration/lib/utils.py @@ -25,6 +25,8 @@ import string import random import imaplib import email +import socket +import urlparse import datetime from marvin.cloudstackAPI import * from marvin.remoteSSHClient import remoteSSHClient @@ -154,16 +156,23 @@ def fetch_api_client(config_file='datacenterCfg'): ) ) -def get_host_credentials(config, hostname): - """Get login information for a host `hostname` from marvin's `config` +def get_host_credentials(config, hostip): + """Get login information for a host `hostip` (ipv4) 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 + if str(host.url).startswith('http'): + hostname = urlparse.urlsplit(str(host.url)).netloc + else: + hostname = str(host.url) + try: + if socket.getfqdn(hostip) == socket.getfqdn(hostname): + return host.username, host.password + except socket.error, e: + raise Exception("Unresolvable host %s error is %s" % (hostip, e)) raise KeyError("Please provide the marvin configuration file with credentials to your hosts")