@@ -294,8 +294,8 @@ def test_detach_device_with_retry_device_not_found_alt_name(self):
294294
295295 @mock .patch .object (libvirt_guest .Guest , "detach_device" )
296296 def _test_detach_device_with_retry_second_detach_failure (
297- self , mock_detach , error_code = fakelibvirt . VIR_ERR_DEVICE_MISSING ,
298- error_message = "device not found: disk vdb not found" ):
297+ self , mock_detach , error_code = None , error_message = None ,
298+ supports_device_missing = False ):
299299 # This simulates a retry of the transient/live domain detach
300300 # failing because the device is not found
301301 conf = mock .Mock (spec = vconfig .LibvirtConfigGuestDevice )
@@ -312,7 +312,8 @@ def _test_detach_device_with_retry_second_detach_failure(
312312 mock_detach .side_effect = [None , fake_exc ]
313313 retry_detach = self .guest .detach_device_with_retry (
314314 get_config , fake_device , live = True ,
315- inc_sleep_time = .01 , max_retry_count = 3 )
315+ inc_sleep_time = .01 , max_retry_count = 3 ,
316+ supports_device_missing_error_code = supports_device_missing )
316317 # Some time later, we can do the wait/retry to ensure detach
317318 self .assertRaises (exception .DeviceNotFound , retry_detach )
318319 # Check that the save_and_reraise_exception context manager didn't log
@@ -325,20 +326,25 @@ def _test_detach_device_with_retry_second_detach_failure(
325326 def test_detach_device_with_retry_second_detach_operation_failed (self ):
326327 self ._test_detach_device_with_retry_second_detach_failure (
327328 error_code = fakelibvirt .VIR_ERR_OPERATION_FAILED ,
328- error_message = "operation failed: disk vdb not found" )
329+ error_message = "operation failed: disk vdb not found" ,
330+ supports_device_missing = False )
329331
330332 # TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
331333 def test_detach_device_with_retry_second_detach_internal_error (self ):
332334 self ._test_detach_device_with_retry_second_detach_failure (
333335 error_code = fakelibvirt .VIR_ERR_INTERNAL_ERROR ,
334- error_message = "operation failed: disk vdb not found" )
336+ error_message = "operation failed: disk vdb not found" ,
337+ supports_device_missing = False )
335338
336339 def test_detach_device_with_retry_second_detach_device_missing (self ):
337- self ._test_detach_device_with_retry_second_detach_failure ()
340+ self ._test_detach_device_with_retry_second_detach_failure (
341+ error_code = fakelibvirt .VIR_ERR_DEVICE_MISSING ,
342+ error_message = "device not found: disk vdb not found" ,
343+ supports_device_missing = True )
338344
339345 def _test_detach_device_with_retry_first_detach_failure (
340- self , error_code = fakelibvirt . VIR_ERR_DEVICE_MISSING ,
341- error_message = "device not found: disk vdb not found" ):
346+ self , error_code = None , error_message = None ,
347+ supports_device_missing = False ):
342348 # This simulates a persistent or live domain detach failing because the
343349 # device is not found during the first attempt to detach the device.
344350 # We should still attempt to detach the device from the live config if
@@ -369,7 +375,8 @@ def _test_detach_device_with_retry_first_detach_failure(
369375 # succeeds afterward
370376 self .domain .detachDeviceFlags .side_effect = [fake_exc , None ]
371377 retry_detach = self .guest .detach_device_with_retry (get_config ,
372- fake_device , live = True , inc_sleep_time = .01 , max_retry_count = 3 )
378+ fake_device , live = True , inc_sleep_time = .01 , max_retry_count = 3 ,
379+ supports_device_missing_error_code = supports_device_missing )
373380 # We should have tried to detach from the persistent domain
374381 self .domain .detachDeviceFlags .assert_called_once_with (
375382 "</xml>" , flags = (fakelibvirt .VIR_DOMAIN_AFFECT_CONFIG |
@@ -385,22 +392,28 @@ def _test_detach_device_with_retry_first_detach_failure(
385392 def test_detach_device_with_retry_first_detach_operation_failed (self ):
386393 self ._test_detach_device_with_retry_first_detach_failure (
387394 error_code = fakelibvirt .VIR_ERR_OPERATION_FAILED ,
388- error_message = "operation failed: disk vdb not found" )
395+ error_message = "operation failed: disk vdb not found" ,
396+ supports_device_missing = False )
389397
390398 # TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
391399 def test_detach_device_with_retry_first_detach_internal_error (self ):
392400 self ._test_detach_device_with_retry_first_detach_failure (
393401 error_code = fakelibvirt .VIR_ERR_INTERNAL_ERROR ,
394- error_message = "operation failed: disk vdb not found" )
402+ error_message = "operation failed: disk vdb not found" ,
403+ supports_device_missing = False )
395404
396405 # TODO(lyarwood): Remove this test once MIN_LIBVIRT_VERSION is >= 4.1.0
397406 def test_detach_device_with_retry_first_detach_invalid_arg (self ):
398407 self ._test_detach_device_with_retry_first_detach_failure (
399408 error_code = fakelibvirt .VIR_ERR_INVALID_ARG ,
400- error_message = "invalid argument: no target device vdb" )
409+ error_message = "invalid argument: no target device vdb" ,
410+ supports_device_missing = False )
401411
402412 def test_detach_device_with_retry_first_detach_device_missing (self ):
403- self ._test_detach_device_with_retry_first_detach_failure ()
413+ self ._test_detach_device_with_retry_first_detach_failure (
414+ error_code = fakelibvirt .VIR_ERR_DEVICE_MISSING ,
415+ error_message = "device not found: disk vdb not found" ,
416+ supports_device_missing = True )
404417
405418 def test_get_xml_desc (self ):
406419 self .guest .get_xml_desc ()
0 commit comments