Skip to content

Commit 07ad622

Browse files
fix: follow-up fixes
fix(linstor): prevent use of e before assignment in nested try-except fix(linstor): add default value for log_failed_call to prevent unassigned value fix(linstor): convert dict_keys and dict_values to list before indexed access fix(linstor): use ternary for default value management in log_failed_call fix(linstor): use util.get_master_ref to get the master ref Co-authored-by: Damien Thenot <damien.thenot@vates.tech> Signed-off-by: Mathieu Labourier <mathieu.labourier@vates.tech>
1 parent d8fa6d9 commit 07ad622

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

drivers/linstorvhdutil.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@ def log_successful_call(target_host, device_path, vdi_uuid, remote_method, respo
8383
priority=util.LOG_DEBUG
8484
)
8585

86-
def log_failed_call(target_host, next_target, device_path, vdi_uuid, remote_method, e):
86+
def log_failed_call(target_host, next_target, device_path, vdi_uuid, remote_method, e=None):
8787
util.SMlog(
88-
'Failed to call method on {} for device {} ({}): {}. Trying accessing on {}... (cause: {})'.format(target_host, device_path, vdi_uuid, remote_method, next_target, e),
88+
'Failed to call method on {} for device {} ({}): {}. Trying accessing on {}... (cause: {})'.format(
89+
target_host,
90+
device_path,
91+
vdi_uuid,
92+
remote_method,
93+
next_target,
94+
e if e else "no error provided"
95+
),
8996
priority=util.LOG_DEBUG
9097
)
9198

@@ -107,7 +114,7 @@ def wrapper(*args, **kwargs):
107114
remote_args = {str(key): str(value) for key, value in remote_args.items()}
108115

109116
try:
110-
host_ref_attached = util.get_hosts_attached_on(self._session, [vdi_uuid])[0]
117+
host_ref_attached = list(util.get_hosts_attached_on(self._session, [vdi_uuid]))[0]
111118
if host_ref_attached:
112119
response = call_remote_method(
113120
self._session, host_ref_attached, remote_method, device_path, remote_args
@@ -118,7 +125,7 @@ def wrapper(*args, **kwargs):
118125
log_failed_call('attached node', 'master', device_path, vdi_uuid, remote_method, e)
119126

120127
try:
121-
master_ref = self._session.xenapi.pool.get_all_records().values()[0]['master']
128+
master_ref = util.get_master_ref(self._session)
122129
response = call_remote_method(self._session, master_ref, remote_method, device_path, remote_args)
123130
log_successful_call('master', device_path, vdi_uuid, remote_method, response)
124131
return response_parser(self, vdi_uuid, response)
@@ -136,7 +143,7 @@ def wrapper(*args, **kwargs):
136143
except Exception as remote_e:
137144
self._raise_openers_exception(device_path, remote_e)
138145
else:
139-
log_failed_call('primary', 'another node', device_path, vdi_uuid, remote_method, e)
146+
log_failed_call('primary', 'another node', device_path, vdi_uuid, remote_method)
140147

141148
try:
142149
host = self._get_readonly_host(vdi_uuid, device_path, nodes)

drivers/linstorvolumemanager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ def update_volume_uuid(self, volume_uuid, new_volume_uuid, force=False):
10581058

10591059
# 5. Ok!
10601060
volume_properties[self.PROP_NOT_EXISTS] = self.STATE_EXISTS
1061-
except Exception as e:
1061+
except Exception as err:
10621062
try:
10631063
# Clear the new volume properties in case of failure.
10641064
assert volume_properties.namespace == \
@@ -1070,7 +1070,7 @@ def update_volume_uuid(self, volume_uuid, new_volume_uuid, force=False):
10701070
.format(e)
10711071
)
10721072
raise LinstorVolumeManagerError(
1073-
'Failed to copy volume properties: {}'.format(e)
1073+
'Failed to copy volume properties: {}'.format(err)
10741074
)
10751075

10761076
try:

0 commit comments

Comments
 (0)