Skip to content

Commit 38bb4e7

Browse files
committed
flake8: resolve linter errors
Signed-off-by: Ales Novak <alnovak@suse.com>
1 parent 693a662 commit 38bb4e7

4 files changed

Lines changed: 50 additions & 40 deletions

File tree

nvmet/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .nvme import Root, Subsystem, Namespace, Port, Host, Referral, ANAGroup, Passthru, \
2-
DEFAULT_SAVE_FILE
1+
from .nvme import Root, Subsystem, Namespace, Port, Host, Referral, ANAGroup, \
2+
Passthru, DEFAULT_SAVE_FILE # noqa: F401

nvmet/nvme.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _create_in_cfs(self, mode):
8484
if not self.exists:
8585
try:
8686
os.mkdir(self.path)
87-
except:
87+
except Exception:
8888
raise CFSError("Could not create %s in configFS" %
8989
self.__class__.__name__)
9090
self.get_enable()
@@ -110,7 +110,7 @@ def list_attrs(self, group, writable=None):
110110

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

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

211211
def dump(self):
212212
d = {}
@@ -261,7 +261,7 @@ def _modprobe(self, modname):
261261

262262
try:
263263
kmod.Kmod().modprobe(modname)
264-
except Exception as e:
264+
except Exception:
265265
pass
266266
except ImportError:
267267
# Try the binary specified in /proc
@@ -272,7 +272,7 @@ def _modprobe(self, modname):
272272
if modprobe_cmd:
273273
subprocess.run(shlex.split(modprobe_cmd) + [modname],
274274
check=False)
275-
except Exception as e:
275+
except Exception:
276276
pass
277277

278278
def _list_subsystems(self):
@@ -291,7 +291,7 @@ def _list_ports(self):
291291
yield Port(d, 'lookup')
292292

293293
ports = property(_list_ports,
294-
doc="Get the list of Ports.")
294+
doc="Get the list of Ports.")
295295

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

491491
allowed_hosts = property(_list_allowed_hosts,
492-
doc="Get the list of Allowed Hosts for the Subsystem.")
492+
doc="Get the list of Allowed Hosts for the "
493+
+ "Subsystem.")
493494

494495
def add_allowed_host(self, nqn):
495496
'''
@@ -658,6 +659,7 @@ def dump(self):
658659
d['ana_grpid'] = self.grpid
659660
return d
660661

662+
661663
class Passthru(CFSNode):
662664
'''
663665
This is an interface to a NVMe passthru in ConfigFS.
@@ -682,7 +684,7 @@ def _get_clear_ids(self):
682684
return _ids
683685

684686
ids = property(_get_clear_ids,
685-
doc = "Get the passthru namespace clear_ids attribute.")
687+
doc="Get the passthru namespace clear_ids attribute.")
686688

687689
def set_clear_ids(self, clear):
688690
self._check_self()
@@ -701,7 +703,7 @@ def _get_admin_timeout(self):
701703
return _timeout
702704

703705
admin_timeout = property(_get_admin_timeout,
704-
doc = "Get the passthru admin command timeout.")
706+
doc="Get the passthru admin command timeout.")
705707

706708
def set_admin_timeout(self, timeout):
707709
self._check_self()
@@ -720,7 +722,7 @@ def _get_io_timeout(self):
720722
return _timeout
721723

722724
io_timeout = property(_get_io_timeout,
723-
doc = "Get the passthru IO command timeout.")
725+
doc="Get the passthru IO command timeout.")
724726

725727
def set_io_timeout(self, timeout):
726728
self._check_self()
@@ -751,6 +753,7 @@ def dump(self):
751753
d['io_timeout'] = self.io_timeout
752754
return d
753755

756+
754757
class Port(CFSNode):
755758
'''
756759
This is an interface to a NVMe Port in configFS.
@@ -946,7 +949,8 @@ def __init__(self, port, grpid, mode='any'):
946949
else:
947950
grpid = int(grpid)
948951
if grpid < 1 or grpid > self.MAX_GRPID:
949-
raise CFSError("GRPID %d must be 1 to %d" % (grpid, self.MAX_GRPID))
952+
raise CFSError("GRPID %d must be 1 to %d"
953+
% (grpid, self.MAX_GRPID))
950954

951955
self.attr_groups = ['ana']
952956
self._port = port
@@ -1030,7 +1034,7 @@ def setup(cls, t, err_func):
10301034
return
10311035

10321036
try:
1033-
h = Host(t['nqn'])
1037+
Host(t['nqn'])
10341038
except CFSError as e:
10351039
err_func("Could not create Host object: %s" % e)
10361040
return
@@ -1045,5 +1049,6 @@ def _test():
10451049
from doctest import testmod
10461050
testmod()
10471051

1052+
10481053
if __name__ == "__main__":
10491054
_test()

nvmet/test_nvmet.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def test_namespace(self):
115115
self.assertEqual(len(list(s.namespaces)), 0)
116116

117117
@unittest.skipUnless(test_devices_present(),
118-
"Devices %s not available or suitable" % ','.join(NVMET_TEST_DEVICES))
118+
"Devices %s not available or suitable"
119+
% ','.join(NVMET_TEST_DEVICES))
119120
def test_namespace_attrs(self):
120121
root = nvme.Root()
121122
root.clear_existing()
@@ -157,8 +158,8 @@ def test_recursive_delete(self):
157158
root.clear_existing()
158159

159160
s = nvme.Subsystem(nqn='testnqn', mode='create')
160-
n1 = nvme.Namespace(s, mode='create')
161-
n2 = nvme.Namespace(s, mode='create')
161+
nvme.Namespace(s, mode='create')
162+
nvme.Namespace(s, mode='create')
162163

163164
s.delete()
164165
self.assertEqual(len(list(root.subsystems)), 0)
@@ -203,7 +204,7 @@ def test_loop_port(self):
203204
root = nvme.Root()
204205
root.clear_existing()
205206

206-
s = nvme.Subsystem(nqn='testnqn', mode='create')
207+
nvme.Subsystem(nqn='testnqn', mode='create')
207208
p = nvme.Port(portid=0, mode='create')
208209

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

374375
def test_allowed_hosts(self):
375-
root = nvme.Root()
376+
nvme.Root()
376377

377-
h = nvme.Host(nqn='hostnqn', mode='create')
378+
nvme.Host(nqn='hostnqn', mode='create')
378379

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

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

408-
for l in [ 257, 512, 1024, 2048 ]:
409+
for x in [257, 512, 1024, 2048]:
409410
toolong = ''.join(random.choice(string.ascii_lowercase)
410-
for i in range(l))
411+
for i in range(x))
411412
self.assertRaises(nvme.CFSError, nvme.Subsystem,
412413
nqn=toolong, mode='create')
413414

@@ -425,7 +426,7 @@ def test_save_restore(self):
425426
root = nvme.Root()
426427
root.clear_existing()
427428

428-
h = nvme.Host(nqn='hostnqn', mode='create')
429+
nvme.Host(nqn='hostnqn', mode='create')
429430

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

462463
# rebuild our view of the world
463-
h = nvme.Host(nqn='hostnqn', mode='lookup')
464+
nvme.Host(nqn='hostnqn', mode='lookup')
464465
s = nvme.Subsystem(nqn='testnqn', mode='lookup')
465466
s2 = nvme.Subsystem(nqn='testnqn2', mode='lookup')
466467
n = nvme.Namespace(s, nsid=42, mode='lookup')

nvmetcli

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class UIRootNode(UINode):
9797
ui_desc_discovery = {
9898
'nqn': ('string', 'Discovery NQN'),
9999
}
100+
100101
def __init__(self, shell):
101102
UINode.__init__(self, '/', parent=None, cfnode=nvme.Root(),
102103
shell=shell)
@@ -188,9 +189,10 @@ class UISubsystemNode(UINode):
188189
info.append("serial=" + self.cfnode.get_attr("attr", "serial"))
189190
return (", ".join(info), True)
190191

192+
191193
class UIPassthruNode(UINode):
192194
ui_desc_device = {
193-
'path' : ('string', 'Passthru device path')
195+
'path': ('string', 'Passthru device path')
194196
}
195197

196198
def __init__(self, parent):
@@ -207,7 +209,7 @@ class UIPassthruNode(UINode):
207209
try:
208210
self.cfnode.set_enable(1)
209211
self.shell.log.info("The passthru has been enabled.")
210-
except Exception as e:
212+
except Exception:
211213
raise configshell.ExecutionError(
212214
"The passthru could not be enabled.")
213215

@@ -218,7 +220,7 @@ class UIPassthruNode(UINode):
218220
try:
219221
self.cfnode.set_enable(0)
220222
self.shell.log.info("The passthru has been disabled.")
221-
except Exception as e:
223+
except Exception:
222224
raise configshell.ExecutionError(
223225
"The passthru could not be disabled.")
224226

@@ -229,7 +231,7 @@ class UIPassthruNode(UINode):
229231
'''
230232
try:
231233
self.cfnode.set_clear_ids(clear)
232-
except Exception as e:
234+
except Exception:
233235
raise configshell.ExecutionError(
234236
"Failed to set clear_ids for this passthru target.")
235237

