From a3e95c9b5b7757078186441dc012aec91ec368fb Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Tue, 31 Oct 2023 17:34:58 +0800 Subject: [PATCH] refactor(negative): consolidate engine validation Signed-off-by: Chin-Ya Huang --- e2e/libs/engine/crd.py | 20 ++++++++++---------- e2e/libs/engine/engine.py | 11 +---------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/e2e/libs/engine/crd.py b/e2e/libs/engine/crd.py index 8ab7f1e372..4af52eea84 100644 --- a/e2e/libs/engine/crd.py +++ b/e2e/libs/engine/crd.py @@ -29,7 +29,15 @@ def get_engine(self, volume_name, node_name): plural="engines", label_selector=",".join(label_selector) ) - return api_response + + if api_response == "" or api_response is None: + raise Exception(f"failed to get the volume {volume_name} engine") + + engines = api_response["items"] + if len(engines) == 0: + logging.warning(f"cannot get the volume {volume_name} engines") + + return engines def delete_engine(self, volume_name, node_name): if volume_name == "" or node_name == "": @@ -38,15 +46,7 @@ def delete_engine(self, volume_name, node_name): logging.info( f"delete the volume {volume_name} on node {node_name} engine") - resp = self.get_engine(volume_name, node_name) - assert resp != "", "failed to get engines" - - engines = resp['items'] - if len(engines) == 0: - logging.warning("cannot find engines") - return - - for engine in engines: + for engine in self.get_engine(volume_name, node_name): engine_name = engine['metadata']['name'] self.obj_api.delete_namespaced_custom_object( group="longhorn.io", diff --git a/e2e/libs/engine/engine.py b/e2e/libs/engine/engine.py index 3c4bc2cf9f..fe3b6cfc51 100644 --- a/e2e/libs/engine/engine.py +++ b/e2e/libs/engine/engine.py @@ -24,17 +24,8 @@ def delete_engine(self, volume_name="", node_name=""): def get_engine_state(self, volume_name, node_name): logging(f"Getting the volume {volume_name} engine on the node {node_name} state") - resp = self.get_engine(volume_name, node_name) - if resp == "" or resp is None: - raise Exception(f"failed to get the volume {volume_name} engine") - - engines = resp["items"] - if len(engines) == 0: - logging.warning(f"cannot get the volume {volume_name} engines") - return - engines_states = {} - for engine in engines: + for engine in self.engine.get_engine(volume_name, node_name): engine_name = engine["metadata"]["name"] engine_state = engine['status']['currentState'] engines_states[engine_name] = engine_state