From: sousaedu Date: Wed, 5 Jan 2022 11:39:35 +0000 (+0000) Subject: Enabling Flake8 and import sorting X-Git-Tag: v12.0.0rc1~43 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F11503%2F2;p=osm%2FRO.git Enabling Flake8 and import sorting Enabling flake8 verifications in tox.ini and adding import sorting. All the plugins have been fixed for flake8 errors and the imports have been sorted. Change-Id: Icdefe9a877e891a683cc833315e4c3f94fffbab9 Signed-off-by: sousaedu --- diff --git a/NG-RO/osm_ng_ro/html_out.py b/NG-RO/osm_ng_ro/html_out.py index 132bf68a..1b01cb85 100644 --- a/NG-RO/osm_ng_ro/html_out.py +++ b/NG-RO/osm_ng_ro/html_out.py @@ -15,9 +15,10 @@ Contains html text in variables to make and html response """ -import yaml -from http import HTTPStatus from html import escape as html_escape +from http import HTTPStatus + +import yaml __author__ = "Alfonso Tierno " diff --git a/NG-RO/osm_ng_ro/ns.py b/NG-RO/osm_ng_ro/ns.py index b95667fa..706454d5 100644 --- a/NG-RO/osm_ng_ro/ns.py +++ b/NG-RO/osm_ng_ro/ns.py @@ -16,39 +16,39 @@ # limitations under the License. ## -# import yaml +from http import HTTPStatus import logging -from typing import Any, Dict, Tuple +from random import choice as random_choice +from threading import Lock +from time import time from traceback import format_exc as traceback_format_exc -from osm_ng_ro.ns_thread import NsWorker, NsWorkerException, deep_get -from osm_ng_ro.validation import validate_input, deploy_schema +from typing import Any, Dict, Tuple +from uuid import uuid4 + +from cryptography.hazmat.backends import default_backend as crypto_default_backend +from cryptography.hazmat.primitives import serialization as crypto_serialization +from cryptography.hazmat.primitives.asymmetric import rsa +from jinja2 import ( + Environment, + StrictUndefined, + TemplateError, + TemplateNotFound, + UndefinedError, +) from osm_common import ( - dbmongo, dbmemory, + dbmongo, fslocal, fsmongo, - msglocal, msgkafka, + msglocal, version as common_version, ) from osm_common.dbbase import DbException from osm_common.fsbase import FsException from osm_common.msgbase import MsgException -from http import HTTPStatus -from uuid import uuid4 -from threading import Lock -from random import choice as random_choice -from time import time -from jinja2 import ( - Environment, - TemplateError, - TemplateNotFound, - StrictUndefined, - UndefinedError, -) -from cryptography.hazmat.primitives import serialization as crypto_serialization -from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.backends import default_backend as crypto_default_backend +from osm_ng_ro.ns_thread import deep_get, NsWorker, NsWorkerException +from osm_ng_ro.validation import deploy_schema, validate_input __author__ = "Alfonso Tierno " min_common_version = "0.1.16" diff --git a/NG-RO/osm_ng_ro/ns_thread.py b/NG-RO/osm_ng_ro/ns_thread.py index 5df74c5c..01c894dd 100644 --- a/NG-RO/osm_ng_ro/ns_thread.py +++ b/NG-RO/osm_ng_ro/ns_thread.py @@ -24,25 +24,23 @@ A single ro_task refers to a VIM element (flavor, image, network, ...). A ro_task can contain several 'tasks', each one with a target, where to store the results """ -import logging -import queue -import threading -import time -import yaml from copy import deepcopy from http import HTTPStatus +import logging from os import mkdir -from importlib_metadata import entry_points +import queue from shutil import rmtree +import threading +import time from unittest.mock import Mock -# from osm_common import dbmongo, dbmemory, fslocal, fsmongo, msglocal, msgkafka, version as common_version +from importlib_metadata import entry_points from osm_common.dbbase import DbException -from osm_ro_plugin.vim_dummy import VimDummyConnector -from osm_ro_plugin.sdn_dummy import SdnDummyConnector -from osm_ro_plugin import vimconn, sdnconn from osm_ng_ro.vim_admin import LockRenew - +from osm_ro_plugin import sdnconn, vimconn +from osm_ro_plugin.sdn_dummy import SdnDummyConnector +from osm_ro_plugin.vim_dummy import VimDummyConnector +import yaml __author__ = "Alfonso Tierno" __date__ = "$28-Sep-2017 12:07:15$" diff --git a/NG-RO/osm_ng_ro/ro_main.py b/NG-RO/osm_ng_ro/ro_main.py index c9cad857..eb5ff6c8 100644 --- a/NG-RO/osm_ng_ro/ro_main.py +++ b/NG-RO/osm_ng_ro/ro_main.py @@ -18,29 +18,30 @@ # limitations under the License. ## -import cherrypy -import time + +from codecs import getreader +import getopt +from http import HTTPStatus import json -import yaml -import osm_ng_ro.html_out as html import logging import logging.handlers -import getopt +from os import environ, path import sys +import time -from osm_ng_ro.ns import Ns, NsException -from osm_ng_ro.validation import ValidationError -from osm_ng_ro.vim_admin import VimAdminThread +import cherrypy from osm_common.dbbase import DbException from osm_common.fsbase import FsException from osm_common.msgbase import MsgException -from http import HTTPStatus -from codecs import getreader -from os import environ, path from osm_ng_ro import version as ro_version, version_date as ro_version_date +import osm_ng_ro.html_out as html +from osm_ng_ro.ns import Ns, NsException +from osm_ng_ro.validation import ValidationError +from osm_ng_ro.vim_admin import VimAdminThread +import yaml -__author__ = "Alfonso Tierno " +__author__ = "Alfonso Tierno " __version__ = "0.1." # file version, not NBI version version_date = "May 2020" diff --git a/NG-RO/osm_ng_ro/tests/test_ns.py b/NG-RO/osm_ng_ro/tests/test_ns.py index 6cc5f778..34590c12 100644 --- a/NG-RO/osm_ng_ro/tests/test_ns.py +++ b/NG-RO/osm_ng_ro/tests/test_ns.py @@ -16,7 +16,7 @@ ####################################################################################### import unittest -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch from osm_ng_ro.ns import Ns diff --git a/NG-RO/osm_ng_ro/validation.py b/NG-RO/osm_ng_ro/validation.py index efd940cb..91ea6137 100644 --- a/NG-RO/osm_ng_ro/validation.py +++ b/NG-RO/osm_ng_ro/validation.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from jsonschema import validate as js_v, exceptions as js_e from http import HTTPStatus +from jsonschema import exceptions as js_e, validate as js_v + __author__ = "Alfonso Tierno " __version__ = "0.1" version_date = "Jun 2020" diff --git a/NG-RO/osm_ng_ro/vim_admin.py b/NG-RO/osm_ng_ro/vim_admin.py index d8752724..2582ee2a 100644 --- a/NG-RO/osm_ng_ro/vim_admin.py +++ b/NG-RO/osm_ng_ro/vim_admin.py @@ -19,15 +19,15 @@ It is based on asyncio. It is in charge of load tasks assigned to VIMs that nobody is in chage of it """ -import logging -import threading import asyncio from http import HTTPStatus +import logging +import threading +from time import time -from osm_common import dbmongo, dbmemory, msglocal, msgkafka +from osm_common import dbmemory, dbmongo, msgkafka, msglocal from osm_common.dbbase import DbException from osm_common.msgbase import MsgException -from time import time __author__ = "Alfonso Tierno " diff --git a/NG-RO/setup.py b/NG-RO/setup.py index 46613860..b60a3b80 100644 --- a/NG-RO/setup.py +++ b/NG-RO/setup.py @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from setuptools import setup, find_packages +from setuptools import find_packages, setup _name = "osm_ng_ro" _version_command = ("git describe --match v* --tags --long --dirty", "pep440-git-full") diff --git a/RO-SDN-arista_cloudvision/osm_rosdn_arista_cloudvision/wimconn_arista.py b/RO-SDN-arista_cloudvision/osm_rosdn_arista_cloudvision/wimconn_arista.py index 314c6733..99ab4fa9 100644 --- a/RO-SDN-arista_cloudvision/osm_rosdn_arista_cloudvision/wimconn_arista.py +++ b/RO-SDN-arista_cloudvision/osm_rosdn_arista_cloudvision/wimconn_arista.py @@ -27,28 +27,21 @@ # This work has been performed in the context of Arista Telefonica OSM PoC. ## -from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError -import re -import socket - -# Required by compare function import difflib - -# Library that uses Levenshtein Distance to calculate the differences -# between strings. -# from fuzzywuzzy import fuzz - +from enum import Enum import logging +import re +import socket import uuid -from enum import Enum -from requests import RequestException, ConnectionError, ConnectTimeout, Timeout -from cvprac.cvp_client import CvpClient -from cvprac.cvp_api import CvpApi -from cvprac.cvp_client_errors import CvpLoginError, CvpSessionLogOutError, CvpApiError -from cvprac import __version__ as cvprac_version +from cvprac import __version__ as cvprac_version +from cvprac.cvp_api import CvpApi +from cvprac.cvp_client import CvpClient +from cvprac.cvp_client_errors import CvpApiError, CvpLoginError, CvpSessionLogOutError +from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError from osm_rosdn_arista_cloudvision.aristaConfigLet import AristaSDNConfigLet from osm_rosdn_arista_cloudvision.aristaTask import AristaCVPTask +from requests import ConnectionError, ConnectTimeout, RequestException, Timeout class SdnError(Enum): diff --git a/RO-SDN-dpb/osm_rosdn_dpb/wimconn_dpb.py b/RO-SDN-dpb/osm_rosdn_dpb/wimconn_dpb.py index b8a9123b..075b1a84 100755 --- a/RO-SDN-dpb/osm_rosdn_dpb/wimconn_dpb.py +++ b/RO-SDN-dpb/osm_rosdn_dpb/wimconn_dpb.py @@ -27,12 +27,11 @@ import json import logging -import paramiko -import requests import struct -# import sys from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError +import paramiko +import requests class DpbSshInterface: diff --git a/RO-SDN-dynpac/osm_rosdn_dynpac/wimconn_dynpac.py b/RO-SDN-dynpac/osm_rosdn_dynpac/wimconn_dynpac.py index 7a84f222..dfd4b358 100644 --- a/RO-SDN-dynpac/osm_rosdn_dynpac/wimconn_dynpac.py +++ b/RO-SDN-dynpac/osm_rosdn_dynpac/wimconn_dynpac.py @@ -21,12 +21,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import requests +from enum import Enum import json import logging -from enum import Enum from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError +import requests class SdnError(Enum): diff --git a/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/floodlight_of.py b/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/floodlight_of.py index 238b4347..c5fec1a1 100644 --- a/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/floodlight_of.py +++ b/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/floodlight_of.py @@ -28,17 +28,18 @@ It creates the class OF_conn to create dataplane connections with static rules based on packet destination MAC address """ -__author__ = "Pablo Montes, Alfonso Tierno" -__date__ = "$28-oct-2014 12:07:15$" - import json -import requests import logging + from osm_ro_plugin.openflow_conn import ( OpenflowConn, - OpenflowConnUnexpectedResponse, OpenflowConnConnectionException, + OpenflowConnUnexpectedResponse, ) +import requests + +__author__ = "Pablo Montes, Alfonso Tierno" +__date__ = "$28-oct-2014 12:07:15$" class OfConnFloodLight(OpenflowConn): diff --git a/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py b/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py index bd37be8b..78ce6069 100644 --- a/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py +++ b/RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/sdnconn_floodlightof.py @@ -20,7 +20,9 @@ """ import logging + from osm_ro_plugin.openflow_conn import SdnConnectorOpenFlow + from .floodlight_of import OfConnFloodLight diff --git a/RO-SDN-ietfl2vpn/osm_rosdn_ietfl2vpn/wimconn_ietfl2vpn.py b/RO-SDN-ietfl2vpn/osm_rosdn_ietfl2vpn/wimconn_ietfl2vpn.py index 1a581bc6..ada0d72f 100644 --- a/RO-SDN-ietfl2vpn/osm_rosdn_ietfl2vpn/wimconn_ietfl2vpn.py +++ b/RO-SDN-ietfl2vpn/osm_rosdn_ietfl2vpn/wimconn_ietfl2vpn.py @@ -30,12 +30,12 @@ This SDN/WIM connector implements the standard IETF RFC 8466 "A YANG Data It receives the endpoints and the necessary details to request the Layer 2 service. """ -import requests -import uuid + import logging -from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError +import uuid -"""Check layer where we move it""" +from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError +import requests class WimconnectorIETFL2VPN(SdnConnectorBase): diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py index 963f6cfd..4c04c1c9 100644 --- a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py +++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py @@ -14,11 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. -import requests -import json import copy - +import json from time import time + +import requests from requests.exceptions import ConnectionError diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py index af7184ee..38b4db57 100644 --- a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py +++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py @@ -14,8 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. -import logging import json +import logging from osm_ro_plugin.sdnconn import SdnConnectorError from osm_rosdn_juniper_contrail.rest_lib import ContrailHttp diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py index 29b187b8..6714132e 100644 --- a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py +++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py @@ -18,16 +18,13 @@ # import logging -import yaml import random from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError - -# from osm_rosdn_juniper_contrail.rest_lib import ContrailHttp -# from osm_rosdn_juniper_contrail.rest_lib import NotFound from osm_rosdn_juniper_contrail.rest_lib import DuplicateFound from osm_rosdn_juniper_contrail.rest_lib import HttpException from osm_rosdn_juniper_contrail.sdn_api import UnderlayApi +import yaml class JuniperContrail(SdnConnectorBase): diff --git a/RO-SDN-odl_openflow/osm_rosdn_odlof/odl_of.py b/RO-SDN-odl_openflow/osm_rosdn_odlof/odl_of.py index 644507f9..a8a6cc7f 100644 --- a/RO-SDN-odl_openflow/osm_rosdn_odlof/odl_of.py +++ b/RO-SDN-odl_openflow/osm_rosdn_odlof/odl_of.py @@ -28,15 +28,16 @@ It creates the class OF_conn to create dataplane connections with static rules based on packet destination MAC address """ -import json -import requests import base64 +import json import logging + from osm_ro_plugin.openflow_conn import ( OpenflowConn, OpenflowConnConnectionException, OpenflowConnUnexpectedResponse, ) +import requests # OpenflowConnException, OpenflowConnAuthException, OpenflowConnNotFoundException, # OpenflowConnConflictException, OpenflowConnNotSupportedException, OpenflowConnNotImplemented diff --git a/RO-SDN-odl_openflow/osm_rosdn_odlof/sdnconn_odlof.py b/RO-SDN-odl_openflow/osm_rosdn_odlof/sdnconn_odlof.py index ce53b0df..31f92055 100644 --- a/RO-SDN-odl_openflow/osm_rosdn_odlof/sdnconn_odlof.py +++ b/RO-SDN-odl_openflow/osm_rosdn_odlof/sdnconn_odlof.py @@ -20,7 +20,9 @@ """ import logging + from osm_ro_plugin.openflow_conn import SdnConnectorOpenFlow + from .odl_of import OfConnOdl diff --git a/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py b/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py index cba505cb..34359ae0 100644 --- a/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py +++ b/RO-SDN-onos_openflow/osm_rosdn_onosof/onos_of.py @@ -28,15 +28,16 @@ controller. It creates the class OF_conn to create dataplane connections with static rules based on packet destination MAC address """ -import json -import requests import base64 +import json import logging + from osm_ro_plugin.openflow_conn import ( OpenflowConn, OpenflowConnConnectionException, OpenflowConnUnexpectedResponse, ) +import requests # OpenflowConnException, OpenflowConnAuthException, OpenflowConnNotFoundException, \ # OpenflowConnConflictException, OpenflowConnNotSupportedException, OpenflowConnNotImplemented diff --git a/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py b/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py index ed70b326..6144a3f2 100644 --- a/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py +++ b/RO-SDN-onos_openflow/osm_rosdn_onosof/sdnconn_onosof.py @@ -20,7 +20,9 @@ """ import logging + from osm_ro_plugin.openflow_conn import SdnConnectorOpenFlow + from .onos_of import OfConnOnos diff --git a/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py b/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py index 1c68fe77..fa22f101 100644 --- a/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py +++ b/RO-SDN-onos_vpls/osm_rosdn_onos_vpls/sdn_assist_onos_vpls.py @@ -20,15 +20,15 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: bdiaz@whitestack.com or glavado@whitestack.com ## + +import copy import logging import uuid -import copy +from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError import requests from requests.auth import HTTPBasicAuth -from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError - class OnosVpls(SdnConnectorBase): """ diff --git a/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py b/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py index 9dec75ab..77adecd8 100644 --- a/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py +++ b/RO-VIM-aws/osm_rovim_aws/vimconn_aws.py @@ -25,18 +25,18 @@ AWS-connector implements all the methods to interact with AWS using the BOTO client """ -__author__ = "Saboor Ahmad" -__date__ = "10-Apr-2017" - -from osm_ro_plugin import vimconn -import yaml import logging -import netaddr import time import boto import boto.ec2 import boto.vpc +import netaddr +from osm_ro_plugin import vimconn +import yaml + +__author__ = "Saboor Ahmad" +__date__ = "10-Apr-2017" class vimconnector(vimconn.VimConnector): diff --git a/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py b/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py index 68f77113..729db828 100755 --- a/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py +++ b/RO-VIM-azure/osm_rovim_azure/vimconn_azure.py @@ -14,28 +14,27 @@ ## import base64 -from osm_ro_plugin import vimconn import logging -import netaddr +from os import getenv import re -from os import getenv +from azure.core.exceptions import ResourceNotFoundError from azure.identity import ClientSecretCredential -from azure.mgmt.resource import ResourceManagementClient -from azure.mgmt.network import NetworkManagementClient from azure.mgmt.compute import ComputeManagementClient from azure.mgmt.compute.models import DiskCreateOption -from azure.core.exceptions import ResourceNotFoundError +from azure.mgmt.network import NetworkManagementClient +from azure.mgmt.resource import ResourceManagementClient from azure.profiles import ProfileDefinition -from msrestazure.azure_exceptions import CloudError +from cryptography.hazmat.backends import default_backend as crypto_default_backend +from cryptography.hazmat.primitives import serialization as crypto_serialization +from cryptography.hazmat.primitives.asymmetric import rsa from msrest.exceptions import AuthenticationError +from msrestazure.azure_exceptions import CloudError import msrestazure.tools as azure_tools +import netaddr +from osm_ro_plugin import vimconn from requests.exceptions import ConnectionError -from cryptography.hazmat.primitives import serialization as crypto_serialization -from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.backends import default_backend as crypto_default_backend - __author__ = "Isabel Lloret, Sergio Gonzalez, Alfonso Tierno, Gerardo Garcia" __date__ = "$18-apr-2019 23:59:59$" diff --git a/RO-VIM-gcp/osm_rovim_gcp/vimconn_gcp.py b/RO-VIM-gcp/osm_rovim_gcp/vimconn_gcp.py index 4a3258c4..e73f2780 100644 --- a/RO-VIM-gcp/osm_rovim_gcp/vimconn_gcp.py +++ b/RO-VIM-gcp/osm_rovim_gcp/vimconn_gcp.py @@ -13,23 +13,18 @@ # under the License. ## -import base64 -from osm_ro_plugin import vimconn import logging -import time +from os import getenv import random from random import choice as random_choice -from os import getenv - -from google.api_core.exceptions import NotFound -import googleapiclient.discovery -from google.oauth2 import service_account +import time +from cryptography.hazmat.backends import default_backend as crypto_default_backend from cryptography.hazmat.primitives import serialization as crypto_serialization from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.backends import default_backend as crypto_default_backend - -import logging +from google.oauth2 import service_account +import googleapiclient.discovery +from osm_ro_plugin import vimconn __author__ = "Sergio Gallardo Ruiz" __date__ = "$11-aug-2021 08:30:00$" @@ -324,7 +319,8 @@ class vimconnector(vimconn.VimConnector): "description": net_name, "network": network, "ipCidrRange": subnet_address, - # "autoCreateSubnetworks": True, # The network is created in AUTO mode (one subnet per region is created) + # The network is created in AUTO mode (one subnet per region is created) + # "autoCreateSubnetworks": True, "autoCreateSubnetworks": False, } @@ -337,7 +333,7 @@ class vimconnector(vimconn.VimConnector): self.logger.debug("created network_name: {}".format(net_name)) # Adding firewall rules to allow the traffic in the network: - rules_list = self._create_firewall_rules(net_name) + self._create_firewall_rules(net_name) # create subnetwork, even if there is no profile @@ -512,11 +508,9 @@ class vimconnector(vimconn.VimConnector): net_name = self._get_resource_name_from_resource_id(net_id) # Check associated VMs - vms = ( - self.conn_compute.instances() - .list(project=self.project, zone=self.zone) - .execute() - ) + self.conn_compute.instances().list( + project=self.project, zone=self.zone + ).execute() net_id = self.delete_subnet(net_name, created_items) @@ -545,7 +539,8 @@ class vimconnector(vimconn.VimConnector): try: # If the network has no more subnets, it will be deleted too net_info = self.get_network(net_id) - # If the subnet is in use by another resource, the deletion will be retried N times before abort the operation + # If the subnet is in use by another resource, the deletion will + # be retried N times before abort the operation created_items = created_items or {} created_items[net_id] = False @@ -582,7 +577,7 @@ class vimconnector(vimconn.VimConnector): try: # Deletion of the associated firewall rules: - rules_list = self._delete_firewall_rules(network_name) + self._delete_firewall_rules(network_name) operation = ( self.conn_compute.networks() @@ -845,12 +840,11 @@ class vimconnector(vimconn.VimConnector): + "-" + "".join(random_choice("0123456789abcdef") for _ in range(12)) ) - response = ( - self.conn_compute.instances() - .get(project=self.project, zone=self.zone, instance=random_name) - .execute() - ) - # If no exception is arisen, the random name exists for an instance, so a new random name must be generated + self.conn_compute.instances().get( + project=self.project, zone=self.zone, instance=random_name + ).execute() + # If no exception is arisen, the random name exists for an instance, + # so a new random name must be generated except Exception as e: if e.args[0]["status"] == "404": @@ -1012,11 +1006,9 @@ class vimconnector(vimconn.VimConnector): self._format_vimconn_exception(e) def _build_metadata(self, vm_name, cloud_config): - # initial metadata metadata = {} metadata["items"] = [] - key_pairs = {} # if there is a cloud-init load it if cloud_config: @@ -1152,7 +1144,7 @@ class vimconnector(vimconn.VimConnector): self._get_resource_name_from_resource_id(netIface["subnetwork"]) in self.nets_to_be_deleted ): - net_id = self._get_resource_name_from_resource_id( + self._get_resource_name_from_resource_id( self.delete_network(netIface["subnetwork"]) ) @@ -1222,7 +1214,6 @@ class vimconnector(vimconn.VimConnector): for net_id in net_list: try: - netName = self._get_net_name_from_resource_id(net_id) resName = self._get_resource_name_from_resource_id(net_id) net = ( @@ -1334,7 +1325,6 @@ class vimconnector(vimconn.VimConnector): interface_list = [] for network_interface in interfaces: interface_dict = {} - nic_name = network_interface["name"] interface_dict["vim_interface_id"] = network_interface["name"] ips = [] @@ -1380,11 +1370,9 @@ class vimconnector(vimconn.VimConnector): "network": "global/networks/" + network, "allowed": [{"IPProtocol": "tcp", "ports": ["80"]}], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() # Adding firewall rule to allow ssh: self.logger.debug("creating firewall rule to allow ssh") @@ -1393,11 +1381,9 @@ class vimconnector(vimconn.VimConnector): "network": "global/networks/" + network, "allowed": [{"IPProtocol": "tcp", "ports": ["22"]}], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() # Adding firewall rule to allow ping: self.logger.debug("creating firewall rule to allow ping") @@ -1406,11 +1392,9 @@ class vimconnector(vimconn.VimConnector): "network": "global/networks/" + network, "allowed": [{"IPProtocol": "icmp"}], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() # Adding firewall rule to allow internal: self.logger.debug("creating firewall rule to allow internal") @@ -1423,11 +1407,9 @@ class vimconnector(vimconn.VimConnector): {"IPProtocol": "icmp"}, ], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() # Adding firewall rule to allow microk8s: self.logger.debug("creating firewall rule to allow microk8s") @@ -1436,11 +1418,9 @@ class vimconnector(vimconn.VimConnector): "network": "global/networks/" + network, "allowed": [{"IPProtocol": "tcp", "ports": ["16443"]}], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() # Adding firewall rule to allow rdp: self.logger.debug("creating firewall rule to allow rdp") @@ -1449,11 +1429,9 @@ class vimconnector(vimconn.VimConnector): "network": "global/networks/" + network, "allowed": [{"IPProtocol": "tcp", "ports": ["3389"]}], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() # Adding firewall rule to allow osm: self.logger.debug("creating firewall rule to allow osm") @@ -1462,11 +1440,9 @@ class vimconnector(vimconn.VimConnector): "network": "global/networks/" + network, "allowed": [{"IPProtocol": "tcp", "ports": ["9001", "9999"]}], } - operation_firewall = ( - self.conn_compute.firewalls() - .insert(project=self.project, body=firewall_rule_body) - .execute() - ) + self.conn_compute.firewalls().insert( + project=self.project, body=firewall_rule_body + ).execute() self.logger.debug( "_create_firewall_rules Return: list_rules %s", rules_list @@ -1495,11 +1471,9 @@ class vimconnector(vimconn.VimConnector): ) for item in rules_list["items"]: if network == self._get_resource_name_from_resource_id(item["network"]): - operation_firewall = ( - self.conn_compute.firewalls() - .delete(project=self.project, firewall=item["name"]) - .execute() - ) + self.conn_compute.firewalls().delete( + project=self.project, firewall=item["name"] + ).execute() self.logger.debug("_delete_firewall_rules Return: list_rules %s", 0) return rules_list diff --git a/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py index 19c9d521..c5f7038a 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/tests/test_vimconn_openstack.py @@ -29,11 +29,9 @@ import unittest import mock from neutronclient.v2_0.client import Client - from osm_ro_plugin import vimconn from osm_rovim_openstack.vimconn_openstack import vimconnector - __author__ = "Igor D.C." __date__ = "$23-aug-2017 23:59:59$" diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py index 4869da16..dcbf5cad 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -30,32 +30,29 @@ to the VIM connector's SFC resources as follows: - Service Function Path (OSM) -> Port Chain (Neutron) """ -from osm_ro_plugin import vimconn - -# import json +import copy +from http.client import HTTPException import logging -import netaddr -import time -import yaml +from pprint import pformat import random import re -import copy -from pprint import pformat -from novaclient import client as nClient, exceptions as nvExceptions -from keystoneauth1.identity import v2, v3 +import time + +from cinderclient import client as cClient +from glanceclient import client as glClient +import glanceclient.exc as gl1Exceptions from keystoneauth1 import session +from keystoneauth1.identity import v2, v3 import keystoneclient.exceptions as ksExceptions -import keystoneclient.v3.client as ksClient_v3 import keystoneclient.v2_0.client as ksClient_v2 -from glanceclient import client as glClient -import glanceclient.exc as gl1Exceptions -from cinderclient import client as cClient - -# TODO py3 check that this base exception matches python2 httplib.HTTPException -from http.client import HTTPException -from neutronclient.neutron import client as neClient +import keystoneclient.v3.client as ksClient_v3 +import netaddr from neutronclient.common import exceptions as neExceptions +from neutronclient.neutron import client as neClient +from novaclient import client as nClient, exceptions as nvExceptions +from osm_ro_plugin import vimconn from requests.exceptions import ConnectionError +import yaml __author__ = "Alfonso Tierno, Gerardo Garcia, Pablo Montes, xFlow Research, Igor D.C., Eduardo Sousa" __date__ = "$22-sep-2017 23:59:59$" diff --git a/RO-VIM-openvim/osm_rovim_openvim/vimconn_openvim.py b/RO-VIM-openvim/osm_rovim_openvim/vimconn_openvim.py index 18d2cd61..79a5c7ba 100644 --- a/RO-VIM-openvim/osm_rovim_openvim/vimconn_openvim.py +++ b/RO-VIM-openvim/osm_rovim_openvim/vimconn_openvim.py @@ -27,22 +27,23 @@ vimconnector implements all the methods to interact with openvim using the openv __author__ = "Alfonso Tierno, Gerardo Garcia" __date__ = "$26-aug-2014 11:09:29$" -from osm_ro_plugin import vimconn -import requests import json -import yaml import logging import math +from urllib.parse import quote + +from jsonschema import exceptions as js_e, validate as js_v from osm_ro.openmano_schemas import ( + description_schema, id_schema, + integer0_schema, name_schema, nameshort_schema, - description_schema, vlan1000_schema, - integer0_schema, ) -from jsonschema import validate as js_v, exceptions as js_e -from urllib.parse import quote +from osm_ro_plugin import vimconn +import requests +import yaml """contain the openvim virtual machine status to openmano status""" vmStatus2manoFormat = { diff --git a/RO-VIM-vmware/osm_rovim_vmware/tests/test_vimconn_vmware.py b/RO-VIM-vmware/osm_rovim_vmware/tests/test_vimconn_vmware.py index 77f4808e..8c096bba 100755 --- a/RO-VIM-vmware/osm_rovim_vmware/tests/test_vimconn_vmware.py +++ b/RO-VIM-vmware/osm_rovim_vmware/tests/test_vimconn_vmware.py @@ -21,23 +21,23 @@ # contact: osslegalrouting@vmware.com ## +import os +from os import path +import unittest +from unittest import mock -from osm_rovim_vmware.vimconn_vmware import vimconnector +from lxml import etree as lxmlElementTree from osm_ro_plugin.vimconn import ( - VimConnUnexpectedResponse, - VimConnNotFoundException, VimConnException, + VimConnNotFoundException, + VimConnUnexpectedResponse, ) +from osm_rovim_vmware.vimconn_vmware import vimconnector from pyvcloud.vcd.client import Client -from lxml import etree as lxmlElementTree from pyvcloud.vcd.org import Org -from pyvcloud.vcd.vdc import VDC from pyvcloud.vcd.vapp import VApp -import os -import unittest -from unittest import mock +from pyvcloud.vcd.vdc import VDC import tests.test_vimconn_vmware_xml_response as xml_resp -from os import path __author__ = "Prakash Kasar" diff --git a/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py b/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py index a3c25ca0..5a58cf98 100644 --- a/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py +++ b/RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py @@ -25,26 +25,13 @@ vimconn_vmware implementation an Abstract class in order to interact with VMware vCloud Director. """ -from lxml import etree as lxmlElementTree -from osm_ro_plugin import vimconn -from progressbar import Percentage, Bar, ETA, FileTransferSpeed, ProgressBar -from pyVim.connect import SmartConnect, Disconnect -from pyVmomi import vim, vmodl # @UnresolvedImport -from pyvcloud.vcd.client import BasicLoginCredentials, Client -from pyvcloud.vcd.org import Org -from pyvcloud.vcd.vapp import VApp -from pyvcloud.vcd.vdc import VDC -from xml.etree import ElementTree as XmlElementTree -from xml.sax.saxutils import escape import atexit import hashlib import json import logging -import netaddr import os import random import re -import requests import shutil import socket import ssl @@ -54,6 +41,20 @@ import tempfile import time import traceback import uuid +from xml.etree import ElementTree as XmlElementTree +from xml.sax.saxutils import escape + +from lxml import etree as lxmlElementTree +import netaddr +from osm_ro_plugin import vimconn +from progressbar import Bar, ETA, FileTransferSpeed, Percentage, ProgressBar +from pyvcloud.vcd.client import BasicLoginCredentials, Client +from pyvcloud.vcd.org import Org +from pyvcloud.vcd.vapp import VApp +from pyvcloud.vcd.vdc import VDC +from pyVim.connect import Disconnect, SmartConnect +from pyVmomi import vim, vmodl # @UnresolvedImport +import requests import yaml # global variable for vcd connector type diff --git a/RO-plugin/osm_ro_plugin/openflow_conn.py b/RO-plugin/osm_ro_plugin/openflow_conn.py index 17351b0d..f1869e85 100644 --- a/RO-plugin/osm_ro_plugin/openflow_conn.py +++ b/RO-plugin/osm_ro_plugin/openflow_conn.py @@ -15,11 +15,14 @@ # under the License. # ## -import logging + from http import HTTPStatus -from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError +import logging from uuid import uuid4 +from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError + + """ Implement an Abstract class 'OpenflowConn' and an engine 'SdnConnectorOpenFlow' used for base class for SDN plugings that implements a pro-active opeflow rules. diff --git a/RO-plugin/osm_ro_plugin/sdn_dummy.py b/RO-plugin/osm_ro_plugin/sdn_dummy.py index fb7c5524..03181568 100644 --- a/RO-plugin/osm_ro_plugin/sdn_dummy.py +++ b/RO-plugin/osm_ro_plugin/sdn_dummy.py @@ -20,10 +20,12 @@ This WIM does nothing and allows using it for testing and when no WIM is needed """ +from http import HTTPStatus import logging from uuid import uuid4 + from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError -from http import HTTPStatus + __author__ = "Alfonso Tierno " diff --git a/RO-plugin/osm_ro_plugin/sdnconn.py b/RO-plugin/osm_ro_plugin/sdnconn.py index a1849c9e..467d05df 100644 --- a/RO-plugin/osm_ro_plugin/sdnconn.py +++ b/RO-plugin/osm_ro_plugin/sdnconn.py @@ -37,8 +37,8 @@ and intranet SDN connectivity. It receives information from ports to be connected . """ -import logging from http import HTTPStatus +import logging class SdnConnectorError(Exception): diff --git a/RO-plugin/osm_ro_plugin/vim_dummy.py b/RO-plugin/osm_ro_plugin/vim_dummy.py index fe3a8115..f003ba9f 100644 --- a/RO-plugin/osm_ro_plugin/vim_dummy.py +++ b/RO-plugin/osm_ro_plugin/vim_dummy.py @@ -20,12 +20,14 @@ Implements a Dummy vim plugin. """ -import yaml -from osm_ro_plugin import vimconn -from uuid import uuid4 from copy import deepcopy import logging from random import randrange +from uuid import uuid4 + +from osm_ro_plugin import vimconn +import yaml + __author__ = "Alfonso Tierno" __date__ = "2020-04-20" diff --git a/RO-plugin/osm_ro_plugin/vimconn.py b/RO-plugin/osm_ro_plugin/vimconn.py index cc087f0a..b4e936c1 100644 --- a/RO-plugin/osm_ro_plugin/vimconn.py +++ b/RO-plugin/osm_ro_plugin/vimconn.py @@ -26,17 +26,18 @@ vimconn implement an Abstract class for the vim connector plugins with the definition of the method to be implemented. """ -import logging -import paramiko -import socket -from io import StringIO -import yaml -import sys from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from http import HTTPStatus +from io import StringIO +import logging +import socket +import sys import warnings +import paramiko +import yaml + __author__ = "Alfonso Tierno, Igor D.C." __date__ = "$14-aug-2017 23:59:59$" diff --git a/integration-tests/test_vimconn_gcp.py b/integration-tests/test_vimconn_gcp.py index f9735381..ea9783bc 100644 --- a/integration-tests/test_vimconn_gcp.py +++ b/integration-tests/test_vimconn_gcp.py @@ -24,12 +24,11 @@ This module contains unit tests for the OpenStack VIM connector Run this directly with python2 or python3. """ -import logging +from datetime import datetime import json +import logging from osm_rovim_gcp.vimconn_gcp import vimconnector -from datetime import datetime - __author__ = "Sergio G.R." __date__ = "$05-nov-2021 12:00:00$" diff --git a/releasenotes/notes/enabling_flake8-007bf2cc6afb7cf1.yaml b/releasenotes/notes/enabling_flake8-007bf2cc6afb7cf1.yaml new file mode 100644 index 00000000..8ea0d732 --- /dev/null +++ b/releasenotes/notes/enabling_flake8-007bf2cc6afb7cf1.yaml @@ -0,0 +1,21 @@ +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# 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. +####################################################################################### +--- +other: + - | + Enabling flake8 verifications in tox.ini and adding import sorting. All the plugins + have been fixed for flake8 errors and the imports have been sorted. diff --git a/tox.ini b/tox.ini index dd4b1e6d..699ff96b 100644 --- a/tox.ini +++ b/tox.ini @@ -133,27 +133,29 @@ commands = ####################################################################################### [testenv:flake8] -deps = flake8 +deps = + flake8 + flake8-import-order skip_install = true commands = flake8 NG-RO/osm_ng_ro/ NG-RO/setup.py - - flake8 RO-plugin/osm_ro_plugin/ RO-plugin/setup.py - - flake8 RO-SDN-arista_cloudvision/osm_rosdn_arista_cloudvision/ RO-SDN-arista_cloudvision/setup.py - - flake8 RO-SDN-dpb/osm_rosdn_dpb/ RO-SDN-dpb/setup.py - - flake8 RO-SDN-dynpac/osm_rosdn_dynpac/ RO-SDN-dynpac/setup.py - - flake8 RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/ RO-SDN-floodlight_openflow/setup.py - - flake8 RO-SDN-ietfl2vpn/osm_rosdn_ietfl2vpn/ RO-SDN-ietfl2vpn/setup.py - - flake8 RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/ RO-SDN-juniper_contrail/setup.py - - flake8 RO-SDN-odl_openflow/osm_rosdn_odlof/ RO-SDN-odl_openflow/setup.py - - flake8 RO-SDN-onos_openflow/osm_rosdn_onosof/ RO-SDN-onos_openflow/setup.py - - flake8 RO-SDN-onos_vpls/osm_rosdn_onos_vpls/ RO-SDN-onos_vpls/setup.py - - flake8 RO-VIM-aws/osm_rovim_aws/ RO-VIM-aws/setup.py - - flake8 RO-VIM-azure/osm_rovim_azure/ RO-VIM-azure/setup.py - - flake8 RO-VIM-openstack/osm_rovim_openstack/ RO-VIM-openstack/setup.py - - flake8 RO-VIM-openvim/osm_rovim_openvim/ RO-VIM-openvim/setup.py - - flake8 RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py RO-VIM-vmware/osm_rovim_vmware/tests/test_vimconn_vmware.py RO-VIM-vmware/setup.py - - flake8 RO-VIM-gcp/osm_rovim_gcp/ RO-VIM-gcp/setup.py - - flake8 integration-tests/ + flake8 RO-plugin/osm_ro_plugin/ RO-plugin/setup.py + flake8 RO-SDN-arista_cloudvision/osm_rosdn_arista_cloudvision/ RO-SDN-arista_cloudvision/setup.py + flake8 RO-SDN-dpb/osm_rosdn_dpb/ RO-SDN-dpb/setup.py + flake8 RO-SDN-dynpac/osm_rosdn_dynpac/ RO-SDN-dynpac/setup.py + flake8 RO-SDN-floodlight_openflow/osm_rosdn_floodlightof/ RO-SDN-floodlight_openflow/setup.py + flake8 RO-SDN-ietfl2vpn/osm_rosdn_ietfl2vpn/ RO-SDN-ietfl2vpn/setup.py + flake8 RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/ RO-SDN-juniper_contrail/setup.py + flake8 RO-SDN-odl_openflow/osm_rosdn_odlof/ RO-SDN-odl_openflow/setup.py + flake8 RO-SDN-onos_openflow/osm_rosdn_onosof/ RO-SDN-onos_openflow/setup.py + flake8 RO-SDN-onos_vpls/osm_rosdn_onos_vpls/ RO-SDN-onos_vpls/setup.py + flake8 RO-VIM-aws/osm_rovim_aws/ RO-VIM-aws/setup.py + flake8 RO-VIM-azure/osm_rovim_azure/ RO-VIM-azure/setup.py + flake8 RO-VIM-openstack/osm_rovim_openstack/ RO-VIM-openstack/setup.py + flake8 RO-VIM-openvim/osm_rovim_openvim/ RO-VIM-openvim/setup.py + flake8 RO-VIM-vmware/osm_rovim_vmware/vimconn_vmware.py RO-VIM-vmware/osm_rovim_vmware/tests/test_vimconn_vmware.py RO-VIM-vmware/setup.py + flake8 RO-VIM-gcp/osm_rovim_gcp/ RO-VIM-gcp/setup.py + flake8 integration-tests/ ####################################################################################### @@ -449,3 +451,4 @@ exclude = max-line-length = 120 show-source = True builtins = _ +import-order-style = google