2022-07-14 07:33:45 +00:00
|
|
|
#!/usr/bin/python3.9
|
2022-05-26 13:40:18 +00:00
|
|
|
|
|
|
|
"""
|
2022-07-26 19:44:05 +00:00
|
|
|
This module contains keywords for tests that check management of storage nodes.
|
2022-05-26 13:40:18 +00:00
|
|
|
"""
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import logging
|
2022-05-26 13:40:18 +00:00
|
|
|
import random
|
2022-07-08 17:24:55 +00:00
|
|
|
import re
|
2022-08-04 21:03:06 +00:00
|
|
|
import time
|
2022-07-08 17:24:55 +00:00
|
|
|
from dataclasses import dataclass
|
2022-07-14 07:33:45 +00:00
|
|
|
from typing import Optional
|
2022-05-26 13:40:18 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
import allure
|
2022-09-23 11:09:41 +00:00
|
|
|
from common import MORPH_BLOCK_TIME, NEOFS_NETMAP_DICT, STORAGE_WALLET_PASS
|
2022-08-04 21:03:06 +00:00
|
|
|
from data_formatters import get_wallet_public_key
|
|
|
|
from epoch import tick_epoch
|
2022-07-26 19:44:05 +00:00
|
|
|
from service_helper import get_storage_service_helper
|
2022-09-23 11:09:41 +00:00
|
|
|
from utility import parse_time
|
2022-05-26 13:40:18 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
logger = logging.getLogger("NeoLogger")
|
2022-05-26 13:40:18 +00:00
|
|
|
|
2022-06-09 13:08:11 +00:00
|
|
|
|
2022-07-08 17:24:55 +00:00
|
|
|
@dataclass
|
|
|
|
class HealthStatus:
|
|
|
|
network_status: str = None
|
|
|
|
health_status: str = None
|
|
|
|
|
|
|
|
@staticmethod
|
2022-09-20 15:03:52 +00:00
|
|
|
def from_stdout(output: str) -> "HealthStatus":
|
2022-07-08 17:24:55 +00:00
|
|
|
network, health = None, None
|
2022-09-20 15:03:52 +00:00
|
|
|
for line in output.split("\n"):
|
|
|
|
if "Network status" in line:
|
|
|
|
network = line.split(":")[-1].strip()
|
|
|
|
if "Health status" in line:
|
|
|
|
health = line.split(":")[-1].strip()
|
2022-07-08 17:24:55 +00:00
|
|
|
return HealthStatus(network, health)
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Stop Nodes")
|
2022-07-14 07:20:39 +00:00
|
|
|
def stop_nodes(number: int, nodes: list) -> list:
|
2022-05-26 13:40:18 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function shuts down the given number of randomly
|
|
|
|
selected nodes in docker.
|
|
|
|
Args:
|
|
|
|
number (int): the number of nodes to shut down
|
|
|
|
nodes (list): the list of nodes for possible shut down
|
|
|
|
Returns:
|
|
|
|
(list): the list of nodes which have been shut down
|
2022-05-26 13:40:18 +00:00
|
|
|
"""
|
2022-07-26 19:44:05 +00:00
|
|
|
helper = get_storage_service_helper()
|
|
|
|
nodes_to_stop = random.sample(nodes, number)
|
|
|
|
for node in nodes_to_stop:
|
|
|
|
helper.stop_node(node)
|
|
|
|
return nodes_to_stop
|
2022-05-26 13:40:18 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Start Nodes")
|
2022-07-07 18:48:47 +00:00
|
|
|
def start_nodes(nodes: list) -> None:
|
2022-05-26 13:40:18 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function raises the given nodes.
|
|
|
|
Args:
|
|
|
|
nodes (list): the list of nodes to raise
|
|
|
|
Returns:
|
|
|
|
(void)
|
2022-05-26 13:40:18 +00:00
|
|
|
"""
|
2022-07-26 19:44:05 +00:00
|
|
|
helper = get_storage_service_helper()
|
2022-05-26 13:40:18 +00:00
|
|
|
for node in nodes:
|
2022-07-26 19:44:05 +00:00
|
|
|
helper.start(node)
|
2022-07-05 21:35:32 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get control endpoint and wallet")
|
|
|
|
def get_control_endpoint_and_wallet(endpoint_number: str = ""):
|
2022-07-05 21:35:32 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
Gets control endpoint for a random or given node
|
2022-07-05 21:35:32 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
Args:
|
|
|
|
endpoint_number (optional, str): the number of the node
|
|
|
|
in the form of 's01', 's02', etc.
|
|
|
|
given in NEOFS_NETMAP_DICT as keys
|
|
|
|
Returns:
|
|
|
|
(str): the number of the node
|
|
|
|
(str): endpoint control for the node
|
|
|
|
(str): the wallet of the respective node
|
2022-07-05 21:35:32 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
if endpoint_number == "":
|
2022-07-05 21:35:32 +00:00
|
|
|
endpoint_num = random.choice(list(NEOFS_NETMAP_DICT.keys()))
|
2022-09-20 15:03:52 +00:00
|
|
|
logger.info(f"Random node chosen: {endpoint_num}")
|
2022-07-05 21:35:32 +00:00
|
|
|
else:
|
|
|
|
endpoint_num = endpoint_number
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
endpoint_values = NEOFS_NETMAP_DICT[f"{endpoint_num}"]
|
|
|
|
endpoint_control = endpoint_values["control"]
|
|
|
|
wallet = endpoint_values["wallet_path"]
|
2022-07-05 21:35:32 +00:00
|
|
|
|
2022-07-14 07:33:45 +00:00
|
|
|
return endpoint_num, endpoint_control, wallet
|
2022-07-05 21:35:32 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get Locode")
|
2022-07-05 21:35:32 +00:00
|
|
|
def get_locode():
|
|
|
|
endpoint_values = random.choice(list(NEOFS_NETMAP_DICT.values()))
|
2022-09-20 15:03:52 +00:00
|
|
|
locode = endpoint_values["UN-LOCODE"]
|
|
|
|
logger.info(f"Random locode chosen: {locode}")
|
2022-07-05 21:35:32 +00:00
|
|
|
|
|
|
|
return locode
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Healthcheck for node")
|
2022-07-07 18:48:47 +00:00
|
|
|
def node_healthcheck(node_name: str) -> HealthStatus:
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function returns node's health status.
|
|
|
|
Args:
|
|
|
|
node_name str: node name to use for netmap snapshot operation
|
|
|
|
Returns:
|
|
|
|
health status as HealthStatus object.
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-07-14 07:33:45 +00:00
|
|
|
command = "control healthcheck"
|
2022-07-26 19:44:05 +00:00
|
|
|
output = _run_control_command(node_name, command)
|
2022-07-14 07:33:45 +00:00
|
|
|
return HealthStatus.from_stdout(output)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Set status for node")
|
2022-07-26 19:44:05 +00:00
|
|
|
def node_set_status(node_name: str, status: str, retries: int = 0) -> None:
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function sets particular status for given node.
|
|
|
|
Args:
|
|
|
|
node_name str: node name to use for netmap snapshot operation
|
|
|
|
status str: online or offline.
|
|
|
|
retries (optional, int): number of retry attempts if it didn't work from the first time
|
|
|
|
Returns:
|
|
|
|
(void)
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-07-14 07:33:45 +00:00
|
|
|
command = f"control set-status --status {status}"
|
2022-07-26 19:44:05 +00:00
|
|
|
_run_control_command(node_name, command, retries)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Get netmap snapshot")
|
2022-07-14 07:33:45 +00:00
|
|
|
def get_netmap_snapshot(node_name: Optional[str] = None) -> str:
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function returns string representation of netmap-snapshot.
|
|
|
|
Args:
|
|
|
|
node_name str: node name to use for netmap snapshot operation
|
|
|
|
Returns:
|
|
|
|
string representation of netmap-snapshot
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
|
|
|
node_name = node_name or list(NEOFS_NETMAP_DICT)[0]
|
2022-07-14 07:33:45 +00:00
|
|
|
command = "control netmap-snapshot"
|
2022-07-26 19:44:05 +00:00
|
|
|
return _run_control_command(node_name, command)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Shard list for node")
|
2022-07-14 07:33:45 +00:00
|
|
|
def node_shard_list(node_name: str) -> list[str]:
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function returns list of shards for particular node.
|
|
|
|
Args:
|
|
|
|
node_name str: node name to use for netmap snapshot operation
|
|
|
|
Returns:
|
|
|
|
list of shards.
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-07-14 07:33:45 +00:00
|
|
|
command = "control shards list"
|
2022-07-26 19:44:05 +00:00
|
|
|
output = _run_control_command(node_name, command)
|
2022-09-20 15:03:52 +00:00
|
|
|
return re.findall(r"Shard (.*):", output)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Shard list for node")
|
2022-07-07 18:48:47 +00:00
|
|
|
def node_shard_set_mode(node_name: str, shard: str, mode: str) -> str:
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function sets mode for node's particular shard.
|
|
|
|
Args:
|
|
|
|
node_name str: node name to use for netmap snapshot operation
|
|
|
|
Returns:
|
|
|
|
health status as HealthStatus object.
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-07-14 07:33:45 +00:00
|
|
|
command = f"control shards set-mode --id {shard} --mode {mode}"
|
2022-07-26 19:44:05 +00:00
|
|
|
return _run_control_command(node_name, command)
|
2022-07-08 17:24:55 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Drop object from node {node_name}")
|
2022-07-07 18:48:47 +00:00
|
|
|
def drop_object(node_name: str, cid: str, oid: str) -> str:
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-09-20 15:03:52 +00:00
|
|
|
The function drops object from particular node.
|
|
|
|
Args:
|
|
|
|
node_name str: node name to use for netmap snapshot operation
|
|
|
|
Returns:
|
|
|
|
health status as HealthStatus object.
|
2022-07-08 17:24:55 +00:00
|
|
|
"""
|
2022-07-14 07:33:45 +00:00
|
|
|
command = f"control drop-objects -o {cid}/{oid}"
|
2022-07-26 19:44:05 +00:00
|
|
|
return _run_control_command(node_name, command)
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Delete data of node {node_name}")
|
2022-08-08 07:56:04 +00:00
|
|
|
def delete_node_data(node_name: str) -> None:
|
2022-08-04 21:03:06 +00:00
|
|
|
helper = get_storage_service_helper()
|
2022-08-15 14:40:04 +00:00
|
|
|
helper.stop_node(node_name)
|
2022-08-08 07:56:04 +00:00
|
|
|
helper.delete_node_data(node_name)
|
2022-09-23 11:09:41 +00:00
|
|
|
time.sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-08-04 21:03:06 +00:00
|
|
|
|
|
|
|
|
2022-09-23 14:45:44 +00:00
|
|
|
@allure.step("Exclude node {node_to_exclude} from network map")
|
2022-08-04 21:03:06 +00:00
|
|
|
def exclude_node_from_network_map(node_to_exclude, alive_node):
|
2022-09-20 15:03:52 +00:00
|
|
|
node_wallet_path = NEOFS_NETMAP_DICT[node_to_exclude]["wallet_path"]
|
|
|
|
node_netmap_key = get_wallet_public_key(node_wallet_path, STORAGE_WALLET_PASS, format="base58")
|
2022-08-04 21:03:06 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
node_set_status(node_to_exclude, status="offline")
|
2022-08-04 21:03:06 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
time.sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-08-04 21:03:06 +00:00
|
|
|
tick_epoch()
|
|
|
|
|
|
|
|
snapshot = get_netmap_snapshot(node_name=alive_node)
|
2022-09-20 15:03:52 +00:00
|
|
|
assert (
|
|
|
|
node_netmap_key not in snapshot
|
|
|
|
), f"Expected node with key {node_netmap_key} not in network map"
|
2022-08-04 21:03:06 +00:00
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Include node {node_to_include} into network map")
|
2022-08-04 21:03:06 +00:00
|
|
|
def include_node_to_network_map(node_to_include: str, alive_node: str) -> None:
|
2022-09-20 15:03:52 +00:00
|
|
|
node_set_status(node_to_include, status="online")
|
2022-08-04 21:03:06 +00:00
|
|
|
|
2022-09-23 11:09:41 +00:00
|
|
|
time.sleep(parse_time(MORPH_BLOCK_TIME))
|
2022-08-04 21:03:06 +00:00
|
|
|
tick_epoch()
|
|
|
|
|
|
|
|
check_node_in_map(node_to_include, alive_node)
|
|
|
|
|
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
@allure.step("Check node {node_name} in network map")
|
2022-08-04 21:03:06 +00:00
|
|
|
def check_node_in_map(node_name: str, alive_node: str = None):
|
|
|
|
alive_node = alive_node or node_name
|
2022-09-20 15:03:52 +00:00
|
|
|
node_wallet_path = NEOFS_NETMAP_DICT[node_name]["wallet_path"]
|
|
|
|
node_netmap_key = get_wallet_public_key(node_wallet_path, STORAGE_WALLET_PASS, format="base58")
|
2022-08-04 21:03:06 +00:00
|
|
|
|
2022-09-20 15:03:52 +00:00
|
|
|
logger.info(f"Node {node_name} netmap key: {node_netmap_key}")
|
2022-08-04 21:03:06 +00:00
|
|
|
|
|
|
|
snapshot = get_netmap_snapshot(node_name=alive_node)
|
2022-09-20 15:03:52 +00:00
|
|
|
assert node_netmap_key in snapshot, f"Expected node with key {node_netmap_key} in network map"
|
2022-08-04 21:03:06 +00:00
|
|
|
|
|
|
|
|
2022-07-26 19:44:05 +00:00
|
|
|
def _run_control_command(node_name: str, command: str, retries: int = 0) -> str:
|
|
|
|
helper = get_storage_service_helper()
|
|
|
|
for attempt in range(1 + retries): # original attempt + specified retries
|
|
|
|
try:
|
|
|
|
return helper.run_control_command(node_name, command)
|
|
|
|
except AssertionError as err:
|
|
|
|
if attempt < retries:
|
2022-09-20 15:03:52 +00:00
|
|
|
logger.warning(f"Command {command} failed with error {err} and will be retried")
|
2022-07-26 19:44:05 +00:00
|
|
|
continue
|
2022-09-20 15:03:52 +00:00
|
|
|
raise AssertionError(f"Command {command} failed with error {err}") from err
|