Skip to content

Commit 433d583

Browse files
author
Prasanna Santhanam
committed
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 <tsp@apache.org>
1 parent b11a8e1 commit 433d583

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

  • tools/marvin/marvin/integration/lib

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import random
2626
import imaplib
2727
import email
28+
import socket
29+
import urlparse
2830
import datetime
2931
from marvin.cloudstackAPI import *
3032
from marvin.remoteSSHClient import remoteSSHClient
@@ -154,16 +156,23 @@ def fetch_api_client(config_file='datacenterCfg'):
154156
)
155157
)
156158

157-
def get_host_credentials(config, hostname):
158-
"""Get login information for a host `hostname` from marvin's `config`
159+
def get_host_credentials(config, hostip):
160+
"""Get login information for a host `hostip` (ipv4) from marvin's `config`
159161
160162
@return the tuple username, password for the host else raise keyerror"""
161163
for zone in config.zones:
162164
for pod in zone.pods:
163165
for cluster in pod.clusters:
164166
for host in cluster.hosts:
165-
if str(host.url).find(str(hostname)) > 0:
166-
return host.username, host.password
167+
if str(host.url).startswith('http'):
168+
hostname = urlparse.urlsplit(str(host.url)).netloc
169+
else:
170+
hostname = str(host.url)
171+
try:
172+
if socket.getfqdn(hostip) == socket.getfqdn(hostname):
173+
return host.username, host.password
174+
except socket.error, e:
175+
raise Exception("Unresolvable host %s error is %s" % (hostip, e))
167176
raise KeyError("Please provide the marvin configuration file with credentials to your hosts")
168177

169178

0 commit comments

Comments
 (0)