@@ -239,7 +241,7 @@ class UIPassthruNode(UINode):
239241
'''
240242
try:
241243
self.cfnode.set_admin_timeout(timeout)
242-
except Exception as e:
244+
except Exception:
243245
raise configshell.ExecutionError(
244246
"Failed to set the admin passthru command timeout.")
245247

@@ -249,7 +251,7 @@ class UIPassthruNode(UINode):
249251
'''
250252
try:
251253
self.cfnode.set_io_timeout(timeout)
252-
except Exception as e:
254+
except Exception:
253255
raise configshell.ExecutionError(
254256
"Failed to set the IO passthru command timeout.")
255257

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

270+
268271
class UINamespacesNode(UINode):
269272
def __init__(self, parent):
270273
UINode.__init__(self, 'namespaces', parent)
@@ -329,7 +332,7 @@ class UINamespaceNode(UINode):
329332
try:
330333
self.cfnode.set_enable(1)
331334
self.shell.log.info("The Namespace has been enabled.")
332-
except Exception as e:
335+
except Exception:
333336
raise configshell.ExecutionError(
334337
"The Namespace could not be enabled.")
335338

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

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

@@ -513,7 +516,7 @@ class UIPortNode(UINode):
513516
'''
514517
try:
515518
inline_data_size = self.cfnode.get_attr("param", "inline_data_size")
516-
except Exception as e:
519+
except Exception:
517520
inline_data_size = "n/a"
518521
if inline_data_size != "n/a":
519522
info.append("inline_data_size=" + inline_data_size)
@@ -648,7 +651,7 @@ class UIReferralNode(UINode):
648651
try:
649652
self.cfnode.set_enable(1)
650653
self.shell.log.info("The Referral has been enabled.")
651-
except Exception as e:
654+
except Exception:
652655
raise configshell.ExecutionError(
653656
"The Referral could not be enabled.")
654657

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

@@ -706,7 +709,7 @@ class UIANAGroupsNode(UINode):
706709

707710
class UIANAGroupNode(UINode):
708711
ui_desc_ana = {
709-
'state' : ('string', 'ANA state'),
712+
'state': ('string', 'ANA state'),
710713
}
711714

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

723+
720724
class UIHostsNode(UINode):
721725
def __init__(self, parent):
722726
UINode.__init__(self, 'hosts', parent)

0 commit comments

Comments
 (0)