From 04e03c0149139c6b5b5dfdccf415f85c2f1f4c0b Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Thu, 8 Aug 2024 20:54:49 +0000 Subject: [PATCH] Before all tests refresh and delete indices Signed-off-by: Peter Nied --- .../console_link/console_link/middleware/clusters.py | 12 ++++++++++-- .../lib/integ_test/integ_test/replayer_tests.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/middleware/clusters.py b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/middleware/clusters.py index c72f5cc35..2cd4a89ba 100644 --- a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/middleware/clusters.py +++ b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/console_link/console_link/middleware/clusters.py @@ -57,6 +57,14 @@ def run_test_benchmarks(cluster: Cluster): # As a default we exclude system indices and searchguard indices def clear_indices(cluster: Cluster): + try: + cluster.call_api("/_refresh", method=HttpMethod.POST, params={"ignore_unavailable": "true"}) + except Exception as e: + logging.debug(f"Ignoring error received when attempting to refresh indexes: {e}") + clear_indices_path = "/*,-.*,-searchguard*,-sg7*,.migrations_working_state" - r = cluster.call_api(clear_indices_path, method=HttpMethod.DELETE, params={"ignore_unavailable": "true"}) - return r.content + try: + r = cluster.call_api(clear_indices_path, method=HttpMethod.DELETE, params={"ignore_unavailable": "true"}) + return r.content + except Exception as e: + logging.debug(f"Ignoring error recieved when attempting to delete indexes: {e}") diff --git a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/integ_test/integ_test/replayer_tests.py b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/integ_test/integ_test/replayer_tests.py index 450a318c1..dca2f1652 100644 --- a/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/integ_test/integ_test/replayer_tests.py +++ b/TrafficCapture/dockerSolution/src/main/docker/migrationConsole/lib/integ_test/integ_test/replayer_tests.py @@ -54,6 +54,17 @@ def setup_replayer(request): wait_for_running_replayer(replayer=replayer) +@pytest.fixture(scope="function", autouse=True) +def clear_cluster(): + logger.info("Clearing out all cluster contents") + + source_cluster: Cluster = pytest.console_env.source_cluster + target_cluster: Cluster = pytest.console_env.target_cluster + + clear_indices(source_cluster) + clear_indices(target_cluster) + + @pytest.fixture(scope="session", autouse=True) def cleanup_after_tests(): # Setup code @@ -94,7 +105,6 @@ def test_replayer_0001_empty_index(self): get_index(cluster=target_cluster, index_name=index_name, expected_status_code=HTTPStatus.NOT_FOUND, test_case=self) - @unittest.skip("Flaky test - https://opensearch.atlassian.net/browse/MIGRATIONS-1925") def test_replayer_0002_single_document(self): # This test will verify that a document will be created (then deleted) on the target cluster when one is created # on the source cluster by going through the proxy first. It will verify that the traffic is captured by the