From f891df345afa57c0c7734e8f04cca9a3d5881778 Mon Sep 17 00:00:00 2001 From: Douglas Jordan Date: Sat, 10 Mar 2018 07:20:08 +0100 Subject: This commit fixes get_hostname on the AzureDataSource. LP: #1754495 --- cloudinit/sources/DataSourceAzure.py | 2 ++ tests/unittests/test_datasource/test_azure.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 4bcbf3a4..0bb7fad9 100644 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -223,6 +223,8 @@ DEF_PASSWD_REDACTION = 'REDACTED' def get_hostname(hostname_command='hostname'): + if not isinstance(hostname_command, (list, tuple)): + hostname_command = (hostname_command,) return util.subp(hostname_command, capture=True)[0].strip() diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py index 254e9876..da7da0ca 100644 --- a/tests/unittests/test_datasource/test_azure.py +++ b/tests/unittests/test_datasource/test_azure.py @@ -643,6 +643,21 @@ fdescfs /dev/fd fdescfs rw 0 0 expected_config['config'].append(blacklist_config) self.assertEqual(netconfig, expected_config) + @mock.patch("cloudinit.sources.DataSourceAzure.util.subp") + def test_get_hostname_with_no_args(self, subp): + dsaz.get_hostname() + subp.assert_called_once_with(("hostname",), capture=True) + + @mock.patch("cloudinit.sources.DataSourceAzure.util.subp") + def test_get_hostname_with_string_arg(self, subp): + dsaz.get_hostname(hostname_command="hostname") + subp.assert_called_once_with(("hostname",), capture=True) + + @mock.patch("cloudinit.sources.DataSourceAzure.util.subp") + def test_get_hostname_with_iterable_arg(self, subp): + dsaz.get_hostname(hostname_command=("hostname",)) + subp.assert_called_once_with(("hostname",), capture=True) + class TestAzureBounce(CiTestCase): -- cgit v1.2.3