Stop console at first if console is enabled when destroy node

Previously, when node was deleted with console enabled,
the console process was not stopped.
Now stop console at first, then delete the node.

Closes-Bug: #1418804
Change-Id: Ia994b20c42df0a1f2882889a1be6dd4f426ee569
This commit is contained in:
chenglch 2015-02-11 00:26:38 -05:00
parent cf9932fe63
commit ab551a1774
2 changed files with 19 additions and 0 deletions

View File

@ -1022,6 +1022,13 @@ class ConductorManager(periodic_task.PeriodicTasks):
msg = (_("Node %s can't be deleted because it's not "
"powered off") % node.uuid)
raise exception.NodeInWrongPowerState(msg)
if node.console_enabled:
try:
task.driver.console.stop_console(task)
except Exception as err:
LOG.error(_LE('Failed to stop console while deleting '
'the node %(node)s: %(err)s.'),
{'node': node.uuid, 'err': err})
node.destroy()
LOG.info(_LI('Successfully deleted node %(node)s.'),
{'node': node.uuid})

View File

@ -1675,6 +1675,18 @@ class DestroyNodeTestCase(_ServiceSetUpMixin, tests_db_base.DbTestCase):
power_state=states.POWER_OFF)
self.service.destroy_node(self.context, node.uuid)
def test_destroy_node_console_enabled(self):
self._start_service()
node = obj_utils.create_test_node(self.context, driver='fake',
console_enabled=True)
with mock.patch.object(self.driver.console,
'stop_console') as mock_sc:
self.service.destroy_node(self.context, node.uuid)
mock_sc.assert_called_once_with(mock.ANY)
self.assertRaises(exception.NodeNotFound,
self.dbapi.get_node_by_uuid,
node.uuid)
@_mock_record_keepalive
class UpdatePortTestCase(_ServiceSetUpMixin, tests_db_base.DbTestCase):