Skip to content

Commit e7b3831

Browse files
Merge pull request #488 from martin-belanger/update-libnvme-python-api
fix: adapt to new libnvme Python API (Phase 2 + exception hierarchy)
2 parents 7c0a4c4 + 96168ee commit e7b3831

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

staslib/ctrl.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class Controller(stas.ControllerABC):
5050
def __init__(self, tid: trid.TID, service, discovery_ctrl: bool = False):
5151
sysconf = conf.SysConf()
5252
self._nvme_options = conf.NvmeOptions()
53-
self._root = nvme.global_ctx()
54-
self._host = nvme.host(
53+
self._root = nvme.GlobalCtx()
54+
self._host = nvme.Host(
5555
self._root, hostnqn=sysconf.hostnqn, hostid=sysconf.hostid, hostsymname=sysconf.hostsymname
5656
)
57-
self._host.dhchap_key = sysconf.hostkey if self._nvme_options.dhchap_hostkey_supp else None
57+
self._host.dhchap_host_key = sysconf.hostkey if self._nvme_options.dhchap_hostkey_supp else None
5858
self._udev = udev.UDEV
5959
self._device = None # Refers to the nvme device (e.g. /dev/nvme[n])
6060
self._ctrl = None # libnvme's nvme.ctrl object
@@ -93,7 +93,7 @@ def all_ops_completed(self) -> bool:
9393

9494
def connected(self):
9595
'''@brief Return whether a connection is established'''
96-
return self._ctrl and self._ctrl.connected()
96+
return self._ctrl and self._ctrl.connected
9797

9898
def controller_id_dict(self) -> dict:
9999
'''@brief return the controller ID as a dict.'''
@@ -218,7 +218,7 @@ def _get_cfg(self):
218218

219219
def _do_connect(self):
220220
cfg = self._get_cfg()
221-
self._ctrl = nvme.ctrl(self._root, cfg)
221+
self._ctrl = nvme.Ctrl(self._root, cfg)
222222

223223
self._ctrl.discovery_ctrl = self._discovery_ctrl
224224

@@ -330,7 +330,7 @@ def cback(controller: Controller, success: bool)
330330
logging.debug(
331331
'Controller.disconnect() - %s | %s: keep_connection=%s', self.id, self.device, keep_connection
332332
)
333-
if self._ctrl and self._ctrl.connected() and not keep_connection:
333+
if self._ctrl and self._ctrl.connected and not keep_connection:
334334
logging.info('%s | %s - Disconnect initiated', self.id, self.device)
335335
op = gutil.AsyncTask(self._on_disconn_success, self._on_disconn_fail, self._ctrl.disconnect)
336336
op.run_async(disconnected_cb)
@@ -552,7 +552,7 @@ def _find_existing_connection(self):
552552
def _post_registration_actions(self):
553553
if conf.SvcConf().pleo_enabled and self._is_ddc():
554554
self._get_supported_op = gutil.AsyncTask(
555-
self._on_get_supported_success, self._on_get_supported_fail, self._ctrl.supported_log_pages
555+
self._on_get_supported_success, self._on_get_supported_fail, self._ctrl.get_supported_log_pages
556556
)
557557
self._get_supported_op.run_async()
558558
else:
@@ -656,10 +656,7 @@ def _on_get_supported_success(self, op_obj: gutil.AsyncTask, data):
656656
)
657657
return
658658

659-
try:
660-
dlp_supp_opts = data[nvme.NVME_LOG_LID_DISCOVERY] >> 16
661-
except (TypeError, IndexError):
662-
dlp_supp_opts = 0
659+
dlp_supp_opts = data[nvme.NVME_LOG_LID_DISCOVERY] >> 16
663660

664661
logging.debug(
665662
'Dc._on_get_supported_success() - %s | %s: supported options = 0x%04X = %s',

staslib/nbft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
def get_nbft_files(root_dir=defs.NBFT_SYSFS_PATH):
1818
"""Return a dictionary containing the NBFT data for all the NBFT binary files located in @root_dir"""
1919
pathname = os.path.join(root_dir, defs.NBFT_SYSFS_FILENAME)
20-
root = nvme.global_ctx()
20+
root = nvme.GlobalCtx()
2121
return {fname: nvme.nbft_get(root, fname) or {} for fname in glob.iglob(pathname=pathname)}

test/test-controller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Ctrl:
2828
def __init__(this):
2929
this.name = 'nvme666'
3030

31+
@property
3132
def connected(this):
3233
return self._connected
3334

0 commit comments

Comments
 (0)