Cleanup pylint error: redefined-outer-name

un-suppress the pylint error check for redefined-outer-name,
and update the code to fix that error

Test Plan:
PASS: system host-show controller-0
PASS: system device-label-list
PASS: system host-device-label-list
PASS: system host-pv-add

Story: 2008943
Task: 44050

Signed-off-by: Jia Hu <jia.hu@windriver.com>
Change-Id: I7e367b5735e1a8b0c174d0cd416925d72c5d4244
This commit is contained in:
Jia Hu 2021-11-23 13:45:04 -05:00
parent ced5ccd805
commit 5923349485
9 changed files with 33 additions and 34 deletions

View File

@ -546,8 +546,8 @@ def find_resource(manager, name_or_id):
raise exc.CommandError(msg) raise exc.CommandError(msg)
def string_to_bool(arg): def string_to_bool(s):
return arg.strip().lower() in ('t', 'true', 'yes', '1') return s.strip().lower() in ('t', 'true', 'yes', '1')
def env(*vars, **kwargs): def env(*vars, **kwargs):

View File

@ -46,9 +46,9 @@ def do_device_label_list(cc, args):
setattr(dl, 'devicename', "") setattr(dl, 'devicename', "")
setattr(dl, 'hostname', "") setattr(dl, 'hostname', "")
else: else:
pci_device = cc.pci_device.get(dl.pcidevice_uuid) pci_device_name = cc.pci_device.get(dl.pcidevice_uuid)
setattr(dl, 'devicename', getattr(pci_device, 'name')) setattr(dl, 'devicename', getattr(pci_device_name, 'name'))
host = ihost_utils._find_ihost(cc, getattr(pci_device, 'host_uuid')) host = ihost_utils._find_ihost(cc, getattr(pci_device_name, 'host_uuid'))
setattr(dl, 'hostname', host.hostname) setattr(dl, 'hostname', host.hostname)
field_labels = ['hostname', 'PCI device name', 'label key', 'label value'] field_labels = ['hostname', 'PCI device name', 'label key', 'label value']
fields = ['hostname', 'devicename', 'label_key', 'label_value'] fields = ['hostname', 'devicename', 'label_key', 'label_value']

View File

@ -63,10 +63,10 @@ def get_disk_display_name(d):
return '(' + str(d.uuid)[-8:] + ')' return '(' + str(d.uuid)[-8:] + ')'
def _find_disk(cc, ihost, idisk): def _find_disk(cc, ihost, idisk_id):
if utils.is_uuid_like(idisk): if utils.is_uuid_like(idisk_id):
try: try:
disk = cc.idisk.get(idisk) disk = cc.idisk.get(idisk_id)
except exc.HTTPNotFound: except exc.HTTPNotFound:
return None return None
else: else:
@ -74,7 +74,7 @@ def _find_disk(cc, ihost, idisk):
else: else:
disklist = cc.idisk.list(ihost.uuid) disklist = cc.idisk.list(ihost.uuid)
for disk in disklist: for disk in disklist:
if disk.device_node == idisk or disk.device_path == idisk: if disk.device_node == idisk_id or disk.device_path == idisk_id:
return disk return disk
else: else:
return None return None

View File

@ -153,18 +153,18 @@ class ihostManager(base.Manager):
return self.resource_class(self, body) return self.resource_class(self, body)
def _find_ihost(cc, ihost): def _find_ihost(cc, ihost_id):
if ihost.isdigit() or utils.is_uuid_like(ihost): if ihost_id.isdigit() or utils.is_uuid_like(ihost_id):
try: try:
h = cc.ihost.get(ihost) h = cc.ihost.get(ihost_id)
except exc.HTTPNotFound: except exc.HTTPNotFound:
raise exc.CommandError('host not found: %s' % ihost) raise exc.CommandError('host not found: %s' % ihost_id)
else: else:
return h return h
else: else:
hostlist = cc.ihost.list() hostlist = cc.ihost.list()
for h in hostlist: for h in hostlist:
if h.hostname == ihost: if h.hostname == ihost_id:
return h return h
else: else:
raise exc.CommandError('host not found: %s' % ihost) raise exc.CommandError('host not found: %s' % ihost_id)

View File

