spdkcli: Check for uninitialized spdk instance

At start of spdkcli and on each configuration call
check if spdk subsystems are initialized.
Disallow using get/create/delete commands if system is
not initialized.

Change-Id: I8b9e0362c31a5007e6460d4f79cf3f9e91f71054
Signed-off-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-on: https://review.gerrithub.io/419510
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Pawel Kaminski <pawelx.kaminski@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Karol Latecki 2018-07-17 12:25:19 +02:00 committed by Jim Harris
parent ff3cd4315e
commit cf43428221

View File

@ -15,8 +15,21 @@ class UIRoot(UINode):
self.current_vhost_ctrls = [] self.current_vhost_ctrls = []
self.set_rpc_target(s) self.set_rpc_target(s)
self.verbose = False self.verbose = False
self.is_init = self.check_init()
def refresh(self): def refresh(self):
if self.is_init is False:
methods = self.get_rpc_methods(current=True)
methods = "\n".join(methods)
self.shell.log.warning("SPDK Application is not yet initialized.\n"
"Please initialize subsystems with start_subsystem_init command.\n"
"List of available commands in current state:\n"
"%s" % methods)
else:
# Pass because we'd like to build main tree structure for "ls"
# even if state is uninitialized
pass
self._children = set([]) self._children = set([])
UIBdevs(self) UIBdevs(self)
UILvolStores(self) UILvolStores(self)
@ -40,17 +53,29 @@ class UIRoot(UINode):
return r return r
return w return w
def ui_command_start_subsystem_init(self):
if rpc.start_subsystem_init(self.client):
self.is_init = True
self.refresh()
def get_rpc_methods(self, current=False):
return rpc.get_rpc_methods(self.client, current=current)
def check_init(self):
return "start_subsystem_init" not in self.get_rpc_methods(current=True)
def get_bdevs(self, bdev_type): def get_bdevs(self, bdev_type):
self.current_bdevs = rpc.bdev.get_bdevs(self.client) if self.is_init:
# Following replace needs to be done in order for some of the bdev self.current_bdevs = rpc.bdev.get_bdevs(self.client)
# listings to work: logical volumes, split disk. # Following replace needs to be done in order for some of the bdev
# For example logical volumes: listing in menu is "Logical_Volume" # listings to work: logical volumes, split disk.
# (cannot have space), but the product name in SPDK is "Logical Volume" # For example logical volumes: listing in menu is "Logical_Volume"
bdev_type = bdev_type.replace("_", " ") # (cannot have space), but the product name in SPDK is "Logical Volume"
for bdev in filter(lambda x: bdev_type in x["product_name"].lower(), bdev_type = bdev_type.replace("_", " ")
self.current_bdevs): for bdev in filter(lambda x: bdev_type in x["product_name"].lower(),
test = Bdev(bdev) self.current_bdevs):
yield test test = Bdev(bdev)
yield test
def get_bdevs_iostat(self, **kwargs): def get_bdevs_iostat(self, **kwargs):
return rpc.bdev.get_bdevs_iostat(self.client, **kwargs) return rpc.bdev.get_bdevs_iostat(self.client, **kwargs)
@ -132,9 +157,10 @@ class UIRoot(UINode):
rpc.bdev.delete_error_bdev(self.client, **kwargs) rpc.bdev.delete_error_bdev(self.client, **kwargs)
def get_lvol_stores(self): def get_lvol_stores(self):
self.current_lvol_stores = rpc.lvol.get_lvol_stores(self.client) if self.is_init:
for lvs in self.current_lvol_stores: self.current_lvol_stores = rpc.lvol.get_lvol_stores(self.client)
yield LvolStore(lvs) for lvs in self.current_lvol_stores:
yield LvolStore(lvs)
@verbose @verbose
def create_lvol_store(self, **kwargs): def create_lvol_store(self, **kwargs):
@ -185,18 +211,21 @@ class UIRoot(UINode):
return response return response
def get_virtio_scsi_devs(self): def get_virtio_scsi_devs(self):
for bdev in rpc.vhost.get_virtio_scsi_devs(self.client): if self.is_init:
test = Bdev(bdev) for bdev in rpc.vhost.get_virtio_scsi_devs(self.client):
yield test test = Bdev(bdev)
yield test
def list_vhost_ctrls(self): def list_vhost_ctrls(self):
self.current_vhost_ctrls = rpc.vhost.get_vhost_controllers(self.client) if self.is_init:
self.current_vhost_ctrls = rpc.vhost.get_vhost_controllers(self.client)
def get_vhost_ctrlrs(self, ctrlr_type): def get_vhost_ctrlrs(self, ctrlr_type):
self.list_vhost_ctrls() if self.is_init:
for ctrlr in filter(lambda x: ctrlr_type in x["backend_specific"].keys(), self.list_vhost_ctrls()
self.current_vhost_ctrls): for ctrlr in filter(lambda x: ctrlr_type in x["backend_specific"].keys(),
yield VhostCtrlr(ctrlr) self.current_vhost_ctrls):
yield VhostCtrlr(ctrlr)
@verbose @verbose
def remove_vhost_controller(self, **kwargs): def remove_vhost_controller(self, **kwargs):