Merge "fix cellv2 delete_host" into stable/queens

This commit is contained in:
Zuul 2019-08-09 15:41:21 +00:00 committed by Gerrit Code Review
commit 62ae97e63a
2 changed files with 37 additions and 2 deletions

View File

@ -1593,7 +1593,10 @@ class CellV2Commands(object):
with context.target_cell(ctxt, cell_mapping) as cctxt: with context.target_cell(ctxt, cell_mapping) as cctxt:
instances = objects.InstanceList.get_by_host(cctxt, host) instances = objects.InstanceList.get_by_host(cctxt, host)
nodes = objects.ComputeNodeList.get_all_by_host(cctxt, host) try:
nodes = objects.ComputeNodeList.get_all_by_host(cctxt, host)
except exception.ComputeHostNotFound:
nodes = []
if instances: if instances:
print(_('There are instances on the host %s.') % host) print(_('There are instances on the host %s.') % host)

View File

@ -2075,7 +2075,7 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host') @mock.patch.object(objects.ComputeNodeList, 'get_all_by_host')
def test_delete_host_success(self, mock_get_cn, mock_destroy, def test_delete_host_success(self, mock_get_cn, mock_destroy,
mock_get_by_host): mock_get_by_host):
"""Tests trying to delete a host that has not instances.""" """Tests trying to delete a host that has no instances."""
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
# create the cell mapping # create the cell mapping
cm1 = objects.CellMapping( cm1 = objects.CellMapping(
@ -2100,6 +2100,38 @@ class CellV2CommandsTestCase(test.NoDBTestCase):
self.assertEqual(0, node.mapped) self.assertEqual(0, node.mapped)
node.save.assert_called_once_with() node.save.assert_called_once_with()
@mock.patch.object(objects.InstanceList, 'get_by_host',
return_value=[])
@mock.patch.object(objects.HostMapping, 'destroy')
@mock.patch.object(objects.ComputeNodeList, 'get_all_by_host',
side_effect=exception.ComputeHostNotFound(host='fake-host'))
def test_delete_host_success_compute_host_not_found(self, mock_get_cn,
mock_destroy,
mock_get_by_host):
"""Tests trying to delete a host that has no instances, but cannot
be found by ComputeNodeList.get_all_by_host.
"""
ctxt = context.get_admin_context()
# create the cell mapping
cm1 = objects.CellMapping(
context=ctxt, uuid=uuidsentinel.cell1,
database_connection='fake:///db', transport_url='fake:///mq')
cm1.create()
# create a host mapping in the cell
hm = objects.HostMapping(
context=ctxt, host='fake-host', cell_mapping=cm1)
hm.create()
self.assertEqual(0, self.commands.delete_host(uuidsentinel.cell1,
'fake-host'))
output = self.output.getvalue().strip()
self.assertEqual('', output)
mock_get_by_host.assert_called_once_with(
test.MatchType(context.RequestContext), 'fake-host')
mock_destroy.assert_called_once_with()
mock_get_cn.assert_called_once_with(
test.MatchType(context.RequestContext), 'fake-host')
class TestNovaManageMain(test.NoDBTestCase): class TestNovaManageMain(test.NoDBTestCase):
"""Tests the nova-manage:main() setup code.""" """Tests the nova-manage:main() setup code."""