Re-enable important py3k checks for sysinv

Re-enabling some of the disabled tox warnings present on
the pylint.rc file

Re-enabling:

W1619: old-division
W1620: dict-iter-method
W1630: cmp-method
W1633: round-builtin
W1641: eq-without-hash
W1645: exception-message-attribute
W1655: dict-keys-not-iterating

Test Plan: Sanity test run on AIO-SX:

PASS: test_system_health_pre_session[pods]
PASS: test_system_health_pre_session[alarms]
PASS: test_system_health_pre_session[system_apps]
PASS: test_wr_analytics[deploy_and_remove]
PASS: test_horizon_host_inventory_display
PASS: test_lock_unlock_host[controller]
PASS: test_pod_to_pod_connection
PASS: test_pod_to_service_connection
PASS: test_host_to_service_connection

Story: 2006796
Task: 43399
Signed-off-by: Bernardo Decco <bernardo.deccodesiqueira@windriver.com>
Change-Id: Idac57d70ecd520607b5a49ccb20bda0167c6e542
This commit is contained in:
Bernardo Decco 2021-09-22 17:11:19 -03:00
parent ba7790c7b7
commit 280a31be43
22 changed files with 58 additions and 52 deletions

View File

@ -163,22 +163,13 @@ enable=E1603,E1609,E1610,E1602,E1606,E1608,E1607,E1605,E1604,E1601,E1611,W1652,
# W1505: deprecated-method
# W1509: subprocess-popen-preexec-fn
# W1618: no-absolute-import
# W1619: old-division
# W1620: dict-iter-method
# W1630: cmp-method
# W1633: round-builtin
# W1641: eq-without-hash
# W1645: exception-message-attribute
# W1655: dict-keys-not-iterating
# All these errors should be fixed:
# E1101: no-member
# E1111: assignment-from-no-return
disable=C, R, fixme, W0101, W0105, W0106, W0107, W0108, W0110, W0123, W0150,
W0201, W0211, W0212, W0221, W0223, W0231, W0235, W0311, W0402, W0403,
W0404, W0603, W0612, W0613, W0621, W0622, W0631, W0632, W0701, W0703,
W0706, W1113, W1201, W1401, W1505, W1509, W1618, W1619, W1620, W1630,
W1633, W1641, W1645, W1655,
W0706, W1113, W1201, W1401, W1505, W1509, W1618,
E1101, E1111
[REPORTS]

View File

