Guard return value from get_hostname

It's possible that the get_hostname call use when resolving the
full hostname of a IP address may return None in the event that
a hostname cannot be resolved via DNS.

Ensure that None values are not added to the list of hostnames
to validated for SSH key configuration.

Change-Id: I910224f9c22b7e0b8e53faddc64e3715389cc691
Closes-Bug: 1641614
This commit is contained in:
James Page
2016-11-14 14:24:32 +00:00
parent 7fe23b9dc3
commit 366398e0b3

View File

@@ -769,10 +769,11 @@ def ssh_compute_add(public_key, rid=None, unit=None, user=None):
hosts.append(short)
else:
hn = get_hostname(private_address)
hosts.append(hn)
short = hn.split('.')[0]
if ns_query(short):
hosts.append(short)
if hn:
hosts.append(hn)
short = hn.split('.')[0]
if ns_query(short):
hosts.append(short)
for host in list(set(hosts)):
add_known_host(host, unit, user)