From 5f53e80f932dfa1f0dcbd3e012f9d6fe5c91de7d Mon Sep 17 00:00:00 2001 From: Vladimir Domnich Date: Thu, 28 Jul 2022 08:35:50 +0300 Subject: [PATCH] Fixes in tests to enable them to run in a cloud environment Few small fixes were made: - Fix path to binaries on storage node in cloud env. - Add logic to prepend ssh command with sudo. - Make re-encoding of homomorphic hash conditional. - Increase ssh timeout. Signed-off-by: Vladimir Domnich --- Makefile | 1 + pytest_tests/helpers/ssh_helper.py | 10 +++++++--- robot/resources/lib/python_keywords/epoch.py | 9 +++++++-- .../lib/python_keywords/json_transformers.py | 20 ++++++++++--------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 029d148..990ddbd 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ DEV_IMAGE_PY ?= registry.spb.yadro.com/tools/pytest-neofs-x86_64:7 SETUP_DIR ?= $(CURDIR)/.setup DEV_ENV_DEPLOY_DIR ?= /opt/dev-env +DOCKER_NETWORK = --network host ifeq ($(shell uname -s),Darwin) DOCKER_NETWORK = --network bridge -p 389:389 -p 636:636 endif diff --git a/pytest_tests/helpers/ssh_helper.py b/pytest_tests/helpers/ssh_helper.py index 0536b6f..dad4c94 100644 --- a/pytest_tests/helpers/ssh_helper.py +++ b/pytest_tests/helpers/ssh_helper.py @@ -61,7 +61,7 @@ class SSHCommand: class HostClient: ssh_client: SSHClient SSH_CONNECTION_ATTEMPTS: ClassVar[int] = 3 - CONNECTION_TIMEOUT = 30 + CONNECTION_TIMEOUT = 90 TIMEOUT_RESTORE_CONNECTION = 10, 24 @@ -74,14 +74,16 @@ class HostClient: if init_ssh_client: self.create_connection(self.SSH_CONNECTION_ATTEMPTS) - def exec(self, cmd: str, verify=True, timeout=30) -> SSHCommand: + def exec(self, cmd: str, verify=True, timeout=90) -> SSHCommand: cmd_result = self._inner_exec(cmd, timeout) if verify: assert cmd_result.rc == 0, f'Non zero rc from command: "{cmd}"' return cmd_result @log_command - def exec_with_confirmation(self, cmd: str, confirmation: list, verify=True, timeout=10) -> SSHCommand: + def exec_with_confirmation(self, cmd: str, confirmation: list, verify=True, timeout=90) -> SSHCommand: + if self.login != "root": + cmd = f"sudo {cmd}" ssh_stdin, ssh_stdout, ssh_stderr = self.ssh_client.exec_command(cmd, timeout=timeout) for line in confirmation: if not line.endswith('\n'): @@ -195,6 +197,8 @@ class HostClient: def _inner_exec(self, cmd: str, timeout: int) -> SSHCommand: if not self.ssh_client: self.create_connection() + if self.login != "root": + cmd = f"sudo {cmd}" for _ in range(self.SSH_CONNECTION_ATTEMPTS): try: _, stdout, stderr = self.ssh_client.exec_command(cmd, timeout=timeout) diff --git a/robot/resources/lib/python_keywords/epoch.py b/robot/resources/lib/python_keywords/epoch.py index c8a2e61..33e9e59 100644 --- a/robot/resources/lib/python_keywords/epoch.py +++ b/robot/resources/lib/python_keywords/epoch.py @@ -28,8 +28,13 @@ def tick_epoch(): # If neofs-adm is available, then we tick epoch with it (to be consistent with UAT tests) cmd = f"{NEOFS_ADM_EXEC} morph force-new-epoch -c {NEOFS_ADM_CONFIG_PATH}" logger.info(f"Executing shell command: {cmd}") - out = wrappers.run_sh(cmd) - logger.info(f"Command completed with output: {out}") + try: + out = wrappers.run_sh(cmd) + logger.info(f"Command completed with output: {out}") + except Exception as exc: + logger.error(exc) + raise RuntimeError("Failed to tick epoch") from exc + return # Otherwise we tick epoch using transaction diff --git a/robot/resources/lib/python_keywords/json_transformers.py b/robot/resources/lib/python_keywords/json_transformers.py index 218d9fd..fafc136 100644 --- a/robot/resources/lib/python_keywords/json_transformers.py +++ b/robot/resources/lib/python_keywords/json_transformers.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/python3.9 """ When doing requests to NeoFS, we get JSON output as an automatically decoded @@ -144,13 +144,15 @@ def decode_common_fields(data: dict): header contains several common fields. This function rearranges these fields. """ - # reencoding binary IDs data["objectID"] = json_reencode(data["objectID"]["value"]) - data["header"]["containerID"] = json_reencode(data["header"]["containerID"]["value"]) - data["header"]["ownerID"] = json_reencode(data["header"]["ownerID"]["value"]) - data["header"]["homomorphicHash"] = json_reencode(data["header"]["homomorphicHash"]["sum"]) - data["header"]["payloadHash"] = json_reencode(data["header"]["payloadHash"]["sum"]) - data["header"]["version"] = ( - f"{data['header']['version']['major']}{data['header']['version']['minor']}" - ) + + header = data["header"] + header["containerID"] = json_reencode(header["containerID"]["value"]) + header["ownerID"] = json_reencode(header["ownerID"]["value"]) + header["payloadHash"] = json_reencode(header["payloadHash"]["sum"]) + header["version"] = f"{header['version']['major']}{header['version']['minor']}" + # Homomorphic hash is optional and its calculation might be disabled in trusted network + if header.get("homomorphicHash"): + header["homomorphicHash"] = json_reencode(header["homomorphicHash"]["sum"]) + return data