Handle the choice of reboot of the instance in osutils.set_host_name

Since the sethostname plugin was moved in plugins.common, there was a bit
of Windows specific functionality inside it, the fact that it returns reboot_required
in order to set the hostname on Windows. Now this choice is moved to
osutils.set_host_name, which will simply return False for non-Windows systems.

Change-Id: Ic7774f2c7dd86f3ade82a19520df4301bc9674a7
This commit is contained in:
Claudiu Popa 2015-02-16 19:06:48 +02:00
parent c5ebf8deec
commit e1d9e6b9c3
4 changed files with 4 additions and 3 deletions

View File

@ -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)."""

View File

@ -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)

View File

@ -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,

View File

@ -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