@ -28,11 +28,6 @@ class Key(object):
def __hash__(self):
return hash((self.chassisid, self.portid, self.portname))
def __cmp__(self, rhs):
return ((self.chassisid < rhs.chassisid) or
(self.portid < rhs.portid) or
(self.portname < rhs.portname))
def __eq__(self, rhs):
return (self.chassisid == rhs.chassisid and
self.portid == rhs.portid and

View File

@ -70,6 +70,10 @@ class CPU(object):
self.core == rhs.core and
self.thread == rhs.thread)
def __hash__(self):
return hash((self.cpu, self.numa_node, self.core, self.thread,
self.cpu_family, self.cpu_model, self.revision))
def __ne__(self, rhs):
return (self.cpu != rhs.cpu or
self.numa_node != rhs.numa_node or

View File

@ -103,6 +103,10 @@ class PCI(object):
return (self.pvendor == rhs.pvendor and
self.pdevice == rhs.pdevice)
def __hash__(self):
return hash((self.pciaddr, self.pclass, self.pvendor, self.pdevice,
self.prevision, self.psvendor, self.psdevice))
def __ne__(self, rhs):
return (self.pvendor != rhs.pvendor or
self.pdevice != rhs.pdevice)

View File

@ -22,6 +22,7 @@
import datetime
import os
import pecan
import six
import ssl
import wsme
import wsmeext.pecan as wsme_pecan
@ -439,7 +440,7 @@ class CertificateController(rest.RestController):
if domain:
msg = _check_cert_dns_name(cert, domain)
if msg is not True:
return dict(success="", error=msg.message)
return dict(success="", error=six.text_type(msg))
elif msg:
return dict(success="", error=msg)

View File

@ -159,7 +159,7 @@ class EthernetPort(base.APIBase):
"Represent a list containing a self link and associated port links"
def __init__(self, **kwargs):
self.fields = objects.ethernet_port.fields.keys()
self.fields = objects.ethernet_port.fields
for k in self.fields:
setattr(self, k, kwargs.get(k))

View File

@ -4295,7 +4295,7 @@ class HostController(rest.RestController):
if (active_controller_used > standby_controller_allocated_space):
# Round up the needed space from float to integer
needed_space = math.ceil(float(
needed_space = math.ceil(float( # pylint: disable=W1619
active_controller_used -
standby_controller_allocated_space) / (1024 ** 3))
msg = _("Standby controller does not have enough space allocated to "

View File

@ -283,7 +283,7 @@ class KubeAppController(rest.RestController):
if directive == 'apply':
if not values:
mode = None
elif name not in constants.HELM_APP_APPLY_MODES.keys():
elif name not in constants.HELM_APP_APPLY_MODES:
raise wsme.exc.ClientSideError(_(
"Application-apply rejected: Mode is not supported "
"for app {}.".format(name)))

View File

@ -76,7 +76,7 @@ class KubeRootCAGenerateController(rest.RestController):
"format of 'C=<Country> ST=<State/Province> "
"L=<Locality> O=<Organization> OU=<OrganizationUnit> "
"CN=<commonName>"))
if 'CN' not in subject_dict.keys():
if 'CN' not in list(subject_dict.keys()):
raise wsme.exc.ClientSideError(_("The CN=<commonName> parameter is required to be "
"specified in subject argument"))
return subject_dict
@ -172,7 +172,7 @@ class KubeRootCAUpdate(base.APIBase):
"A list containing a self link and associated kubernetes rootca update links"
def __init__(self, **kwargs):
self.fields = objects.kube_rootca_update.fields.keys()
self.fields = list(objects.kube_rootca_update.fields.keys())
for k in self.fields:
if not hasattr(self, k):
continue
@ -229,7 +229,7 @@ class KubeRootCAHostUpdate(base.APIBase):
"update links"
def __init__(self, **kwargs):
self.fields = objects.kube_rootca_host_update.fields.keys()
self.fields = list(objects.kube_rootca_host_update.fields.keys())
for k in self.fields:
if not hasattr(self, k):
continue

View File

@ -460,7 +460,7 @@ class MemoryController(rest.RestController):
except wsme.exc.ClientSideError as e:
inode = pecan.request.dbapi.inode_get(inode_id=rpc_port.forinodeid)
numa_node = inode.numa_node
msg = _('Processor {0}:'.format(numa_node)) + e.message
msg = _('Processor {0}:'.format(numa_node)) + six.text_type(e)
raise wsme.exc.ClientSideError(msg)
else:
# Standard/system controller or storage node

View File

@ -387,7 +387,7 @@ def _partition_pre_patch_checks(partition_obj, patch_obj, host_obj):
raise wsme.exc.ClientSideError(
_("Requested partition size must be larger than current "
"size: %s GiB <= %s GiB") % (int(p['value']) // 1024,
math.floor(float(partition_obj.size_mib) / 1024 * 1000) / 1000.0))
math.floor(float(partition_obj.size_mib) / 1024 * 1000) / 1000.0)) # pylint: disable=W1619
def _is_user_created_partition(guid):
@ -512,7 +512,8 @@ def _semantic_checks(operation, partition):
raise wsme.exc.ClientSideError(
_("Requested size %s GiB is larger than the %s GiB "
"available.") % (partition['size_mib'] // 1024,
math.floor(float(idisk.available_mib) / 1024 * 1000) / 1000.0))
math.floor(float(idisk.available_mib) / # pylint: disable=W1619
1024 * 1000) / 1000.0))
_are_partition_operations_simultaneous(ihost, partition,
constants.PARTITION_CMD_CREATE)
@ -592,7 +593,8 @@ def _semantic_checks(operation, partition):
raise wsme.exc.ClientSideError(
_("Requested extra size %s GiB is larger than the %s GiB "
"available.") % (extra_size // 1024,
math.floor(float(idisk.available_mib) / 1024 * 1000) / 1000.0))
math.floor(float(idisk.available_mib) / # pylint: disable=W1619
1024 * 1000) / 1000.0))
elif operation == constants.PARTITION_CMD_DELETE:
############

View File

