2022-07-08 17:24:55 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2022-07-07 18:48:47 +00:00
|
|
|
from epoch import tick_epoch
|
2022-09-28 12:07:16 +00:00
|
|
|
from python_keywords.container import (
|
|
|
|
create_container,
|
|
|
|
delete_container,
|
|
|
|
get_container,
|
|
|
|
list_containers,
|
|
|
|
wait_for_container_creation,
|
|
|
|
wait_for_container_deletion,
|
|
|
|
)
|
2022-07-08 17:24:55 +00:00
|
|
|
from utility import placement_policy_from_container
|
2022-08-12 07:23:23 +00:00
|
|
|
from wellknown_acl import PRIVATE_ACL_F
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@pytest.mark.parametrize("name", ["", "test-container"], ids=["No name", "Set particular name"])
|
2022-07-08 17:24:55 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.container
|
|
|
|
def test_container_creation(prepare_wallet_and_deposit, name):
|
2022-09-28 12:07:16 +00:00
|
|
|
scenario_title = f"with name {name}" if name else "without name"
|
|
|
|
allure.dynamic.title(f"User can create container {scenario_title}")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-08-12 07:23:23 +00:00
|
|
|
wallet = prepare_wallet_and_deposit
|
|
|
|
with open(wallet) as file:
|
|
|
|
json_wallet = json.load(file)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
placement_rule = "REP 2 IN X CBF 1 SELECT 2 FROM * AS X"
|
2022-08-19 02:22:20 +00:00
|
|
|
cid = create_container(wallet, rule=placement_rule, name=name)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
containers = list_containers(wallet)
|
2022-09-28 12:07:16 +00:00
|
|
|
assert cid in containers, f"Expected container {cid} in containers: {containers}"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-08-19 02:22:20 +00:00
|
|
|
container_info: str = get_container(wallet, cid, json_mode=False)
|
2022-08-25 10:57:55 +00:00
|
|
|
container_info = container_info.casefold() # To ignore case when comparing with expected values
|
2022-08-12 07:23:23 +00:00
|
|
|
|
|
|
|
info_to_check = {
|
2022-09-28 12:07:16 +00:00
|
|
|
f"basic ACL: {PRIVATE_ACL_F} (private)",
|
|
|
|
f"owner ID: {json_wallet.get('accounts')[0].get('address')}",
|
|
|
|
f"container ID: {cid}",
|
2022-08-12 07:23:23 +00:00
|
|
|
}
|
|
|
|
if name:
|
2022-09-28 12:07:16 +00:00
|
|
|
info_to_check.add(f"Name={name}")
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Check container has correct information"):
|
2022-08-12 16:44:10 +00:00
|
|
|
expected_policy = placement_rule.casefold()
|
2022-08-12 07:23:23 +00:00
|
|
|
actual_policy = placement_policy_from_container(container_info)
|
2022-09-28 12:07:16 +00:00
|
|
|
assert (
|
|
|
|
actual_policy == expected_policy
|
|
|
|
), f"Expected policy\n{expected_policy} but got policy\n{actual_policy}"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
for info in info_to_check:
|
2022-08-12 16:44:10 +00:00
|
|
|
expected_info = info.casefold()
|
2022-09-28 12:07:16 +00:00
|
|
|
assert (
|
|
|
|
expected_info in container_info
|
|
|
|
), f"Expected {expected_info} in container info:\n{container_info}"
|
2022-07-08 17:24:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Delete container and check it was deleted"):
|
2022-07-08 17:24:55 +00:00
|
|
|
delete_container(wallet, cid)
|
|
|
|
tick_epoch()
|
|
|
|
wait_for_container_deletion(wallet, cid)
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.title("Parallel container creation and deletion")
|
2022-08-19 02:22:20 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.container
|
|
|
|
def test_container_creation_deletion_parallel(prepare_wallet_and_deposit):
|
|
|
|
containers_count = 3
|
|
|
|
wallet = prepare_wallet_and_deposit
|
2022-09-28 12:07:16 +00:00
|
|
|
placement_rule = "REP 2 IN X CBF 1 SELECT 2 FROM * AS X"
|
2022-08-19 02:22:20 +00:00
|
|
|
|
|
|
|
cids: list[str] = []
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Create {containers_count} containers"):
|
2022-08-19 02:22:20 +00:00
|
|
|
for _ in range(containers_count):
|
2022-09-28 12:07:16 +00:00
|
|
|
cids.append(
|
|
|
|
create_container(
|
|
|
|
wallet, rule=placement_rule, await_mode=False, wait_for_creation=False
|
|
|
|
)
|
|
|
|
)
|
2022-08-19 02:22:20 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Wait for containers occur in container list"):
|
2022-08-19 02:22:20 +00:00
|
|
|
for cid in cids:
|
|
|
|
wait_for_container_creation(wallet, cid, sleep_interval=containers_count)
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Delete containers and check they were deleted"):
|
2022-08-19 02:22:20 +00:00
|
|
|
for cid in cids:
|
|
|
|
delete_container(wallet, cid)
|
|
|
|
tick_epoch()
|
|
|
|
wait_for_container_deletion(wallet, cid)
|