Merge "Pass user context to virt driver when detaching volume" into stable/queens

This commit is contained in:
Zuul 2018-03-07 16:29:36 +00:00 committed by Gerrit Code Review
commit 3f165795e9
12 changed files with 39 additions and 33 deletions

View File

@ -204,8 +204,8 @@ class HyperVDriverTestCase(test_base.HyperVBaseTestCase):
def test_detach_volume(self):
mock_instance = fake_instance.fake_instance_obj(self.context)
self.driver.detach_volume(
mock.sentinel.connection_info, mock_instance,
mock.sentinel.mountpoint, mock.sentinel.encryption)
mock.sentinel.context, mock.sentinel.connection_info,
mock_instance, mock.sentinel.mountpoint, mock.sentinel.encryption)
self.driver._volumeops.detach_volume.assert_called_once_with(
mock.sentinel.connection_info,

View File

@ -6901,7 +6901,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
for state in (power_state.RUNNING, power_state.PAUSED):
mock_dom.info.return_value = [state, 512, 512, 2, 1234, 5678]
mock_get_domain.return_value = mock_dom
drvr.detach_volume(connection_info, instance, '/dev/vdc')
drvr.detach_volume(
self.context, connection_info, instance, '/dev/vdc')
mock_get_domain.assert_called_with(instance)
mock_dom.detachDeviceFlags.assert_called_with(
@ -6911,7 +6912,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
</disk>
""", flags=flags)
mock_disconnect_volume.assert_called_with(
None, connection_info, instance, encryption=None)
self.context, connection_info, instance, encryption=None)
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
@mock.patch('nova.virt.libvirt.host.Host._get_domain')
@ -6933,11 +6934,12 @@ class LibvirtConnTestCase(test.NoDBTestCase,
5678]
mock_get_domain.return_value = mock_dom
drvr.detach_volume(connection_info, instance, '/dev/vdc')
drvr.detach_volume(
self.context, connection_info, instance, '/dev/vdc')
mock_get_domain.assert_called_once_with(instance)
mock_disconnect_volume.assert_called_once_with(
None, connection_info, instance, encryption=None)
self.context, connection_info, instance, encryption=None)
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
@ -6962,11 +6964,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
5678]
mock_get_domain.return_value = mock_dom
drvr.detach_volume(connection_info, instance, '/dev/vdc',
encryption)
drvr.detach_volume(self.context, connection_info, instance,
'/dev/vdc', encryption)
mock_disconnect_volume.assert_called_once_with(
None, connection_info, instance, encryption=encryption)
self.context, connection_info, instance, encryption=encryption)
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_driver')
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
@ -6998,8 +7000,9 @@ class LibvirtConnTestCase(test.NoDBTestCase,
"data": {"device_path": "/fake",
"access_mode": "rw"}}
encryption = {"provider": "NoOpEncryptor"}
drvr.detach_volume(connection_info, instance, '/dev/vdc',
encryption=encryption)
drvr.detach_volume(
self.context, connection_info, instance, '/dev/vdc',
encryption=encryption)
mock_order.assert_has_calls([
mock.call.detach_volume(),
@ -15126,10 +15129,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
mock.patch.object(drvr, '_disconnect_volume')
) as (_get_domain, _disconnect_volume):
connection_info = {'driver_volume_type': 'fake'}
drvr.detach_volume(connection_info, instance, '/dev/sda')
drvr.detach_volume(
self.context, connection_info, instance, '/dev/sda')
_get_domain.assert_called_once_with(instance)
_disconnect_volume.assert_called_once_with(None, connection_info,
instance, encryption=None)
_disconnect_volume.assert_called_once_with(
self.context, connection_info, instance, encryption=None)
def _test_attach_detach_interface_get_config(self, method_name):
"""Tests that the get_config() method is properly called in

View File

@ -555,7 +555,7 @@ class TestDriverBlockDevice(test.NoDBTestCase):
test.TestingException)
if driver_attach:
self.virt_driver.detach_volume(
expected_conn_info, instance,
self.context, expected_conn_info, instance,
bdm_dict['device_name'],
encryption=enc_data).AndReturn(None)
self.volume_api.terminate_connection(

View File

@ -481,7 +481,8 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
self.connection.attach_volume(None, connection_info, instance_ref,
'/dev/sda'))
self.assertIsNone(
self.connection.detach_volume(connection_info, instance_ref,
self.connection.detach_volume(mock.sentinel.context,
connection_info, instance_ref,
'/dev/sda'))
@catch_notimplementederror
@ -542,7 +543,8 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
driver_block_device.DriverVolumeBlockDevice, 'save'):
self.connection.power_on(
self.ctxt, instance_ref, network_info, bdm)
self.connection.detach_volume(connection_info,
self.connection.detach_volume(mock.sentinel.context,
connection_info,
instance_ref,
'/dev/sda')

View File

@ -1750,7 +1750,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
self._create_vm()
connection_info = self._test_vmdk_connection_info('vmdk')
mount_point = '/dev/vdc'
self.conn.detach_volume(connection_info, self.instance, mount_point,
self.conn.detach_volume(mock.sentinel.context, connection_info,
self.instance, mount_point,
encryption=None)
mock_detach_volume_vmdk.assert_called_once_with(connection_info,
self.instance)
@ -1797,7 +1798,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
with mock.patch.object(volumeops.VMwareVolumeOps,
'detach_volume') as detach_volume:
self.conn.detach_volume(connection_info, self.instance,
self.conn.detach_volume(mock.sentinel.context, connection_info,
self.instance,
'/dev/vdc', encryption=None)
detach_volume.assert_called_once_with(connection_info,
self.instance)
@ -1819,7 +1821,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
self._create_vm()
connection_info = self._test_vmdk_connection_info('iscsi')
mount_point = '/dev/vdc'
self.conn.detach_volume(connection_info, self.instance, mount_point,
self.conn.detach_volume(mock.sentinel.context, connection_info,
self.instance, mount_point,
encryption=None)
mock_detach_volume_iscsi.assert_called_once_with(connection_info,
self.instance)
@ -1903,7 +1906,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
device = 'fake_device'
mock_get_rdm_disk.return_value = device
self.conn.detach_volume(connection_info, self.instance, mount_point,
self.conn.detach_volume(mock.sentinel.context, connection_info,
self.instance, mount_point,
encryption=None)
mock_iscsi_get_target.assert_called_once_with(connection_info['data'])

View File

@ -296,7 +296,7 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
encryption = encryptors.get_encryption_metadata(context,
volume_api, volume_id, connection_info)
virt_driver.detach_volume(connection_info, instance, mp,
virt_driver.detach_volume(context, connection_info, instance, mp,
encryption=encryption)
except exception.DiskNotFound as err:
LOG.warning('Ignoring DiskNotFound exception while '

View File

@ -466,7 +466,7 @@ class ComputeDriver(object):
"""Attach the disk to the instance at mountpoint using info."""
raise NotImplementedError()
def detach_volume(self, connection_info, instance, mountpoint,
def detach_volume(self, context, connection_info, instance, mountpoint,
encryption=None):
"""Detach the disk attached to the instance."""
raise NotImplementedError()

View File

@ -309,7 +309,7 @@ class FakeDriver(driver.ComputeDriver):
self._mounts[instance_name] = {}
self._mounts[instance_name][mountpoint] = connection_info
def detach_volume(self, connection_info, instance, mountpoint,
def detach_volume(self, context, connection_info, instance, mountpoint,
encryption=None):
"""Detach the disk attached to the instance."""
try:

View File

@ -183,7 +183,7 @@ class HyperVDriver(driver.ComputeDriver):
return self._volumeops.attach_volume(connection_info,
instance.name)
def detach_volume(self, connection_info, instance, mountpoint,
def detach_volume(self, context, connection_info, instance, mountpoint,
encryption=None):
return self._volumeops.detach_volume(connection_info,
instance.name)

View File

@ -1539,7 +1539,7 @@ class LibvirtDriver(driver.ComputeDriver):
block_device_info=block_device_info)
return xml
def detach_volume(self, connection_info, instance, mountpoint,
def detach_volume(self, context, connection_info, instance, mountpoint,
encryption=None):
disk_dev = mountpoint.rpartition("/")[2]
try:
@ -1580,11 +1580,7 @@ class LibvirtDriver(driver.ComputeDriver):
else:
raise
# NOTE(lyarwood): We can provide None as the request context here as we
# already have the encryption metadata dict from the compute layer.
# This avoids the need to add the request context to the signature of
# detach_volume requiring changes across all drivers.
self._disconnect_volume(None, connection_info, instance,
self._disconnect_volume(context, connection_info, instance,
encryption=encryption)
def extend_volume(self, connection_info, instance):

View File

@ -396,7 +396,7 @@ class VMwareVCDriver(driver.ComputeDriver):
"""Attach volume storage to VM instance."""
return self._volumeops.attach_volume(connection_info, instance)
def detach_volume(self, connection_info, instance, mountpoint,
def detach_volume(self, context, connection_info, instance, mountpoint,
encryption=None):
"""Detach volume storage to VM instance."""
return self._volumeops.detach_volume(connection_info, instance)

View File

@ -445,7 +445,7 @@ class XenAPIDriver(driver.ComputeDriver):
instance['name'],
mountpoint)
def detach_volume(self, connection_info, instance, mountpoint,
def detach_volume(self, context, connection_info, instance, mountpoint,
encryption=None):
"""Detach volume storage from VM instance."""
self._volumeops.detach_volume(connection_info,