Fix Python linting issues in Python scripts
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>
diff --git a/test/mocks/pnfsimulator/netconfsimulator/netconf/netopeer_change_saver.py b/test/mocks/pnfsimulator/netconfsimulator/netconf/netopeer_change_saver.py
index 0a9e841..92f8846 100644
--- a/test/mocks/pnfsimulator/netconfsimulator/netconf/netopeer_change_saver.py
+++ b/test/mocks/pnfsimulator/netconfsimulator/netconf/netopeer_change_saver.py
@@ -71,7 +71,7 @@
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:
diff --git a/test/mocks/pnfsimulator/simulator-cli/tests/test_netconf_simulator.py b/test/mocks/pnfsimulator/simulator-cli/tests/test_netconf_simulator.py
index 46ce846..2b78a1b 100644
--- a/test/mocks/pnfsimulator/simulator-cli/tests/test_netconf_simulator.py
+++ b/test/mocks/pnfsimulator/simulator-cli/tests/test_netconf_simulator.py
@@ -112,7 +112,7 @@
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 @@
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')
diff --git a/test/vcpe/config_sdnc_so.py b/test/vcpe/config_sdnc_so.py
index eac7c59..6e02577 100755
--- a/test/vcpe/config_sdnc_so.py
+++ b/test/vcpe/config_sdnc_so.py
@@ -22,7 +22,7 @@
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 @@
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 @@
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 @@
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," \
diff --git a/test/vcpe/csar_parser.py b/test/vcpe/csar_parser.py
index da6fa43..da1903c 100755
--- a/test/vcpe/csar_parser.py
+++ b/test/vcpe/csar_parser.py
@@ -178,7 +178,7 @@
},
"""
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',
diff --git a/test/vcpe/preload.py b/test/vcpe/preload.py
index 117b63e..62c036c 100755
--- a/test/vcpe/preload.py
+++ b/test/vcpe/preload.py
@@ -26,7 +26,7 @@
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:
diff --git a/test/vcpe/tests/test_imports.py b/test/vcpe/tests/test_imports.py
index 728c293..63e551f 100644
--- a/test/vcpe/tests/test_imports.py
+++ b/test/vcpe/tests/test_imports.py
@@ -9,7 +9,6 @@
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
diff --git a/test/vcpe/vcpe.py b/test/vcpe/vcpe.py
index f6c85ec..e6038e7 100755
--- a/test/vcpe/vcpe.py
+++ b/test/vcpe/vcpe.py
@@ -68,7 +68,7 @@
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 @@
# 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 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_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 tmp_sniro():
- logger = logging.getLogger(__name__)
+ logger = logging.getLogger(__name__) # pylint: disable=W0612
vcpecommon = VcpeCommon(cfg_file=args.config)
diff --git a/test/vcpe/vcpecommon.py b/test/vcpe/vcpecommon.py
index 8bc5ef1..971082c 100755
--- a/test/vcpe/vcpecommon.py
+++ b/test/vcpe/vcpecommon.py
@@ -520,7 +520,7 @@
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 @@
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