@ -1112,7 +1112,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the cinder pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['cinder_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
elif ceph_pool['name'] == constants.CEPH_POOL_KUBE_NAME:
if (int(storceph['kube_pool_gib']) > 0 and
(int(ceph_pool['stats']['bytes_used']) >
@ -1121,7 +1121,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the kube pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['kube_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
elif ceph_pool['name'] == constants.CEPH_POOL_EPHEMERAL_NAME:
if (int(storceph['ephemeral_pool_gib']) > 0 and
(int(ceph_pool['stats']['bytes_used']) >
@ -1130,7 +1130,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the ephemeral pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['ephemeral_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
elif ceph_pool['name'] == constants.CEPH_POOL_IMAGES_NAME:
if (int(storceph['glance_pool_gib']) > 0 and
(int(ceph_pool['stats']['bytes_used']) >
@ -1139,7 +1139,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the glance pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['glance_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
elif ceph_pool['name'] in constants.CEPH_POOL_OBJECT_GATEWAY_NAME:
if (int(storceph['object_pool_gib']) > 0 and
(int(ceph_pool['stats']['bytes_used']) >
@ -1148,7 +1148,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the object pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['object_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
else:
if storceph['tier_name'] in ceph_pool['name']:
if constants.CEPH_POOL_VOLUMES_NAME in ceph_pool['name']:
@ -1159,7 +1159,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the cinder pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['cinder_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
elif K8RbdProvisioner.get_pool(storceph) == ceph_pool['name']:
if (int(storceph['kube_pool_gib']) > 0 and
(int(ceph_pool['stats']['bytes_used']) >
@ -1168,7 +1168,7 @@ def _check_pool_quotas_data(ostorceph, storceph):
_("The configured quota for the kube pool (%s GiB) "
"must be greater than the already occupied space (%s GiB)")
% (storceph['kube_pool_gib'],
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3)))
float(ceph_pool['stats']['bytes_used']) / (1024 ** 3))) # pylint: disable=W1619
# sanity check the quota
total_quota_gib = 0

View File

@ -384,8 +384,10 @@ def _discover_and_validate_cinder_hiera_data(caps_dict):
'while for %s is %s GiB.') %
(constants.LVG_CINDER_VOLUMES,
constants.CINDER_LVM_MINIMUM_DEVICE_SIZE_GIB,
pv_sizes[0]['host'], math.floor(float(pv_sizes[0]['size']) / 1024 * 1000) / 1000.0,
pv_sizes[1]['host'], math.floor(float(pv_sizes[1]['size']) / 1024 * 1000) / 1000.0))
pv_sizes[0]['host'], math.floor(float(pv_sizes[0]['size']) / # pylint: disable=W1619
1024 * 1000) / 1000.0,
pv_sizes[1]['host'], math.floor(float(pv_sizes[1]['size']) / # pylint: disable=W1619
1024 * 1000) / 1000.0))
raise wsme.exc.ClientSideError(msg)
if pv_sizes[0]['size'] < (constants.CINDER_LVM_MINIMUM_DEVICE_SIZE_GIB * 1024):
@ -393,7 +395,7 @@ def _discover_and_validate_cinder_hiera_data(caps_dict):
'Current allocation is: %s GiB.') %
(constants.LVG_CINDER_VOLUMES,
constants.CINDER_LVM_MINIMUM_DEVICE_SIZE_GIB,
math.floor(float(pv_sizes[0]['size']) / 1024 * 1000) / 1000.0))
math.floor(float(pv_sizes[0]['size']) / 1024 * 1000) / 1000.0)) # pylint: disable=W1619
raise wsme.exc.ClientSideError(msg)
# Log all the LVM parameters

View File

@ -17,6 +17,9 @@ class pci_device_class_acclr(object):
def __eq__(self, other):
return (other in self.pci_class_ids)
def __hash__(self):
return hash(''.join(self.pci_class_ids))
def __ne__(self, other):
return (other not in self.pci_class_ids)

View File

@ -94,7 +94,7 @@ class SysinvException(Exception):
if not message:
try:
message = self.message % kwargs
message = self.message % kwargs # pylint: disable=W1645
except Exception as e:
# kwargs doesn't match a variable in the message
@ -107,7 +107,7 @@ class SysinvException(Exception):
raise e
else:
# at least get the core message out if something happened
message = self.message
message = self.message # pylint: disable=W1645
super(SysinvException, self).__init__(message)
@ -1207,7 +1207,7 @@ class OpenStackException(PickleableException):
"""
Return a tuple so that we can properly pickle the exception
"""
return OpenStackException, (self.message, self._reason)
return OpenStackException, (self.message, self._reason) # pylint: disable=W1645
@property
def message(self):
@ -1228,6 +1228,8 @@ class OpenStackRestAPIException(PickleableException):
"""
OpenStack Rest-API Exception
"""
message = _("An unknown exception occurred.")
def __init__(self, message, http_status_code, reason):
"""
Create an OpenStack Rest-API exception
@ -1235,6 +1237,7 @@ class OpenStackRestAPIException(PickleableException):
super(OpenStackRestAPIException, self).__init__(message)
self._http_status_code = http_status_code # as defined in RFC 2616
self._reason = reason # a message string or another exception
self._message = message
def __str__(self):
"""
@ -1253,7 +1256,7 @@ class OpenStackRestAPIException(PickleableException):
"""
Return a tuple so that we can properly pickle the exception
"""
return OpenStackRestAPIException, (self.message,
return OpenStackRestAPIException, (self.message, # pylint: disable=W1645
self._http_status_code,
self._reason)

View File

@ -193,7 +193,7 @@ class Retrying(object):
return reject
def call(self, fn, *args, **kwargs):
start_time = int(round(time.time() * 1000))
start_time = int(round(time.time() * 1000)) # pylint: disable=W1633
attempt_number = 1
while True:
try:
@ -205,7 +205,7 @@ class Retrying(object):
if not self.should_reject(attempt):
return attempt.get(self._wrap_exception)
delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time
delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time # pylint: disable=W1633
if self.stop(attempt_number, delay_since_first_attempt_ms):
if not self._wrap_exception and attempt.has_exception:
# get() on an attempt with an exception should cause it to be raised, but raise just in case

View File

@ -1303,11 +1303,11 @@ def output_to_dict(output):
def bytes_to_GiB(bytes_number):
return bytes_number / float(1024 ** 3)
return bytes_number / float(1024 ** 3) # pylint: disable=W1619
def bytes_to_MiB(bytes_number):
return bytes_number / float(1024 ** 2)
return bytes_number / float(1024 ** 2) # pylint: disable=W1619
def check_lock_path():

View File

@ -1452,7 +1452,8 @@ class AppOperator(object):
adjust))
tadjust = 0
percent = round((float(num) / (charts_count - tadjust)) * 100)
percent = round((float(num) / # pylint: disable=W1619
(charts_count - tadjust)) * 100)
progress_str = "processing chart: {}, overall completion: {}%".\
format(last, percent)

View File

@ -4142,7 +4142,7 @@ class ConductorManager(service.PeriodicService):
partitions = self.dbapi.partition_get_by_ihost(host.id)
partition4 = next((p for p in partitions if p.device_node == pv4_name), None)
part_size_mib = float(pv_cgts_vg.lvm_pv_size) / (1024 ** 2) - int(partition4.size_mib)
part_size_mib = float(pv_cgts_vg.lvm_pv_size) / (1024 ** 2) - int(partition4.size_mib) # pylint: disable=W1619
if part_size_mib > 0:
LOG.info("%s is not enough for R4 cgts-vg" % pv4_name)
else:
@ -11666,7 +11666,7 @@ class ConductorManager(service.PeriodicService):
constants.PARTITION_TABLE_SIZE
# Convert bytes to GiB and round to be sure.
partition_size = int(round(
partition_size = int(round( # pylint: disable=W1633
cutils.bytes_to_GiB(partition_size)))
return partition_size

View File

@ -412,7 +412,7 @@ class SysinvObject(object):
yield name, getattr(self, name)
def items(self):
return list(self.iteritems())
return list(self.iteritems()) # pylint: disable=dict-iter-method
def __getitem__(self, name):
"""For backwards-compatibility with dict-based objects.

View File

@ -77,7 +77,7 @@ class RPCException(Exception):
if not message:
try:
message = self.message % kwargs
message = self.message % kwargs # pylint: disable=W1645
except Exception:
# kwargs doesn't match a variable in the message
@ -86,7 +86,7 @@ class RPCException(Exception):
for name, value in kwargs.items():
LOG.error("%s: %s" % (name, value))
# at least get the core message out if something happened
message = self.message
message = self.message # pylint: disable=W1645
super(RPCException, self).__init__(message)

View File

@ -1895,7 +1895,7 @@ class ManagerTestCase(base.DbTestCase):
iface_db_list = self.dbapi.iinterface_get_by_ihost(ihost['uuid'])
self.assertEqual(len(iface_db_list), len(inic_dict_array))
for iface in iface_db_list:
self.assertIn(iface.imac, inic_mac_dict.keys())
self.assertIn(iface.imac, inic_mac_dict)
self.assertEqual(inic_mac_dict[iface.imac]['pname'], iface.ifname)
self.assertEqual(inic_mac_dict[iface.imac]['mac'], iface.imac)
@ -1905,7 +1905,7 @@ class ManagerTestCase(base.DbTestCase):
port_db_list = self.dbapi.port_get_by_host(ihost['uuid'])
self.assertEqual(len(port_db_list), len(inic_dict_array))
for port in port_db_list:
self.assertIn(port.pciaddr, inic_pciaddr_dict.keys())
self.assertIn(port.pciaddr, inic_pciaddr_dict)
self.assertEqual(inic_pciaddr_dict[port.pciaddr]['pciaddr'], port.pciaddr)
self.assertEqual(inic_pciaddr_dict[port.pciaddr]['pname'], port.name)
self.assertEqual(inic_pciaddr_dict[port.pciaddr]['numa_node'], port.numa_node)