forked from TrueCloudLab/frostfs-testlib
[#133] Change reporter usage
Signed-off-by: Andrey Berezin <a.berezin@yadro.com>
This commit is contained in:
parent
39a17f3634
commit
dc6b0e407f
37 changed files with 478 additions and 678 deletions
|
@ -19,10 +19,9 @@ from typing import Dict, List, TypedDict, Union
|
|||
|
||||
import pexpect
|
||||
|
||||
from frostfs_testlib.reporter import get_reporter
|
||||
from frostfs_testlib import reporter
|
||||
from frostfs_testlib.storage.dataclasses.storage_object_info import NodeNetmapInfo
|
||||
|
||||
reporter = get_reporter()
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
COLOR_GREEN = "\033[92m"
|
||||
COLOR_OFF = "\033[0m"
|
||||
|
@ -65,9 +64,7 @@ def _configure_aws_cli(cmd: str, key_id: str, access_key: str, out_format: str =
|
|||
return cmd.decode()
|
||||
|
||||
|
||||
def _attach_allure_log(
|
||||
cmd: str, output: str, return_code: int, start_time: datetime, end_time: datetime
|
||||
) -> None:
|
||||
def _attach_allure_log(cmd: str, output: str, return_code: int, start_time: datetime, end_time: datetime) -> None:
|
||||
command_attachment = (
|
||||
f"COMMAND: '{cmd}'\n"
|
||||
f"OUTPUT:\n {output}\n"
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
import logging
|
||||
import re
|
||||
|
||||
from frostfs_testlib.reporter import get_reporter
|
||||
from frostfs_testlib import reporter
|
||||
|
||||
reporter = get_reporter()
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
|
||||
|
||||
@reporter.step_deco("Read environment.properties")
|
||||
@reporter.step("Read environment.properties")
|
||||
def read_env_properties(file_path: str) -> dict:
|
||||
with open(file_path, "r") as file:
|
||||
raw_content = file.read()
|
||||
|
@ -23,7 +22,7 @@ def read_env_properties(file_path: str) -> dict:
|
|||
return env_properties
|
||||
|
||||
|
||||
@reporter.step_deco("Update data in environment.properties")
|
||||
@reporter.step("Update data in environment.properties")
|
||||
def save_env_properties(file_path: str, env_data: dict) -> None:
|
||||
with open(file_path, "a+") as env_file:
|
||||
for env, env_value in env_data.items():
|
||||
|
|
|
@ -3,7 +3,7 @@ from dataclasses import dataclass
|
|||
from time import sleep
|
||||
from typing import Optional
|
||||
|
||||
from frostfs_testlib.reporter import get_reporter
|
||||
from frostfs_testlib import reporter
|
||||
from frostfs_testlib.resources.common import SERVICE_MAX_STARTUP_TIME
|
||||
from frostfs_testlib.shell import Shell
|
||||
from frostfs_testlib.steps.cli.object import neo_go_dump_keys
|
||||
|
@ -15,12 +15,10 @@ from frostfs_testlib.storage.dataclasses.node_base import ServiceClass
|
|||
from frostfs_testlib.testing.test_control import wait_for_success
|
||||
from frostfs_testlib.utils.datetime_utils import parse_time
|
||||
|
||||
reporter = get_reporter()
|
||||
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
|
||||
|
||||
@reporter.step_deco("Check and return status of given service")
|
||||
@reporter.step("Check and return status of given service")
|
||||
def service_status(service: str, shell: Shell) -> str:
|
||||
return shell.exec(f"sudo systemctl is-active {service}").stdout.rstrip()
|
||||
|
||||
|
@ -73,14 +71,14 @@ class TopCommand:
|
|||
)
|
||||
|
||||
|
||||
@reporter.step_deco("Run `top` command with specified PID")
|
||||
@reporter.step("Run `top` command with specified PID")
|
||||
def service_status_top(service: str, shell: Shell) -> TopCommand:
|
||||
pid = service_pid(service, shell)
|
||||
output = shell.exec(f"sudo top -b -n 1 -p {pid}").stdout
|
||||
return TopCommand.from_stdout(output, pid)
|
||||
|
||||
|
||||
@reporter.step_deco("Restart service n times with sleep")
|
||||
@reporter.step("Restart service n times with sleep")
|
||||
def multiple_restart(
|
||||
service_type: type[NodeBase],
|
||||
node: ClusterNode,
|
||||
|
@ -95,8 +93,7 @@ def multiple_restart(
|
|||
sleep(sleep_interval)
|
||||
|
||||
|
||||
@reporter.step_deco("Get status of list of services and check expected status")
|
||||
@wait_for_success(60, 5)
|
||||
@wait_for_success(60, 5, title="Wait for services become {expected_status} on node {cluster_node}")
|
||||
def check_services_status(cluster_node: ClusterNode, service_list: list[ServiceClass], expected_status: str):
|
||||
cmd = ""
|
||||
for service in service_list:
|
||||
|
@ -112,8 +109,7 @@ def check_services_status(cluster_node: ClusterNode, service_list: list[ServiceC
|
|||
), f"Requested status={expected_status} not found in requested services={service_list}, list of statuses={result}"
|
||||
|
||||
|
||||
@reporter.step_deco("Wait for active status of passed service")
|
||||
@wait_for_success(60, 5)
|
||||
@wait_for_success(60, 5, title="Wait for {service} become active")
|
||||
def wait_service_in_desired_state(service: str, shell: Shell, expected_status: Optional[str] = "active"):
|
||||
real_status = service_status(service=service, shell=shell)
|
||||
assert (
|
||||
|
@ -121,8 +117,7 @@ def wait_service_in_desired_state(service: str, shell: Shell, expected_status: O
|
|||
), f"Service {service}: expected status= {expected_status}, real status {real_status}"
|
||||
|
||||
|
||||
@reporter.step_deco("Run healthcheck against passed service")
|
||||
@wait_for_success(parse_time(SERVICE_MAX_STARTUP_TIME), 1)
|
||||
@wait_for_success(parse_time(SERVICE_MAX_STARTUP_TIME), 1, title="Wait for {service_type} passes healtcheck on {node}")
|
||||
def service_type_healthcheck(
|
||||
service_type: type[NodeBase],
|
||||
node: ClusterNode,
|
||||
|
@ -133,26 +128,25 @@ def service_type_healthcheck(
|
|||
), f"Healthcheck failed for {service.get_service_systemctl_name()}, IP={node.host_ip}"
|
||||
|
||||
|
||||
@reporter.step_deco("Kill by process name")
|
||||
@reporter.step("Kill by process name")
|
||||
def kill_by_service_name(service_type: type[NodeBase], node: ClusterNode):
|
||||
service_systemctl_name = node.service(service_type).get_service_systemctl_name()
|
||||
pid = service_pid(service_systemctl_name, node.host.get_shell())
|
||||
node.host.get_shell().exec(f"sudo kill -9 {pid}")
|
||||
|
||||
|
||||
@reporter.step_deco("Service {service} suspend")
|
||||
@reporter.step("Suspend {service}")
|
||||
def suspend_service(shell: Shell, service: str):
|
||||
shell.exec(f"sudo kill -STOP {service_pid(service, shell)}")
|
||||
|
||||
|
||||
@reporter.step_deco("Service {service} resume")
|
||||
@reporter.step("Resume {service}")
|
||||
def resume_service(shell: Shell, service: str):
|
||||
shell.exec(f"sudo kill -CONT {service_pid(service, shell)}")
|
||||
|
||||
|
||||
@reporter.step_deco("Retrieve service's pid")
|
||||
# retry mechanism cause when the task has been started recently '0' PID could be returned
|
||||
@wait_for_success(10, 1)
|
||||
@wait_for_success(10, 1, title="Get {service} pid")
|
||||
def service_pid(service: str, shell: Shell) -> int:
|
||||
output = shell.exec(f"systemctl show --property MainPID {service}").stdout.rstrip()
|
||||
splitted = output.split("=")
|
||||
|
@ -161,7 +155,7 @@ def service_pid(service: str, shell: Shell) -> int:
|
|||
return PID
|
||||
|
||||
|
||||
@reporter.step_deco("Wrapper for neo-go dump keys command")
|
||||
@reporter.step("Wrapper for neo-go dump keys command")
|
||||
def dump_keys(shell: Shell, node: ClusterNode) -> dict:
|
||||
host = node.host
|
||||
service_config = host.get_service_config(node.service(MorphChain).name)
|
||||
|
@ -169,7 +163,7 @@ def dump_keys(shell: Shell, node: ClusterNode) -> dict:
|
|||
return neo_go_dump_keys(shell=shell, wallet=wallet)
|
||||
|
||||
|
||||
@reporter.step_deco("Wait for object replication")
|
||||
@reporter.step("Wait for object replication")
|
||||
def wait_object_replication(
|
||||
cid: str,
|
||||
oid: str,
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
from frostfs_testlib.reporter import get_reporter
|
||||
from frostfs_testlib import reporter
|
||||
from frostfs_testlib.storage.dataclasses.node_base import NodeBase
|
||||
|
||||
reporter = get_reporter()
|
||||
|
||||
|
||||
class FileKeeper:
|
||||
"""This class is responsible to make backup copy of modified file and restore when required (mostly after the test)"""
|
||||
|
||||
files_to_restore: dict[NodeBase, list[str]] = {}
|
||||
|
||||
@reporter.step_deco("Adding {file_to_restore} from node {node} to restore list")
|
||||
@reporter.step("Adding {file_to_restore} from node {node} to restore list")
|
||||
def add(self, node: NodeBase, file_to_restore: str):
|
||||
if node in self.files_to_restore and file_to_restore in self.files_to_restore[node]:
|
||||
# Already added
|
||||
|
@ -26,7 +24,7 @@ class FileKeeper:
|
|||
shell = node.host.get_shell()
|
||||
shell.exec(f"cp {file_to_restore} {file_to_restore}.bak")
|
||||
|
||||
@reporter.step_deco("Restore files")
|
||||
@reporter.step("Restore files")
|
||||
def restore_files(self):
|
||||
nodes = self.files_to_restore.keys()
|
||||
if not nodes:
|
||||
|
@ -41,7 +39,7 @@ class FileKeeper:
|
|||
# Iterate through results for exception check if any
|
||||
pass
|
||||
|
||||
@reporter.step_deco("Restore files on node {node}")
|
||||
@reporter.step("Restore files on node {node}")
|
||||
def _restore_files_on_node(self, node: NodeBase):
|
||||
shell = node.host.get_shell()
|
||||
for file_to_restore in self.files_to_restore[node]:
|
||||
|
|
|
@ -4,10 +4,9 @@ import os
|
|||
import uuid
|
||||
from typing import Any, Optional
|
||||
|
||||
from frostfs_testlib.reporter import get_reporter
|
||||
from frostfs_testlib import reporter
|
||||
from frostfs_testlib.resources.common import ASSETS_DIR
|
||||
|
||||
reporter = get_reporter()
|
||||
logger = logging.getLogger("NeoLogger")
|
||||
|
||||
|
||||
|
@ -61,7 +60,7 @@ def generate_file_with_content(
|
|||
return file_path
|
||||
|
||||
|
||||
@reporter.step_deco("Get File Hash")
|
||||
@reporter.step("Get File Hash")
|
||||
def get_file_hash(file_path: str, len: Optional[int] = None, offset: Optional[int] = None) -> str:
|
||||
"""Generates hash for the specified file.
|
||||
|
||||
|
@ -88,7 +87,7 @@ def get_file_hash(file_path: str, len: Optional[int] = None, offset: Optional[in
|
|||
return file_hash.hexdigest()
|
||||
|
||||
|
||||
@reporter.step_deco("Concatenation set of files to one file")
|
||||
@reporter.step("Concatenation set of files to one file")
|
||||
def concat_files(file_paths: list, resulting_file_path: Optional[str] = None) -> str:
|
||||
"""Concatenates several files into a single file.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue