diff --git a/cloudbaseinit/osutils/windows.py b/cloudbaseinit/osutils/windows.py index 7280bdd8..18eb4a38 100644 --- a/cloudbaseinit/osutils/windows.py +++ b/cloudbaseinit/osutils/windows.py @@ -466,6 +466,7 @@ class WindowsUtils(base.BaseOSUtils): six.text_type(new_host_name)) if not ret_val: raise exception.CloudbaseInitException("Cannot set host name") + return True def get_network_adapters(self): """Return available adapters as a list of tuples of (name, mac).""" diff --git a/cloudbaseinit/plugins/common/sethostname.py b/cloudbaseinit/plugins/common/sethostname.py index 13ce96ad..050d8081 100644 --- a/cloudbaseinit/plugins/common/sethostname.py +++ b/cloudbaseinit/plugins/common/sethostname.py @@ -63,7 +63,6 @@ class SetHostNamePlugin(base.BasePlugin): reboot_required = False else: LOG.info("Setting hostname: %s" % new_host_name) - osutils.set_host_name(new_host_name) - reboot_required = True + reboot_required = osutils.set_host_name(new_host_name) return (base.PLUGIN_EXECUTION_DONE, reboot_required) diff --git a/cloudbaseinit/tests/osutils/test_windows.py b/cloudbaseinit/tests/osutils/test_windows.py index 8b0f53a2..3fbe7722 100644 --- a/cloudbaseinit/tests/osutils/test_windows.py +++ b/cloudbaseinit/tests/osutils/test_windows.py @@ -466,7 +466,7 @@ class TestWindowsUtils(unittest.TestCase): self.assertRaises(exception.CloudbaseInitException, self._winutils.set_host_name, 'fake name') else: - self._winutils.set_host_name('fake name') + self.assertTrue(self._winutils.set_host_name('fake name')) mock_SetComputerNameExW.assert_called_with( self._winutils.ComputerNamePhysicalDnsHostname, diff --git a/cloudbaseinit/tests/plugins/common/test_sethostname.py b/cloudbaseinit/tests/plugins/common/test_sethostname.py index 9ccaff19..b22b535e 100644 --- a/cloudbaseinit/tests/plugins/common/test_sethostname.py +++ b/cloudbaseinit/tests/plugins/common/test_sethostname.py @@ -52,6 +52,7 @@ class SetHostNamePluginPluginTests(unittest.TestCase): mock_service.get_host_name.return_value = None mock_get_os_utils.return_value = mock_osutils + mock_get_os_utils.return_value.set_host_name.return_value = True if hostname_exists is True: length = sethostname.NETBIOS_HOST_NAME_MAX_LEN