spdkcli: Exit with 1 when rpc throws JSONRPCException

Fixes #593

Change-Id: Ib9eebdc1c74b82e8d193708b57afea7fefa7aa98
Signed-off-by: Pawel Kaminski <pawelx.kaminski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443887
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
This commit is contained in:
Pawel Kaminski 2019-02-08 06:47:45 -05:00 committed by Jim Harris
parent b0602c5da0
commit 53e25260df
4 changed files with 52 additions and 15 deletions

View File

@ -3,6 +3,7 @@ import sys
import argparse
import configshell_fb
from os import getuid
from rpc.client import JSONRPCException
from configshell_fb import ConfigShell, shell, ExecutionError
from spdkcli import UIRoot
from pyparsing import (alphanums, Optional, Suppress, Word, Regex,
@ -61,7 +62,7 @@ def main():
while not spdk_shell._exit:
try:
spdk_shell.run_interactive()
except ExecutionError as e:
except (JSONRPCException, ExecutionError) as e:
spdk_shell.log.error("%s" % e)

View File

@ -37,8 +37,8 @@ class UINode(ConfigNode):
try:
result = ConfigNode.execute_command(self, command,
pparams, kparams)
except Exception as msg:
self.shell.log.error(str(msg))
except Exception as e:
raise e
else:
self.shell.log.debug("Command %s succeeded." % command)
return result
@ -116,11 +116,14 @@ class UILvolStores(UINode):
self.delete(name, uuid)
def ui_command_delete_all(self):
rpc_messages = ""
for lvs in self._children:
try:
self.delete(None, lvs.lvs.uuid)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Lvol stores: %s" % len(self.children), None
@ -142,11 +145,14 @@ class UIBdev(UINode):
def ui_command_delete_all(self):
"""Delete all bdevs from this tree node."""
rpc_messages = ""
for bdev in self._children:
try:
self.delete(bdev.name)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Bdevs: %d" % len(self.children), None
@ -288,6 +294,7 @@ class UINvmeBdev(UIBdev):
self.shell.log.info(ret_name)
def ui_command_delete_all(self):
rpc_messages = ""
ctrlrs = [x.name for x in self._children]
ctrlrs = [x.rsplit("n", 1)[0] for x in ctrlrs]
ctrlrs = set(ctrlrs)
@ -295,7 +302,9 @@ class UINvmeBdev(UIBdev):
try:
self.delete(ctrlr)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.messages
if rpc_messages:
raise JSONRPCException(rpc_messages)
def ui_command_delete(self, name):
"""

View File

@ -125,11 +125,14 @@ class UIISCSIDevices(UINode):
def ui_command_delete_all(self):
"""Delete all target nodes"""
rpc_messages = ""
for device in self.scsi_devices:
try:
self.delete(device.device_name)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def ui_command_add_lun(self, name, bdev_name, lun_id=None):
"""Add lun to the target node.
@ -317,11 +320,14 @@ class UIPortalGroups(UINode):
def ui_command_delete_all(self):
"""Delete all portal groups"""
rpc_messages = ""
for pg in self.pgs:
try:
self.delete(pg.tag)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def refresh(self):
self._children = set([])
@ -392,11 +398,14 @@ class UIInitiatorGroups(UINode):
def ui_command_delete_all(self):
"""Delete all initiator groups"""
rpc_messages = ""
for ig in self.igs:
try:
self.delete(ig.tag)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def ui_command_add_initiator(self, tag, initiators, netmasks):
"""Add initiators to an existing initiator group.
@ -542,11 +551,14 @@ class UIISCSIAuthGroups(UINode):
def ui_command_delete_all(self):
"""Delete all authentication groups."""
rpc_messages = ""
for iscsi_auth_group in self.iscsi_auth_groups:
try:
self.delete(iscsi_auth_group['tag'])
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def ui_command_add_secret(self, tag, user, secret,
muser=None, msecret=None):
@ -581,6 +593,7 @@ class UIISCSIAuthGroups(UINode):
Args:
tag: Authentication group tag (unique, integer > 0)
"""
rpc_messages = ""
tag = self.ui_eval_param(tag, "number", None)
for ag in self.iscsi_auth_groups:
if ag['tag'] == tag:
@ -588,7 +601,9 @@ class UIISCSIAuthGroups(UINode):
try:
self.delete_secret(tag, secret['user'])
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Groups: %s" % len(self.iscsi_auth_groups), None

View File

@ -102,11 +102,14 @@ class UINVMfSubsystems(UINode):
def ui_command_delete_all(self):
"""Delete all subsystems"""
rpc_messages = ""
for child in self._children:
try:
self.delete(child.subsystem.nqn)
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Subsystems: %s" % len(self.children), None
@ -206,11 +209,14 @@ class UINVMfSubsystemListeners(UINode):
def ui_command_delete_all(self):
"""Remove all address listeners from subsystem."""
rpc_messages = ""
for la in self.listen_addresses:
try:
self.delete(la['trtype'], la['traddr'], la['trsvcid'], la['adrfam'])
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Addresses: %s" % len(self.listen_addresses), None
@ -266,11 +272,14 @@ class UINVMfSubsystemHosts(UINode):
def ui_command_delete_all(self):
"""Delete host from subsystem"""
rpc_messages = ""
for host in self.hosts:
try:
self.delete(host['nqn'])
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Hosts: %s" % len(self.hosts), None
@ -331,11 +340,14 @@ class UINVMfSubsystemNamespaces(UINode):
def ui_command_delete_all(self):
"""Delete all namespaces from subsystem."""
rpc_messages = ""
for namespace in self.namespaces:
try:
self.delete(namespace['nsid'])
except JSONRPCException as e:
self.shell.log.error(e.message)
rpc_messages += e.message
if rpc_messages:
raise JSONRPCException(rpc_messages)
def summary(self):
return "Namespaces: %s" % len(self.namespaces), None