diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d50d20c --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# ignore test result files under any path +**/log.html +**/output.xml +**/report.html + +# ignore pycache under any path +**/__pycache__ diff --git a/robot/resources/lib/assertions.py b/robot/resources/lib/assertions.py new file mode 100644 index 0000000..f39844d --- /dev/null +++ b/robot/resources/lib/assertions.py @@ -0,0 +1,21 @@ +#!/usr/bin/python3 + +""" +A file with specific assertions that Robot Framework +doesn't have in its builtins. +""" + +from robot.api.deco import keyword +from robot.utils.asserts import assert_equal + +@keyword('Should Be Equal as Binaries') +def sbe_as_binaries(fst: str, snd: str): + """ + Assertion to compare binary contents of + two files. Parameters: + - `fst`: path to first file + - `snd`: path to second file + """ + fst_fd, snd_fd = open(fst, 'rb'), open(snd, 'rb') + fst_bytes, snd_bytes = fst_fd.read(), snd_fd.read() + assert_equal(fst_bytes, snd_bytes, msg='Given files are not equal as binaries') diff --git a/robot/resources/lib/kws_module.py b/robot/resources/lib/kws_module.py new file mode 100644 index 0000000..281fcca --- /dev/null +++ b/robot/resources/lib/kws_module.py @@ -0,0 +1,70 @@ +#!/usr/bin/python3 + +import subprocess +import re + +from robot.api.deco import keyword +from robot.api import logger + +ROBOT_AUTO_KEYWORDS = False + +NEOFS_ENDPOINT = '85.143.219.93:8080' +NEOFS_KEY = 'KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr' + +@keyword('Create container') +def create_container(): + logger.info("Creating container") + + createContainerCmd = f'neofs-cli --host {NEOFS_ENDPOINT} --key {NEOFS_KEY} container put --rule "RF 1 SELECT 2 Node"' + complProc = subprocess.run(createContainerCmd, check=True, universal_newlines=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=15, shell=True) + cid = parse_cid(complProc.stdout) + return cid + +def parse_cid(output: str): + """ + This function parses CID from given CLI output. + Parameters: + - output: a string with command run output + """ + m = re.search(r'Success! Container <(([a-zA-Z0-9])+)> created', output) + if m.start() != m.end(): # e.g., if match found something + cid = m.group(1) + else: + logger.warn("no CID was parsed from command output: \t%s" % output) + return + return cid + +@keyword('Write object to NeoFS') +def write_object(path: str, cid: str): + logger.info("Going to put an object") + + putObjectCmd = f'neofs-cli --host {NEOFS_ENDPOINT} --key {NEOFS_KEY} object put --file {path} --cid {cid}' + complProc = subprocess.run(putObjectCmd, check=True, universal_newlines=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=15, shell=True) + oid = parse_oid(complProc.stdout) + return oid + +def parse_oid(output: str): + """ + This function parses OID from given CLI output. + Parameters: + - output: a string with command run output + """ + m = re.search(r'ID: ([a-zA-Z0-9-]+)', output) + if m.start() != m.end(): # e.g., if match found something + oid = m.group(1) + else: + logger.warn("no OID was parsed from command output: \t%s" % output) + return + return oid + + +@keyword('Read object from NeoFS') +def read_object(cid: str, oid: str, read_object: str): + logger.info("Going to get an object") + + getObjectCmd = f'neofs-cli --host {NEOFS_ENDPOINT} --key {NEOFS_KEY} object get --cid {cid} --oid {oid} --file {read_object}' + complProc = subprocess.run(getObjectCmd, check=True, universal_newlines=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=15, shell=True) + logger.info(complProc.stdout) diff --git a/robot/testsuites/integration/rw_test.robot b/robot/testsuites/integration/rw_test.robot new file mode 100644 index 0000000..1a46d9d --- /dev/null +++ b/robot/testsuites/integration/rw_test.robot @@ -0,0 +1,16 @@ +*** Settings *** +Variables ../../variables/common.py + +Library ${RESOURCES}/kws_module.py +Library ${RESOURCES}/assertions.py + +*** Variables *** +${OBJECT} ${TESTSUITES}/test_file +${READ_OBJECT} ${TESTSUITES}/read_file + +*** Test cases *** +Read and Write to NeoFS + ${CID} = Create container + ${OID} = Write object to NeoFS ${OBJECT} ${CID} + Read object from NeoFS ${CID} ${OID} ${READ_OBJECT} + Should Be Equal as Binaries ${OBJECT} ${READ_OBJECT} diff --git a/robot/testsuites/integration/test_file b/robot/testsuites/integration/test_file new file mode 100644 index 0000000..190a180 --- /dev/null +++ b/robot/testsuites/integration/test_file @@ -0,0 +1 @@ +123 diff --git a/robot/variables/common.py b/robot/variables/common.py new file mode 100644 index 0000000..0ec056b --- /dev/null +++ b/robot/variables/common.py @@ -0,0 +1,6 @@ +#!/usr/bin/python3 + +ROOT='../..' + +RESOURCES="%s/resources/lib" % ROOT +TESTSUITES="%s/testsuites/integration" % ROOT