From: tierno Date: Tue, 2 Apr 2019 11:49:31 +0000 (+0000) Subject: Adding flake8 tests over some files X-Git-Tag: v6.0.0~21 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F81%2F7381%2F5;p=osm%2FRO.git Adding flake8 tests over some files Change-Id: Ic00ddca13ac3dfa21b1279030026891239989e28 Signed-off-by: tierno --- diff --git a/Dockerfile b/Dockerfile index cdef6955..10efe45a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ FROM ubuntu:16.04 RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get -y install git make python python-pip debhelper python3 python3-all python3-pip python3-setuptools && \ - DEBIAN_FRONTEND=noninteractive apt-get -y install wget tox apt-utils && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install wget tox apt-utils flake8 python-nose python-mock && \ DEBIAN_FRONTEND=noninteractive pip install pip==9.0.3 && \ DEBIAN_FRONTEND=noninteractive pip3 install pip==9.0.3 && \ DEBIAN_FRONTEND=noninteractive pip install -U setuptools setuptools-version-command stdeb && \ diff --git a/devops-stages/stage-test.sh b/devops-stages/stage-test.sh index 49296c71..cb72fb1e 100755 --- a/devops-stages/stage-test.sh +++ b/devops-stages/stage-test.sh @@ -1,2 +1,18 @@ #!/bin/sh -echo "UNITTEST" + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +flake8 osm_ro/wim osm_ro/vim_thread.py --max-line-length 120 \ + --exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp,osm_im --ignore W291,W293,E226,E402,W504 + diff --git a/osm_ro/wim/persistence.py b/osm_ro/wim/persistence.py index 2e72640b..636676a4 100644 --- a/osm_ro/wim/persistence.py +++ b/osm_ro/wim/persistence.py @@ -45,7 +45,7 @@ from hashlib import sha1 from itertools import groupby from operator import itemgetter from sys import exc_info -from time import time +# from time import time from uuid import uuid1 as generate_uuid from six import reraise @@ -681,8 +681,7 @@ class WimPersistence(object): 'LIMIT {:d},{:d}').format( self.safe_str(wim_account_id), ','.join(type_options), - group_offset, group_limit - ) + group_offset, group_limit) join = 'vim_wim_actions NATURAL JOIN ({}) AS items'.format(items) db_results = self.db.get_rows( @@ -697,7 +696,7 @@ class WimPersistence(object): 'task_index': task_index} try: action = self.query_one('vim_wim_actions', WHERE=condition) - except: + except Exception: actions = self.query('vim_wim_actions', WHERE=condition) self.logger.error('More then one action found:\n%s', json.dumps(actions, indent=4)) @@ -710,8 +709,7 @@ class WimPersistence(object): updates = preprocess_record( merge_dicts(action, properties, extra=extra)) - num_changes = self.db.update_rows('vim_wim_actions', - UPDATE=updates, WHERE=condition) + num_changes = self.db.update_rows('vim_wim_actions', UPDATE=updates, WHERE=condition) if num_changes is None: raise UnexpectedDatabaseError( @@ -782,8 +780,7 @@ class WimPersistence(object): if not changes: return 0 - return self.db.update_rows('instance_actions', - WHERE={'uuid': uuid}, UPDATE=changes) + return self.db.update_rows('instance_actions', WHERE={'uuid': uuid}, UPDATE=changes) def get_only_vm_with_external_net(self, instance_net_id, **kwargs): """Return an instance VM if that is the only VM connected to an diff --git a/osm_ro/wim/tests/fixtures.py b/osm_ro/wim/tests/fixtures.py index cb662ab0..c39e9d7d 100644 --- a/osm_ro/wim/tests/fixtures.py +++ b/osm_ro/wim/tests/fixtures.py @@ -121,9 +121,8 @@ def datacenter_account(datacenter, tenant): def datacenter_tenant_association(datacenter, tenant): return {'nfvo_tenant_id': uuid('tenant%d' % tenant), - 'datacenter_id': uuid('dc%d' % datacenter), - 'datacenter_tenant_id': - uuid('dc-account%d%d' % (tenant, datacenter))} + 'datacenter_id': uuid('dc%d' % datacenter), + 'datacenter_tenant_id': uuid('dc-account%d%d' % (tenant, datacenter))} def datacenter_set(identifier=0, tenant=0): diff --git a/osm_ro/wim/wim_thread.py b/osm_ro/wim/wim_thread.py index fa64fbba..f8d52bbe 100644 --- a/osm_ro/wim/wim_thread.py +++ b/osm_ro/wim/wim_thread.py @@ -51,7 +51,7 @@ from time import time, sleep from six import reraise from six.moves import queue -from . import wan_link_actions, wimconn_odl, wimconn_dynpac # wimconn_tapi +from . import wan_link_actions, wimconn_odl, wimconn_dynpac # wimconn_tapi from ..utils import ensure, partition, pipe from .actions import IGNORE, PENDING, REFRESH from .errors import ( diff --git a/osm_ro/wim/wimconn_dynpac.py b/osm_ro/wim/wimconn_dynpac.py index 18169370..c0652e2b 100644 --- a/osm_ro/wim/wimconn_dynpac.py +++ b/osm_ro/wim/wimconn_dynpac.py @@ -211,8 +211,7 @@ class DynpacConnector(WimConnector): selected_ports = [] for connection_point in connection_points: endpoint_id = connection_point.get(self.__SERVICE_ENDPOINT_PARAM) - port = filter(lambda x: x.get(self.__WAN_SERVICE_ENDPOINT_PARAM) - == endpoint_id, port_mapping)[0] + port = filter(lambda x: x.get(self.__WAN_SERVICE_ENDPOINT_PARAM) == endpoint_id, port_mapping)[0] wsmpi_json = port.get(self.__WAN_MAPPING_INFO_PARAM) port_info = json.loads(wsmpi_json) selected_ports.append(port_info) @@ -226,7 +225,7 @@ class DynpacConnector(WimConnector): }, { "wan_switch_dpid": selected_ports[1].get(self.__SW_ID_PARAM), "wan_switch_port": selected_ports[1].get(self.__SW_PORT_PARAM), - "wan_vlan": connection_points[1].get(self.__ENCAPSULATION_INFO_PARAM).get(self.__VLAN_PARAM) + "wan_vlan": connection_points[1].get(self.__ENCAPSULATION_INFO_PARAM).get(self.__VLAN_PARAM) }], "bandwidth": kwargs.get(self.__BANDWIDTH_PARAM), "service_type": service_type, diff --git a/tox.ini b/tox.ini index 025f4a0e..e451bb80 100644 --- a/tox.ini +++ b/tox.ini @@ -11,12 +11,13 @@ commands=nosetests [testenv:flake8] basepython = python deps = flake8 -commands = - flake8 setup.py +# TODO for the moment few files are tested. +commands = flake8 osm_ro/wim --max-line-length 120 \ + --exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp,osm_im --ignore W291,W293,E226,E402,W504 [testenv:build] basepython = python deps = stdeb setuptools-version-command commands = python setup.py --command-packages=stdeb.command bdist_deb - +