From 53f6cc598e78251628b0e7f78f181eddb3184126 Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Thu, 30 Mar 2023 07:41:47 +0200 Subject: [PATCH] Ignore HTTP 404 consistently in runners (#1691) Some runners that deleted resources have ignored HTTP 404 already but we did not apply this consistently. With this commit, all runners that delete resources ignore HTTP 404 to avoid spurious request errors. --- esrally/driver/runner.py | 8 ++++---- tests/driver/runner_test.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/esrally/driver/runner.py b/esrally/driver/runner.py index 1ae81e155..ad5e68edd 100644 --- a/esrally/driver/runner.py +++ b/esrally/driver/runner.py @@ -1396,7 +1396,7 @@ async def __call__(self, es, params): try: for index_name in indices: if not only_if_exists: - await es.indices.delete(index=index_name, params=request_params) + await es.indices.delete(index=index_name, ignore=[404], params=request_params) ops += 1 elif only_if_exists and await es.indices.exists(index=index_name): self.logger.info("Index [%s] already exists. Deleting it.", index_name) @@ -1602,7 +1602,7 @@ async def __call__(self, es, params): try: for template_name, delete_matching_indices, index_pattern in template_names: if not only_if_exists: - await es.indices.delete_template(name=template_name, params=request_params) + await es.indices.delete_template(name=template_name, ignore=[404], params=request_params) ops_count += 1 elif only_if_exists and await es.indices.exists_template(name=template_name): self.logger.info("Index template [%s] already exists. Deleting it.", template_name) @@ -1976,7 +1976,7 @@ class DeleteSnapshotRepository(Runner): """ async def __call__(self, es, params): - await es.snapshot.delete_repository(repository=mandatory(params, "repository", repr(self))) + await es.snapshot.delete_repository(repository=mandatory(params, "repository", repr(self)), ignore=[404]) def __repr__(self, *args, **kwargs): return "delete-snapshot-repository" @@ -2677,7 +2677,7 @@ async def __call__(self, es, params): timeout = request_params.get("timeout", None) await es.ilm.delete_lifecycle( - name=policy_name, error_trace=error_trace, filter_path=filter_path, master_timeout=master_timeout, timeout=timeout + name=policy_name, error_trace=error_trace, filter_path=filter_path, master_timeout=master_timeout, timeout=timeout, ignore=[404] ) return { "weight": 1, diff --git a/tests/driver/runner_test.py b/tests/driver/runner_test.py index fb94ce62e..05d756112 100644 --- a/tests/driver/runner_test.py +++ b/tests/driver/runner_test.py @@ -2782,8 +2782,8 @@ async def test_deletes_all_indices(self, es): ) es.indices.delete.assert_has_awaits( [ - mock.call(index="indexA", params=params["request-params"]), - mock.call(index="indexB", params=params["request-params"]), + mock.call(index="indexA", params=params["request-params"], ignore=[404]), + mock.call(index="indexB", params=params["request-params"], ignore=[404]), ] ) assert es.indices.exists.call_count == 0 @@ -2920,9 +2920,9 @@ async def test_deletes_all_index_templates(self, es): es.indices.delete_template.assert_has_awaits( [ - mock.call(name="templateA", params=params["request-params"]), - mock.call(name="templateB", params=params["request-params"]), - mock.call(name="templateC", params=params["request-params"]), + mock.call(name="templateA", ignore=[404], params=params["request-params"]), + mock.call(name="templateB", ignore=[404], params=params["request-params"]), + mock.call(name="templateC", ignore=[404], params=params["request-params"]), ] ) es.indices.delete.assert_has_awaits( @@ -3777,7 +3777,7 @@ async def test_delete_snapshot_repository(self, es): r = runner.DeleteSnapshotRepository() await r(es, params) - es.snapshot.delete_repository.assert_called_once_with(repository="backups") + es.snapshot.delete_repository.assert_called_once_with(repository="backups", ignore=[404]) class TestCreateSnapshotRepository: @@ -5222,6 +5222,7 @@ async def test_delete_ilm_policy_with_request_params(self, es): timeout=self.params["request-params"].get("timeout"), error_trace=None, filter_path=None, + ignore=[404], ) @mock.patch("elasticsearch.Elasticsearch") @@ -5244,6 +5245,7 @@ async def test_delete_ilm_policy_without_request_params(self, es): timeout=None, error_trace=None, filter_path=None, + ignore=[404], )