Pass user context to virt driver when detaching volume
We need this in a later change to pull volume attachment information from cinder for the volume being detached so that we can do some attachment counting for multiattach volumes being detached from instances on the same host. Change-Id: I751fcb7532679905c4279744919c6cce84a11eb4 Related-Bug: #1752115
This commit is contained in:
parent
fa50107c14
commit
d2941bfd16
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
|
@ -15129,10 +15132,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
|
||||
|
|
|
@ -573,7 +573,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(
|
||||
|
|
|
@ -478,7 +478,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
|
||||
|
@ -539,7 +540,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')
|
||||
|
||||
|
|
|
@ -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'])
|
||||
|
|
|
@ -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 '
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1550,7 +1550,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:
|
||||
|
@ -1591,11 +1591,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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue