INFRA-140 test prototypes

This commit is contained in:
anastasia prasolova 2020-04-30 16:14:32 +03:00
parent 10d0d540d7
commit 25810a756d
6 changed files with 121 additions and 0 deletions

7
.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
# ignore test result files under any path
**/log.html
**/output.xml
**/report.html
# ignore pycache under any path
**/__pycache__

View file

@ -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')

View file

@ -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)

View file

@ -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}

View file

@ -0,0 +1 @@
123

View file

@ -0,0 +1,6 @@
#!/usr/bin/python3
ROOT='../..'
RESOURCES="%s/resources/lib" % ROOT
TESTSUITES="%s/testsuites/integration" % ROOT