Files
scylladb/test/rest_api/rest_util.py
Benny Halevy e95ecbbea6 test: rest_api: storage_service: add test_storage_service_snapshot
Test the snapshot operations via the rest api.

Added test/rest_api/rest_util.py with
new_test_snapshot that creates a new test snapshot
and automagically deletes it when the `with` block
if exited, similar to new_test_keyspace and new_test_table.

Signed-off-by: Benny Halevy <bhalevy@scylladb.com>
2022-05-10 09:56:44 +03:00

33 lines
1.2 KiB
Python

import time
from contextlib import contextmanager
# A utility function for creating a new temporary snapshot.
# If no keyspaces are given, a snapshot is taken over all keyspaces and tables.
# If no tables are given, a snapshot is taken over all tables in the keyspace.
# If no tag is given, a unique tag will be computed using the current time, in milliseconds.
# It can be used in a "with", as:
# with new_test_snapshot(cql, tag, keyspace, [table(s)]) as snapshot:
# This is not a fixture - see those in conftest.py.
@contextmanager
def new_test_snapshot(rest_api, keyspaces=[], tables=[], tag=""):
if not tag:
tag = f"test_snapshot_{int(time.time() * 1000)}"
params = { "tag": tag }
if type(keyspaces) is str:
params["kn"] = keyspaces
else:
params["kn"] = ",".join(keyspaces)
if tables:
if type(tables) is str:
params["cf"] = tables
else:
params["cf"] = ",".join(tables)
resp = rest_api.send("POST", "storage_service/snapshots", params)
resp.raise_for_status()
try:
yield tag
finally:
resp = rest_api.send("DELETE", "storage_service/snapshots", params)
resp.raise_for_status()