Fix Python linting issues in Python scripts 24/103124/2
authorBartek Grzybowski <b.grzybowski@partner.samsung.com>
Thu, 5 Mar 2020 12:21:59 +0000 (13:21 +0100)
committerMarco Platania <platania@research.att.com>
Thu, 5 Mar 2020 15:27:02 +0000 (15:27 +0000)
Fixed pylint issues for categories len-as-condition, using-constant-test,
undefined-variable and reimported.

Change-Id: Idad710958c3ca0ac6da78fb4709da03e5f079b34
Issue-ID: INT-1427
Signed-off-by: Bartek Grzybowski <b.grzybowski@partner.samsung.com>
test/mocks/pnfsimulator/netconfsimulator/netconf/netopeer_change_saver.py
test/mocks/pnfsimulator/simulator-cli/tests/test_netconf_simulator.py
test/vcpe/config_sdnc_so.py
test/vcpe/csar_parser.py
test/vcpe/preload.py
test/vcpe/tests/test_imports.py
test/vcpe/vcpe.py
test/vcpe/vcpecommon.py

index 0a9e841..92f8846 100644 (file)
@@ -71,7 +71,7 @@ def send_message(message):
 
 
 def create_producer(server):
-    for i in range(10):
+    for i in range(10): # pylint: disable=W0612
         try:
             return KafkaProducer(bootstrap_servers=server, value_serializer=lambda v: json.dumps(v).encode('utf-8'))
         except Exception:
index 46ce846..2b78a1b 100644 (file)
@@ -112,7 +112,7 @@ class TestNetconfSimulatorClient(unittest.TestCase):
         client = NetconfSimulatorClient('localhost')
         client.logger = logging.getLogger()
 
-        with self.assertRaises(AttributeError) as context:
+        with self.assertRaises(AttributeError) as context: # pylint: disable=W0612
             client.get_config(module_name="test")
 
     @patch('cli.netconf_simulator.NetconfSimulatorClient._configure_logger')
@@ -120,7 +120,7 @@ class TestNetconfSimulatorClient(unittest.TestCase):
         client = NetconfSimulatorClient('localhost')
         client.logger = logging.getLogger()
 
-        with self.assertRaises(AttributeError) as context:
+        with self.assertRaises(AttributeError) as context: # pylint: disable=W0612
             client.get_config(container="test")
 
     @patch('cli.netconf_simulator.requests')
index eac7c59..6e02577 100755 (executable)
@@ -22,7 +22,7 @@ def insert_customer_service_to_sdnc(vcpecommon):
     parser.parse_csar(csar_file)
     cmds = []
 
