From dffdd9613a0ece20aebb0832ecf31316c571b120 Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 13 Oct 2022 09:27:00 +0200 Subject: [PATCH] fix flake8 --- IM/VirtualMachine.py | 2 +- IM/connectors/Azure.py | 3 ++- IM/connectors/CloudConnector.py | 1 - IM/connectors/Docker.py | 4 ++-- IM/connectors/OCCI.py | 2 +- IM/connectors/OpenStack.py | 4 ++-- IM/connectors/vSphere.py | 1 - IM/db.py | 2 +- IM/tosca/Tosca.py | 2 +- test/loadtest/LoadTest.py | 4 ++-- test/loadtest/LoadTestR.py | 4 ++-- test/loadtest/LoadTestREST.py | 4 ++-- test/loadtest/LoadTestRESTR.py | 8 ++++---- test/unit/connectors/Fogbow.py | 2 +- test/unit/connectors/Kubernetes.py | 1 - tox.ini | 2 +- 16 files changed, 22 insertions(+), 24 deletions(-) diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index caa3a3143..437769777 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -1009,7 +1009,7 @@ def get_ctxt_output(self, remote_dir, ssh, delete=False): # And process it self.process_ctxt_agent_out(ctxt_agent_out) msg = "Contextualization agent output processed successfully" - except IOError as ex: + except IOError: msg = "Error getting contextualization agent output " + \ remote_dir + "/ctxt_agent.out: No such file." self.log_error(msg) diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index a36a6f0d3..681e5cb21 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -53,6 +53,7 @@ except Exception as ex: AZURE_IDENTITY_AVAILABLE = False print("WARN: Python azure-identity not installed. AzureCloudConnector may not work properly!.") + print(ex) class AzureInstanceTypeInfo: @@ -888,7 +889,7 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data): deleted, msg = self.delete_resource_group(inf, rg_name, resource_client, max_retries=1) if not deleted: self.log_warn("Error removing errored RG %s: %s" % (rg_name, msg)) - except Exception as ex: + except Exception: self.log_exception("Error removing errored RG: %s" % rg_name) if remaining_vms == 0: diff --git a/IM/connectors/CloudConnector.py b/IM/connectors/CloudConnector.py index 6d18b7d6f..ce5e97dfe 100644 --- a/IM/connectors/CloudConnector.py +++ b/IM/connectors/CloudConnector.py @@ -24,7 +24,6 @@ from IM.config import Config from IM.LoggerMixin import LoggerMixin from netaddr import IPNetwork, spanning_cidr -import IM.connectors class CloudConnector(LoggerMixin): diff --git a/IM/connectors/Docker.py b/IM/connectors/Docker.py index 51c855520..a38555504 100644 --- a/IM/connectors/Docker.py +++ b/IM/connectors/Docker.py @@ -162,7 +162,7 @@ def _generate_create_svc_request_data(self, image_name, outports, vm, ssh_port, svc_data = {} system = vm.info.systems[0] - cpu = int(system.getValue('cpu.count')) - 1 + # cpu = int(system.getValue('cpu.count')) - 1 memory = int(system.getFeature('memory.size').getValue('B')) name = system.getValue("disk.0.image.name") if not name: @@ -241,7 +241,7 @@ def _generate_create_cont_request_data(self, image_name, outports, vm, ssh_port) cont_data = {} system = vm.info.systems[0] - cpu = int(system.getValue('cpu.count')) - 1 + # cpu = int(system.getValue('cpu.count')) - 1 memory = system.getFeature('memory.size').getValue('B') # name = system.getValue("disk.0.image.name") diff --git a/IM/connectors/OCCI.py b/IM/connectors/OCCI.py index eeb5f6d93..c2125e9c8 100644 --- a/IM/connectors/OCCI.py +++ b/IM/connectors/OCCI.py @@ -307,7 +307,7 @@ def get_floating_pool(occi_data): pools = [] for line in lines: if 'http://schemas.openstack.org/network/floatingippool#' in line: - for elem in l.split(';'): + for elem in line.split(';'): if elem.startswith('Category: '): pools.append(elem[10:]) if pools: diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 2f19932c0..19c620537 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -1600,7 +1600,7 @@ def finalize(self, vm, last, auth_data): self.log_debug("Dettaching volume %s." % vol_id) volume = node.driver.ex_get_volume(vol_id) node.driver.detach_volume(volume) - except Exception as ex: + except Exception: self.log_exception("Error dettaching volume %s." % vol_id) for sg_name in self._get_security_names(vm.inf): @@ -1608,7 +1608,7 @@ def finalize(self, vm, last, auth_data): self.log_debug("Dettaching SG %s." % sg_name) security_group = OpenStackSecurityGroup(None, None, sg_name, "", node.driver) node.driver.ex_remove_security_group_from_node(security_group, node) - except Exception as ex: + except Exception: self.log_exception("Error dettaching SG %s." % sg_name) res = node.destroy() diff --git a/IM/connectors/vSphere.py b/IM/connectors/vSphere.py index 5b9896059..4914ff48e 100644 --- a/IM/connectors/vSphere.py +++ b/IM/connectors/vSphere.py @@ -14,7 +14,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import time from netaddr import IPNetwork, IPAddress try: diff --git a/IM/db.py b/IM/db.py index 488c859ce..8a27e3885 100644 --- a/IM/db.py +++ b/IM/db.py @@ -188,7 +188,7 @@ def _execute_retry(self, sql, args, fetch=False): self.connect() else: raise ex - except sqlite.IntegrityError as ex: + except sqlite.IntegrityError: raise IntegrityError() def execute(self, sql, args=None): diff --git a/IM/tosca/Tosca.py b/IM/tosca/Tosca.py index fde78f879..5c0b8d446 100644 --- a/IM/tosca/Tosca.py +++ b/IM/tosca/Tosca.py @@ -769,7 +769,7 @@ def _gen_configure_from_interfaces(self, node, compute, interfaces): script_content = resp.text if resp.status_code != 200: raise Exception(resp.reason + "\n" + resp.text) - except Exception as ex: + except Exception: raise Exception("Implementation file: '%s' is not located in the artifacts folder '%s' " "or in the artifacts remote url '%s'." % (implementation, Tosca.ARTIFACTS_PATH, diff --git a/test/loadtest/LoadTest.py b/test/loadtest/LoadTest.py index d761dc90b..051cda4e3 100755 --- a/test/loadtest/LoadTest.py +++ b/test/loadtest/LoadTest.py @@ -347,8 +347,8 @@ def test_23_removeresource(self): def print_response_times(self): total = 0.0 - for time in self.response_times: - total += time + for rtime in self.response_times: + total += rtime print("Mean Time: %.4f" % (total / len(self.response_times))) def test_50_destroy(self): diff --git a/test/loadtest/LoadTestR.py b/test/loadtest/LoadTestR.py index 1cabf7111..f3a86d95c 100755 --- a/test/loadtest/LoadTestR.py +++ b/test/loadtest/LoadTestR.py @@ -111,8 +111,8 @@ def getstate(self, inf_id): def print_response_times(self): total = 0.0 - for time in self.response_times: - total += time + for rtime in self.response_times: + total += rtime print("Mean Time: %.4f" % (total / len(self.response_times))) diff --git a/test/loadtest/LoadTestREST.py b/test/loadtest/LoadTestREST.py index 174458686..a3fec08b3 100755 --- a/test/loadtest/LoadTestREST.py +++ b/test/loadtest/LoadTestREST.py @@ -329,8 +329,8 @@ def test_95_destroy(self): def print_response_times(self): total = 0.0 - for time in self.response_times: - total += time + for rtime in self.response_times: + total += rtime print("Mean Time: %.4f" % (total / len(self.response_times))) diff --git a/test/loadtest/LoadTestRESTR.py b/test/loadtest/LoadTestRESTR.py index 5390bbf86..e5a78c2dc 100755 --- a/test/loadtest/LoadTestRESTR.py +++ b/test/loadtest/LoadTestRESTR.py @@ -107,13 +107,13 @@ def getstate(self, inf_id): self.assertEqual( resp.status_code, 200, msg="ERROR getting the infrastructure state:" + resp.text) res = json.loads(resp.text) - state = res['state']['state'] - vm_states = res['state']['vm_states'] + # state = res['state']['state'] + # vm_states = res['state']['vm_states'] def print_response_times(self): total = 0.0 - for time in self.response_times: - total += time + for rtime in self.response_times: + total += rtime print("Mean Time: %.4f" % (total / len(self.response_times))) diff --git a/test/unit/connectors/Fogbow.py b/test/unit/connectors/Fogbow.py index f6e2d552a..ad9500270 100755 --- a/test/unit/connectors/Fogbow.py +++ b/test/unit/connectors/Fogbow.py @@ -79,7 +79,7 @@ def get_response(self, method, url, verify, headers={}, data=None): resp = MagicMock() parts = urlparse(url) url = parts[2] - params = parts[4] + # params = parts[4] if method not in self.call_count: self.call_count[method] = {} diff --git a/test/unit/connectors/Kubernetes.py b/test/unit/connectors/Kubernetes.py index 14b7b62c8..8888cb23c 100755 --- a/test/unit/connectors/Kubernetes.py +++ b/test/unit/connectors/Kubernetes.py @@ -26,7 +26,6 @@ from IM.auth import Authentication from radl import radl_parse from IM.VirtualMachine import VirtualMachine -from IM.InfrastructureInfo import InfrastructureInfo from IM.connectors.Kubernetes import KubernetesCloudConnector try: from urlparse import urlparse diff --git a/tox.ini b/tox.ini index 347224215..896832a2c 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ commands = bash -c "nosetests -v test/unit/*.py test/unit/connectors/*.py -v --s commands = bandit IM -r -f html -o bandit.html -s B108,B601,B104 --severity-level medium [flake8] -ignore = E402,E265 +ignore = E402,E265,W605,W504,F811 max-line-length = 120 exclude = doc,scripts