Call terminate_connection when shelve_offloading

When nova performs a shelve offload for an instance, it needs to terminate
all the volume connections for that instance as with the shelve offload
it is not guaranteed that the instance will be placed on the same host once
it gets unshelved.
This change adds the call to the terminate_volume_connections on the
_shelve_offload_instance method in the compute manager.

Closes-Bug: #1547142

Change-Id: I8849ae0f54605e003d5b294ca3d66dcef89d7d27
This commit is contained in:
Andrea Rosa 2017-09-14 13:47:06 -04:00 committed by Matt Riedemann
parent 65129e41e9
commit e89e1bdc60
2 changed files with 20 additions and 3 deletions

View File

@ -4383,11 +4383,19 @@ class ComputeManager(manager.Manager):
self.network_api.cleanup_instance_network_on_host(context, instance,
instance.host)
network_info = self.network_api.get_instance_nw_info(context, instance)
bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
context, instance.uuid)
block_device_info = self._get_instance_block_device_info(context,
instance)
instance,
bdms=bdms)
self.driver.destroy(context, instance, network_info,
block_device_info)
# the instance is going to be removed from the host so we want to
# terminate all the connections with the volume server and the host
self._terminate_volume_connections(context, instance, bdms)
instance.power_state = current_power_state
# NOTE(mriedem): The vm_state has to be set before updating the
# resource tracker, see vm_states.ALLOW_RESOURCE_REMOVAL. The host/node

View File

@ -47,6 +47,8 @@ def _fake_resources():
class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
@mock.patch.object(nova.compute.manager.ComputeManager,
'_terminate_volume_connections')
@mock.patch.object(nova.virt.fake.SmallFakeDriver, 'power_off')
@mock.patch.object(nova.virt.fake.SmallFakeDriver, 'snapshot')
@mock.patch.object(nova.compute.manager.ComputeManager, '_get_power_state')
@ -55,7 +57,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def _shelve_instance(self, shelved_offload_time, mock_notify,
mock_notify_instance_usage, mock_get_power_state,
mock_snapshot, mock_power_off,
mock_snapshot, mock_power_off, mock_terminate,
clean_shutdown=True):
mock_get_power_state.return_value = 123
@ -159,6 +161,9 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
'fake_image_id', mock.ANY)
mock_get_power_state.assert_has_calls(mock_get_power_state_call_list)
if CONF.shelved_offload_time == 0:
self.assertTrue(mock_terminate.called)
def test_shelve(self):
self._shelve_instance(-1)
@ -179,6 +184,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
instance = self._shelve_offload(clean_shutdown=False)
mock_power_off.assert_called_once_with(instance, 0, 0)
@mock.patch.object(nova.compute.manager.ComputeManager,
'_terminate_volume_connections')
@mock.patch('nova.compute.resource_tracker.ResourceTracker.'
'delete_allocation_for_shelve_offloaded_instance')
@mock.patch.object(nova.compute.manager.ComputeManager,
@ -190,7 +197,8 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
@mock.patch('nova.compute.utils.notify_about_instance_action')
def _shelve_offload(self, mock_notify, mock_notify_instance_usage,
mock_get_power_state, mock_update_resource_tracker,
mock_delete_alloc, clean_shutdown=True):
mock_delete_alloc, mock_terminate,
clean_shutdown=True):
host = 'fake-mini'
instance = self._create_fake_instance_obj(params={'host': host})
instance.task_state = task_states.SHELVING
@ -208,6 +216,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase):
self.assertEqual(vm_states.SHELVED_OFFLOADED, instance.vm_state)
self.assertIsNone(instance.task_state)
self.assertTrue(mock_terminate.called)
# prepare expect call lists
mock_notify_instance_usage_call_list = [