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
|
2022-10-09 20:01:59 +00:00
|
|
|
from neofs_testlib.hosting import Hosting
|
2022-10-13 16:13:45 +00:00
|
|
|
from neofs_testlib.shell import Shell
|
2022-08-01 06:16:36 +00:00
|
|
|
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,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
excluded_nodes: Optional[list[str]] = None,
|
|
|
|
) -> list[str]:
|
2022-08-01 06:16:36 +00:00
|
|
|
excluded_nodes = excluded_nodes or []
|
2022-10-13 16:13:45 +00:00
|
|
|
sleep_interval, attempts = 15, 20
|
2022-08-01 06:16:36 +00:00
|
|
|
nodes = []
|
|
|
|
for __attempt in range(attempts):
|
2022-10-13 18:53:44 +00:00
|
|
|
nodes = get_nodes_with_object(wallet, cid, oid, shell=shell, skip_nodes=excluded_nodes)
|
2022-10-21 14:53:54 +00:00
|
|
|
if len(nodes) >= expected_copies:
|
2022-08-01 06:16:36 +00:00
|
|
|
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-10-09 20:01:59 +00:00
|
|
|
def wait_all_storage_node_returned(hosting: Hosting) -> None:
|
2022-10-13 08:04:42 +00:00
|
|
|
sleep_interval, attempts = 15, 20
|
2022-08-01 06:16:36 +00:00
|
|
|
for __attempt in range(attempts):
|
2022-10-09 20:01:59 +00:00
|
|
|
if is_all_storage_node_returned(hosting):
|
2022-08-01 06:16:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2022-10-09 20:01:59 +00:00
|
|
|
def is_all_storage_node_returned(hosting: Hosting) -> 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:
|
2022-10-09 20:01:59 +00:00
|
|
|
health_check = node_healthcheck(hosting, node_name)
|
2022-08-01 06:16:36 +00:00
|
|
|
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
|