Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nvmet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .nvme import Root, Subsystem, Namespace, Port, Host, Referral, ANAGroup, Passthru, \
DEFAULT_SAVE_FILE
from .nvme import Root, Subsystem, Namespace, Port, Host, Referral, ANAGroup, \
Passthru, DEFAULT_SAVE_FILE # noqa: F401
35 changes: 20 additions & 15 deletions nvmet/nvme.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _create_in_cfs(self, mode):
if not self.exists:
try:
os.mkdir(self.path)
except:
except Exception:
raise CFSError("Could not create %s in configFS" %
self.__class__.__name__)
self.get_enable()
Expand All @@ -110,7 +110,7 @@ def list_attrs(self, group, writable=None):

names = [os.path.basename(name).split('_', 1)[1]
for name in glob("%s/%s_*" % (self._path, group))
if os.path.isfile(name)]
if os.path.isfile(name)]

if writable is True:
names = [name for name in names
Expand Down Expand Up @@ -203,10 +203,10 @@ def delete(self):
path = property(_get_path,
doc="Get the configFS object path.")
exists = property(_exists,
doc="Is True as long as the underlying configFS object exists. "
+ "If the underlying configFS objects gets deleted "
+ "either by calling the delete() method, or by any "
+ "other means, it will be False.")
doc="Is True as long as the underlying configFS object"
+ " exists. If the underlying configFS objects gets"
+ " deleted either by calling the delete() method, or by"
+ " any other means, it will be False.")

def dump(self):
d = {}
Expand Down Expand Up @@ -261,7 +261,7 @@ def _modprobe(self, modname):

try:
kmod.Kmod().modprobe(modname)
except Exception as e:
except Exception:
pass
except ImportError:
# Try the binary specified in /proc
Expand All @@ -272,7 +272,7 @@ def _modprobe(self, modname):
if modprobe_cmd:
subprocess.run(shlex.split(modprobe_cmd) + [modname],
check=False)
except Exception as e:
except Exception:
pass

def _list_subsystems(self):
Expand All @@ -291,7 +291,7 @@ def _list_ports(self):
yield Port(d, 'lookup')

ports = property(_list_ports,
doc="Get the list of Ports.")
doc="Get the list of Ports.")

def _list_hosts(self):
self._check_self()
Expand Down Expand Up @@ -489,7 +489,8 @@ def _list_allowed_hosts(self):
for name in os.listdir("%s/allowed_hosts/" % self._path)]

allowed_hosts = property(_list_allowed_hosts,
doc="Get the list of Allowed Hosts for the Subsystem.")
doc="Get the list of Allowed Hosts for the "
+ "Subsystem.")

def add_allowed_host(self, nqn):
'''
Expand Down Expand Up @@ -658,6 +659,7 @@ def dump(self):
d['ana_grpid'] = self.grpid
return d


class Passthru(CFSNode):
'''
This is an interface to a NVMe passthru in ConfigFS.
Expand All @@ -682,7 +684,7 @@ def _get_clear_ids(self):
return _ids

ids = property(_get_clear_ids,
doc = "Get the passthru namespace clear_ids attribute.")
doc="Get the passthru namespace clear_ids attribute.")

def set_clear_ids(self, clear):
self._check_self()
Expand All @@ -701,7 +703,7 @@ def _get_admin_timeout(self):
return _timeout

admin_timeout = property(_get_admin_timeout,
doc = "Get the passthru admin command timeout.")
doc="Get the passthru admin command timeout.")

def set_admin_timeout(self, timeout):
self._check_self()
Expand All @@ -720,7 +722,7 @@ def _get_io_timeout(self):
return _timeout

io_timeout = property(_get_io_timeout,
doc = "Get the passthru IO command timeout.")
doc="Get the passthru IO command timeout.")

def set_io_timeout(self, timeout):
self._check_self()
Expand Down Expand Up @@ -751,6 +753,7 @@ def dump(self):
d['io_timeout'] = self.io_timeout
return d


class Port(CFSNode):
'''
This is an interface to a NVMe Port in configFS.
Expand Down Expand Up @@ -946,7 +949,8 @@ def __init__(self, port, grpid, mode='any'):
else:
grpid = int(grpid)
if grpid < 1 or grpid > self.MAX_GRPID:
raise CFSError("GRPID %d must be 1 to %d" % (grpid, self.MAX_GRPID))
raise CFSError("GRPID %d must be 1 to %d"
% (grpid, self.MAX_GRPID))

self.attr_groups = ['ana']
self._port = port
Expand Down Expand Up @@ -1030,7 +1034,7 @@ def setup(cls, t, err_func):
return

try:
h = Host(t['nqn'])
Host(t['nqn'])
except CFSError as e:
err_func("Could not create Host object: %s" % e)
return
Expand All @@ -1045,5 +1049,6 @@ def _test():
from doctest import testmod
testmod()


if __name__ == "__main__":
_test()
21 changes: 11 additions & 10 deletions nvmet/test_nvmet.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def test_namespace(self):
self.assertEqual(len(list(s.namespaces)), 0)

@unittest.skipUnless(test_devices_present(),
"Devices %s not available or suitable" % ','.join(NVMET_TEST_DEVICES))
"Devices %s not available or suitable"
% ','.join(NVMET_TEST_DEVICES))
def test_namespace_attrs(self):
root = nvme.Root()
root.clear_existing()
Expand Down Expand Up @@ -157,8 +158,8 @@ def test_recursive_delete(self):
root.clear_existing()

s = nvme.Subsystem(nqn='testnqn', mode='create')
n1 = nvme.Namespace(s, mode='create')
n2 = nvme.Namespace(s, mode='create')
nvme.Namespace(s, mode='create')
nvme.Namespace(s, mode='create')

s.delete()
self.assertEqual(len(list(root.subsystems)), 0)
Expand Down Expand Up @@ -203,7 +204,7 @@ def test_loop_port(self):
root = nvme.Root()
root.clear_existing()

s = nvme.Subsystem(nqn='testnqn', mode='create')
nvme.Subsystem(nqn='testnqn', mode='create')
p = nvme.Port(portid=0, mode='create')

# subsystem doesn't exists, should fail
Expand Down Expand Up @@ -372,9 +373,9 @@ def test_referral(self):
self.assertEqual(len(list(p.referrals)), 0)

def test_allowed_hosts(self):
root = nvme.Root()
nvme.Root()

h = nvme.Host(nqn='hostnqn', mode='create')
nvme.Host(nqn='hostnqn', mode='create')

s = nvme.Subsystem(nqn='testnqn', mode='create')

Expand Down Expand Up @@ -405,9 +406,9 @@ def test_invalid_input(self):
self.assertRaises(nvme.CFSError, nvme.Subsystem,
nqn='/', mode='create')

for l in [ 257, 512, 1024, 2048 ]:
for x in [257, 512, 1024, 2048]:
toolong = ''.join(random.choice(string.ascii_lowercase)
for i in range(l))
for i in range(x))
self.assertRaises(nvme.CFSError, nvme.Subsystem,
nqn=toolong, mode='create')

Expand All @@ -425,7 +426,7 @@ def test_save_restore(self):
root = nvme.Root()
root.clear_existing()

h = nvme.Host(nqn='hostnqn', mode='create')
nvme.Host(nqn='hostnqn', mode='create')

s = nvme.Subsystem(nqn='testnqn', mode='create')
s.add_allowed_host(nqn='hostnqn')
Expand Down Expand Up @@ -460,7 +461,7 @@ def test_save_restore(self):
root.restore_from_file('test.json', True)

# rebuild our view of the world
h = nvme.Host(nqn='hostnqn', mode='lookup')
nvme.Host(nqn='hostnqn', mode='lookup')
s = nvme.Subsystem(nqn='testnqn', mode='lookup')
s2 = nvme.Subsystem(nqn='testnqn2', mode='lookup')
n = nvme.Namespace(s, nsid=42, mode='lookup')
Expand Down
30 changes: 17 additions & 13 deletions nvmetcli
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class UIRootNode(UINode):
ui_desc_discovery = {
'nqn': ('string', 'Discovery NQN'),
}

def __init__(self, shell):
UINode.__init__(self, '/', parent=None, cfnode=nvme.Root(),
shell=shell)
Expand Down Expand Up @@ -188,9 +189,10 @@ class UISubsystemNode(UINode):
info.append("serial=" + self.cfnode.get_attr("attr", "serial"))
return (", ".join(info), True)


class UIPassthruNode(UINode):
ui_desc_device = {
'path' : ('string', 'Passthru device path')
'path': ('string', 'Passthru device path')
}

def __init__(self, parent):
Expand All @@ -207,7 +209,7 @@ class UIPassthruNode(UINode):
try:
self.cfnode.set_enable(1)
self.shell.log.info("The passthru has been enabled.")
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"The passthru could not be enabled.")

Expand All @@ -218,7 +220,7 @@ class UIPassthruNode(UINode):
try:
self.cfnode.set_enable(0)
self.shell.log.info("The passthru has been disabled.")
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"The passthru could not be disabled.")

Expand All @@ -229,7 +231,7 @@ class UIPassthruNode(UINode):
'''
try:
self.cfnode.set_clear_ids(clear)
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"Failed to set clear_ids for this passthru target.")

