summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-12 10:50:21 +0000
committerGerrit Code Review <review@openstack.org>2017-06-12 10:50:21 +0000
commit677ef33d6536f0803a8497d5394c382919835b84 (patch)
tree94e199a72c4ebc55675890c4bb33f28913c753db
parent9fd1fd7f4314ed612e228586f7bfca9cd156f117 (diff)
parente221784560c71eeab7c5eeeb42e7c6e910d29340 (diff)
Merge "make sure to rebuild claim on recreate" into stable/ocata
-rw-r--r--nova/compute/manager.py16
-rw-r--r--nova/tests/unit/compute/test_compute.py2
-rw-r--r--nova/tests/unit/compute/test_compute_mgr.py4
3 files changed, 20 insertions, 2 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index e84c3b8..1a3c49f 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -2714,7 +2714,21 @@ class ComputeManager(manager.Manager):
2714 context = context.elevated() 2714 context = context.elevated()
2715 2715
2716 LOG.info(_LI("Rebuilding instance"), instance=instance) 2716 LOG.info(_LI("Rebuilding instance"), instance=instance)
2717 if scheduled_node is not None: 2717
2718 # NOTE(gyee): there are three possible scenarios.
2719 #
2720 # 1. instance is being rebuilt on the same node. In this case,
2721 # recreate should be False and scheduled_node should be None.
2722 # 2. instance is being rebuilt on a node chosen by the
2723 # scheduler (i.e. evacuate). In this case, scheduled_node should
2724 # be specified and recreate should be True.
2725 # 3. instance is being rebuilt on a node chosen by the user. (i.e.
2726 # force evacuate). In this case, scheduled_node is not specified
2727 # and recreate is set to True.
2728 #
2729 # For scenarios #2 and #3, we must do rebuild claim as server is
2730 # being evacuated to a different node.
2731 if recreate or scheduled_node is not None:
2718 rt = self._get_resource_tracker() 2732 rt = self._get_resource_tracker()
2719 rebuild_claim = rt.rebuild_claim 2733 rebuild_claim = rt.rebuild_claim
2720 else: 2734 else:
diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py
index e886791..7083a0a9 100644
--- a/nova/tests/unit/compute/test_compute.py
+++ b/nova/tests/unit/compute/test_compute.py
@@ -11936,9 +11936,11 @@ class EvacuateHostTestCase(BaseTestCase):
11936 patch_spawn = mock.patch.object(self.compute.driver, 'spawn') 11936 patch_spawn = mock.patch.object(self.compute.driver, 'spawn')
11937 patch_on_disk = mock.patch.object( 11937 patch_on_disk = mock.patch.object(
11938 self.compute.driver, 'instance_on_disk', return_value=True) 11938 self.compute.driver, 'instance_on_disk', return_value=True)
11939 self.compute._resource_tracker.rebuild_claim = mock.MagicMock()
11939 with patch_spawn, patch_on_disk: 11940 with patch_spawn, patch_on_disk:
11940 self._rebuild(migration=migration) 11941 self._rebuild(migration=migration)
11941 11942
11943 self.assertTrue(self.compute._resource_tracker.rebuild_claim.called)
11942 self.assertEqual('done', migration.status) 11944 self.assertEqual('done', migration.status)
11943 migration.save.assert_called_once_with() 11945 migration.save.assert_called_once_with()
11944 11946
diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py
index 37a0739..7e08d60 100644
--- a/nova/tests/unit/compute/test_compute_mgr.py
+++ b/nova/tests/unit/compute/test_compute_mgr.py
@@ -3035,17 +3035,19 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
3035 node=dead_node) 3035 node=dead_node)
3036 instance.migration_context = None 3036 instance.migration_context = None
3037 with test.nested( 3037 with test.nested(
3038 mock.patch.object(self.compute, '_get_resource_tracker'),
3038 mock.patch.object(self.compute, '_get_compute_info'), 3039 mock.patch.object(self.compute, '_get_compute_info'),
3039 mock.patch.object(self.compute, '_do_rebuild_instance_with_claim'), 3040 mock.patch.object(self.compute, '_do_rebuild_instance_with_claim'),
3040 mock.patch.object(objects.Instance, 'save'), 3041 mock.patch.object(objects.Instance, 'save'),
3041 mock.patch.object(self.compute, '_set_migration_status') 3042 mock.patch.object(self.compute, '_set_migration_status')
3042 ) as (mock_get, mock_rebuild, mock_save, mock_set): 3043 ) as (mock_rt, mock_get, mock_rebuild, mock_save, mock_set):
3043 mock_get.return_value.hypervisor_hostname = 'new-node' 3044 mock_get.return_value.hypervisor_hostname = 'new-node'
3044 self.compute.rebuild_instance(self.context, instance, None, None, 3045 self.compute.rebuild_instance(self.context, instance, None, None,
3045 None, None, None, None, True) 3046 None, None, None, None, True)
3046 mock_get.assert_called_once_with(mock.ANY, self.compute.host) 3047 mock_get.assert_called_once_with(mock.ANY, self.compute.host)
3047 self.assertEqual('new-node', instance.node) 3048 self.assertEqual('new-node', instance.node)
3048 mock_set.assert_called_once_with(None, 'done') 3049 mock_set.assert_called_once_with(None, 'done')
3050 mock_rt.assert_called_once_with()
3049 3051
3050 def test_rebuild_default_impl(self): 3052 def test_rebuild_default_impl(self):
3051 def _detach(context, bdms): 3053 def _detach(context, bdms):