Skip to content

Commit e7801da

Browse files
Millefeuille42NambrokWescoeur
committed
fix(linstor): subsequent fixes for linstorhostcall
fix(linstor): prevent use of e before assignment in nested try-except fix(linstor): use util.get_master_ref to get the master ref fix(linstor): log host_ref instead UUID to prevent XAPI call fix(log_failed_call): set error value for the call without an actual error fix(linstorhostcall): use next iter instead of list conversion cleanup(linstor): remove currently unused get_primary function Signed-off-by: Mathieu Labourier <[email protected]> Co-authored-by: Damien Thenot <[email protected]> Co-authored-by: Ronan Abhamon <[email protected]>
1 parent 9ef1c17 commit e7801da

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

drivers/linstorvhdutil.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,18 @@
3131

3232

3333
def call_remote_method(session, host_ref, method, device_path, args):
34-
host_rec = session.xenapi.host.get_record(host_ref)
35-
host_uuid = host_rec['uuid']
36-
3734
try:
3835
response = session.xenapi.host.call_plugin(
3936
host_ref, MANAGER_PLUGIN, method, args
4037
)
4138
except Exception as e:
4239
util.SMlog('call-plugin on {} ({} with {}) exception: {}'.format(
43-
host_uuid, method, args, e
40+
host_ref, method, args, e
4441
))
4542
raise util.SMException(str(e))
4643

4744
util.SMlog('call-plugin on {} ({} with {}) returned: {}'.format(
48-
host_uuid, method, args, response
45+
host_ref, method, args, response
4946
))
5047

5148
return response
@@ -85,7 +82,14 @@ def log_successful_call(target_host, device_path, vdi_uuid, remote_method, respo
8582

8683
def log_failed_call(target_host, next_target, device_path, vdi_uuid, remote_method, e):
8784
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),
85+
'Failed to call method on {} for device {} ({}): {}. Trying accessing on {}... (cause: {})'.format(
86+
target_host,
87+
device_path,
88+
vdi_uuid,
89+
remote_method,
90+
next_target,
91+
e
92+
),
8993
priority=util.LOG_DEBUG
9094
)
9195

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

109113
try:
110-
host_ref_attached = util.get_hosts_attached_on(self._session, [vdi_uuid])[0]
114+
host_ref_attached = next(iter(util.get_hosts_attached_on(self._session, [vdi_uuid])))
111115
if host_ref_attached:
112116
response = call_remote_method(
113117
self._session, host_ref_attached, remote_method, device_path, remote_args
@@ -118,7 +122,7 @@ def wrapper(*args, **kwargs):
118122
log_failed_call('attached node', 'master', device_path, vdi_uuid, remote_method, e)
119123

120124
try:
121-
master_ref = self._session.xenapi.pool.get_all_records().values()[0]['master']
125+
master_ref = util.get_master_ref(self._session)
122126
response = call_remote_method(self._session, master_ref, remote_method, device_path, remote_args)
123127
log_successful_call('master', device_path, vdi_uuid, remote_method, response)
124128
return response_parser(self, vdi_uuid, response)
@@ -136,7 +140,14 @@ def wrapper(*args, **kwargs):
136140
except Exception as remote_e:
137141
self._raise_openers_exception(device_path, remote_e)
138142
else:
139-
log_failed_call('primary', 'another node', device_path, vdi_uuid, remote_method, e)
143+
log_failed_call(
144+
'primary',
145+
'another node',
146+
device_path,
147+
vdi_uuid,
148+
remote_method,
149+
'no primary'
150+
)
140151

141152
try:
142153
host = self._get_readonly_host(vdi_uuid, device_path, nodes)

drivers/linstorvolumemanager.py

Lines changed: 2 additions & 20 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:
@@ -1439,24 +1439,6 @@ def find_up_to_date_diskful_nodes(self, volume_uuid):
14391439

14401440
return (node_names, in_use_by)
14411441

1442-
def get_primary(self, volume_uuid):
1443-
"""
1444-
Find the node that opened a volume, i.e. the primary.
1445-
:rtype: str
1446-
"""
1447-
volume_name = self.get_volume_name(volume_uuid)
1448-
1449-
resource_states = filter(
1450-
lambda resource_state: resource_state.name == volume_name,
1451-
self._get_resource_cache().resource_states
1452-
)
1453-
1454-
for resource_state in resource_states:
1455-
if resource_state.in_use:
1456-
return resource_state.node_name
1457-
1458-
return None
1459-
14601442
def invalidate_resource_cache(self):
14611443
"""
14621444
If resources are impacted by external commands like vhdutil,

0 commit comments

Comments
 (0)