(#87) Service tests update

Signed-off-by: EliChin <elizaveta@nspcc.ru>
This commit is contained in:
EliChin 2021-08-16 12:28:43 +03:00 committed by Elizaveta Chichindaeva
parent ea6a01b3de
commit fe99c143aa
5 changed files with 46 additions and 43 deletions

View file

@ -9,6 +9,7 @@ import subprocess
import boto3
import uuid
import io
import pexpect
from robot.api.deco import keyword
from robot.api import logger
@ -20,24 +21,25 @@ from common import *
ROBOT_AUTO_KEYWORDS = False
CDNAUTH_EXEC = os.getenv('CDNAUTH_EXEC', 'cdn-authmate')
NEOFS_EXEC = os.getenv('NEOFS_EXEC', 'neofs-authmate')
@keyword('Init S3 Credentials')
def init_s3_credentials(private_key: str, s3_key):
def init_s3_credentials(wallet):
bucket = str(uuid.uuid4())
records = ' \' {"records":[{"operation":"PUT","action":"ALLOW","filters":[],"targets":[{"role":"OTHERS","keys":[]}]}, {"operation":"SEARCH","action":"ALLOW","filters":[],"targets":[{"role":"OTHERS","keys":[]}]}, {"operation":"GET","action":"ALLOW","filters":[],"targets":[{"role":"OTHERS","keys":[]}]}]} \' '
Cmd = (
f'{CDNAUTH_EXEC} --debug --with-log issue-secret --neofs-key {private_key} '
f'--gate-public-key={s3_key} --peer {NEOFS_ENDPOINT} '
f'--container-friendly-name {bucket}'
f'{NEOFS_EXEC} --debug --with-log issue-secret --wallet {wallet} '
f'--gate-public-key={GATE_PUB_KEY} --peer {NEOFS_ENDPOINT} '
f'--container-friendly-name {bucket} --create-session-token '
f'--bearer-rules {records}'
)
logger.info("Cmd: %s" % Cmd)
try:
complProc = subprocess.run(Cmd, check=True, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=360, shell=True)
output = complProc.stdout
logger.info("Output: %s" % output)
logger.info(f"Executing command: {Cmd}")
m = re.search(r'"cid":\s+"(\w+)"', output)
try:
output = _run_with_passwd(Cmd)
logger.info(f"Command completed with output: {output}")
m = re.search(r'"container_id":\s+"(\w+)"', output)
cid = m.group(1)
logger.info("cid: %s" % cid)
@ -56,8 +58,15 @@ def init_s3_credentials(private_key: str, s3_key):
return cid, bucket, access_key_id, secret_access_key, owner_private_key
except subprocess.CalledProcessError as e:
raise Exception("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
raise Exception(f"Error: \nreturn code: {e.returncode}. \nOutput: {e.stderr}")
def _run_with_passwd(cmd):
p = pexpect.spawn(cmd)
p.expect(".*")
p.sendline('\r')
p.wait()
cmd = p.read()
return cmd.decode()
@keyword('Config S3 client')
def config_s3_client(access_key_id, secret_access_key):
@ -72,7 +81,6 @@ def config_s3_client(access_key_id, secret_access_key):
return s3_client
@keyword('List objects S3 v2')
def list_objects_s3_v2(s3_client, bucket):
response = s3_client.list_objects_v2(Bucket=bucket)
@ -94,6 +102,12 @@ def list_objects_s3(s3_client, bucket):
logger.info("Found s3 objects: %s" % obj_list)
return obj_list
@keyword('Create bucket S3')
def create_bucket_s3(s3_client):
bucket_name = str(uuid.uuid4())
s3_bucket = s3_client.create_bucket(Bucket=bucket_name)
logger.info("Created S3 bucket: %s" % s3_bucket)
return bucket_name
@keyword('List buckets S3')
def list_buckets_s3(s3_client):
@ -106,7 +120,6 @@ def list_buckets_s3(s3_client):
return found_buckets
@keyword('Put object S3')
def put_object_s3(s3_client, bucket, filepath):
filename = os.path.basename(filepath)

View file

@ -294,7 +294,6 @@ def create_container(private_key: str, basic_acl:str, rule:str, user_headers: st
except subprocess.CalledProcessError as e:
raise Exception("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
@keyword('Container List')
def container_list(private_key: str):
Cmd = (
@ -1004,7 +1003,7 @@ def get_object(private_key: str, cid: str, oid: str, bearer_token: str,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=120, shell=True)
logger.info("Output: %s" % complProc.stdout)
except subprocess.CalledProcessError as e:
raise Exception("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
raise Exception("Error: \nreturn code: {}. \nOutput: {}".format(e.returncode, e.stderr))
return file_path

View file

@ -10,7 +10,7 @@ Library ${KEYWORDS}/rpc_call_keywords.py
Resource ../${RESOURCES}/setup_teardown.robot
*** Variables ***
${PLACEMENT_RULE} = "REP 1 IN X CBF 1 SELECT 1 FROM * AS X"
${PLACEMENT_RULE} = REP 1 IN X CBF 1 SELECT 1 FROM * AS X
${TRANSFER_AMOUNT} = ${6}
${DEPOSIT_AMOUNT} = ${5}
@ -34,7 +34,7 @@ NeoFS HTTP Gateway
Wait Until Keyword Succeeds ${MAINNET_TIMEOUT} ${MAINNET_BLOCK_TIME}
... Transaction accepted in block ${TX_DEPOSIT}
${CID} = Create container ${WIF} public ${PLACEMENT_RULE}
${CID} = Create container ${WIF} 0x0FFFFFFF ${PLACEMENT_RULE}
Wait Until Keyword Succeeds 2 min 30 sec
... Container Existing ${WIF} ${CID}

View file

@ -14,8 +14,9 @@ ${WIF} = ${MAINNET_WALLET_WIF}
*** Test cases ***
NeoFS S3 Gateway
# TODO: check uploading an s3 object via neofs-cli and a neofs object via s3-gate
[Documentation] Execute operations via S3 Gate
[Timeout] 5 min
[Timeout] 10 min
[Setup] Setup
@ -36,51 +37,40 @@ NeoFS S3 Gateway
... ${BUCKET}
... ${ACCESS_KEY_ID}
... ${SEC_ACCESS_KEY}
... ${OWNER_PRIV_KEY} = Init S3 Credentials ${WIF} keys/s3_docker_hcs.pub.key
... ${OWNER_PRIV_KEY} = Init S3 Credentials ${WALLET}
${CONTEINERS_LIST} = Container List ${WIF}
List Should Contain Value ${CONTEINERS_LIST} ${CID}
${S3_CLIENT} = Config S3 client ${ACCESS_KEY_ID} ${SEC_ACCESS_KEY}
${S3_BUCKET} = Create Bucket S3 ${S3_CLIENT}
${LIST_S3_BUCKETS} = List buckets S3 ${S3_CLIENT}
List Should Contain Value ${LIST_S3_BUCKETS} ${BUCKET}
List Should Contain Value ${LIST_S3_BUCKETS} ${S3_BUCKET}
Put object S3 ${S3_CLIENT} ${BUCKET} ${FILE_S3}
Head object S3 ${S3_CLIENT} ${BUCKET} ${FILE_S3_NAME}
${OID_S3} = Put object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3}
Head object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3_NAME}
${OID_FS} = Put object ${WIF} ${FILE_FS} ${CID} ${EMPTY} ${EMPTY}
Head object ${WIF} ${CID} ${OID_FS} ${EMPTY}
${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${BUCKET}
${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${S3_BUCKET}
List Should Contain Value ${LIST_S3_OBJECTS} ${FILE_S3_NAME}
List Should Contain Value ${LIST_S3_OBJECTS} ${FILE_FS_NAME}
${LIST_V2_S3_OBJECTS} = List objects S3 v2 ${S3_CLIENT} ${BUCKET}
${LIST_V2_S3_OBJECTS} = List objects S3 v2 ${S3_CLIENT} ${S3_BUCKET}
List Should Contain Value ${LIST_V2_S3_OBJECTS} ${FILE_S3_NAME}
List Should Contain Value ${LIST_V2_S3_OBJECTS} ${FILE_S3_NAME}
${OID_LIST_S3} = Search object ${WIF} ${CID} ${EMPTY} ${EMPTY} FileName=${FILE_S3_NAME}
${OID_S3} = Get From List ${OID_LIST_S3} 0
Get object S3 ${S3_CLIENT} ${BUCKET} ${FILE_S3_NAME} s3_obj_get_s3
Get object S3 ${S3_CLIENT} ${BUCKET} ${FILE_FS_NAME} fs_obj_get_s3
Get object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3_NAME} s3_obj_get_s3
Verify file hash s3_obj_get_s3 ${FILE_S3_HASH}
Verify file hash fs_obj_get_s3 ${FILE_FS_HASH}
Get object ${WIF} ${CID} ${OID_S3} ${EMPTY} s3_obj_get_fs
Get object ${WIF} ${CID} ${OID_FS} ${EMPTY} fs_obj_get_fs
Verify file hash s3_obj_get_fs ${FILE_S3_HASH}
Verify file hash fs_obj_get_fs ${FILE_FS_HASH}
Copy object S3 ${S3_CLIENT} ${BUCKET} ${FILE_S3_NAME} NewName
${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${BUCKET}
Copy object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3_NAME} NewName
${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${S3_BUCKET}
List Should Contain Value ${LIST_S3_OBJECTS} NewName
Delete object S3 ${S3_CLIENT} ${BUCKET} ${FILE_S3_NAME}
${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${BUCKET}
${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${S3_BUCKET}
List Should Not Contain Value ${LIST_S3_OBJECTS} FILE_S3_NAME
[Teardown] Teardown s3_gate

View file

@ -46,3 +46,4 @@ COMMON_PLACEMENT_RULE = "REP 2 IN X CBF 1 SELECT 4 FROM * AS X"
ASSETS_DIR = os.getenv("ASSETS_DIR", "TemporaryDir/")
MORPH_MAGIC = os.environ["MORPH_MAGIC"]
GATE_PUB_KEY = '0313b1ac3a8076e155a7e797b24f0b650cccad5941ea59d7cfd51a024a8b2a06bf'