Fix node management tests
Remote connection was created to the 1st storage node only. While in reality we want to create connection to a specific node. Signed-off-by: Vladimir Domnich <v.domnich@yadro.com>
This commit is contained in:
parent
68cbb7deea
commit
be39480ade
5 changed files with 99 additions and 99 deletions
|
@ -7,11 +7,12 @@
|
|||
|
||||
import random
|
||||
import re
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
|
||||
import docker
|
||||
from common import NEOFS_NETMAP_DICT, STORAGE_NODE_BIN_PATH, STORAGE_NODE_CONFIG_PATH
|
||||
from common import NEOFS_NETMAP_DICT, STORAGE_NODE_BIN_PATH, STORAGE_NODE_CONFIG_PATH, STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT, STORAGE_NODE_PWD, STORAGE_NODE_USER
|
||||
from robot.api import logger
|
||||
from robot.api.deco import keyword
|
||||
from ssh_helper import HostClient
|
||||
|
@ -35,8 +36,23 @@ class HealthStatus:
|
|||
return HealthStatus(network, health)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def create_ssh_client(node_name: str) -> HostClient:
|
||||
if node_name not in NEOFS_NETMAP_DICT:
|
||||
raise AssertionError(f'Node {node_name} is not found!')
|
||||
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
host = node_config.get('control').split(':')[0]
|
||||
ssh_client = HostClient(host, STORAGE_NODE_USER, STORAGE_NODE_PWD)
|
||||
|
||||
try:
|
||||
yield ssh_client
|
||||
finally:
|
||||
ssh_client.drop()
|
||||
|
||||
|
||||
@keyword('Stop Nodes')
|
||||
def stop_nodes(number: int, nodes: list):
|
||||
def stop_nodes(number: int, nodes: list) -> None:
|
||||
"""
|
||||
The function shuts down the given number of randomly
|
||||
selected nodes in docker.
|
||||
|
@ -55,7 +71,7 @@ def stop_nodes(number: int, nodes: list):
|
|||
|
||||
|
||||
@keyword('Start Nodes')
|
||||
def start_nodes(nodes: list):
|
||||
def start_nodes(nodes: list) -> None:
|
||||
"""
|
||||
The function raises the given nodes.
|
||||
Args:
|
||||
|
@ -106,12 +122,11 @@ def get_locode():
|
|||
|
||||
|
||||
@keyword('Stop Nodes Remote')
|
||||
def stop_nodes_remote(client: HostClient, number: int, nodes: list):
|
||||
def stop_nodes_remote(number: int, nodes: list) -> None:
|
||||
"""
|
||||
The function shuts down the given number of randomly
|
||||
selected nodes in docker.
|
||||
Args:
|
||||
client (HostClient): client that implements exec command
|
||||
number (int): the number of nodes to shut down
|
||||
nodes (list): the list of nodes for possible shut down
|
||||
Returns:
|
||||
|
@ -120,137 +135,123 @@ def stop_nodes_remote(client: HostClient, number: int, nodes: list):
|
|||
nodes = random.sample(nodes, number)
|
||||
for node in nodes:
|
||||
node = node.split('.')[0]
|
||||
client.exec(f'docker stop {node}')
|
||||
with create_ssh_client(node) as ssh_client:
|
||||
ssh_client.exec(f'docker stop {node}')
|
||||
return nodes
|
||||
|
||||
|
||||
@keyword('Start Nodes Remote')
|
||||
def start_nodes_remote(client: HostClient, nodes: list):
|
||||
def start_nodes_remote(nodes: list) -> None:
|
||||
"""
|
||||
The function starts nodes in docker.
|
||||
Args:
|
||||
client (HostClient): client that implements exec command
|
||||
nodes (list): the list of nodes for possible shut down
|
||||
"""
|
||||
for node in nodes:
|
||||
node = node.split('.')[0]
|
||||
client.exec(f'docker start {node}')
|
||||
with create_ssh_client(node) as ssh_client:
|
||||
ssh_client.exec(f'docker start {node}')
|
||||
|
||||
|
||||
@keyword('Healthcheck for node')
|
||||
def node_healthcheck(client: HostClient, node_name: str) -> HealthStatus:
|
||||
def node_healthcheck(node_name: str) -> HealthStatus:
|
||||
"""
|
||||
The function returns node's health status.
|
||||
Args:
|
||||
client HostClient: client that implements exec command.
|
||||
node_name str: node name to use for netmap snapshot operation
|
||||
Returns:
|
||||
health status as HealthStatus object.
|
||||
"""
|
||||
if node_name not in NEOFS_NETMAP_DICT:
|
||||
raise AssertionError(f'Node {node_name} is not found!')
|
||||
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
control_url = node_config.get('control')
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control healthcheck --endpoint {control_url} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH}'
|
||||
output = client.exec_with_confirmation(cmd, [''])
|
||||
return HealthStatus.from_stdout(output.stdout)
|
||||
with create_ssh_client(node_name) as ssh_client:
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control healthcheck ' \
|
||||
f'--endpoint {STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH}'
|
||||
output = ssh_client.exec_with_confirmation(cmd, [''])
|
||||
return HealthStatus.from_stdout(output.stdout)
|
||||
|
||||
|
||||
@keyword('Set status for node')
|
||||
def node_set_status(client: HostClient, node_name: str, status: str):
|
||||
def node_set_status(node_name: str, status: str):
|
||||
"""
|
||||
The function sets particular status for given node.
|
||||
Args:
|
||||
client HostClient: client that implements exec command.
|
||||
node_name str: node name to use for netmap snapshot operation
|
||||
status str: online or offline.
|
||||
Returns:
|
||||
(void)
|
||||
"""
|
||||
if node_name not in NEOFS_NETMAP_DICT:
|
||||
raise AssertionError(f'Node {node_name} is not found!')
|
||||
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
control_url = node_config.get('control')
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control set-status --endpoint {control_url} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH} --status {status}'
|
||||
client.exec_with_confirmation(cmd, [''])
|
||||
with create_ssh_client(node_name) as ssh_client:
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control set-status ' \
|
||||
f'--endpoint {STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH} --status {status}'
|
||||
ssh_client.exec_with_confirmation(cmd, [''])
|
||||
|
||||
|
||||
@keyword('Get netmap snapshot')
|
||||
def get_netmap_snapshot(client: HostClient, node_name: str = None) -> str:
|
||||
def get_netmap_snapshot(node_name: str = None) -> str:
|
||||
"""
|
||||
The function returns string representation of netmap-snapshot.
|
||||
Args:
|
||||
client HostClient: client that implements exec command.
|
||||
node_name str: node name to use for netmap snapshot operation
|
||||
Returns:
|
||||
string representation of netmap-snapshot
|
||||
"""
|
||||
node_name = node_name or list(NEOFS_NETMAP_DICT)[0]
|
||||
|
||||
if node_name not in NEOFS_NETMAP_DICT:
|
||||
raise AssertionError(f'Node {node_name} is not found!')
|
||||
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
control_url = node_config.get('control')
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control netmap-snapshot --endpoint {control_url} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH}'
|
||||
output = client.exec_with_confirmation(cmd, [''])
|
||||
return output.stdout
|
||||
with create_ssh_client(node_name) as ssh_client:
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control netmap-snapshot ' \
|
||||
f'--endpoint {STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH}'
|
||||
output = ssh_client.exec_with_confirmation(cmd, [''])
|
||||
return output.stdout
|
||||
|
||||
|
||||
@keyword('Shard list for node')
|
||||
def node_shard_list(client: HostClient, node_name: str) -> List[str]:
|
||||
def node_shard_list(node_name: str) -> List[str]:
|
||||
"""
|
||||
The function returns list of shards for particular node.
|
||||
Args:
|
||||
client HostClient: client that implements exec command.
|
||||
node_name str: node name to use for netmap snapshot operation
|
||||
Returns:
|
||||
list of shards.
|
||||
"""
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
control_url = node_config.get('control')
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control shards list --endpoint {control_url} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH}'
|
||||
output = client.exec_with_confirmation(cmd, [''])
|
||||
return re.findall(r'Shard (.*):', output.stdout)
|
||||
with create_ssh_client(node_name) as ssh_client:
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control shards list ' \
|
||||
f'--endpoint {STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH}'
|
||||
output = ssh_client.exec_with_confirmation(cmd, [''])
|
||||
return re.findall(r'Shard (.*):', output.stdout)
|
||||
|
||||
|
||||
@keyword('Shard list for node')
|
||||
def node_shard_set_mode(client: HostClient, node_name: str, shard: str, mode: str) -> str:
|
||||
def node_shard_set_mode(node_name: str, shard: str, mode: str) -> str:
|
||||
"""
|
||||
The function sets mode for node's particular shard.
|
||||
Args:
|
||||
client HostClient: client that implements exec command.
|
||||
node_name str: node name to use for netmap snapshot operation
|
||||
Returns:
|
||||
health status as HealthStatus object.
|
||||
"""
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
control_url = node_config.get('control')
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control shards set-mode --endpoint {control_url} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH} --id {shard} --mode {mode}'
|
||||
output = client.exec_with_confirmation(cmd, [''])
|
||||
return output.stdout
|
||||
with create_ssh_client(node_name) as ssh_client:
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control shards set-mode ' \
|
||||
f'--endpoint {STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH} --id {shard} --mode {mode}'
|
||||
output = ssh_client.exec_with_confirmation(cmd, [''])
|
||||
return output.stdout
|
||||
|
||||
|
||||
@keyword('Drop object from node {node_name}')
|
||||
def drop_object(client: HostClient, node_name: str, cid: str, oid: str) -> str:
|
||||
def drop_object(node_name: str, cid: str, oid: str) -> str:
|
||||
"""
|
||||
The function drops object from particular node.
|
||||
Args:
|
||||
client HostClient: client that implements exec command.
|
||||
node_name str: node name to use for netmap snapshot operation
|
||||
Returns:
|
||||
health status as HealthStatus object.
|
||||
"""
|
||||
node_config = NEOFS_NETMAP_DICT.get(node_name)
|
||||
control_url = node_config.get('control')
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control drop-objects --endpoint {control_url} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH} -o {cid}/{oid}'
|
||||
output = client.exec_with_confirmation(cmd, [''])
|
||||
return output.stdout
|
||||
with create_ssh_client(node_name) as ssh_client:
|
||||
cmd = f'{STORAGE_NODE_BIN_PATH}/neofs-cli control drop-objects ' \
|
||||
f'--endpoint {STORAGE_NODE_PRIVATE_CONTROL_ENDPOINT} ' \
|
||||
f'--config {STORAGE_NODE_CONFIG_PATH} -o {cid}/{oid}'
|
||||
output = ssh_client.exec_with_confirmation(cmd, [''])
|
||||
return output.stdout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue