Skip to content

Commit 3d6c66e

Browse files
committed
Decorate blktap2:_get_pool_config() with call_XAPI_until_httpOK
This method gets data, therefore it can be retried. Signed-off-by: Arnaud Garcia-Fernandez <arnaud.garcia-fernandez@vates.tech>
1 parent 9960a59 commit 3d6c66e

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

drivers/blktap2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from lock import Lock
3131
import util
3232
import xmlrpc.client
33-
import http.client
3433
import errno
3534
import signal
3635
import subprocess
@@ -1621,8 +1620,9 @@ def _remove_tag(self, vdi_uuid):
16211620
else:
16221621
util.SMlog("_remove_tag: host key %s not found, ignore" % host_key)
16231622

1623+
@util.call_XAPI_until_httpOK
16241624
def _get_pool_config(self, pool_name):
1625-
pool_info = dict()
1625+
pool_info = {}
16261626
vdi_ref = self.target.vdi.sr.srcmd.params.get('vdi_ref')
16271627
if not vdi_ref:
16281628
# attach_from_config context: HA disks don't need to be in any
@@ -1940,6 +1940,7 @@ def _deactivate_locked(self, sr_uuid, vdi_uuid, caching_params):
19401940
self._detach(sr_uuid, vdi_uuid)
19411941
if self.tap_wanted():
19421942
self._remove_tag(vdi_uuid)
1943+
19431944
return True
19441945

19451946
def _resetPhylink(self, sr_uuid, vdi_uuid, path):

drivers/util.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -784,25 +784,24 @@ def get_localAPI_session():
784784
return session
785785

786786

787-
def call_XAPI_until_httpOK(function):
787+
def xapi_safe_call(function):
788788
"""
789-
Decorator to catch classic XAPI connexion problems and retry forever
790-
The method called should be only for XAPI calls
789+
Decorator to catch classic XAPI connection problems and retry forever.
790+
The method should be only called for XAPI calls.
791791
eg: blktap2.py#VDI:_remove_tag()
792792
"""
793793
def wrapper(*args, **kwargs):
794-
errmsg = f"{function.__name__}(args={args}, kwargs={kwargs})"
794+
call_str = f"{function.__name__}(args={args}, kwargs={kwargs})"
795795
while True:
796796
try:
797797
return function(*args, **kwargs)
798798
except xmlrpc.client.ProtocolError as e:
799799
# If there's a connection error, keep trying forever.
800800
if e.errcode == http.HTTPStatus.INTERNAL_SERVER_ERROR.value:
801801
continue
802-
SMlog(f"failed XAPI call [{e}]: {errmsg}")
803802
raise
804803
except Exception as e:
805-
SMlog(f"failed XAPI call [{e}]: {errmsg}")
804+
SMlog(f"Failed XAPI call `{call_str}`: `{e}`")
806805
raise
807806
return wrapper
808807

0 commit comments

Comments
 (0)