From 60a3a96717d7c36ba7a65573da59a6bc039f5e28 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Fri, 3 Feb 2023 13:20:46 +0100 Subject: [PATCH] Fix black issues Change-Id: I5e253d477005a0c8c6e9d2c531dbea71aaf31225 Signed-off-by: garciadeblas --- n2vc/k8s_conn.py | 1 - n2vc/k8s_helm3_conn.py | 9 --------- n2vc/k8s_helm_base_conn.py | 12 ------------ n2vc/k8s_helm_conn.py | 6 ------ n2vc/libjuju.py | 3 --- n2vc/loggable.py | 2 -- n2vc/n2vc_conn.py | 1 - n2vc/n2vc_juju_conn.py | 1 - n2vc/tests/unit/test_k8s_helm3_conn.py | 2 -- n2vc/tests/unit/test_libjuju.py | 5 ----- n2vc/tests/unit/utils.py | 1 - 11 files changed, 43 deletions(-) diff --git a/n2vc/k8s_conn.py b/n2vc/k8s_conn.py index 632ac29..2624ddc 100644 --- a/n2vc/k8s_conn.py +++ b/n2vc/k8s_conn.py @@ -435,7 +435,6 @@ class K8sConnector(abc.ABC, Loggable): self.log.debug("status={}".format(status)) try: - the_table = db_dict["collection"] the_filter = db_dict["filter"] the_path = db_dict["path"] diff --git a/n2vc/k8s_helm3_conn.py b/n2vc/k8s_helm3_conn.py index 298c44e..787be03 100644 --- a/n2vc/k8s_helm3_conn.py +++ b/n2vc/k8s_helm3_conn.py @@ -144,7 +144,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): return True async def inspect_kdu(self, kdu_model: str, repo_url: str = None) -> str: - self.log.debug( "inspect kdu_model {} from (optional) repo: {}".format(kdu_model, repo_url) ) @@ -245,7 +244,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): return namespace in namespaces if namespaces else False async def _get_namespaces(self, cluster_id: str): - self.log.debug("get namespaces cluster_id {}".format(cluster_id)) # init config, env @@ -267,7 +265,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): return namespaces async def _create_namespace(self, cluster_id: str, namespace: str): - self.log.debug(f"create namespace: {cluster_id} for cluster_id: {namespace}") # init config, env @@ -288,7 +285,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): async def _get_services( self, cluster_id: str, kdu_instance: str, namespace: str, kubeconfig: str ): - # init config, env paths, env = self._init_paths_env( cluster_name=cluster_id, create_if_not_exist=True @@ -330,7 +326,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): pass async def _instances_list(self, cluster_id: str): - # init paths, env paths, env = self._init_paths_env( cluster_name=cluster_id, create_if_not_exist=True @@ -363,7 +358,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): yaml_format: bool = False, show_error_log: bool = False, ) -> Union[str, dict]: - self.log.debug( "status of kdu_instance: {}, namespace: {} ".format(kdu_instance, namespace) ) @@ -422,7 +416,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): timeout: float, kubeconfig: str, ) -> str: - timeout_str = "" if timeout: timeout_str = "--timeout {}s".format(timeout) @@ -468,7 +461,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): timeout: float, kubeconfig: str, ) -> str: - timeout_str = "" if timeout: timeout_str = "--timeout {}s".format(timeout) @@ -514,7 +506,6 @@ class K8sHelm3Connector(K8sHelmBaseConnector): def _get_uninstall_command( self, kdu_instance: str, namespace: str, kubeconfig: str ) -> str: - return "env KUBECONFIG={} {} uninstall {} --namespace={}".format( kubeconfig, self._helm_command, kdu_instance, namespace ) diff --git a/n2vc/k8s_helm_base_conn.py b/n2vc/k8s_helm_base_conn.py index 2a2e935..149b064 100644 --- a/n2vc/k8s_helm_base_conn.py +++ b/n2vc/k8s_helm_base_conn.py @@ -252,7 +252,6 @@ class K8sHelmBaseConnector(K8sConnector): return [] async def repo_remove(self, cluster_uuid: str, name: str): - _, cluster_id = self._get_namespace_cluster_id(cluster_uuid) self.log.debug("remove {} repositories for cluster {}".format(name, cluster_id)) @@ -423,7 +422,6 @@ class K8sHelmBaseConnector(K8sConnector): output, rc = exec_task.result() else: - output, rc = await self._local_async_exec( command=command, raise_exception_on_error=False, env=env ) @@ -506,7 +504,6 @@ class K8sHelmBaseConnector(K8sConnector): self.log.debug("upgrading: {}".format(command)) if atomic: - # exec helm in a task exec_task = asyncio.ensure_future( coro_or_future=self._local_async_exec( @@ -532,7 +529,6 @@ class K8sHelmBaseConnector(K8sConnector): output, rc = exec_task.result() else: - output, rc = await self._local_async_exec( command=command, raise_exception_on_error=False, env=env ) @@ -590,7 +586,6 @@ class K8sHelmBaseConnector(K8sConnector): async def rollback( self, cluster_uuid: str, kdu_instance: str, revision=0, db_dict: dict = None ): - _, cluster_id = self._get_namespace_cluster_id(cluster_uuid) self.log.debug( "rollback kdu_instance {} to revision {} from cluster {}".format( @@ -827,7 +822,6 @@ class K8sHelmBaseConnector(K8sConnector): async def get_service( self, cluster_uuid: str, service_name: str, namespace: str ) -> object: - self.log.debug( "get service, service_name: {}, namespace: {}, cluster_uuid: {}".format( service_name, namespace, cluster_uuid @@ -912,7 +906,6 @@ class K8sHelmBaseConnector(K8sConnector): return status async def values_kdu(self, kdu_model: str, repo_url: str = None) -> str: - self.log.debug( "inspect kdu_model values {} from (optional) repo: {}".format( kdu_model, repo_url @@ -924,7 +917,6 @@ class K8sHelmBaseConnector(K8sConnector): ) async def help_kdu(self, kdu_model: str, repo_url: str = None) -> str: - self.log.debug( "inspect kdu_model {} readme.md from repo: {}".format(kdu_model, repo_url) ) @@ -934,7 +926,6 @@ class K8sHelmBaseConnector(K8sConnector): ) async def synchronize_repos(self, cluster_uuid: str): - self.log.debug("synchronize repos for cluster helm-id: {}".format(cluster_uuid)) try: db_repo_ids = self._get_helm_chart_repos_ids(cluster_uuid) @@ -1235,7 +1226,6 @@ class K8sHelmBaseConnector(K8sConnector): encode_utf8: bool = False, env: dict = None, ) -> (str, int): - command = K8sHelmBaseConnector._remove_multiple_spaces(command) self.log.debug( "Executing async local command: {}, env: {}".format(command, env) @@ -1306,7 +1296,6 @@ class K8sHelmBaseConnector(K8sConnector): encode_utf8: bool = False, env: dict = None, ): - command1 = K8sHelmBaseConnector._remove_multiple_spaces(command1) command2 = K8sHelmBaseConnector._remove_multiple_spaces(command2) command = "{} | {}".format(command1, command2) @@ -1500,7 +1489,6 @@ class K8sHelmBaseConnector(K8sConnector): # params for use in -f file # returns values file option and filename (in order to delete it at the end) def _params_to_file_option(self, cluster_id: str, params: dict) -> (str, str): - if params and len(params) > 0: self._init_paths_env(cluster_name=cluster_id, create_if_not_exist=True) diff --git a/n2vc/k8s_helm_conn.py b/n2vc/k8s_helm_conn.py index b20ee87..c8c95ee 100644 --- a/n2vc/k8s_helm_conn.py +++ b/n2vc/k8s_helm_conn.py @@ -164,7 +164,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): return True async def inspect_kdu(self, kdu_model: str, repo_url: str = None) -> str: - self.log.debug( "inspect kdu_model {} from (optional) repo: {}".format(kdu_model, repo_url) ) @@ -235,7 +234,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): return paths, env async def _get_services(self, cluster_id, kdu_instance, namespace, kubeconfig): - # init config, env paths, env = self._init_paths_env( cluster_name=cluster_id, create_if_not_exist=True @@ -419,7 +417,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): self.log.debug("namespace not found") async def _instances_list(self, cluster_id): - # init paths, env paths, env = self._init_paths_env( cluster_name=cluster_id, create_if_not_exist=True @@ -458,7 +455,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): yaml_format: bool = False, show_error_log: bool = False, ) -> Union[str, dict]: - self.log.debug( "status of kdu_instance: {}, namespace: {} ".format(kdu_instance, namespace) ) @@ -595,7 +591,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): timeout, kubeconfig, ) -> str: - timeout_str = "" if timeout: timeout_str = "--timeout {}".format(timeout) @@ -641,7 +636,6 @@ class K8sHelmConnector(K8sHelmBaseConnector): timeout, kubeconfig, ) -> str: - timeout_str = "" if timeout: timeout_str = "--timeout {}".format(timeout) diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index 5e4bef3..9f73425 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -597,7 +597,6 @@ class Libjuju: application = self._get_application(model, application_name) if application is not None: - # Checks if the given machine id in the model, # otherwise function raises an error _machine, _series = self._get_machine_info(model, machine_id) @@ -752,7 +751,6 @@ class Libjuju: try: if application_name not in model.applications: - if machine_id is not None: machine, series = self._get_machine_info(model, machine_id) @@ -808,7 +806,6 @@ class Libjuju: return application async def resolve(self, model_name: str): - controller = await self.get_controller() model = await self.get_model(controller, model_name) all_units_active = False diff --git a/n2vc/loggable.py b/n2vc/loggable.py index d588a1d..cbaa116 100644 --- a/n2vc/loggable.py +++ b/n2vc/loggable.py @@ -31,7 +31,6 @@ import time class Loggable: def __init__(self, log, log_to_console: bool = False, prefix: str = ""): - self._last_log_time = None # used for time increment in logging self._log_to_console = log_to_console self._prefix = prefix @@ -93,7 +92,6 @@ class Loggable: include_thread: bool = False, include_coroutine: bool = True, ) -> str: - # time increment from last log now = time.perf_counter() if self._last_log_time is None: diff --git a/n2vc/n2vc_conn.py b/n2vc/n2vc_conn.py index 6b0df89..6f2e587 100644 --- a/n2vc/n2vc_conn.py +++ b/n2vc/n2vc_conn.py @@ -434,7 +434,6 @@ class N2VCConnector(abc.ABC, Loggable): # .format(str(status.value), detailed_status, vca_status, entity_type)) try: - the_table = db_dict["collection"] the_filter = db_dict["filter"] the_path = db_dict["path"] diff --git a/n2vc/n2vc_juju_conn.py b/n2vc/n2vc_juju_conn.py index c470b1b..943d70d 100644 --- a/n2vc/n2vc_juju_conn.py +++ b/n2vc/n2vc_juju_conn.py @@ -1136,7 +1136,6 @@ class N2VCJujuConnector(N2VCConnector): ) def _write_ee_id_db(self, db_dict: dict, ee_id: str): - # write ee_id to database: _admin.deployed.VCA.x try: the_table = db_dict["collection"] diff --git a/n2vc/tests/unit/test_k8s_helm3_conn.py b/n2vc/tests/unit/test_k8s_helm3_conn.py index cb4a1dc..7a76e7e 100644 --- a/n2vc/tests/unit/test_k8s_helm3_conn.py +++ b/n2vc/tests/unit/test_k8s_helm3_conn.py @@ -134,7 +134,6 @@ class TestK8sHelm3Conn(asynctest.TestCase): @asynctest.fail_on(active_handles=True) async def test_repo_list(self): - self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0)) await self.helm_conn.repo_list(self.cluster_uuid) @@ -150,7 +149,6 @@ class TestK8sHelm3Conn(asynctest.TestCase): @asynctest.fail_on(active_handles=True) async def test_repo_remove(self): - self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0)) repo_name = "bitnami" await self.helm_conn.repo_remove(self.cluster_uuid, repo_name) diff --git a/n2vc/tests/unit/test_libjuju.py b/n2vc/tests/unit/test_libjuju.py index f590057..c5f80cf 100644 --- a/n2vc/tests/unit/test_libjuju.py +++ b/n2vc/tests/unit/test_libjuju.py @@ -776,7 +776,6 @@ class ExecuteActionTest(LibjujuTestCase): mock_get_model, mock_get_controller, ): - mock_get_model.return_value = juju.model.Model() mock__get_application.return_value = FakeApplication() output = None @@ -1227,7 +1226,6 @@ class ConfigureApplicationTest(LibjujuTestCase): mock_get_model, mock_get_controller, ): - mock_get_application.return_value = FakeApplication() self.loop.run_until_complete( @@ -1249,7 +1247,6 @@ class ConfigureApplicationTest(LibjujuTestCase): mock_get_model, mock_get_controller, ): - mock_get_application.side_effect = Exception() with self.assertRaises(Exception): @@ -1271,7 +1268,6 @@ class ConfigureApplicationTest(LibjujuTestCase): mock_get_model, mock_get_controller, ): - result = {"error": "not found", "response": "response", "request-id": 1} mock_get_controller.side_effect = JujuAPIError(result) @@ -1296,7 +1292,6 @@ class ConfigureApplicationTest(LibjujuTestCase): mock_get_model, mock_get_controller, ): - result = {"error": "not found", "response": "response", "request-id": 1} mock_get_model.side_effect = JujuAPIError(result) diff --git a/n2vc/tests/unit/utils.py b/n2vc/tests/unit/utils.py index b2d5c60..807c892 100644 --- a/n2vc/tests/unit/utils.py +++ b/n2vc/tests/unit/utils.py @@ -130,7 +130,6 @@ class FakeManualMachine(MagicMock): class FakeWatcher(AsyncMock): - delta_to_return = None async def Next(self): -- 2.17.1