From 0d86352cbed4c188988925881eebc8cef7c54cca Mon Sep 17 00:00:00 2001 From: Elizaveta Chichindaeva Date: Mon, 10 Jan 2022 14:02:57 +0300 Subject: [PATCH] [#163] Setup and Teardown restart dev-env Signed-off-by: Elizaveta Chichindaeva --- README.md | 6 ++-- robot/resources/lib/python/cli_helpers.py | 4 +-- .../resources/lib/python/utility_keywords.py | 35 ++++++++++++++++--- .../resources/lib/robot/setup_teardown.robot | 3 ++ .../integration/services/http_gate.robot | 5 ++- .../integration/services/s3_gate_bucket.robot | 4 ++- .../integration/services/s3_gate_object.robot | 5 ++- 7 files changed, 49 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6b9b9ee..5b278a8 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,8 @@ Test cases are designed to run on Python 3.8. ## Run -Execute `./run.sh` script. It will run all the tests available in this repo. To run an arbitrary UserScenario or testcase(s), you need to run the command: -`./run.sh robot/testsuites/integration/` or `./run.sh robot/testsuites/integration//.robot` - -Logs will be saved in the artifacts/ directory after tests with any of the statuses are completed. +To run an arbitrary UserScenario or testcase, you need to run the command: +`robot --outputdir artifacts/ robot/testsuites/integration/` or `robot --outputdir artifacts/ robot/testsuites/integration//.robot` The following UserScenarios and testcases are available for execution: diff --git a/robot/resources/lib/python/cli_helpers.py b/robot/resources/lib/python/cli_helpers.py index a18ee3d..3bf1e1b 100644 --- a/robot/resources/lib/python/cli_helpers.py +++ b/robot/resources/lib/python/cli_helpers.py @@ -13,14 +13,14 @@ from robot.api import logger ROBOT_AUTO_KEYWORDS = False -def _cmd_run(cmd): +def _cmd_run(cmd, timeout=30): """ Runs given shell command , in case of success returns its stdout, in case of failure returns error message. """ try: compl_proc = subprocess.run(cmd, check=True, universal_newlines=True, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=30, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=timeout, shell=True) output = compl_proc.stdout logger.info(f"Output: {output}") diff --git a/robot/resources/lib/python/utility_keywords.py b/robot/resources/lib/python/utility_keywords.py index b311ef3..b45e2c4 100644 --- a/robot/resources/lib/python/utility_keywords.py +++ b/robot/resources/lib/python/utility_keywords.py @@ -1,16 +1,17 @@ #!/usr/bin/python3.8 -import docker import os import tarfile import uuid +import docker from neo3 import wallet from robot.api.deco import keyword from robot.api import logger from robot.libraries.BuiltIn import BuiltIn - from common import * +from cli_helpers import _cmd_run + ROBOT_AUTO_KEYWORDS = False @@ -48,6 +49,32 @@ def get_container_logs(testcase_name: str) -> None: def wif_to_binary(wif: str) -> str: priv_key = wallet.Account.private_key_from_wif(wif) path = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" - with open(path, "wb") as f: - f.write(priv_key) + with open(path, "wb") as out: + out.write(priv_key) return path + +@keyword('Make Up') +def make_up(services=['']): + test_path = os.getcwd() + dev_path = os.getenv('DEVENV_PATH', '../neofs-dev-env') + os.chdir(dev_path) + + if services != ['']: + for service in services: + cmd = f'make up/{service}' + _cmd_run(cmd, timeout=80) + else: + cmd = f'make up/basic; make update.max_object_size val={SIMPLE_OBJ_SIZE}' + _cmd_run(cmd, timeout=80) + + os.chdir(test_path) + +@keyword('Make Down') +def make_down(): + test_path = os.getcwd() + dev_path = os.getenv('DEVENV_PATH', '../neofs-dev-env') + os.chdir(dev_path) + + cmd = 'make down; make clean' + _cmd_run(cmd) + os.chdir(test_path) diff --git a/robot/resources/lib/robot/setup_teardown.robot b/robot/resources/lib/robot/setup_teardown.robot index 1268e3c..7ee9529 100644 --- a/robot/resources/lib/robot/setup_teardown.robot +++ b/robot/resources/lib/robot/setup_teardown.robot @@ -7,9 +7,12 @@ Library utility_keywords.py *** Keywords *** Setup + [Arguments] + Make Up Create Directory ${ASSETS_DIR} Teardown [Arguments] ${LOGFILE} Remove Directory ${ASSETS_DIR} True Get Docker Logs ${LOGFILE} + Make Down diff --git a/robot/testsuites/integration/services/http_gate.robot b/robot/testsuites/integration/services/http_gate.robot index 52a5ea3..2a6fdb8 100644 --- a/robot/testsuites/integration/services/http_gate.robot +++ b/robot/testsuites/integration/services/http_gate.robot @@ -7,6 +7,7 @@ Library payment_neogo.py Library gates.py Library wallet_keywords.py Library rpc_call_keywords.py +Library utility_keywords.py Resource payment_operations.robot Resource setup_teardown.robot @@ -16,6 +17,7 @@ ${PLACEMENT_RULE} = REP 1 IN X CBF 1 SELECT 1 FROM * AS X ${TRANSFER_AMOUNT} = ${6} ${DEPOSIT_AMOUNT} = ${5} ${CONTAINER_WAIT_INTERVAL} = 1 min +@{INCLUDE_SVC} = http_gate *** Test cases *** @@ -23,7 +25,8 @@ NeoFS HTTP Gateway [Documentation] Creates container and does PUT, GET via HTTP Gate [Timeout] 5 min - [Setup] Setup + [Setup] Setup + Make Up ${INCLUDE_SVC} ${WALLET} ${ADDR} ${WIF} = Prepare Wallet And Deposit diff --git a/robot/testsuites/integration/services/s3_gate_bucket.robot b/robot/testsuites/integration/services/s3_gate_bucket.robot index 25b85c5..17a5a48 100644 --- a/robot/testsuites/integration/services/s3_gate_bucket.robot +++ b/robot/testsuites/integration/services/s3_gate_bucket.robot @@ -16,13 +16,15 @@ Resource payment_operations.robot ${DEPOSIT} = ${30} ${WIF} = ${MAINNET_WALLET_WIF} ${DEPOSIT_TIMEOUT}= 30s +@{INCLUDE_SVC} = s3_gate *** Test cases *** Buckets in NeoFS S3 Gateway [Documentation] Execute operations with bucket via S3 Gate [Timeout] 10 min - [Setup] Setup + [Setup] Setup + Make Up ${INCLUDE_SVC} ${WALLET} ${ADDR} ${WIF} = Prepare Wallet And Deposit ${FILE_S3} = Generate file of bytes ${COMPLEX_OBJ_SIZE} diff --git a/robot/testsuites/integration/services/s3_gate_object.robot b/robot/testsuites/integration/services/s3_gate_object.robot index 1c397cc..057cd17 100644 --- a/robot/testsuites/integration/services/s3_gate_object.robot +++ b/robot/testsuites/integration/services/s3_gate_object.robot @@ -7,12 +7,14 @@ Library payment_neogo.py Library gates.py Library wallet_keywords.py Library contract_keywords.py +Library utility_keywords.py Resource setup_teardown.robot *** Variables *** ${DEPOSIT_AMOUNT} = ${5} ${WIF} = ${MAINNET_WALLET_WIF} +@{INCLUDE_SVC} = s3_gate *** Test cases *** Objects in NeoFS S3 Gateway @@ -20,7 +22,8 @@ Objects in NeoFS S3 Gateway [Documentation] Execute operations with objects via S3 Gate [Timeout] 10 min - [Setup] Setup + [Setup] Setup + Make Up ${INCLUDE_SVC} ${WALLET} ${ADDR} = Init Wallet from WIF ${ASSETS_DIR} ${WIF} ${TX_DEPOSIT} = NeoFS Deposit ${WIF} ${DEPOSIT_AMOUNT}