From 022802997c10fc4ed56b1e1875cd7ccb16cc0688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Gagne=CC=81?= Date: Thu, 24 Sep 2015 13:43:27 -0400 Subject: [PATCH] Fix evacuate support with Nova cells v1 Cells v1 does not properly support evacuate when destination node is provided. If a destination node is provided, evacuated instance will stay in 'REBUILDING' state forever. The evacuate method expects host to be the actual node name, not one with complete cell_path. Stripping the cell_path from the host fixes the problem. Closes-bug: #1552046 Change-Id: Ib48990100ecc02325d323c8e933a859fa839a1a2 --- nova/compute/cells_api.py | 9 +++++---- nova/tests/unit/compute/test_compute_cells.py | 11 ++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py index 50ad4826bc..118ac6e3c1 100644 --- a/nova/compute/cells_api.py +++ b/nova/compute/cells_api.py @@ -261,11 +261,12 @@ class ComputeCellsAPI(compute_api.API): self._cast_to_cells(context, instance, 'restore') @check_instance_cell - def evacuate(self, context, instance, *args, **kwargs): + def evacuate(self, context, instance, host, *args, **kwargs): """Evacuate the given instance with the provided attributes.""" - super(ComputeCellsAPI, self).evacuate(context, instance, *args, - **kwargs) - self._cast_to_cells(context, instance, 'evacuate', *args, **kwargs) + if host: + cell_path, host = cells_utils.split_cell_and_item(host) + self._cast_to_cells(context, instance, 'evacuate', + host, *args, **kwargs) @check_instance_cell def add_fixed_ip(self, context, instance, *args, **kwargs): diff --git a/nova/tests/unit/compute/test_compute_cells.py b/nova/tests/unit/compute/test_compute_cells.py index e4376cce7a..5ed01a180a 100644 --- a/nova/tests/unit/compute/test_compute_cells.py +++ b/nova/tests/unit/compute/test_compute_cells.py @@ -131,7 +131,16 @@ class CellsComputeAPITestCase(test_compute.ComputeAPITestCase): self.skipTest("Test is incompatible with cells.") def test_evacuate(self): - self.skipTest("Test is incompatible with cells.") + @mock.patch.object(compute_api.API, 'evacuate') + def _test(mock_evacuate): + instance = objects.Instance(uuid=uuids.evacuate_instance, + cell_name='fake_cell_name') + dest_host = 'fake_cell_name@fakenode2' + self.compute_api.evacuate(self.context, instance, host=dest_host) + mock_evacuate.assert_called_once_with( + self.context, instance, 'fakenode2') + + _test() def test_error_evacuate(self): self.skipTest("Test is incompatible with cells.")