-    if False:
+    if False: # pylint: disable=W0125
         cmds.append("INSERT INTO SERVICE_MODEL (`service_uuid`, `model_yaml`,`invariant_uuid`,`version`,`name`," \
                 "`description`,`type`,`category`,`ecomp_naming`,`service_instance_name_prefix`,`filename`," \
                 "`naming_policy`) values ('{0}', null, '{1}',null,'{2}', 'vCPEService', 'Service','Network L1-3'," \
@@ -34,7 +34,7 @@ def insert_customer_service_to_sdnc(vcpecommon):
 
     for model in parser.vnf_models:
         if 'tunnel' in model['modelCustomizationName'].lower() or 'brg' in model['modelCustomizationName'].lower():
-            if False:
+            if False: # pylint: disable=W0125
                 cmds.append("INSERT INTO ALLOTTED_RESOURCE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`," \
                         "`uuid`,`version`,`naming_policy`,`ecomp_generated_naming`,`depending_service`,`role`,`type`," \
                         "`service_dependency`,`allotted_resource_type`) VALUES ('{0}',NULL,'{1}','{2}','1.0'," \
@@ -44,7 +44,7 @@ def insert_customer_service_to_sdnc(vcpecommon):
             cmds.append("UPDATE ALLOTTED_RESOURCE_MODEL SET `ecomp_generated_naming`='Y' " \
                     "WHERE `customization_uuid`='{0}'".format(model['modelCustomizationId']))
         else:
-            if False:
+            if False: # pylint: disable=W0125
                 cmds.append("INSERT INTO VF_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`," \
                         "`name`,`naming_policy`,`ecomp_generated_naming`,`avail_zone_max_count`,`nf_function`," \
                         "`nf_code`,`nf_type`,`nf_role`,`vendor`,`vendor_version`) VALUES ('{0}',NULL,'{1}','{2}'," \
@@ -54,7 +54,7 @@ def insert_customer_service_to_sdnc(vcpecommon):
             cmds.append("UPDATE VF_MODEL SET `ecomp_generated_naming`='Y' " \
                         "WHERE `customization_uuid`='{0}'".format(model['modelCustomizationId']))
 
-    if False:
+    if False: # pylint: disable=W0125
         model = parser.vfmodule_models[0]
         cmds.append("INSERT INTO VF_MODULE_MODEL (`customization_uuid`,`model_yaml`,`invariant_uuid`,`uuid`,`version`," \
                     "`vf_module_type`,`availability_zone_count`,`ecomp_generated_vm_assignments`) VALUES ('{0}', NULL," \
index da6fa43..da1903c 100755 (executable)
@@ -178,7 +178,7 @@ class CsarParser:
             },
         """
         node_dic = svc_template['topology_template']['groups']
-        for node_name, v in node_dic.items():
+        for node_name, v in node_dic.items(): # pylint: disable=W0612
             if v['type'].startswith('org.openecomp.groups.VfModule'):
                 model = {
                     'modelType': 'vfModule',
index 117b63e..62c036c 100755 (executable)
@@ -26,7 +26,7 @@ class Preload:
         with open(template_file) as json_input:
             json_data = json.load(json_input)
             stk = [json_data]
-            while len(stk) > 0:
+            while stk:
                 data = stk.pop()
                 for k, v in data.items():
                     if type(v) is dict:
index 728c293..63e551f 100644 (file)
@@ -9,7 +9,6 @@ import preload
 import sdcutils
 import soutils
 import vcpe_custom_service
-import vcpecommon
 
 # This will test whether all modules that vcpe scripts leverage
 # are included in setuptools configuration
index f6c85ec..e6038e7 100755 (executable)
@@ -68,7 +68,7 @@ def create_one_service(vcpecommon, csar_file, vnf_template_file, preload_dict, s
 
 
 def deploy_brg_only():
-    logger = logging.getLogger(__name__)
+    logger = logging.getLogger(__name__) # pylint: disable=W0612
 
     vcpecommon = VcpeCommon(cfg_file=args.config)
     preload_dict = vcpecommon.load_preload_data()
@@ -174,7 +174,7 @@ def deploy_custom_service():
 
     # clean up
     host_dic = {k: vcpecommon.hosts[k] for k in nodes}
-    if False:
+    if False: # pylint: disable=W0125
         if not vcpecommon.delete_vxlan_interfaces(host_dic):
             sys.exit(1)
         custom_service.del_all_vgw_stacks(vcpecommon.vgw_name_keyword)
@@ -215,7 +215,7 @@ def closed_loop(lossrate=0):
 
 
 def init_so_sdnc():
-    logger = logging.getLogger('__name__')
+    logger = logging.getLogger('__name__') # pylint: disable=W0612
     vcpecommon = VcpeCommon(cfg_file=args.config)
     config_sdnc_so.insert_sdnc_ip_pool(vcpecommon)
     config_sdnc_so.insert_customer_service_to_so(vcpecommon)
@@ -234,7 +234,7 @@ def init():
 
 
 def init_sdc(vcpecommon):
-    sdc = sdcutils.SdcUtils(vcpecommon)
+    sdc = sdcutils.SdcUtils(vcpecommon) # pylint: disable=W0612
     # default SDC creates BRG - remove this in frankfurt
     #sdc.create_allotted_resource_subcategory('BRG')
 
@@ -245,7 +245,7 @@ def download_vcpe_service_templates(vcpecommon):
 
 
 def tmp_sniro():
-    logger = logging.getLogger(__name__)
+    logger = logging.getLogger(__name__) # pylint: disable=W0612
 
     vcpecommon = VcpeCommon(cfg_file=args.config)
 
index 8bc5ef1..971082c 100755 (executable)
@@ -520,7 +520,7 @@ class VcpeCommon:
         nova = openstackclient.Client(2, self.cloud['--os-username'], self.cloud['--os-password'], self.cloud['--os-tenant-id'], self.cloud['--os-auth-url'])
         for i in nova.servers.list():
             if i.name == vm:
-                for k, v in i.networks.items():
+                for k, v in i.networks.items(): # pylint: disable=W0612
                     for ip in v:
                         if IPAddress(ip) in subnet:
                             return ip
@@ -717,7 +717,7 @@ class VcpeCommon:
                 url = self.vpp_inf_url.format(ip) + '/interface/' + inf
                 requests.delete(url, headers=self.vpp_api_headers, auth=self.vpp_api_userpass)
 
-            if len(self.get_vxlan_interfaces(ip)) > 0:
+            if self.get_vxlan_interfaces(ip):
                 self.logger.error("Error deleting VxLAN from {0}, try to restart the VM, IP is {1}.".format(host, ip))
                 return False