From: Benjamin Diaz Date: Wed, 10 Apr 2019 20:06:19 +0000 (-0300) Subject: Adds pylint to tox test pipeline and fixes related errors X-Git-Tag: v6.0.0~14 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FMON.git;a=commitdiff_plain;h=649e6b264fb9e92103267dabd16ed9a3dbadb302 Adds pylint to tox test pipeline and fixes related errors Change-Id: I0965b2818898d144a441208391f4c831fa28279b Signed-off-by: Benjamin Diaz --- diff --git a/osm_mon/collector/vnf_collectors/openstack.py b/osm_mon/collector/vnf_collectors/openstack.py index da98cc6..2005ebe 100644 --- a/osm_mon/collector/vnf_collectors/openstack.py +++ b/osm_mon/collector/vnf_collectors/openstack.py @@ -123,13 +123,13 @@ class OpenstackCollector(BaseVimCollector): except ValueError: log.warning( "Could not find resource_uuid for vdur %s, vnf_member_index %s, nsr_id %s. " - "Was it recently deleted?".format( - vdur['name'], vnf_member_index, nsr_id)) + "Was it recently deleted?", + vdur['name'], vnf_member_index, nsr_id) continue if self.backend == 'ceilometer': measures = self.client.samples.list(meter_name=openstack_metric_name, limit=1, q=[ {'field': 'resource_id', 'op': 'eq', 'value': resource_id}]) - if len(measures): + if measures: metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, measures[0].counter_volume) metrics.append(metric) @@ -146,7 +146,7 @@ class OpenstackCollector(BaseVimCollector): start=start_date, resource_id=interface['id'], granularity=self.granularity) - if len(measures): + if measures: total_measure += measures[-1][2] except gnocchiclient.exceptions.NotFound as e: @@ -161,7 +161,7 @@ class OpenstackCollector(BaseVimCollector): start=start_date, resource_id=resource_id, granularity=self.granularity) - if len(measures): + if measures: metric = VnfMetric(nsr_id, vnf_member_index, vdur['name'], metric_name, measures[-1][2]) metrics.append(metric) diff --git a/osm_mon/collector/vnf_collectors/vio.py b/osm_mon/collector/vnf_collectors/vio.py index 8e43878..5bcf66e 100644 --- a/osm_mon/collector/vnf_collectors/vio.py +++ b/osm_mon/collector/vnf_collectors/vio.py @@ -65,8 +65,8 @@ METRIC_MAPPINGS = { class VIOCollector(BaseVimCollector): def __init__(self, config: Config, vim_account_id: str): super().__init__(config, vim_account_id) - self.common_db = CommonDbClient() - self.auth_manager = AuthManager() + self.common_db = CommonDbClient(config) + self.auth_manager = AuthManager(config) vim_account_info = self.auth_manager.get_credentials(vim_account_id) cfg = json.loads(vim_account_info.config) self.vrops_site = cfg['vrops_site'] diff --git a/osm_mon/collector/vnf_collectors/vmware.py b/osm_mon/collector/vnf_collectors/vmware.py index ba499c7..557fa38 100644 --- a/osm_mon/collector/vnf_collectors/vmware.py +++ b/osm_mon/collector/vnf_collectors/vmware.py @@ -62,9 +62,6 @@ METRIC_MAPPINGS = { "packets_sent": "net:Aggregate of all instances|packetsTxPerSec", } -# Disable warnings from self-signed certificates. -requests.packages.urllib3.disable_warnings() - class VMwareCollector(BaseVimCollector): def __init__(self, config: Config, vim_account_id: str): diff --git a/osm_mon/evaluator/evaluator.py b/osm_mon/evaluator/evaluator.py index 90c0c17..24e8e43 100644 --- a/osm_mon/evaluator/evaluator.py +++ b/osm_mon/evaluator/evaluator.py @@ -77,7 +77,7 @@ class Evaluator: json_response = r.json() if json_response['status'] == 'success': result = json_response['data']['result'] - if len(result): + if result: metric_value = float(result[0]['value'][1]) log.info("Metric value: %s", metric_value) if alarm.operation.upper() == 'GT': diff --git a/tox.ini b/tox.ini index b10e7f9..898e487 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ # test suite on all supported python versions. To use it, "pip install tox" # and then run "tox" from this directory. [tox] -envlist = py3, flake8 +envlist = py3, flake8, pylint toxworkdir={homedir}/.tox [testenv] @@ -34,6 +34,12 @@ commands=python3 -m unittest discover -v install_command = python3 -m pip install -r requirements.txt -U {opts} {packages} deps = -r{toxinidir}/test-requirements.txt +[testenv:pylint] +basepython = python3 +deps = pylint +commands = + pylint -E osm_mon + [testenv:flake8] basepython = python3 deps = flake8