Merge pull request #215 from gnuoy/get_unit_hostnames-fqdn
Add support for fqdn in get_unit_hostnames
This commit is contained in:
@@ -429,6 +429,20 @@ class TestGenericUtils(ut_utils.BaseTestCase):
|
||||
actual = generic_utils.get_unit_hostnames(_units)
|
||||
|
||||
self.assertEqual(actual, expected)
|
||||
expected_run_calls = [
|
||||
mock.call('testunit/1', 'hostname'),
|
||||
mock.call('testunit/2', 'hostname')]
|
||||
self._run.assert_has_calls(expected_run_calls)
|
||||
|
||||
self._run.reset_mock()
|
||||
self._run.side_effect = [{"Stdout": _hostname1},
|
||||
{"Stdout": _hostname2}]
|
||||
expected_run_calls = [
|
||||
mock.call('testunit/1', 'hostname -f'),
|
||||
mock.call('testunit/2', 'hostname -f')]
|
||||
|
||||
actual = generic_utils.get_unit_hostnames(_units, fqdn=True)
|
||||
self._run.assert_has_calls(expected_run_calls)
|
||||
|
||||
def test_port_knock_units(self):
|
||||
self.patch(
|
||||
|
||||
@@ -113,11 +113,14 @@ def get_network_config(net_topology, ignore_env_vars=False,
|
||||
return net_info
|
||||
|
||||
|
||||
def get_unit_hostnames(units):
|
||||
def get_unit_hostnames(units, fqdn=False):
|
||||
"""Return a dict of juju unit names to hostnames."""
|
||||
host_names = {}
|
||||
for unit in units:
|
||||
output = model.run_on_unit(unit.entity_id, 'hostname')
|
||||
cmd = 'hostname'
|
||||
if fqdn:
|
||||
cmd = cmd + ' -f'
|
||||
output = model.run_on_unit(unit.entity_id, cmd)
|
||||
hostname = output['Stdout'].strip()
|
||||
host_names[unit.entity_id] = hostname
|
||||
return host_names
|
||||
|
||||
Reference in New Issue
Block a user