Skip to content

Commit

Permalink
Ignore HTTP 404 consistently in runners (#1691)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielmitterdorfer authored Mar 30, 2023
1 parent 07e4ce2 commit 53f6cc5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
8 changes: 4 additions & 4 deletions esrally/driver/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 8 additions & 6 deletions tests/driver/runner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand All @@ -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],
)


Expand Down

0 comments on commit 53f6cc5

Please sign in to comment.