diff --git a/monasca_agent/collector/checks/collector.py b/monasca_agent/collector/checks/collector.py index 3a4bb941..94c9cf5e 100644 --- a/monasca_agent/collector/checks/collector.py +++ b/monasca_agent/collector/checks/collector.py @@ -74,8 +74,8 @@ class Collector(util.Dimensions): # to an integer which holds the collection round the # plugin should get called on. derived_collect_periods = ( - ((check.init_config['collect_period'] - 1) - / agent_config['check_freq']) + 1) + ((check.init_config['collect_period'] - 1) / + agent_config['check_freq']) + 1) self.collection_times[check.name] = { 'check': check, 'last_collect_time': 99999999, diff --git a/monasca_agent/collector/checks/utils.py b/monasca_agent/collector/checks/utils.py index 72918bca..8af4d942 100644 --- a/monasca_agent/collector/checks/utils.py +++ b/monasca_agent/collector/checks/utils.py @@ -97,7 +97,7 @@ class KubernetesConnector(object): in a Kubernetes environment """ CACERT_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt' - TOKEN_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token' + TOKEN_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token' # nosec B105 def __init__(self, connection_timeout): self.api_url = None diff --git a/monasca_agent/collector/checks_d/disk.py b/monasca_agent/collector/checks_d/disk.py index 59d72228..b4b68930 100644 --- a/monasca_agent/collector/checks_d/disk.py +++ b/monasca_agent/collector/checks_d/disk.py @@ -69,8 +69,8 @@ class Disk(checks.AgentCheck): total_used = 0 for partition in partitions: if partition.fstype not in fs_types_to_ignore \ - and (not device_blacklist_re - or not device_blacklist_re.match(partition.device)): + and (not device_blacklist_re or + not device_blacklist_re.match(partition.device)): try: device_name = self._get_device_name(partition.device) disk_usage = psutil.disk_usage(partition.mountpoint) diff --git a/monasca_agent/collector/checks_d/lxc.py b/monasca_agent/collector/checks_d/lxc.py index d2dfef20..f0803dbd 100644 --- a/monasca_agent/collector/checks_d/lxc.py +++ b/monasca_agent/collector/checks_d/lxc.py @@ -15,7 +15,7 @@ import re import monasca_agent.collector.checks as checks -_LXC_CGROUP_PWD = '/sys/fs/cgroup' +_LXC_CGROUP_PWD = '/sys/fs/cgroup' # nosec B105 _LXC_CGROUP_CPU_PWD = '{0}/cpu/lxc'.format(_LXC_CGROUP_PWD) _LXC_CGROUP_CPUSET_PWD = '{0}/cpuset/lxc'.format(_LXC_CGROUP_PWD) _LXC_CGROUP_MEM_PWD = '{0}/memory/lxc'.format(_LXC_CGROUP_PWD) diff --git a/monasca_agent/common/util.py b/monasca_agent/common/util.py index f3789e1f..45cb4aec 100644 --- a/monasca_agent/common/util.py +++ b/monasca_agent/common/util.py @@ -194,9 +194,9 @@ class Platform(object): def is_unix(name=None): """Return true if the platform is a unix, False otherwise. """ name = name or sys.platform - return (Platform.is_darwin() - or Platform.is_linux() - or Platform.is_freebsd() + return (Platform.is_darwin() or + Platform.is_linux() or + Platform.is_freebsd() ) @staticmethod diff --git a/monasca_agent/forwarder/daemon.py b/monasca_agent/forwarder/daemon.py index 2c1fb845..91476315 100644 --- a/monasca_agent/forwarder/daemon.py +++ b/monasca_agent/forwarder/daemon.py @@ -116,7 +116,7 @@ class Forwarder(tornado.web.Application): (r"/intake/?", AgentInputHandler) ] - settings = dict( + settings = dict( # nosec B106 cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=", xsrf_cookies=False, debug=False, diff --git a/monasca_setup/detection/plugins/influxdb.py b/monasca_setup/detection/plugins/influxdb.py index e179ef50..1c4f916e 100644 --- a/monasca_setup/detection/plugins/influxdb.py +++ b/monasca_setup/detection/plugins/influxdb.py @@ -46,8 +46,8 @@ class InfluxDB(detection.Plugin): dependencies_installed = self.dependencies_installed() - self.available = (process_found and config_file_found - and dependencies_installed) + self.available = (process_found and config_file_found and + dependencies_installed) if not self.available: err_chunks = [] diff --git a/monasca_setup/detection/plugins/influxdb_relay.py b/monasca_setup/detection/plugins/influxdb_relay.py index e829ee6d..d5383714 100644 --- a/monasca_setup/detection/plugins/influxdb_relay.py +++ b/monasca_setup/detection/plugins/influxdb_relay.py @@ -53,8 +53,8 @@ class InfluxDBRelay(detection.Plugin): dependencies_installed = self.dependencies_installed() - self.available = (process_found and config_file_found - and dependencies_installed) + self.available = (process_found and config_file_found and + dependencies_installed) if not self.available: err_chunks = [] diff --git a/monasca_setup/detection/plugins/kafka_consumer.py b/monasca_setup/detection/plugins/kafka_consumer.py index 70f5eb08..d34c801f 100644 --- a/monasca_setup/detection/plugins/kafka_consumer.py +++ b/monasca_setup/detection/plugins/kafka_consumer.py @@ -158,8 +158,8 @@ class Kafka(Plugin): values = line.split(',') # There will be always 7 values in output # after splitting the line by , - if (values and len(values) - == _CONSUMER_GROUP_COMMAND_LINE_VALUES_LEN): + if (values and len(values) == + _CONSUMER_GROUP_COMMAND_LINE_VALUES_LEN): topics[values[_VIA_KAFKA_TOPIC_INDEX].strip()] = [] if len(topics.keys()): consumers[consumer_group] = topics diff --git a/monasca_setup/detection/plugins/ovs.py b/monasca_setup/detection/plugins/ovs.py index 9cf6a177..d6d754dd 100644 --- a/monasca_setup/detection/plugins/ovs.py +++ b/monasca_setup/detection/plugins/ovs.py @@ -74,8 +74,8 @@ class Ovs(detection.Plugin): has_dependencies = self.dependencies_installed() neutron_conf = self._get_ovs_config_file() if process_exist else '' neutron_conf_exists = os.path.isfile(neutron_conf) - neutron_conf_valid = (neutron_conf_exists - and self._is_neutron_conf_valid(neutron_conf)) + neutron_conf_valid = (neutron_conf_exists and + self._is_neutron_conf_valid(neutron_conf)) self.available = (process_exist is not None and neutron_conf_valid and has_dependencies) diff --git a/monasca_setup/detection/plugins/vcenter.py b/monasca_setup/detection/plugins/vcenter.py index 79f2f215..23c30932 100644 --- a/monasca_setup/detection/plugins/vcenter.py +++ b/monasca_setup/detection/plugins/vcenter.py @@ -91,11 +91,11 @@ class VCenter(Plugin): cfg_section = 'vmware' # extract the vmware config from nova.conf and build instances - if (nova_cfg.has_option(cfg_section, 'host_ip') - and nova_cfg.has_option(cfg_section, 'host_username') - and nova_cfg.has_option(cfg_section, 'host_password') - and nova_cfg.has_option(cfg_section, 'host_port') - and nova_cfg.has_option(cfg_section, 'cluster_name')): + if (nova_cfg.has_option(cfg_section, 'host_ip') and + nova_cfg.has_option(cfg_section, 'host_username') and + nova_cfg.has_option(cfg_section, 'host_password') and + nova_cfg.has_option(cfg_section, 'host_port') and + nova_cfg.has_option(cfg_section, 'cluster_name')): instance = { 'vcenter_ip': nova_cfg.get(cfg_section, 'host_ip'), diff --git a/test-requirements.txt b/test-requirements.txt index a3d4ebae..2ad7fbc3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,7 +1,7 @@ # The order of packages is significant, because pip processes them in the order # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -hacking>=1.0.0,<1.1.0 # Apache-2.0 +hacking>=1.1.0,<1.2.0 # Apache-2.0 bandit!=1.6.0,>=1.1.0 # Apache-2.0 mock>=2.0.0 # BSD coverage!=4.4,>=4.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index 287c98a5..43e64de9 100644 --- a/tox.ini +++ b/tox.ini @@ -91,7 +91,13 @@ max-line-length = 100 max-complexity = 30 # TODO: ignored checks should be enabled in the future # H405 multi line docstring summary not separated with an empty line -ignore = H405 +# E402 module level import not at top of file +# reason: there are numerous places where we import modules +# later for legitimate reasons +# C901 MongoDb.check function in monasca_agent/collector/checks_d/mongo.py +# is too complex. Need to be simplified with less if, for loops and then +# C901 can be removed from here. +ignore = C901,E402,H405 show-source = True exclude=.venv,.git,.tox,dist,*egg,build,tests,tests_to_fix