Expand All @@ -239,7 +241,7 @@ class UIPassthruNode(UINode):
'''
try:
self.cfnode.set_admin_timeout(timeout)
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"Failed to set the admin passthru command timeout.")

Expand All @@ -249,7 +251,7 @@ class UIPassthruNode(UINode):
'''
try:
self.cfnode.set_io_timeout(timeout)
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"Failed to set the IO passthru command timeout.")

Expand All @@ -265,6 +267,7 @@ class UIPassthruNode(UINode):
info.append("enabled" if self.cfnode.get_enable() else "disabled")
return (", ".join(info), True)


class UINamespacesNode(UINode):
def __init__(self, parent):
UINode.__init__(self, 'namespaces', parent)
Expand Down Expand Up @@ -329,7 +332,7 @@ class UINamespaceNode(UINode):
try:
self.cfnode.set_enable(1)
self.shell.log.info("The Namespace has been enabled.")
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"The Namespace could not be enabled.")

Expand All @@ -347,7 +350,7 @@ class UINamespaceNode(UINode):
try:
self.cfnode.set_enable(0)
self.shell.log.info("The Namespace has been disabled.")
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"The Namespace could not be disabled.")

Expand All @@ -357,7 +360,7 @@ class UINamespaceNode(UINode):
'''
try:
self.cfnode.set_grpid(grpid)
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"Failed to set ANA Group ID for this Namespace.")

Expand Down Expand Up @@ -513,7 +516,7 @@ class UIPortNode(UINode):
'''
try:
inline_data_size = self.cfnode.get_attr("param", "inline_data_size")
except Exception as e:
except Exception:
inline_data_size = "n/a"
if inline_data_size != "n/a":
info.append("inline_data_size=" + inline_data_size)
Expand Down Expand Up @@ -648,7 +651,7 @@ class UIReferralNode(UINode):
try:
self.cfnode.set_enable(1)
self.shell.log.info("The Referral has been enabled.")
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"The Referral could not be enabled.")

Expand All @@ -666,7 +669,7 @@ class UIReferralNode(UINode):
try:
self.cfnode.set_enable(0)
self.shell.log.info("The Referral has been disabled.")
except Exception as e:
except Exception:
raise configshell.ExecutionError(
"The Referral could not be disabled.")

Expand Down Expand Up @@ -706,7 +709,7 @@ class UIANAGroupsNode(UINode):

class UIANAGroupNode(UINode):
ui_desc_ana = {
'state' : ('string', 'ANA state'),
'state': ('string', 'ANA state'),
}

def __init__(self, parent, cfnode):
Expand All @@ -717,6 +720,7 @@ class UIANAGroupNode(UINode):
info.append("state=" + self.cfnode.get_attr("ana", "state"))
return (", ".join(info), True)


class UIHostsNode(UINode):
def __init__(self, parent):
UINode.__init__(self, 'hosts', parent)
Expand Down
Loading