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:
@@ -466,6 +466,7 @@ class WindowsUtils(base.BaseOSUtils):
|
|||||||
six.text_type(new_host_name))
|
six.text_type(new_host_name))
|
||||||
if not ret_val:
|
if not ret_val:
|
||||||
raise exception.CloudbaseInitException("Cannot set host name")
|
raise exception.CloudbaseInitException("Cannot set host name")
|
||||||
|
return True
|
||||||
|
|
||||||
def get_network_adapters(self):
|
def get_network_adapters(self):
|
||||||
"""Return available adapters as a list of tuples of (name, mac)."""
|
"""Return available adapters as a list of tuples of (name, mac)."""
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ class SetHostNamePlugin(base.BasePlugin):
|
|||||||
reboot_required = False
|
reboot_required = False
|
||||||
else:
|
else:
|
||||||
LOG.info("Setting hostname: %s" % new_host_name)
|
LOG.info("Setting hostname: %s" % new_host_name)
|
||||||
osutils.set_host_name(new_host_name)
|
reboot_required = osutils.set_host_name(new_host_name)
|
||||||
reboot_required = True
|
|
||||||
|
|
||||||
return (base.PLUGIN_EXECUTION_DONE, reboot_required)
|
return (base.PLUGIN_EXECUTION_DONE, reboot_required)
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ class TestWindowsUtils(unittest.TestCase):
|
|||||||
self.assertRaises(exception.CloudbaseInitException,
|
self.assertRaises(exception.CloudbaseInitException,
|
||||||
self._winutils.set_host_name, 'fake name')
|
self._winutils.set_host_name, 'fake name')
|
||||||
else:
|
else:
|
||||||
self._winutils.set_host_name('fake name')
|
self.assertTrue(self._winutils.set_host_name('fake name'))
|
||||||
|
|
||||||
mock_SetComputerNameExW.assert_called_with(
|
mock_SetComputerNameExW.assert_called_with(
|
||||||
self._winutils.ComputerNamePhysicalDnsHostname,
|
self._winutils.ComputerNamePhysicalDnsHostname,
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class SetHostNamePluginPluginTests(unittest.TestCase):
|
|||||||
mock_service.get_host_name.return_value = None
|
mock_service.get_host_name.return_value = None
|
||||||
|
|
||||||
mock_get_os_utils.return_value = mock_osutils
|
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:
|
if hostname_exists is True:
|
||||||
length = sethostname.NETBIOS_HOST_NAME_MAX_LEN
|
length = sethostname.NETBIOS_HOST_NAME_MAX_LEN
|
||||||
|
|||||||
Reference in New Issue
Block a user