Merge "os-xenapi: add a maximum retry count for vbd unplug"
This commit is contained in:
@@ -28,6 +28,9 @@ import time
|
||||
|
||||
import XenAPI
|
||||
|
||||
# global variable definition
|
||||
MAX_VBD_UNPLUG_RETRIES = 30
|
||||
|
||||
|
||||
# Logging setup
|
||||
|
||||
@@ -120,6 +123,7 @@ def _vbd_unplug_with_retry(session, vbd):
|
||||
understand, we're seeing the device still in use, even when all processes
|
||||
using the device should be dead.
|
||||
"""
|
||||
retry_count = MAX_VBD_UNPLUG_RETRIES
|
||||
while True:
|
||||
try:
|
||||
session.xenapi.VBD.unplug(vbd)
|
||||
@@ -128,6 +132,10 @@ def _vbd_unplug_with_retry(session, vbd):
|
||||
except XenAPI.Failure, e: # noqa
|
||||
if (len(e.details) > 0 and
|
||||
e.details[0] == 'DEVICE_DETACH_REJECTED'):
|
||||
retry_count -= 1
|
||||
if (retry_count <= 0):
|
||||
raise PluginError('VBD.unplug failed after retry %s times.'
|
||||
% MAX_VBD_UNPLUG_RETRIES)
|
||||
logging.debug('VBD.unplug rejected: retrying...')
|
||||
time.sleep(1)
|
||||
elif (len(e.details) > 0 and
|
||||
|
||||
@@ -153,3 +153,16 @@ class PluginlibDom0(plugin_test.PluginTestBase):
|
||||
self.dom0_pluginlib._vbd_unplug_with_retry(self.session,
|
||||
'fake_vbd_ref')
|
||||
self.assertEqual(2, self.session.xenapi.VBD.unplug.call_count)
|
||||
|
||||
def test_vbd_unplug_with_retry_exceed_max_attempts(self):
|
||||
side_effects = ([FakeUnplugException(['DEVICE_DETACH_REJECTED'])]
|
||||
* (self.dom0_pluginlib.MAX_VBD_UNPLUG_RETRIES + 1))
|
||||
|
||||
self.session.xenapi.VBD.unplug.side_effect = side_effects
|
||||
self.dom0_pluginlib.XenAPI.Failure = FakeUnplugException
|
||||
|
||||
self.assertRaises(self.dom0_pluginlib.PluginError,
|
||||
self.dom0_pluginlib._vbd_unplug_with_retry,
|
||||
self.session, 'fake_vbd_ref')
|
||||
self.assertEqual(self.dom0_pluginlib.MAX_VBD_UNPLUG_RETRIES,
|
||||
self.session.xenapi.VBD.unplug.call_count)
|
||||
|
||||
Reference in New Issue
Block a user