Update hacking version to 1.1.x

This commit updates hacking version in test-requirements
and fixes some related pep8 issues

Also ignores false positive bandit test
B105: hardcoded_password_string,
B106: hardcoded_password_funcarg
based on variable or argument names.
For more info refer [1][2]

[1] https://bandit.readthedocs.io/en/latest/plugins/b105_hardcoded_password_string.html
[2] https://bandit.readthedocs.io/en/latest/plugins/b106_hardcoded_password_funcarg.html

Change-Id: If779ebad11926594961577e0744093a8ba691610
Story: 2004930
Task: 29314
This commit is contained in:
akhiljain23 2019-06-12 14:10:17 +05:30
parent 6fa4c8fcaf
commit 3404a6df72
13 changed files with 31 additions and 25 deletions

View File

@ -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,

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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 = []

View File

@ -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 = []

View File

@ -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

View File

@ -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)

View File

@ -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'),

View File

@ -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

View File

@ -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