@ -54,22 +54,22 @@ class ilvgManager(base.Manager):
return self._update(path, patch) return self._update(path, patch)
def _find_ilvg(cc, ihost, ilvg): def _find_ilvg(cc, ihost, ilvg_id):
if ilvg.isdigit(): if ilvg.isdigit():
try: try:
lvg = cc.ilvg.get(ilvg) lvg = cc.ilvg.get(ilvg_id)
except exc.HTTPNotFound: except exc.HTTPNotFound:
raise exc.CommandError('Local volume group not found by id: %s' raise exc.CommandError('Local volume group not found by id: %s'
% ilvg) % ilvg_id)
else: else:
return lvg return lvg
else: else:
lvglist = cc.ilvg.list(ihost.uuid) lvglist = cc.ilvg.list(ihost.uuid)
for lvg in lvglist: for lvg in lvglist:
if lvg.lvm_vg_name == ilvg: if lvg.lvm_vg_name == ilvg_id:
return lvg return lvg
if lvg.uuid == ilvg: if lvg.uuid == ilvg_id:
return lvg return lvg
else: else:
raise exc.CommandError('Local volume group not found by name or ' raise exc.CommandError('Local volume group not found by name or '
'uuid: %s' % ilvg) 'uuid: %s' % ilvg_id)

View File

@ -62,18 +62,18 @@ def _get_disks(cc, ihost, pv):
pv.disks = disk_list pv.disks = disk_list
def _find_ipv(cc, ihost, ipv): def _find_ipv(cc, ihost, ipv_id):
if ipv.isdigit(): if ipv.isdigit():
try: try:
pv = cc.ipv.get(ipv) pv = cc.ipv.get(ipv_id)
except exc.HTTPNotFound: except exc.HTTPNotFound:
raise exc.CommandError('physical volume not found: %s' % ipv) raise exc.CommandError('physical volume not found: %s' % ipv_id)
else: else:
return pv return pv
else: else:
pvlist = cc.ipv.list(ihost.uuid) pvlist = cc.ipv.list(ihost.uuid)
for pv in pvlist: for pv in pvlist:
if pv.uuid == ipv: if pv.uuid == ipv_id:
return pv return pv
else: else:
raise exc.CommandError('physical volume not found: %s' % ipv) raise exc.CommandError('physical volume not found: %s' % ipv_id)

View File

@ -55,10 +55,10 @@ class isystemManager(base.Manager):
return self._update(self._path(isystem_id), patch) return self._update(self._path(isystem_id), patch)
def _find_isystem(cc, isystem): def _find_isystem(cc, isystem_id):
try: try:
h = cc.isystem.get(isystem) h = cc.isystem.get(isystem_id)
except exc.HTTPNotFound: except exc.HTTPNotFound:
raise exc.CommandError('system not found: %s' % isystem) raise exc.CommandError('system not found: %s' % isystem_id)
else: else:
return h return h

View File

@ -56,15 +56,15 @@ class partitionManager(base.Manager):
return self._update(path, patch) return self._update(path, patch)
def _find_partition(cc, ihost, partition, idisk=None): def _find_partition(cc, ihost, partition_id, idisk=None):
if idisk: if idisk:
part_list = cc.partition.list(ihost.uuid, idisk.uuid) part_list = cc.partition.list(ihost.uuid, idisk.uuid)
else: else:
part_list = cc.partition.list(ihost.uuid) part_list = cc.partition.list(ihost.uuid)
for p in part_list: for p in part_list:
if p.device_path == partition: if p.device_path == partition_id:
return p return p
if p.uuid == partition: if p.uuid == partition_id:
return p return p
else: else:
return None return None

View File

@ -128,7 +128,6 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
# W0611: unused-import # W0611: unused-import
# W0612: unused-variable # W0612: unused-variable
# W0613: unused-argument # W0613: unused-argument
# W0621: redefined-outer-name
# W0622: redefined-builtin # W0622: redefined-builtin
# W0631: undefined-loop-variable # W0631: undefined-loop-variable
# W0703: broad-except # W0703: broad-except
@ -136,7 +135,7 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
# W1618: no-absolute-import # W1618: no-absolute-import
disable=C, R, fixme, W0105, W0108, W0110, W0120, W0123, disable=C, R, fixme, W0105, W0108, W0110, W0120, W0123,
W0201, W0212, W0231, W0235, W0402, W0403, W0603, W0611, W0201, W0212, W0231, W0235, W0402, W0403, W0603, W0611,
W0612, W0613, W0621, W0622, W0631, W0703, W1401, W0612, W0613, W0622, W0631, W0703, W1401,
W1618 W1618
[REPORTS] [REPORTS]