Remove redundant variables

Small refactoring that includes:
 - Removed variables that are not used any more.
 - Cleanup in helper functions' names.

Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
Vladimir Domnich 2022-08-01 13:15:02 +03:00
parent 642af0a888
commit 47c55f0060
7 changed files with 77 additions and 66 deletions

View file

@ -3,11 +3,10 @@ from random import choice
from time import sleep
import allure
import base58
import pytest
from cli_helpers import _cmd_run
from data_formatters import get_wallet_public_key
from common import (COMPLEX_OBJ_SIZE, MAINNET_BLOCK_TIME, NEOFS_CONTRACT_CACHE_TIMEOUT,
NEOFS_NETMAP_DICT, NEOGO_CLI_EXEC)
NEOFS_NETMAP_DICT, STORAGE_WALLET_PASS)
from epoch import tick_epoch
from python_keywords.container import create_container, get_container
from python_keywords.neofs_verbs import (delete_object, get_object,
@ -82,9 +81,14 @@ def test_nodes_management(prepare_tmp_dir):
random_node = choice(list(NEOFS_NETMAP_DICT))
alive_node = choice([node for node in NEOFS_NETMAP_DICT if node != random_node])
# Calculate public key that identifies node in netmap
# Calculate public key that identifies node in netmap (we need base58-formatted key
# because keys of storage nodes are base58-encoded in netmap)
random_node_wallet_path = NEOFS_NETMAP_DICT[random_node]['wallet_path']
random_node_netmap_key = get_netmap_public_key_from_wallet(random_node_wallet_path)
random_node_netmap_key = get_wallet_public_key(
random_node_wallet_path,
STORAGE_WALLET_PASS,
format="base58"
)
with allure.step('Check node {random_node} is in netmap'):
snapshot = get_netmap_snapshot(node_name=alive_node)
@ -298,7 +302,7 @@ def validate_object_copies(wallet: str, placement_rule: str, file_path: str, exp
@allure.step('Wait for node {node_name} goes online')
def wait_for_node_go_online(node_name: str):
def wait_for_node_go_online(node_name: str) -> None:
timeout, attempts = 5, 20
for _ in range(attempts):
try:
@ -313,7 +317,8 @@ def wait_for_node_go_online(node_name: str):
@allure.step('Wait for {expected_copies} object copies in the wallet')
def wait_for_expected_object_copies(wallet: str, cid: str, oid: str, expected_copies: int = 2):
def wait_for_expected_object_copies(wallet: str, cid: str, oid: str,
expected_copies: int = 2) -> None:
for i in range(2):
copies = get_simple_object_copies(wallet, cid, oid)
if copies == expected_copies:
@ -325,7 +330,7 @@ def wait_for_expected_object_copies(wallet: str, cid: str, oid: str, expected_co
@allure.step('Wait for object to be dropped')
def wait_for_obj_dropped(wallet: str, cid: str, oid: str, checker):
def wait_for_obj_dropped(wallet: str, cid: str, oid: str, checker) -> None:
for _ in range(3):
try:
checker(wallet, cid, oid)
@ -335,14 +340,3 @@ def wait_for_obj_dropped(wallet: str, cid: str, oid: str, checker):
break
else:
raise AssertionError(f'Object {oid} is not dropped from node')
def get_netmap_public_key_from_wallet(wallet_path: str) -> str:
# Get public key from wallet file (it is printed on 2nd line)
cmd = f"{NEOGO_CLI_EXEC} wallet dump-keys -w {wallet_path}"
output = _cmd_run(cmd)
public_key_hex = output.split("\n")[1].strip()
# Encode public key in base58 (this is how it is present in netmap)
public_key_base58 = base58.b58encode(bytes.fromhex(public_key_hex))
return public_key_base58.decode("utf-8")