fixed miscellaneous errors

Signed-off-by: anastasia prasolova <anastasia@nspcc.ru>
This commit is contained in:
anastasia prasolova 2022-07-08 00:31:58 +03:00 committed by Anastasia Prasolova
parent 2f774f5995
commit ffa40112a1
5 changed files with 122 additions and 76 deletions

View file

@ -28,7 +28,8 @@ def _cmd_run(cmd, timeout=30):
logger.info(f"Executing command: {cmd}") logger.info(f"Executing command: {cmd}")
start_time = datetime.now() start_time = datetime.now()
compl_proc = subprocess.run(cmd, check=True, universal_newlines=True, compl_proc = subprocess.run(cmd, check=True, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=timeout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
timeout=timeout,
shell=True) shell=True)
output = compl_proc.stdout output = compl_proc.stdout
return_code = compl_proc.returncode return_code = compl_proc.returncode
@ -40,6 +41,8 @@ def _cmd_run(cmd, timeout=30):
except subprocess.CalledProcessError as exc: except subprocess.CalledProcessError as exc:
raise RuntimeError(f"Error:\nreturn code: {exc.returncode} " raise RuntimeError(f"Error:\nreturn code: {exc.returncode} "
f"\nOutput: {exc.output}") from exc f"\nOutput: {exc.output}") from exc
except OSError as exc:
raise RuntimeError(f"Output: {exc.strerror}") from exc
except Exception as exc: except Exception as exc:
return_code, _ = subprocess.getstatusoutput(cmd) return_code, _ = subprocess.getstatusoutput(cmd)
logger.info(f"Error:\nreturn code: {return_code}\nOutput: " logger.info(f"Error:\nreturn code: {return_code}\nOutput: "

View file

@ -10,13 +10,12 @@ import random
import re import re
import uuid import uuid
from robot.api import logger
from robot.api.deco import keyword
from common import NEOFS_ENDPOINT, ASSETS_DIR, NEOFS_NETMAP, WALLET_CONFIG
import json_transformers import json_transformers
from cli_helpers import _cmd_run from cli_helpers import _cmd_run
from common import ASSETS_DIR, NEOFS_ENDPOINT, NEOFS_NETMAP, WALLET_CONFIG
from data_formatters import dict_to_attrs from data_formatters import dict_to_attrs
from robot.api import logger
from robot.api.deco import keyword
ROBOT_AUTO_KEYWORDS = False ROBOT_AUTO_KEYWORDS = False
@ -126,7 +125,7 @@ def put_object(wallet: str, path: str, cid: str, bearer: str = "", user_headers:
@keyword('Delete object') @keyword('Delete object')
def delete_object(wallet: str, cid: str, oid: str, bearer: str = "", wallet_config: str = WALLET_CONFIG, def delete_object(wallet: str, cid: str, oid: str, bearer: str = "", wallet_config: str = WALLET_CONFIG,
options: str = ""): options: str = ""):
""" """
DELETE an Object. DELETE an Object.
@ -187,7 +186,7 @@ def get_range(wallet: str, cid: str, oid: str, file_path: str, bearer: str, rang
@keyword('Search object') @keyword('Search object')
def search_object(wallet: str, cid: str, keys: str = "", bearer: str = "", filters: dict = {}, def search_object(wallet: str, cid: str, keys: str = "", bearer: str = "", filters: dict = {},
expected_objects_list=[], wallet_config: str = WALLET_CONFIG): expected_objects_list=[], wallet_config: str = WALLET_CONFIG, options: str = ""):
""" """
SEARCH an Object. SEARCH an Object.
@ -200,6 +199,7 @@ def search_object(wallet: str, cid: str, keys: str = "", bearer: str = "", filte
filters (optional, dict): key=value pairs to filter Objects filters (optional, dict): key=value pairs to filter Objects
expected_objects_list (optional, list): a list of ObjectIDs to compare found Objects with expected_objects_list (optional, list): a list of ObjectIDs to compare found Objects with
wallet_config(optional, str): path to the wallet config wallet_config(optional, str): path to the wallet config
options(optional, str): any other options which `neofs-cli object search` might accept
Returns: Returns:
(list): list of found ObjectIDs (list): list of found ObjectIDs
""" """
@ -207,12 +207,13 @@ def search_object(wallet: str, cid: str, keys: str = "", bearer: str = "", filte
if filters: if filters:
filters_result += "--filters " filters_result += "--filters "
logger.info(filters) logger.info(filters)
filters_result += ','.join(map(lambda i: f"'{i} EQ {filters[i]}'", filters)) filters_result += ','.join(
map(lambda i: f"'{i} EQ {filters[i]}'", filters))
cmd = ( cmd = (
f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} ' f'{NEOFS_CLI_EXEC} --rpc-endpoint {NEOFS_ENDPOINT} --wallet {wallet} '
f'object search {keys} --cid {cid} {filters_result} --config {wallet_config} ' f'object search {keys} --cid {cid} {filters_result} --config {wallet_config} '
f'{"--bearer " + bearer if bearer else ""}' f'{"--bearer " + bearer if bearer else ""} {options}'
) )
output = _cmd_run(cmd) output = _cmd_run(cmd)

View file

@ -2,18 +2,20 @@
import json import json
import neofs_verbs
from neo3 import wallet from neo3 import wallet
from robot.api.deco import keyword from robot.api.deco import keyword
from robot.libraries.BuiltIn import BuiltIn from robot.libraries.BuiltIn import BuiltIn
import neofs_verbs
ROBOT_AUTO_KEYWORDS = False ROBOT_AUTO_KEYWORDS = False
@keyword('Verify Head Tombstone') @keyword('Verify Head Tombstone')
def verify_head_tombstone(wallet_path: str, cid: str, oid_ts: str, oid: str): def verify_head_tombstone(wallet_path: str, cid: str, oid_ts: str, oid: str,
header = neofs_verbs.head_object(wallet_path, cid, oid_ts) bearer: str = "", options: str = ""):
header = neofs_verbs.head_object(wallet_path, cid, oid_ts,
bearer_token=bearer,
options=options)
header = header['header'] header = header['header']
BuiltIn().should_be_equal(header["containerID"], cid, BuiltIn().should_be_equal(header["containerID"], cid,
@ -32,18 +34,18 @@ def verify_head_tombstone(wallet_path: str, cid: str, oid_ts: str, oid: str):
msg="Header Type isn't Tombstone") msg="Header Type isn't Tombstone")
BuiltIn().should_be_equal( BuiltIn().should_be_equal(
header["sessionToken"]["body"]["object"]["verb"], 'DELETE', header["sessionToken"]["body"]["object"]["verb"], 'DELETE',
msg="Header Session Type isn't DELETE" msg="Header Session Type isn't DELETE"
) )
BuiltIn().should_be_equal( BuiltIn().should_be_equal(
header["sessionToken"]["body"]["object"]["address"]["containerID"], header["sessionToken"]["body"]["object"]["address"]["containerID"],
cid, cid,
msg="Header Session ID is wrong" msg="Header Session ID is wrong"
) )
BuiltIn().should_be_equal( BuiltIn().should_be_equal(
header["sessionToken"]["body"]["object"]["address"]["objectID"], header["sessionToken"]["body"]["object"]["address"]["objectID"],
oid, oid,
msg="Header Session OID is wrong" msg="Header Session OID is wrong"
) )

View file

@ -14,7 +14,7 @@ ${CLEANUP_TIMEOUT} = 10s
*** Keywords *** *** Keywords ***
Run All Verbs Except Delete And Expect Success Run All Verbs Except Delete And Expect Success
[Arguments] ${WALLET} ${CID} ${COMPLEXITY} [Arguments] ${WALLET} ${CID} ${COMPLEXITY} ${BEARER_TOKEN}=${EMPTY} ${REQUEST_HEADERS}=${EMPTY}
${OBJ_SIZE} = Run Keyword If """${COMPLEXITY}""" == """Simple""" ${OBJ_SIZE} = Run Keyword If """${COMPLEXITY}""" == """Simple"""
... Set Variable ${SIMPLE_OBJ_SIZE} ... Set Variable ${SIMPLE_OBJ_SIZE}
@ -24,7 +24,11 @@ Run All Verbs Except Delete And Expect Success
${FILE} ${FILE_HASH} = Generate file ${OBJ_SIZE} ${FILE} ${FILE_HASH} = Generate file ${OBJ_SIZE}
${OID} = Put object ${WALLET} ${FILE} ${CID} ${OID} = Put object ${WALLET} ${FILE} ${CID}
... bearer=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
${OBJ_PATH} = Get object ${WALLET} ${CID} ${OID} ${OBJ_PATH} = Get object ${WALLET} ${CID} ${OID}
... bearer_token=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
${DOWNLOADED_FILE_HASH} = ${DOWNLOADED_FILE_HASH} =
... Get file hash ${OBJ_PATH} ... Get file hash ${OBJ_PATH}
Should Be Equal ${DOWNLOADED_FILE_HASH} ${FILE_HASH} Should Be Equal ${DOWNLOADED_FILE_HASH} ${FILE_HASH}
@ -32,29 +36,43 @@ Run All Verbs Except Delete And Expect Success
# TODO: get rid of ${EMPTY} # TODO: get rid of ${EMPTY}
${RANGE_FILE} ${RANGE_FILE}
... ${DATA_RANGE} = ... ${DATA_RANGE} =
... Get Range ${WALLET} ${CID} ${OID} ${EMPTY} ${EMPTY} 0:10 ... Get Range ${WALLET} ${CID} ${OID} file_path=${EMPTY}
... bearer=${BEARER_TOKEN}
... range_cut=0:10
... options=${REQUEST_HEADERS}
${FILE_CONTENT} = Get Binary File ${FILE} ${FILE_CONTENT} = Get Binary File ${FILE}
Should Contain ${FILE_CONTENT} ${DATA_RANGE} Should Contain ${FILE_CONTENT} ${DATA_RANGE}
# TODO: get rid of ${EMPTY} # TODO: get rid of ${EMPTY}
${RANGE_HASH} = Get Range Hash ${WALLET} ${CID} ${OID} ${EMPTY} 0:10 ${RANGE_HASH} = Get Range Hash ${WALLET} ${CID} ${OID}
... bearer_token=${BEARER_TOKEN}
... range_cut=0:10
... options=${REQUEST_HEADERS}
${GR_HASH} = Get File Hash ${RANGE_FILE} ${GR_HASH} = Get File Hash ${RANGE_FILE}
Should Be Equal ${GR_HASH} ${RANGE_HASH} Should Be Equal ${GR_HASH} ${RANGE_HASH}
${FOUND_OBJECTS} = Search object ${WALLET} ${CID} keys=${OID} ${FOUND_OBJECTS} = Search object ${WALLET} ${CID} keys=${OID}
... bearer=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
List Should Contain Value List Should Contain Value
... ${FOUND_OBJECTS} ... ${FOUND_OBJECTS}
... ${OID} ... ${OID}
&{RESPONSE} = Head object ${WALLET} ${CID} ${OID} &{RESPONSE} = Head object ${WALLET} ${CID} ${OID}
... bearer_token=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
[Return] ${OID} [Return] ${OID}
Delete Object And Validate Tombstone Delete Object And Validate Tombstone
[Arguments] ${WALLET} ${CID} ${OID} [Arguments] ${WALLET} ${CID} ${OID} ${BEARER_TOKEN}=${EMPTY} ${REQUEST_HEADERS}=${EMPTY}
${TOMBSTONE_ID} = Delete object ${WALLET} ${CID} ${OID} ${TOMBSTONE_ID} = Delete object ${WALLET} ${CID} ${OID}
... bearer=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
Verify Head tombstone ${WALLET} ${CID} ${TOMBSTONE_ID} ${OID} Verify Head tombstone ${WALLET} ${CID} ${TOMBSTONE_ID} ${OID}
... bearer=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
Tick Epoch Tick Epoch
# we assume that during this time objects must be deleted # we assume that during this time objects must be deleted
@ -62,4 +80,41 @@ Delete Object And Validate Tombstone
${ERR} = Run Keyword And Expect Error * ${ERR} = Run Keyword And Expect Error *
... Get object ${WALLET} ${CID} ${OID} ... Get object ${WALLET} ${CID} ${OID}
... bearer_token=${BEARER_TOKEN}
... options=${REQUEST_HEADERS}
Should Contain ${ERR} code = 2052 message = object already removed Should Contain ${ERR} code = 2052 message = object already removed
Run All Verbs And Expect Failure
[Arguments] ${ERROR} ${WALLET} ${CID} ${OID}
${FILE} ${_} = Generate file ${SIMPLE_OBJ_SIZE}
${ERR} = Run Keyword And Expect Error *
... Put object ${WALLET} ${FILE} ${CID}
Should Contain ${ERR} ${ERROR}
${ERR} = Run Keyword And Expect Error *
... Get object ${WALLET} ${CID} ${OID}
Should Contain ${ERR} ${ERROR}
# TODO: get rid of ${EMPTY}
${ERR} = Run Keyword And Expect Error *
... Get Range ${WALLET} ${CID} ${OID} ${EMPTY} ${EMPTY} 0:10
Should Contain ${ERR} ${ERROR}
# TODO: get rid of ${EMPTY}
${ERR} = Run Keyword And Expect Error *
... Get Range Hash ${WALLET} ${CID} ${OID} ${EMPTY} 0:10
Should Contain ${ERR} ${ERROR}
${ERR} = Run Keyword And Expect Error *
... Search object ${WALLET} ${CID} keys=${OID}
Should Contain ${ERR} ${ERROR}
${ERR} = Run Keyword And Expect Error *
... Head object ${WALLET} ${CID} ${OID}
Should Contain ${ERR} ${ERROR}
${ERR} = Run Keyword And Expect Error *
... Delete object ${WALLET} ${CID} ${OID}
Should Contain ${ERR} ${ERROR}

View file

@ -10,29 +10,21 @@ Resource eacl_tables.robot
Resource common_steps_acl_bearer.robot Resource common_steps_acl_bearer.robot
Resource payment_operations.robot Resource payment_operations.robot
Resource setup_teardown.robot Resource setup_teardown.robot
Resource verbs.robot
*** Variables *** *** Variables ***
&{USER_HEADER} = key1=1 key2=abc ${EACL_ERROR_MSG} = code = 2048 message = access to object operation denied
&{USER_HEADER_DEL} = key1=del key2=del
${EACL_ERROR_MSG} = *
*** Test cases *** *** Test cases ***
BearerToken Operations with Filter Requst Equal BearerToken Operations with Filter Requst Equal
[Documentation] Testcase to validate NeoFS operations with BearerToken with Filter Requst Equal. [Documentation] Testcase to validate NeoFS operations with BearerToken with Filter Requst Equal.
[Tags] ACL BearerToken [Tags] ACL BearerToken
[Timeout] 20 min [Timeout] 5 min
[Setup] Setup [Setup] Setup
${WALLET} ${_} ${_} = Prepare Wallet And Deposit Check eACL Deny and Allow All Bearer Filter Requst Equal Simple
Check eACL Deny and Allow All Bearer Filter Requst Equal Complex
Log Check Bearer token with simple object
${FILE_S} ${_} = Generate file ${SIMPLE_OBJ_SIZE}
Check eACL Deny and Allow All Bearer Filter Requst Equal ${WALLET} ${FILE_S}
Log Check Bearer token with complex object
${FILE_S} ${_} = Generate file ${COMPLEX_OBJ_SIZE}
Check eACL Deny and Allow All Bearer Filter Requst Equal ${WALLET} ${FILE_S}
[Teardown] Teardown acl_bearer_request_filter_xheader_equal [Teardown] Teardown acl_bearer_request_filter_xheader_equal
@ -41,28 +33,31 @@ BearerToken Operations with Filter Requst Equal
*** Keywords *** *** Keywords ***
Check eACL Deny and Allow All Bearer Filter Requst Equal Check eACL Deny and Allow All Bearer Filter Requst Equal
[Arguments] ${WALLET} ${FILE_S} [Arguments] ${COMPLEXITY}
${CID} = Create Container ${WALLET} basic_acl=eacl-public-read-write ${WALLET}
Prepare eACL Role rules ${CID} ... ${_}
${S_OID_USER} = Put object ${WALLET} ${FILE_S} ${CID} user_headers=${USER_HEADER} ... ${_} = Prepare Wallet And Deposit
${S_OID_USER_2} = Put object ${WALLET} ${FILE_S} ${CID} ${CID} = Create Container ${WALLET} basic_acl=eacl-public-read-write
${D_OID_USER} = Put object ${WALLET} ${FILE_S} ${CID} user_headers=${USER_HEADER_DEL}
@{S_OBJ_H} = Create List ${S_OID_USER}
Put object ${WALLET} ${FILE_S} ${CID} ${OID} = Run All Verbs Except Delete And Expect Success
Get object ${WALLET} ${CID} ${S_OID_USER} ${EMPTY} local_file_eacl ... ${WALLET} ${CID} ${COMPLEXITY}
Search object ${WALLET} ${CID} ${EMPTY} ${EMPTY} ${USER_HEADER} ${S_OBJ_H}
Head object ${WALLET} ${CID} ${S_OID_USER}
Get Range ${WALLET} ${CID} ${S_OID_USER} s_get_range ${EMPTY} 0:256
Delete object ${WALLET} ${CID} ${D_OID_USER}
Set eACL ${WALLET} ${CID} ${EACL_DENY_ALL_USER} Delete Object And Validate Tombstone
... ${WALLET} ${CID} ${OID}
# Generating empty file to test operations with it after EACL will be set;
# the size does not matter as we expect to get "operation is not allowed" error
${FILE}
... ${_} = Generate File 0
${OID} = Put object ${WALLET} ${FILE} ${CID}
Set eACL ${WALLET} ${CID} ${EACL_DENY_ALL_USER}
# The current ACL cache lifetime is 30 sec # The current ACL cache lifetime is 30 sec
Sleep ${NEOFS_CONTRACT_CACHE_TIMEOUT} Sleep ${NEOFS_CONTRACT_CACHE_TIMEOUT}
${filters}= Create Dictionary headerType=REQUEST matchType=STRING_EQUAL key=a value=256 ${filters}= Create Dictionary headerType=REQUEST matchType=STRING_EQUAL key=a value=256
${rule1}= Create Dictionary Operation=GET Access=ALLOW Role=USER Filters=${filters} ${rule1}= Create Dictionary Operation=GET Access=ALLOW Role=USER Filters=${filters}
${rule2}= Create Dictionary Operation=HEAD Access=ALLOW Role=USER Filters=${filters} ${rule2}= Create Dictionary Operation=HEAD Access=ALLOW Role=USER Filters=${filters}
${rule3}= Create Dictionary Operation=PUT Access=ALLOW Role=USER Filters=${filters} ${rule3}= Create Dictionary Operation=PUT Access=ALLOW Role=USER Filters=${filters}
@ -74,23 +69,13 @@ Check eACL Deny and Allow All Bearer Filter Requst Equal
${EACL_TOKEN} = Form BearerToken File ${WALLET} ${CID} ${eACL_gen} ${EACL_TOKEN} = Form BearerToken File ${WALLET} ${CID} ${eACL_gen}
Run Keyword And Expect Error ${EACL_ERROR_MSG} Run All Verbs And Expect Failure
... Put object ${WALLET} ${FILE_S} ${CID} user_headers=${USER_HEADER} ... ${EACL_ERROR_MSG} ${WALLET} ${CID} ${OID}
Run Keyword And Expect Error ${EACL_ERROR_MSG}
... Get object ${WALLET} ${CID} ${S_OID_USER} ${EMPTY} local_file_eacl
Run Keyword And Expect Error ${EACL_ERROR_MSG}
... Search object ${WALLET} ${CID} ${EMPTY} ${EMPTY} ${USER_HEADER} ${S_OBJ_H}
Run Keyword And Expect Error ${EACL_ERROR_MSG}
... Head object ${WALLET} ${CID} ${S_OID_USER}
Run Keyword And Expect Error ${EACL_ERROR_MSG}
... Get Range ${WALLET} ${CID} ${S_OID_USER} s_get_range ${EMPTY} 0:256
Run Keyword And Expect Error ${EACL_ERROR_MSG}
... Delete object ${WALLET} ${CID} ${S_OID_USER}
Put object ${WALLET} ${FILE_S} ${CID} bearer=${EACL_TOKEN} user_headers=${USER_HEADER} options=--xhdr a=256 ${OID} = Run All Verbs Except Delete And Expect Success
Get object ${WALLET} ${CID} ${S_OID_USER} ${EACL_TOKEN} local_file_eacl ${EMPTY} --xhdr a=256 ... ${WALLET} ${CID} ${COMPLEXITY}
Search object ${WALLET} ${CID} ${EMPTY} ${EACL_TOKEN} ${USER_HEADER} ${EMPTY} --xhdr a=256 ... ${EACL_TOKEN} --xhdr a=256
Head object ${WALLET} ${CID} ${S_OID_USER} bearer_token=${EACL_TOKEN} options=--xhdr a=256
Get Range ${WALLET} ${CID} ${S_OID_USER} s_get_range ${EACL_TOKEN} 0:256 --xhdr a=256 Delete Object And Validate Tombstone
Get Range Hash ${WALLET} ${CID} ${S_OID_USER} ${EACL_TOKEN} 0:256 --xhdr a=256 ... ${WALLET} ${CID} ${OID}
Delete object ${WALLET} ${CID} ${S_OID_USER} ${EACL_TOKEN} --xhdr a=256 ... ${EACL_TOKEN} --xhdr a=256