Fix call to driver_detach in remove_volume_connection

DriverVolumeBlockDevice.driver_detach is being called with
the wrong number of arguments - there is no 'connector'
argument in that method. This is a result of refactoring
this code in I7a53e08f3fad6abb27a1d8ad425b4f916341cab3.

The related unit test is pretty brittle so it's easy to
see how this was missed in testing, plus we don't have
integration testing for live migration rollbacks.

This change fixes the call and makes the test a bit less
brittle, but would be cleaner if it could use autospec
although figuring out how to make that work eludes me.

Change-Id: I12088f57f6228460b4810d39e9fca93bd589d70b
Closes-Bug: #1694535
This commit is contained in:
Matt Riedemann 2017-05-31 23:58:39 -04:00
parent a1eca94d89
commit f3454e9590
2 changed files with 11 additions and 3 deletions

View File

@ -5148,10 +5148,10 @@ class ComputeManager(manager.Manager):
try:
bdm = objects.BlockDeviceMapping.get_by_volume_and_instance(
context, volume_id, instance.uuid)
connector = self.driver.get_volume_connector(instance)
driver_bdm = driver_block_device.convert_volume(bdm)
driver_bdm.driver_detach(context, instance, connector,
driver_bdm.driver_detach(context, instance,
self.volume_api, self.driver)
connector = self.driver.get_volume_connector(instance)
self.volume_api.terminate_connection(context, volume_id, connector)
except exception.NotFound:
pass

View File

@ -2428,6 +2428,13 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
mock.patch.object(driver_bdm_volume, 'driver_detach'),
) as (mock_volume_api, mock_virt_driver, mock_driver_detach):
connector = mock.Mock()
def fake_driver_detach(context, instance, volume_api, virt_driver):
# This is just here to validate the function signature.
pass
# There should be an easier way to do this with autospec...
mock_driver_detach.side_effect = fake_driver_detach
mock_virt_driver.get_volume_connector.return_value = connector
self.compute.remove_volume_connection(self.context,
uuids.volume_id, inst)
@ -2435,7 +2442,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
bdm_get.assert_called_once_with(self.context, uuids.volume_id,
uuids.instance_uuid)
mock_driver_detach.assert_called_once_with(self.context, inst,
connector, mock_volume_api, mock_virt_driver)
mock_volume_api,
mock_virt_driver)
mock_volume_api.terminate_connection.assert_called_once_with(
self.context, uuids.volume_id, connector)