Merge "Pass user context to virt driver when detaching volume" into stable/queens
This commit is contained in:
commit
3f165795e9
|
@ -204,8 +204,8 @@ class HyperVDriverTestCase(test_base.HyperVBaseTestCase):
|
||||||
def test_detach_volume(self):
|
def test_detach_volume(self):
|
||||||
mock_instance = fake_instance.fake_instance_obj(self.context)
|
mock_instance = fake_instance.fake_instance_obj(self.context)
|
||||||
self.driver.detach_volume(
|
self.driver.detach_volume(
|
||||||
mock.sentinel.connection_info, mock_instance,
|
mock.sentinel.context, mock.sentinel.connection_info,
|
||||||
mock.sentinel.mountpoint, mock.sentinel.encryption)
|
mock_instance, mock.sentinel.mountpoint, mock.sentinel.encryption)
|
||||||
|
|
||||||
self.driver._volumeops.detach_volume.assert_called_once_with(
|
self.driver._volumeops.detach_volume.assert_called_once_with(
|
||||||
mock.sentinel.connection_info,
|
mock.sentinel.connection_info,
|
||||||
|
|
|
@ -6901,7 +6901,8 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
for state in (power_state.RUNNING, power_state.PAUSED):
|
for state in (power_state.RUNNING, power_state.PAUSED):
|
||||||
mock_dom.info.return_value = [state, 512, 512, 2, 1234, 5678]
|
mock_dom.info.return_value = [state, 512, 512, 2, 1234, 5678]
|
||||||
mock_get_domain.return_value = mock_dom
|
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_get_domain.assert_called_with(instance)
|
||||||
mock_dom.detachDeviceFlags.assert_called_with(
|
mock_dom.detachDeviceFlags.assert_called_with(
|
||||||
|
@ -6911,7 +6912,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
</disk>
|
</disk>
|
||||||
""", flags=flags)
|
""", flags=flags)
|
||||||
mock_disconnect_volume.assert_called_with(
|
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.driver.LibvirtDriver._disconnect_volume')
|
||||||
@mock.patch('nova.virt.libvirt.host.Host._get_domain')
|
@mock.patch('nova.virt.libvirt.host.Host._get_domain')
|
||||||
|
@ -6933,11 +6934,12 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
5678]
|
5678]
|
||||||
mock_get_domain.return_value = mock_dom
|
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_get_domain.assert_called_once_with(instance)
|
||||||
mock_disconnect_volume.assert_called_once_with(
|
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._get_volume_encryptor')
|
||||||
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
|
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume')
|
||||||
|
@ -6962,11 +6964,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
5678]
|
5678]
|
||||||
mock_get_domain.return_value = mock_dom
|
mock_get_domain.return_value = mock_dom
|
||||||
|
|
||||||
drvr.detach_volume(connection_info, instance, '/dev/vdc',
|
drvr.detach_volume(self.context, connection_info, instance,
|
||||||
encryption)
|
'/dev/vdc', encryption)
|
||||||
|
|
||||||
mock_disconnect_volume.assert_called_once_with(
|
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_driver')
|
||||||
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
|
@mock.patch('nova.virt.libvirt.driver.LibvirtDriver._get_volume_encryptor')
|
||||||
|
@ -6998,8 +7000,9 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
"data": {"device_path": "/fake",
|
"data": {"device_path": "/fake",
|
||||||
"access_mode": "rw"}}
|
"access_mode": "rw"}}
|
||||||
encryption = {"provider": "NoOpEncryptor"}
|
encryption = {"provider": "NoOpEncryptor"}
|
||||||
drvr.detach_volume(connection_info, instance, '/dev/vdc',
|
drvr.detach_volume(
|
||||||
encryption=encryption)
|
self.context, connection_info, instance, '/dev/vdc',
|
||||||
|
encryption=encryption)
|
||||||
|
|
||||||
mock_order.assert_has_calls([
|
mock_order.assert_has_calls([
|
||||||
mock.call.detach_volume(),
|
mock.call.detach_volume(),
|
||||||
|
@ -15126,10 +15129,11 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||||
mock.patch.object(drvr, '_disconnect_volume')
|
mock.patch.object(drvr, '_disconnect_volume')
|
||||||
) as (_get_domain, _disconnect_volume):
|
) as (_get_domain, _disconnect_volume):
|
||||||
connection_info = {'driver_volume_type': 'fake'}
|
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)
|
_get_domain.assert_called_once_with(instance)
|
||||||
_disconnect_volume.assert_called_once_with(None, connection_info,
|
_disconnect_volume.assert_called_once_with(
|
||||||
instance, encryption=None)
|
self.context, connection_info, instance, encryption=None)
|
||||||
|
|
||||||
def _test_attach_detach_interface_get_config(self, method_name):
|
def _test_attach_detach_interface_get_config(self, method_name):
|
||||||
"""Tests that the get_config() method is properly called in
|
"""Tests that the get_config() method is properly called in
|
||||||
|
|
|
@ -555,7 +555,7 @@ class TestDriverBlockDevice(test.NoDBTestCase):
|
||||||
test.TestingException)
|
test.TestingException)
|
||||||
if driver_attach:
|
if driver_attach:
|
||||||
self.virt_driver.detach_volume(
|
self.virt_driver.detach_volume(
|
||||||
expected_conn_info, instance,
|
self.context, expected_conn_info, instance,
|
||||||
bdm_dict['device_name'],
|
bdm_dict['device_name'],
|
||||||
encryption=enc_data).AndReturn(None)
|
encryption=enc_data).AndReturn(None)
|
||||||
self.volume_api.terminate_connection(
|
self.volume_api.terminate_connection(
|
||||||
|
|
|
@ -481,7 +481,8 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
||||||
self.connection.attach_volume(None, connection_info, instance_ref,
|
self.connection.attach_volume(None, connection_info, instance_ref,
|
||||||
'/dev/sda'))
|
'/dev/sda'))
|
||||||
self.assertIsNone(
|
self.assertIsNone(
|
||||||
self.connection.detach_volume(connection_info, instance_ref,
|
self.connection.detach_volume(mock.sentinel.context,
|
||||||
|
connection_info, instance_ref,
|
||||||
'/dev/sda'))
|
'/dev/sda'))
|
||||||
|
|
||||||
@catch_notimplementederror
|
@catch_notimplementederror
|
||||||
|
@ -542,7 +543,8 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
||||||
driver_block_device.DriverVolumeBlockDevice, 'save'):
|
driver_block_device.DriverVolumeBlockDevice, 'save'):
|
||||||
self.connection.power_on(
|
self.connection.power_on(
|
||||||
self.ctxt, instance_ref, network_info, bdm)
|
self.ctxt, instance_ref, network_info, bdm)
|
||||||
self.connection.detach_volume(connection_info,
|
self.connection.detach_volume(mock.sentinel.context,
|
||||||
|
connection_info,
|
||||||
instance_ref,
|
instance_ref,
|
||||||
'/dev/sda')
|
'/dev/sda')
|
||||||
|
|
||||||
|
|
|
@ -1750,7 +1750,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
|
||||||
self._create_vm()
|
self._create_vm()
|
||||||
connection_info = self._test_vmdk_connection_info('vmdk')
|
connection_info = self._test_vmdk_connection_info('vmdk')
|
||||||
mount_point = '/dev/vdc'
|
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)
|
encryption=None)
|
||||||
mock_detach_volume_vmdk.assert_called_once_with(connection_info,
|
mock_detach_volume_vmdk.assert_called_once_with(connection_info,
|
||||||
self.instance)
|
self.instance)
|
||||||
|
@ -1797,7 +1798,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
|
||||||
|
|
||||||
with mock.patch.object(volumeops.VMwareVolumeOps,
|
with mock.patch.object(volumeops.VMwareVolumeOps,
|
||||||
'detach_volume') as detach_volume:
|
'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)
|
'/dev/vdc', encryption=None)
|
||||||
detach_volume.assert_called_once_with(connection_info,
|
detach_volume.assert_called_once_with(connection_info,
|
||||||
self.instance)
|
self.instance)
|
||||||
|
@ -1819,7 +1821,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
|
||||||
self._create_vm()
|
self._create_vm()
|
||||||
connection_info = self._test_vmdk_connection_info('iscsi')
|
connection_info = self._test_vmdk_connection_info('iscsi')
|
||||||
mount_point = '/dev/vdc'
|
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)
|
encryption=None)
|
||||||
mock_detach_volume_iscsi.assert_called_once_with(connection_info,
|
mock_detach_volume_iscsi.assert_called_once_with(connection_info,
|
||||||
self.instance)
|
self.instance)
|
||||||
|
@ -1903,7 +1906,8 @@ class VMwareAPIVMTestCase(test.NoDBTestCase,
|
||||||
device = 'fake_device'
|
device = 'fake_device'
|
||||||
mock_get_rdm_disk.return_value = 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)
|
encryption=None)
|
||||||
|
|
||||||
mock_iscsi_get_target.assert_called_once_with(connection_info['data'])
|
mock_iscsi_get_target.assert_called_once_with(connection_info['data'])
|
||||||
|
|
|
@ -296,7 +296,7 @@ class DriverVolumeBlockDevice(DriverBlockDevice):
|
||||||
|
|
||||||
encryption = encryptors.get_encryption_metadata(context,
|
encryption = encryptors.get_encryption_metadata(context,
|
||||||
volume_api, volume_id, connection_info)
|
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)
|
encryption=encryption)
|
||||||
except exception.DiskNotFound as err:
|
except exception.DiskNotFound as err:
|
||||||
LOG.warning('Ignoring DiskNotFound exception while '
|
LOG.warning('Ignoring DiskNotFound exception while '
|
||||||
|
|
|
@ -466,7 +466,7 @@ class ComputeDriver(object):
|
||||||
"""Attach the disk to the instance at mountpoint using info."""
|
"""Attach the disk to the instance at mountpoint using info."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def detach_volume(self, connection_info, instance, mountpoint,
|
def detach_volume(self, context, connection_info, instance, mountpoint,
|
||||||
encryption=None):
|
encryption=None):
|
||||||
"""Detach the disk attached to the instance."""
|
"""Detach the disk attached to the instance."""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
|
@ -309,7 +309,7 @@ class FakeDriver(driver.ComputeDriver):
|
||||||
self._mounts[instance_name] = {}
|
self._mounts[instance_name] = {}
|
||||||
self._mounts[instance_name][mountpoint] = connection_info
|
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):
|
encryption=None):
|
||||||
"""Detach the disk attached to the instance."""
|
"""Detach the disk attached to the instance."""
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -183,7 +183,7 @@ class HyperVDriver(driver.ComputeDriver):
|
||||||
return self._volumeops.attach_volume(connection_info,
|
return self._volumeops.attach_volume(connection_info,
|
||||||
instance.name)
|
instance.name)
|
||||||
|
|
||||||
def detach_volume(self, connection_info, instance, mountpoint,
|
def detach_volume(self, context, connection_info, instance, mountpoint,
|
||||||
encryption=None):
|
encryption=None):
|
||||||
return self._volumeops.detach_volume(connection_info,
|
return self._volumeops.detach_volume(connection_info,
|
||||||
instance.name)
|
instance.name)
|
||||||
|
|
|
@ -1539,7 +1539,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
block_device_info=block_device_info)
|
block_device_info=block_device_info)
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
def detach_volume(self, connection_info, instance, mountpoint,
|
def detach_volume(self, context, connection_info, instance, mountpoint,
|
||||||
encryption=None):
|
encryption=None):
|
||||||
disk_dev = mountpoint.rpartition("/")[2]
|
disk_dev = mountpoint.rpartition("/")[2]
|
||||||
try:
|
try:
|
||||||
|
@ -1580,11 +1580,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
# NOTE(lyarwood): We can provide None as the request context here as we
|
self._disconnect_volume(context, connection_info, instance,
|
||||||
# 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,
|
|
||||||
encryption=encryption)
|
encryption=encryption)
|
||||||
|
|
||||||
def extend_volume(self, connection_info, instance):
|
def extend_volume(self, connection_info, instance):
|
||||||
|
|
|
@ -396,7 +396,7 @@ class VMwareVCDriver(driver.ComputeDriver):
|
||||||
"""Attach volume storage to VM instance."""
|
"""Attach volume storage to VM instance."""
|
||||||
return self._volumeops.attach_volume(connection_info, 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):
|
encryption=None):
|
||||||
"""Detach volume storage to VM instance."""
|
"""Detach volume storage to VM instance."""
|
||||||
return self._volumeops.detach_volume(connection_info, instance)
|
return self._volumeops.detach_volume(connection_info, instance)
|
||||||
|
|
|
@ -445,7 +445,7 @@ class XenAPIDriver(driver.ComputeDriver):
|
||||||
instance['name'],
|
instance['name'],
|
||||||
mountpoint)
|
mountpoint)
|
||||||
|
|
||||||
def detach_volume(self, connection_info, instance, mountpoint,
|
def detach_volume(self, context, connection_info, instance, mountpoint,
|
||||||
encryption=None):
|
encryption=None):
|
||||||
"""Detach volume storage from VM instance."""
|
"""Detach volume storage from VM instance."""
|
||||||
self._volumeops.detach_volume(connection_info,
|
self._volumeops.detach_volume(connection_info,
|
||||||
|
|
Loading…
Reference in New Issue