Skip to content

Commit 2a160f6

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "libvirt: Remove MIN_LIBVIRT_VIR_ERR_DEVICE_MISSING"
2 parents 3661339 + 0aff191 commit 2a160f6

File tree

4 files changed

+8
-174
lines changed

4 files changed

+8
-174
lines changed

nova/tests/unit/virt/libvirt/test_driver.py

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9575,51 +9575,6 @@ def test_attach_volume_with_vir_domain_affect_live_flag(self,
95759575
mock_build_metadata.assert_called_with(self.context, instance)
95769576
mock_save.assert_called_with()
95779577

9578-
@mock.patch('nova.virt.libvirt.host.Host.get_guest')
9579-
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion')
9580-
@mock.patch(
9581-
'nova.virt.libvirt.driver.LibvirtDriver._disconnect_volume',
9582-
new=mock.Mock())
9583-
def test_detach_volume_supports_device_missing(
9584-
self, mock_get_version, mock_get_guest):
9585-
"""Assert that VIR_ERR_DEVICE_MISSING is only used if libvirt >= v4.1.0
9586-
"""
9587-
mock_guest = mock.Mock(spec=libvirt_guest.Guest)
9588-
mock_guest.get_power_state.return_value = power_state.RUNNING
9589-
mock_get_guest.return_value = mock_guest
9590-
9591-
v4_0_0 = versionutils.convert_version_to_int((4, 0, 0))
9592-
mock_get_version.return_value = v4_0_0
9593-
9594-
mountpoint = "/dev/foo"
9595-
expected_disk_dev = "foo"
9596-
9597-
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
9598-
drvr.detach_volume(
9599-
self.context, mock.sentinel.connection_info,
9600-
mock.sentinel.instance, mountpoint)
9601-
9602-
# Assert supports_device_missing_error_code=False is used
9603-
mock_guest.detach_device_with_retry.assert_called_once_with(
9604-
mock_guest.get_disk, expected_disk_dev, live=True,
9605-
supports_device_missing_error_code=False)
9606-
9607-
# reset and try again with v4.1.0
9608-
mock_guest.reset_mock()
9609-
mock_get_version.reset_mock()
9610-
9611-
v4_1_0 = versionutils.convert_version_to_int((4, 1, 0))
9612-
mock_get_version.return_value = v4_1_0
9613-
9614-
drvr.detach_volume(
9615-
self.context, mock.sentinel.connection_info,
9616-
mock.sentinel.instance, mountpoint)
9617-
9618-
# Assert supports_device_missing_error_code=True is used
9619-
mock_guest.detach_device_with_retry.assert_called_once_with(
9620-
mock_guest.get_disk, expected_disk_dev, live=True,
9621-
supports_device_missing_error_code=True)
9622-
96239578
@mock.patch('nova.virt.libvirt.host.Host._get_domain')
96249579
def test_detach_volume_with_vir_domain_affect_live_flag(self,
96259580
mock_get_domain):
@@ -19058,51 +19013,6 @@ def test_detach_volume_with_instance_not_found(self):
1905819013
_disconnect_volume.assert_called_once_with(
1905919014
self.context, connection_info, instance, encryption=None)
1906019015

19061-
@mock.patch('nova.virt.libvirt.host.Host.get_guest')
19062-
@mock.patch.object(fakelibvirt.Connection, 'getLibVersion')
19063-
def test_detach_interface_supports_device_missing(
19064-
self, mock_get_version, mock_get_guest):
19065-
"""Assert that VIR_ERR_DEVICE_MISSING is only used if libvirt >= v4.1.0
19066-
"""
19067-
mock_guest = mock.Mock(spec=libvirt_guest.Guest)
19068-
mock_guest.get_power_state.return_value = power_state.RUNNING
19069-
mock_get_guest.return_value = mock_guest
19070-
19071-
v4_0_0 = versionutils.convert_version_to_int((4, 0, 0))
19072-
mock_get_version.return_value = v4_0_0
19073-
19074-
instance = objects.Instance(**self.test_instance)
19075-
19076-
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
19077-
with mock.patch.object(drvr, 'vif_driver') as mock_vif_driver:
19078-
mock_vif_driver.get_config.return_value = mock.sentinel.cfg
19079-
mock_vif_driver.get_vif_devname.return_value = mock.sentinel.dev
19080-
19081-
drvr.detach_interface(
19082-
self.context, instance, mock.sentinel.vif)
19083-
19084-
# Assert supports_device_missing_error_code=False is used
19085-
mock_guest.detach_device_with_retry.assert_called_once_with(
19086-
mock_guest.get_interface_by_cfg, mock.sentinel.cfg, live=True,
19087-
alternative_device_name=mock.sentinel.dev,
19088-
supports_device_missing_error_code=False)
19089-
19090-
# reset and try again with v4.1.0
19091-
mock_guest.reset_mock()
19092-
mock_get_version.reset_mock()
19093-
19094-
v4_1_0 = versionutils.convert_version_to_int((4, 1, 0))
19095-
mock_get_version.return_value = v4_1_0
19096-
19097-
drvr.detach_interface(
19098-
self.context, instance, mock.sentinel.vif)
19099-
19100-
# Assert supports_device_missing_error_code=True is used
19101-
mock_guest.detach_device_with_retry.assert_called_once_with(
19102-
mock_guest.get_interface_by_cfg, mock.sentinel.cfg, live=True,
19103-
alternative_device_name=mock.sentinel.dev,
19104-
supports_device_missing_error_code=True)
19105-
1910619016
def _test_attach_detach_interface_get_config(self, method_name):
1910719017
"""Tests that the get_config() method is properly called in
1910819018
attach_interface() and detach_interface().

nova/tests/unit/virt/libvirt/test_guest.py

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ def _test_detach_device_with_retry_second_detach_failure(
311311
mock_detach.side_effect = [None, fake_exc]
312312
retry_detach = self.guest.detach_device_with_retry(
313313
get_config, fake_device, live=True,
314-
inc_sleep_time=.01, max_retry_count=3,
315-
supports_device_missing_error_code=supports_device_missing)
314+
inc_sleep_time=.01, max_retry_count=3)
316315
# Some time later, we can do the wait/retry to ensure detach
317316
self.assertRaises(exception.DeviceNotFound, retry_detach)
318317
# Check that the save_and_reraise_exception context manager didn't log
@@ -321,20 +320,6 @@ def _test_detach_device_with_retry_second_detach_failure(
321320
self.assertNotIn('Original exception being dropped',
322321
self.stdlog.logger.output)
323322

324-
# TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
325-
def test_detach_device_with_retry_second_detach_operation_failed(self):
326-
self._test_detach_device_with_retry_second_detach_failure(
327-
error_code=fakelibvirt.VIR_ERR_OPERATION_FAILED,
328-
error_message="operation failed: disk vdb not found",
329-
supports_device_missing=False)
330-
331-
# TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
332-
def test_detach_device_with_retry_second_detach_internal_error(self):
333-
self._test_detach_device_with_retry_second_detach_failure(
334-
error_code=fakelibvirt.VIR_ERR_INTERNAL_ERROR,
335-
error_message="operation failed: disk vdb not found",
336-
supports_device_missing=False)
337-
338323
def test_detach_device_with_retry_second_detach_device_missing(self):
339324
self._test_detach_device_with_retry_second_detach_failure(
340325
error_code=fakelibvirt.VIR_ERR_DEVICE_MISSING,
@@ -374,8 +359,7 @@ def _test_detach_device_with_retry_first_detach_failure(
374359
# succeeds afterward
375360
self.domain.detachDeviceFlags.side_effect = [fake_exc, None]
376361
retry_detach = self.guest.detach_device_with_retry(get_config,
377-
fake_device, live=True, inc_sleep_time=.01, max_retry_count=3,
378-
supports_device_missing_error_code=supports_device_missing)
362+
fake_device, live=True, inc_sleep_time=.01, max_retry_count=3)
379363
# We should have tried to detach from the persistent domain
380364
self.domain.detachDeviceFlags.assert_called_once_with(
381365
"</xml>", flags=(fakelibvirt.VIR_DOMAIN_AFFECT_CONFIG |
@@ -387,27 +371,6 @@ def _test_detach_device_with_retry_first_detach_failure(
387371
self.domain.detachDeviceFlags.assert_called_once_with(
388372
"</xml>", flags=fakelibvirt.VIR_DOMAIN_AFFECT_LIVE)
389373

390-
# TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
391-
def test_detach_device_with_retry_first_detach_operation_failed(self):
392-
self._test_detach_device_with_retry_first_detach_failure(
393-
error_code=fakelibvirt.VIR_ERR_OPERATION_FAILED,
394-
error_message="operation failed: disk vdb not found",
395-
supports_device_missing=False)
396-
397-
# TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
398-
def test_detach_device_with_retry_first_detach_internal_error(self):
399-
self._test_detach_device_with_retry_first_detach_failure(
400-
error_code=fakelibvirt.VIR_ERR_INTERNAL_ERROR,
401-
error_message="operation failed: disk vdb not found",
402-
supports_device_missing=False)
403-
404-
# TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
405-
def test_detach_device_with_retry_first_detach_invalid_arg(self):
406-
self._test_detach_device_with_retry_first_detach_failure(
407-
error_code=fakelibvirt.VIR_ERR_INVALID_ARG,
408-
error_message="invalid argument: no target device vdb",
409-
supports_device_missing=False)
410-
411374
def test_detach_device_with_retry_first_detach_device_missing(self):
412375
self._test_detach_device_with_retry_first_detach_failure(
413376
error_code=fakelibvirt.VIR_ERR_DEVICE_MISSING,

nova/virt/libvirt/driver.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ def repr_method(self):
254254
MIN_LIBVIRT_BLOCKDEV = (6, 0, 0)
255255
MIN_QEMU_BLOCKDEV = (4, 2, 0)
256256

257-
MIN_LIBVIRT_VIR_ERR_DEVICE_MISSING = (4, 1, 0)
258-
259257
# Virtual TPM (vTPM) support
260258
MIN_LIBVIRT_VTPM = (5, 6, 0)
261259

@@ -2052,11 +2050,8 @@ def detach_volume(self, context, connection_info, instance, mountpoint,
20522050
# detaching any attached encryptors or disconnecting the underlying
20532051
# volume in _disconnect_volume. Otherwise, the encryptor or volume
20542052
# driver may report that the volume is still in use.
2055-
supports_device_missing = self._host.has_min_version(
2056-
MIN_LIBVIRT_VIR_ERR_DEVICE_MISSING)
20572053
wait_for_detach = guest.detach_device_with_retry(
2058-
guest.get_disk, disk_dev, live=live,
2059-
supports_device_missing_error_code=supports_device_missing)
2054+
guest.get_disk, disk_dev, live=live)
20602055
wait_for_detach()
20612056

20622057
except exception.InstanceNotFound:
@@ -2257,12 +2252,9 @@ def detach_interface(self, context, instance, vif):
22572252
live = state in (power_state.RUNNING, power_state.PAUSED)
22582253
# Now we are going to loop until the interface is detached or we
22592254
# timeout.
2260-
supports_device_missing = self._host.has_min_version(
2261-
MIN_LIBVIRT_VIR_ERR_DEVICE_MISSING)
22622255
wait_for_detach = guest.detach_device_with_retry(
22632256
guest.get_interface_by_cfg, cfg, live=live,
2264-
alternative_device_name=self.vif_driver.get_vif_devname(vif),
2265-
supports_device_missing_error_code=supports_device_missing)
2257+
alternative_device_name=self.vif_driver.get_vif_devname(vif))
22662258
wait_for_detach()
22672259
except exception.DeviceDetachFailed:
22682260
# We failed to detach the device even with the retry loop, so let's

nova/virt/libvirt/guest.py

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ def get_all_devices(self, devtype=None):
368368
def detach_device_with_retry(self, get_device_conf_func, device, live,
369369
max_retry_count=7, inc_sleep_time=10,
370370
max_sleep_time=60,
371-
alternative_device_name=None,
372-
supports_device_missing_error_code=False):
371+
alternative_device_name=None):
373372
"""Detaches a device from the guest. After the initial detach request,
374373
a function is returned which can be used to ensure the device is
375374
successfully removed from the guest domain (retrying the removal as
@@ -390,16 +389,8 @@ def detach_device_with_retry(self, get_device_conf_func, device, live,
390389
max_sleep_time will be used as the sleep time.
391390
:param alternative_device_name: This is an alternative identifier for
392391
the device if device is not an ID, used solely for error messages.
393-
:param supports_device_missing_error_code: does the installed version
394-
of libvirt provide the
395-
VIR_ERR_DEVICE_MISSING error
396-
code.
397392
"""
398393
alternative_device_name = alternative_device_name or device
399-
unplug_libvirt_error_codes = set([
400-
libvirt.VIR_ERR_OPERATION_FAILED,
401-
libvirt.VIR_ERR_INTERNAL_ERROR
402-
])
403394

404395
def _try_detach_device(conf, persistent=False, live=False):
405396
# Raise DeviceNotFound if the device isn't found during detach
@@ -412,31 +403,9 @@ def _try_detach_device(conf, persistent=False, live=False):
412403

413404
except libvirt.libvirtError as ex:
414405
with excutils.save_and_reraise_exception(reraise=False) as ctx:
415-
errcode = ex.get_error_code()
416-
# TODO(lyarwood): Remove libvirt.VIR_ERR_OPERATION_FAILED
417-
# and libvirt.VIR_ERR_INTERNAL_ERROR once
418-
# MIN_LIBVIRT_VERSION is >= 4.1.0
419-
if supports_device_missing_error_code:
420-
unplug_libvirt_error_codes.add(
421-
libvirt.VIR_ERR_DEVICE_MISSING)
422-
if errcode in unplug_libvirt_error_codes:
423-
# TODO(lyarwood): Remove the following error message
424-
# check once we only care about VIR_ERR_DEVICE_MISSING
425-
errmsg = ex.get_error_message()
426-
if 'not found' in errmsg:
427-
# This will be raised if the live domain
428-
# detach fails because the device is not found
429-
raise exception.DeviceNotFound(
430-
device=alternative_device_name)
431-
# TODO(lyarwood): Remove libvirt.VIR_ERR_INVALID_ARG once
432-
# MIN_LIBVIRT_VERSION is >= 4.1.0
433-
elif errcode == libvirt.VIR_ERR_INVALID_ARG:
434-
errmsg = ex.get_error_message()
435-
if 'no target device' in errmsg:
436-
# This will be raised if the persistent domain
437-
# detach fails because the device is not found
438-
raise exception.DeviceNotFound(
439-
device=alternative_device_name)
406+
if ex.get_error_code() == libvirt.VIR_ERR_DEVICE_MISSING:
407+
raise exception.DeviceNotFound(
408+
device=alternative_device_name)
440409
# Re-raise the original exception if we're not raising
441410
# DeviceNotFound instead. This will avoid logging of a
442411
# "Original exception being dropped" traceback.

0 commit comments

Comments
 (0)