Skip to content

Commit e3e3719

Browse files
remove dead code
1 parent 2f5be65 commit e3e3719

File tree

1 file changed

+0
-261
lines changed

1 file changed

+0
-261
lines changed

test_elasticsearch/utils.py

Lines changed: 0 additions & 261 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,6 @@ def wipe_cluster_settings(client):
144144
client.cluster.put_settings(body=new_settings)
145145

146146

147-
def wipe_rollup_jobs(client):
148-
rollup_jobs = client.rollup.get_jobs(id="_all").get("jobs", ())
149-
for job in rollup_jobs:
150-
job_id = job["config"]["id"]
151-
client.options(ignore_status=404).rollup.stop_job(
152-
id=job_id, wait_for_completion=True
153-
)
154-
client.options(ignore_status=404).rollup.delete_job(id=job_id)
155-
156-
157147
def wipe_snapshots(client):
158148
"""Deletes all the snapshots and repositories from the cluster"""
159149
in_progress_snapshots = []
@@ -198,259 +188,8 @@ def wipe_indices(client):
198188
)
199189

200190

201-
def wipe_searchable_snapshot_indices(client):
202-
cluster_metadata = client.cluster.state(
203-
metric="metadata",
204-
filter_path="metadata.indices.*.settings.index.store.snapshot",
205-
)
206-
if cluster_metadata:
207-
for index in cluster_metadata["metadata"]["indices"].keys():
208-
client.indices.delete(index=index)
209-
210-
211-
def wipe_xpack_templates(client):
212-
# Delete index templates (including legacy)
213-
templates = [
214-
x.strip() for x in client.cat.templates(h="name").split("\n") if x.strip()
215-
]
216-
for template in templates:
217-
if is_xpack_template(template):
218-
continue
219-
try:
220-
client.indices.delete_template(name=template)
221-
except NotFoundError as e:
222-
if f"index_template [{template}] missing" in str(e):
223-
client.indices.delete_index_template(name=template)
224-
225-
# Delete component templates
226-
templates = client.cluster.get_component_template()["component_templates"]
227-
templates_to_delete = [
228-
template["name"]
229-
for template in templates
230-
if not is_xpack_template(template["name"])
231-
]
232-
if templates_to_delete:
233-
client.cluster.delete_component_template(name=",".join(templates_to_delete))
234-
235-
236-
def wipe_ilm_policies(client):
237-
for policy in client.ilm.get_lifecycle():
238-
if (
239-
policy
240-
not in {
241-
"ilm-history-ilm-policy",
242-
"slm-history-ilm-policy",
243-
"watch-history-ilm-policy",
244-
"watch-history-ilm-policy-16",
245-
"ml-size-based-ilm-policy",
246-
"logs",
247-
"metrics",
248-
"synthetics",
249-
"7-days-default",
250-
"30-days-default",
251-
"90-days-default",
252-
"180-days-default",
253-
"365-days-default",
254-
".fleet-actions-results-ilm-policy",
255-
".deprecation-indexing-ilm-policy",
256-
".monitoring-8-ilm-policy",
257-
}
258-
and "-history-ilm-polcy" not in policy
259-
and "-meta-ilm-policy" not in policy
260-
and "-data-ilm-policy" not in policy
261-
and "@lifecycle" not in policy
262-
):
263-
client.ilm.delete_lifecycle(name=policy)
264-
265-
266-
def wipe_slm_policies(client):
267-
policies = client.slm.get_lifecycle()
268-
for policy in policies:
269-
if policy not in {"cloud-snapshot-policy"}:
270-
client.slm.delete_lifecycle(policy_id=policy)
271-
272-
273-
def wipe_auto_follow_patterns(client):
274-
for pattern in client.ccr.get_auto_follow_pattern()["patterns"]:
275-
client.ccr.delete_auto_follow_pattern(name=pattern["name"])
276-
277-
278-
def wipe_node_shutdown_metadata(client):
279-
try:
280-
shutdown_status = client.shutdown.get_node()
281-
# If response contains these two keys the feature flag isn't enabled
282-
# on this cluster so skip this step now.
283-
if "_nodes" in shutdown_status and "cluster_name" in shutdown_status:
284-
return
285-
286-
for shutdown_node in shutdown_status.get("nodes", []):
287-
node_id = shutdown_node["node_id"]
288-
client.shutdown.delete_node(node_id=node_id)
289-
290-
# Elastic Cloud doesn't allow this so we skip.
291-
except AuthorizationException:
292-
pass
293-
294-
295-
def wipe_tasks(client):
296-
tasks = client.tasks.list()
297-
for node_name, node in tasks.get("node", {}).items():
298-
for task_id in node.get("tasks", ()):
299-
client.tasks.cancel(task_id=task_id, wait_for_completion=True)
300-
301-
302-
def wait_for_pending_tasks(client, filter, timeout=30):
303-
end_time = time.time() + timeout
304-
while time.time() < end_time:
305-
tasks = client.cat.tasks(detailed=True).split("\n")
306-
if not any(filter in task for task in tasks):
307-
break
308-
309-
310-
def wait_for_pending_datafeeds_and_jobs(client: Elasticsearch, timeout=30):
311-
end_time = time.time() + timeout
312-
while time.time() < end_time:
313-
resp = client.ml.get_datafeeds(datafeed_id="*", allow_no_match=True)
314-
if resp["count"] == 0:
315-
break
316-
for datafeed in resp["datafeeds"]:
317-
client.options(ignore_status=404).ml.delete_datafeed(
318-
datafeed_id=datafeed["datafeed_id"]
319-
)
320-
321-
end_time = time.time() + timeout
322-
while time.time() < end_time:
323-
resp = client.ml.get_jobs(job_id="*", allow_no_match=True)
324-
if resp["count"] == 0:
325-
break
326-
for job in resp["jobs"]:
327-
client.options(ignore_status=404).ml.close_job(job_id=job["job_id"])
328-
client.options(ignore_status=404).ml.delete_job(job_id=job["job_id"])
329-
330-
end_time = time.time() + timeout
331-
while time.time() < end_time:
332-
resp = client.ml.get_data_frame_analytics(id="*")
333-
if resp["count"] == 0:
334-
break
335-
for job in resp["data_frame_analytics"]:
336-
client.options(ignore_status=404).ml.stop_data_frame_analytics(id=job["id"])
337-
client.options(ignore_status=404).ml.delete_data_frame_analytics(
338-
id=job["id"]
339-
)
340-
341-
342-
def wipe_filters(client: Elasticsearch, timeout=30):
343-
end_time = time.time() + timeout
344-
while time.time() < end_time:
345-
resp = client.ml.get_filters(filter_id="*")
346-
if resp["count"] == 0:
347-
break
348-
for filter in resp["filters"]:
349-
client.options(ignore_status=404).ml.delete_filter(
350-
filter_id=filter["filter_id"]
351-
)
352-
353-
354-
def wipe_calendars(client: Elasticsearch, timeout=30):
355-
end_time = time.time() + timeout
356-
while time.time() < end_time:
357-
resp = client.ml.get_calendars(calendar_id="*")
358-
if resp["count"] == 0:
359-
break
360-
for calendar in resp["calendars"]:
361-
client.options(ignore_status=404).ml.delete_calendar(
362-
calendar_id=calendar["calendar_id"]
363-
)
364-
365-
366-
def wipe_transforms(client: Elasticsearch, timeout=30):
367-
end_time = time.time() + timeout
368-
while time.time() < end_time:
369-
resp = client.transform.get_transform(transform_id="*")
370-
if resp["count"] == 0:
371-
break
372-
for trasnform in resp["transforms"]:
373-
client.options(ignore_status=404).transform.stop_transform(
374-
transform_id=trasnform["id"]
375-
)
376-
client.options(ignore_status=404).transform.delete_transform(
377-
transform_id=trasnform["id"]
378-
)
379-
380-
381191
def wait_for_cluster_state_updates_to_finish(client, timeout=30):
382192
end_time = time.time() + timeout
383193
while time.time() < end_time:
384194
if not client.cluster.pending_tasks().get("tasks", ()):
385195
break
386-
387-
388-
def is_xpack_template(name):
389-
if name.startswith("."):
390-
return True
391-
elif name.startswith("behavioral_analytics-events"):
392-
return True
393-
elif name.startswith("elastic-connectors-"):
394-
return True
395-
elif name.startswith("entities_v1_"):
396-
return True
397-
elif name.endswith("@ilm"):
398-
return True
399-
elif name.endswith("@template"):
400-
return True
401-
402-
return name in {
403-
"agentless",
404-
"agentless@mappings",
405-
"agentless@settings",
406-
"apm-10d@lifecycle",
407-
"apm-180d@lifecycle",
408-
"apm-390d@lifecycle",
409-
"apm-90d@lifecycle",
410-
"apm@mappings",
411-
"apm@settings",
412-
"data-streams-mappings",
413-
"data-streams@mappings",
414-
"elastic-connectors",
415-
"ecs@dynamic_templates",
416-
"ecs@mappings",
417-
"ilm-history-7",
418-
"kibana-reporting@settings",
419-
"logs",
420-
"logs-apm.error@mappings",
421-
"logs-apm@settings",
422-
"logs-mappings",
423-
"logs@mappings",
424-
"logs-settings",
425-
"logs@settings",
426-
"metrics",
427-
"metrics-apm@mappings",
428-
"metrics-apm.service_destination@mappings",
429-
"metrics-apm.service_summary@mappings",
430-
"metrics-apm.service_transaction@mappings",
431-
"metrics-apm@settings",
432-
"metrics-apm.transaction@mappings",
433-
"metrics-mappings",
434-
"metrics@mappings",
435-
"metrics-settings",
436-
"metrics@settings",
437-
"metrics-tsdb-settings",
438-
"metrics@tsdb-settings",
439-
"search-acl-filter",
440-
"synthetics",
441-
"synthetics-mappings",
442-
"synthetics@mappings",
443-
"synthetics-settings",
444-
"synthetics@settings",
445-
"traces-apm@mappings",
446-
"traces-apm.rum@mappings",
447-
"traces@mappings",
448-
"traces@settings",
449-
# otel
450-
"metrics-otel@mappings",
451-
"semconv-resource-to-ecs@mappings",
452-
"traces-otel@mappings",
453-
"ecs-tsdb@mappings",
454-
"logs-otel@mappings",
455-
"otel@mappings",
456-
}

0 commit comments

Comments
 (0)