Skip to content

Commit

Permalink
CA-388451: ensure that xapi sessions are logged out
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Syms <[email protected]>
  • Loading branch information
MarkSymsCtx committed Feb 5, 2024
1 parent 7434118 commit a1df4d0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3033,7 +3033,7 @@ def _ensure_xapi_initialised(session):
time.sleep(15)
finally:
if local_session is not None:
local_session.logout()
local_session.xenapi.session.logout()

def _gc(session, srUuid, dryRun=False, immediate=False):
init(srUuid)
Expand Down
2 changes: 1 addition & 1 deletion drivers/mpathcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_dm_major():
def mpc_exit(session, code):
if session is not None:
try:
session.xenapi.logout()
session.xenapi.session.logout()
except:
pass
sys.exit(code)
Expand Down
43 changes: 23 additions & 20 deletions drivers/sr_health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,29 @@ def main():
util.SMlog("Unable to open local XAPI session", priority=util.LOG_ERR)
return

localhost = util.get_localhost_ref(session)

sm_types = [x['type'] for x in session.xenapi.SM.get_all_records_where(
'field "required_api_version" = "1.0"').values()]
for sm_type in sm_types:
srs = session.xenapi.SR.get_all_records_where(
f'field "type" = "{sm_type}"')
for sr in srs:
pbds = session.xenapi.PBD.get_all_records_where(
f'field "SR" = "{sr}" and field "host" = "{localhost}"')
if not pbds:
continue

pbd_ref, pbd = pbds.popitem()
if not pbd['currently_attached']:
continue

sr_uuid = srs[sr]['uuid']
sr_obj = SR.SR.from_uuid(session, sr_uuid)
sr_obj.check_sr(sr_uuid)
try:
localhost = util.get_localhost_ref(session)

sm_types = [x['type'] for x in session.xenapi.SM.get_all_records_where(
'field "required_api_version" = "1.0"').values()]
for sm_type in sm_types:
srs = session.xenapi.SR.get_all_records_where(
f'field "type" = "{sm_type}"')
for sr in srs:
pbds = session.xenapi.PBD.get_all_records_where(
f'field "SR" = "{sr}" and field "host" = "{localhost}"')
if not pbds:
continue

pbd_ref, pbd = pbds.popitem()
if not pbd['currently_attached']:
continue

sr_uuid = srs[sr]['uuid']
sr_obj = SR.SR.from_uuid(session, sr_uuid)
sr_obj.check_sr(sr_uuid)
finally:
session.xenapi.session.logout()


if __name__ == "__main__":
Expand Down
35 changes: 20 additions & 15 deletions drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,18 +378,19 @@ def ioretry_stat(path, maxretry=IORETRY_MAX):
def sr_get_capability(sr_uuid):
result = []
session = get_localAPI_session()
sr_ref = session.xenapi.SR.get_by_uuid(sr_uuid)
sm_type = session.xenapi.SR.get_record(sr_ref)['type']
sm_rec = session.xenapi.SM.get_all_records_where(
"field \"type\" = \"%s\"" % sm_type)

# SM expects at least one entry of any SR type
if len(sm_rec) > 0:
result = list(sm_rec.values())[0]['capabilities']
try:
sr_ref = session.xenapi.SR.get_by_uuid(sr_uuid)
sm_type = session.xenapi.SR.get_record(sr_ref)['type']
sm_rec = session.xenapi.SM.get_all_records_where(
"field \"type\" = \"%s\"" % sm_type)

session.xenapi.logout()
return result
# SM expects at least one entry of any SR type
if len(sm_rec) > 0:
result = list(sm_rec.values())[0]['capabilities']

return result
finally:
session.xenapi.session.logout()

def sr_get_driver_info(driver_info):
results = {}
Expand Down Expand Up @@ -1274,11 +1275,15 @@ def is_active(self, name):

def mark_sr(self, name, sruuid, started):
session = get_localAPI_session()
sr = session.xenapi.SR.get_by_uuid(sruuid)
if started:
session.xenapi.SR.add_to_other_config(sr, name, "active")
else:
session.xenapi.SR.remove_from_other_config(sr, name)
try:
sr = session.xenapi.SR.get_by_uuid(sruuid)

if started:
session.xenapi.SR.add_to_other_config(sr, name, "active")
else:
session.xenapi.SR.remove_from_other_config(sr, name)
finally:
session.xenapi.session.logout()

def activate(self, name, sruuid):
if name in self.points:
Expand Down

0 comments on commit a1df4d0

Please sign in to comment.