From ced05475d2efaa99e1b2de8c29ad230e42ecb515 Mon Sep 17 00:00:00 2001 From: EliChin Date: Thu, 2 Sep 2021 15:17:55 +0300 Subject: [PATCH] (#89) S3 Bucket and S3 Object tests Signed-off-by: EliChin --- robot/resources/lib/gates.py | 23 +++++- .../integration/services/s3_gate_bucket.robot | 71 +++++++++++++++++++ .../{s3_gate.robot => s3_gate_object.robot} | 63 ++++++++-------- 3 files changed, 124 insertions(+), 33 deletions(-) create mode 100644 robot/testsuites/integration/services/s3_gate_bucket.robot rename robot/testsuites/integration/services/{s3_gate.robot => s3_gate_object.robot} (57%) diff --git a/robot/resources/lib/gates.py b/robot/resources/lib/gates.py index a497d5e..037ae53 100644 --- a/robot/resources/lib/gates.py +++ b/robot/resources/lib/gates.py @@ -118,6 +118,20 @@ def list_buckets_s3(s3_client): return found_buckets +@keyword('Delete bucket S3') +def delete_bucket_s3(s3_client, bucket): + response = s3_client.delete_bucket(Bucket=bucket) + logger.info(f"S3 Delete bucket result: {response}") + return response + + +@keyword('HeadBucket S3') +def headbucket(bucket, s3_client): + response = s3_client.head_bucket(Bucket=bucket) + logger.info(f"S3 HeadBucket result: {response}") + return response + + @keyword('Put object S3') def put_object_s3(s3_client, bucket, filepath): filename = os.path.basename(filepath) @@ -148,8 +162,12 @@ def delete_object_s3(s3_client, bucket, object_key): @keyword('Copy object S3') def copy_object_s3(s3_client, bucket, object_key, new_object): - response = s3_client.copy_object(Bucket=bucket, CopySource=bucket+"/"+object_key, Key=new_object) - logger.info("S3 Copy object result: %s" % response) + try: + response = s3_client.copy_object(Bucket=bucket, CopySource=bucket+"/"+object_key, Key=new_object) + logger.info("S3 Copy object result: %s" % response) + except: + raise Exception(f"S3 object {new_object} hasn't been coppied") + return response @@ -189,3 +207,4 @@ def get_via_http_gate(cid: str, oid: str): shutil.copyfileobj(resp.raw, f) del resp return filename + diff --git a/robot/testsuites/integration/services/s3_gate_bucket.robot b/robot/testsuites/integration/services/s3_gate_bucket.robot new file mode 100644 index 0000000..adae458 --- /dev/null +++ b/robot/testsuites/integration/services/s3_gate_bucket.robot @@ -0,0 +1,71 @@ +*** Settings *** +Variables ../../../variables/common.py +Library Collections +Library neofs.py +Library payment_neogo.py +Library gates.py +Library wallet_keywords.py +Library contract_keywords.py + +Resource setup_teardown.robot + +*** Variables *** +${DEPOSIT_AMOUNT} = ${5} +${WIF} = ${MAINNET_WALLET_WIF} +${DEPOSIT_TIMEOUT}= 30s + +*** Test cases *** +Buckets in NeoFS S3 Gateway + [Documentation] Execute operations with bucket via S3 Gate + [Timeout] 10 min + + [Setup] Setup + + ${WALLET} ${ADDR} = Init Wallet from WIF ${ASSETS_DIR} ${WIF} + ${TX_DEPOSIT} = NeoFS Deposit ${WIF} ${DEPOSIT_AMOUNT} + Wait Until Keyword Succeeds ${DEPOSIT_TIMEOUT} ${MAINNET_BLOCK_TIME} + ... Transaction accepted in block ${TX_DEPOSIT} + + ${FILE_S3} = Generate file of bytes ${COMPLEX_OBJ_SIZE} + ${FILE_S3_NAME} = Get file name ${FILE_S3} + + ${CID} + ... ${BUCKET} + ... ${ACCESS_KEY_ID} + ... ${SEC_ACCESS_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} + + ${NEW_BUCKET} = Create Bucket S3 ${S3_CLIENT} + ${NEW_BUCKET_EMPTY} = Create Bucket S3 ${S3_CLIENT} + + HeadBucket S3 ${BUCKET} ${S3_CLIENT} + HeadBucket S3 ${NEW_BUCKET} ${S3_CLIENT} + + Put object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3} + Head object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3_NAME} + + ${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${NEW_BUCKET} + List Should Contain Value ${LIST_S3_OBJECTS} ${FILE_S3_NAME} + + Run Keyword and Expect Error * + ... Delete Bucket S3 ${S3_CLIENT} ${NEW_BUCKET} + HeadBucket S3 ${NEW_BUCKET} ${S3_CLIENT} + + Delete Bucket S3 ${S3_CLIENT} ${NEW_BUCKET_EMPTY} + Tick Epoch + Run Keyword And Expect Error * + ... HeadBucket S3 ${NEW_BUCKET_EMPTY} ${S3_CLIENT} + + ${BUCKET_LIST} = List Buckets S3 ${S3_CLIENT} + Tick Epoch + List Should Contain Value ${BUCKET_LIST} ${NEW_BUCKET} + List Should Not Contain Value ${BUCKET_LIST} ${NEW_BUCKET_EMPTY} + + [Teardown] Teardown s3_gate_bucket + + diff --git a/robot/testsuites/integration/services/s3_gate.robot b/robot/testsuites/integration/services/s3_gate_object.robot similarity index 57% rename from robot/testsuites/integration/services/s3_gate.robot rename to robot/testsuites/integration/services/s3_gate_object.robot index 0be69ea..4385940 100644 --- a/robot/testsuites/integration/services/s3_gate.robot +++ b/robot/testsuites/integration/services/s3_gate_object.robot @@ -1,21 +1,21 @@ *** Settings *** Variables ../../../variables/common.py Library Collections -Library ../${RESOURCES}/neofs.py -Library ../${RESOURCES}/payment_neogo.py -Library ../${RESOURCES}/gates.py -Library ${KEYWORDS}/wallet_keywords.py - -Resource ../${RESOURCES}/setup_teardown.robot +Library neofs.py +Library payment_neogo.py +Library gates.py +Library wallet_keywords.py +Library contract_keywords.py +Resource setup_teardown.robot *** Variables *** ${DEPOSIT_AMOUNT} = ${5} ${WIF} = ${MAINNET_WALLET_WIF} *** Test cases *** -NeoFS S3 Gateway +Objects in 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 + [Documentation] Execute operations with objects via S3 Gate [Timeout] 10 min [Setup] Setup @@ -29,10 +29,6 @@ NeoFS S3 Gateway ${FILE_S3_HASH} = Get file hash ${FILE_S3} ${FILE_S3_NAME} = Get file name ${FILE_S3} - ${FILE_FS} = Generate file of bytes ${COMPLEX_OBJ_SIZE} - ${FILE_FS_HASH} = Get file hash ${FILE_FS} - ${FILE_FS_NAME} = Get file name ${FILE_FS} - ${CID} ... ${BUCKET} ... ${ACCESS_KEY_ID} @@ -43,34 +39,39 @@ NeoFS S3 Gateway 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} - ${OID_S3} = Put object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3} - Head object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3_NAME} + ${NEW_BUCKET} = Create Bucket S3 ${S3_CLIENT} + ${NEW_BUCKET_2} = Create Bucket S3 ${S3_CLIENT} - ${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} ${S3_BUCKET} + Put object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3} + Head object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3_NAME} + Put object S3 ${S3_CLIENT} ${NEW_BUCKET_2} ${FILE_S3} + Head object S3 ${S3_CLIENT} ${NEW_BUCKET_2} ${FILE_S3_NAME} + + ${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${NEW_BUCKET} List Should Contain Value ${LIST_S3_OBJECTS} ${FILE_S3_NAME} + ${LIST_S3_OBJECTS_2} = List objects S3 ${S3_CLIENT} ${NEW_BUCKET_2} + List Should Contain Value ${LIST_S3_OBJECTS_2} ${FILE_S3_NAME} - ${LIST_V2_S3_OBJECTS} = List objects S3 v2 ${S3_CLIENT} ${S3_BUCKET} + ${LIST_V2_S3_OBJECTS} = List objects S3 v2 ${S3_CLIENT} ${NEW_BUCKET} List Should Contain Value ${LIST_V2_S3_OBJECTS} ${FILE_S3_NAME} - List Should Contain Value ${LIST_V2_S3_OBJECTS} ${FILE_S3_NAME} - - Get object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3_NAME} s3_obj_get_s3 + + Get object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3_NAME} s3_obj_get_s3 Verify file hash s3_obj_get_s3 ${FILE_S3_HASH} - Copy object S3 ${S3_CLIENT} ${S3_BUCKET} ${FILE_S3_NAME} NewName - ${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${S3_BUCKET} + #TODO: Solve the issue on CopyObject #260 https://github.com/nspcc-dev/neofs-s3-gw/issues/260 + + Copy object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3_NAME} NewName + ${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${NEW_BUCKET} List Should Contain Value ${LIST_S3_OBJECTS} NewName + Copy object S3 ${S3_CLIENT} ${NEW_BUCKET_2} ${FILE_S3_NAME} NewName_2 + ${LIST_S3_OBJECTS_2} = List objects S3 ${S3_CLIENT} ${NEW_BUCKET_2} + List Should Contain Value ${LIST_S3_OBJECTS_2} NewName_2 - Delete object S3 ${S3_CLIENT} ${BUCKET} ${FILE_S3_NAME} - ${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${S3_BUCKET} - List Should Not Contain Value ${LIST_S3_OBJECTS} FILE_S3_NAME + Delete object S3 ${S3_CLIENT} ${NEW_BUCKET} ${FILE_S3_NAME} + ${LIST_S3_OBJECTS} = List objects S3 ${S3_CLIENT} ${NEW_BUCKET} + List Should Not Contain Value ${LIST_S3_OBJECTS} ${FILE_S3_NAME} + [Teardown] Teardown s3_gate_object \ No newline at end of file