diff --git a/robot/resources/lib/python/utility_keywords.py b/robot/resources/lib/python/utility_keywords.py index 4a490b42..da9fbd23 100644 --- a/robot/resources/lib/python/utility_keywords.py +++ b/robot/resources/lib/python/utility_keywords.py @@ -3,14 +3,14 @@ import os import tarfile import uuid +import hashlib import docker -from neo3 import wallet from common import SIMPLE_OBJ_SIZE, ASSETS_DIR +from cli_helpers import _cmd_run from robot.api.deco import keyword from robot.api import logger from robot.libraries.BuiltIn import BuiltIn -from cli_helpers import _cmd_run ROBOT_AUTO_KEYWORDS = False @@ -22,12 +22,32 @@ def generate_file_of_bytes(size: str) -> str: :param size: the size in bytes, can be declared as 6e+6 for example """ size = int(float(size)) - filename = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" + filename = f"{os.getcwd()}/{ASSETS_DIR}/{uuid.uuid4()}" with open(filename, 'wb') as fout: fout.write(os.urandom(size)) logger.info(f"file with size {size} bytes has been generated: {filename}") return filename +@keyword('Generate file') +def generate_file_and_file_hash(size: str) -> str: + """ + Function generates a big binary file with the specified size in bytes and its hash. + Args: + size (str): the size in bytes, can be declared as 6e+6 for example + Returns: + (str): the path to the generated file + (str): the hash of the generated file + """ + size = int(float(size)) + filename = f"{os.getcwd()}/{ASSETS_DIR}/{str(uuid.uuid4())}" + with open(filename, 'wb') as fout: + fout.write(os.urandom(size)) + logger.info(f"file with size {size} bytes has been generated: {filename}") + + file_hash = _get_file_hash(filename) + + return filename, file_hash + @keyword('Get Docker Logs') def get_container_logs(testcase_name: str) -> None: client = docker.APIClient(base_url='unix://var/run/docker.sock') @@ -80,5 +100,14 @@ def make_down(services: list=[]): else: cmd = 'make down; make clean' _cmd_run(cmd, timeout=60) - + os.chdir(test_path) + +def _get_file_hash(filename: str): + blocksize = 65536 + file_hash = hashlib.md5() + with open(filename, "rb") as out: + for block in iter(lambda: out.read(blocksize), b""): + file_hash.update(block) + logger.info(f"Hash: {file_hash.hexdigest()}") + return file_hash.hexdigest() diff --git a/robot/resources/lib/robot/common_steps_acl_basic.robot b/robot/resources/lib/robot/common_steps_acl_basic.robot deleted file mode 100644 index fbc2856f..00000000 --- a/robot/resources/lib/robot/common_steps_acl_basic.robot +++ /dev/null @@ -1,7 +0,0 @@ -*** Keywords *** - -Generate file - [Arguments] ${SIZE} - ${FILE_S_GEN} = Generate file of bytes ${SIZE} - ${FILE_S_HASH_GEN} = Get file hash ${FILE_S_GEN} - [Return] ${FILE_S_GEN} ${FILE_S_HASH_GEN} diff --git a/robot/testsuites/integration/acl/acl_basic_private_container.robot b/robot/testsuites/integration/acl/acl_basic_private_container.robot index 174fcc56..39a6e224 100644 --- a/robot/testsuites/integration/acl/acl_basic_private_container.robot +++ b/robot/testsuites/integration/acl/acl_basic_private_container.robot @@ -2,11 +2,9 @@ Variables common.py Library container.py -Library neofs.py Library neofs_verbs.py -Library payment_neogo.py +Library utility_keywords.py -Resource common_steps_acl_basic.robot Resource payment_operations.robot Resource setup_teardown.robot diff --git a/robot/testsuites/integration/acl/acl_basic_private_container_storagegroup.robot b/robot/testsuites/integration/acl/acl_basic_private_container_storagegroup.robot index 8a5b967d..09cb90cf 100644 --- a/robot/testsuites/integration/acl/acl_basic_private_container_storagegroup.robot +++ b/robot/testsuites/integration/acl/acl_basic_private_container_storagegroup.robot @@ -2,16 +2,12 @@ Variables common.py Library container.py -Library neofs.py Library neofs_verbs.py -Library payment_neogo.py -Library storage_group.py -Library Collections +Library utility_keywords.py Resource payment_operations.robot Resource setup_teardown.robot Resource storage_group.robot -Resource common_steps_acl_basic.robot *** Test cases *** diff --git a/robot/testsuites/integration/acl/acl_basic_public_container.robot b/robot/testsuites/integration/acl/acl_basic_public_container.robot index 7ec0b001..492c471a 100644 --- a/robot/testsuites/integration/acl/acl_basic_public_container.robot +++ b/robot/testsuites/integration/acl/acl_basic_public_container.robot @@ -2,11 +2,9 @@ Variables common.py Library container.py -Library neofs.py Library neofs_verbs.py -Library payment_neogo.py +Library utility_keywords.py -Resource common_steps_acl_basic.robot Resource payment_operations.robot Resource setup_teardown.robot diff --git a/robot/testsuites/integration/acl/acl_basic_public_container_storagegroup.robot b/robot/testsuites/integration/acl/acl_basic_public_container_storagegroup.robot index 5cedcdf0..8a5c243c 100644 --- a/robot/testsuites/integration/acl/acl_basic_public_container_storagegroup.robot +++ b/robot/testsuites/integration/acl/acl_basic_public_container_storagegroup.robot @@ -2,13 +2,9 @@ Variables common.py Library container.py -Library neofs.py Library neofs_verbs.py -Library payment_neogo.py -Library contract_keywords.py -Library storage_group.py +Library utility_keywords.py -Resource common_steps_acl_basic.robot Resource payment_operations.robot Resource setup_teardown.robot Resource storage_group.robot @@ -52,4 +48,4 @@ Check Public Container # System isn't allowed to DELETE in Public Container Run Storage Group Operations On System's Behalf In RO Container - ... ${PUBLIC_CID} ${OBJECTS} ${RUN_TYPE} + ... ${PUBLIC_CID} ${OBJECTS} ${RUN_TYPE} diff --git a/robot/testsuites/integration/acl/acl_basic_readonly_container.robot b/robot/testsuites/integration/acl/acl_basic_readonly_container.robot index 5785c384..dd4b07f6 100644 --- a/robot/testsuites/integration/acl/acl_basic_readonly_container.robot +++ b/robot/testsuites/integration/acl/acl_basic_readonly_container.robot @@ -2,11 +2,9 @@ Variables common.py Library container.py -Library neofs.py Library neofs_verbs.py -Library payment_neogo.py +Library utility_keywords.py -Resource common_steps_acl_basic.robot Resource payment_operations.robot Resource setup_teardown.robot diff --git a/robot/testsuites/integration/acl/acl_basic_readonly_container_storagegroup.robot b/robot/testsuites/integration/acl/acl_basic_readonly_container_storagegroup.robot index a6d47d4a..fe9c93ff 100644 --- a/robot/testsuites/integration/acl/acl_basic_readonly_container_storagegroup.robot +++ b/robot/testsuites/integration/acl/acl_basic_readonly_container_storagegroup.robot @@ -2,12 +2,9 @@ Variables common.py Library container.py -Library neofs.py Library neofs_verbs.py -Library payment_neogo.py -Library storage_group.py +Library utility_keywords.py -Resource common_steps_acl_basic.robot Resource payment_operations.robot Resource setup_teardown.robot Resource storage_group.robot