2022-08-01 06:16:36 +00:00
|
|
|
import logging
|
|
|
|
from time import sleep
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import allure
|
|
|
|
from common import NEOFS_NETMAP_DICT
|
|
|
|
from python_keywords.node_management import node_healthcheck
|
|
|
|
from storage_policy import get_nodes_with_object
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Wait for object replication")
|
|
|
|
def wait_object_replication_on_nodes(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
expected_copies: int,
|
|
|
|
excluded_nodes: Optional[list[str]] = None,
|
|
|
|
) -> list[str]:
|
2022-08-01 06:16:36 +00:00
|
|
|
excluded_nodes = excluded_nodes or []
|
|
|
|
sleep_interval, attempts = 10, 18
|
|
|
|
nodes = []
|
|
|
|
for __attempt in range(attempts):
|
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid, skip_nodes=excluded_nodes)
|
|
|
|
if len(nodes) == expected_copies:
|
|
|
|
return nodes
|
|
|
|
sleep(sleep_interval)
|
2022-09-28 12:07:16 +00:00
|
|
|
raise AssertionError(
|
|
|
|
f"Expected {expected_copies} copies of object, but found {len(nodes)}. "
|
|
|
|
f"Waiting time {sleep_interval * attempts}"
|
|
|
|
)
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
@allure.step("Wait for storage node returned to cluster")
|
2022-08-01 06:16:36 +00:00
|
|
|
def wait_all_storage_node_returned():
|
|
|
|
sleep_interval, attempts = 10, 12
|
|
|
|
for __attempt in range(attempts):
|
|
|
|
if is_all_storage_node_returned():
|
|
|
|
return
|
|
|
|
sleep(sleep_interval)
|
2022-09-28 12:07:16 +00:00
|
|
|
raise AssertionError("Storage node(s) is broken")
|
2022-08-01 06:16:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_all_storage_node_returned() -> bool:
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step("Run health check for all storage nodes"):
|
2022-08-01 06:16:36 +00:00
|
|
|
for node_name in NEOFS_NETMAP_DICT.keys():
|
|
|
|
try:
|
|
|
|
health_check = node_healthcheck(node_name)
|
|
|
|
except Exception as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
logger.warning(f"Node healthcheck fails with error {err}")
|
2022-08-01 06:16:36 +00:00
|
|
|
return False
|
2022-09-28 12:07:16 +00:00
|
|
|
if health_check.health_status != "READY" or health_check.network_status != "ONLINE":
|
2022-08-01 06:16:36 +00:00
|
|
|
return False
|
|
|
|
return True
|