Skip to content

Commit

Permalink
Fix tox
Browse files Browse the repository at this point in the history
Signed-off-by: ckulal <[email protected]>
  • Loading branch information
ckulal committed Mar 4, 2024
1 parent 4f3a055 commit 6b33d56
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#BZ: BZ2266579
config:
user_count: 1
bucket_count: 1
test_ops:
verify_etag_for_complete_multipart_upload: true
42 changes: 30 additions & 12 deletions rgw/v2/tests/aws/reusable.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,25 @@ def create_multipart_upload(bucket_name, key_name, end_point, ssl=None):
else:
ssl_param = " "
command = list_method.command(
params=[f"--bucket {bucket_name} --key {key_name} --endpoint-url {end_point}", ssl_param]
params=[
f"--bucket {bucket_name} --key {key_name} --endpoint-url {end_point}",
ssl_param,
]
)
try:
response = utils.exec_shell_cmd(command)
if not response:
raise Exception(f"creating multipart upload failed for bucket {bucket_name} with object name {key_name}")
raise Exception(
f"creating multipart upload failed for bucket {bucket_name} with object name {key_name}"
)
return response
except Exception as e:
raise AWSCommandExecError(message=str(e))


def upload_part(bucket_name, key_name, part_number, upload_id, body, end_point, ssl=None):
def upload_part(
bucket_name, key_name, part_number, upload_id, body, end_point, ssl=None
):
"""
Upload part to the key in a bucket
Ex: /usr/local/bin/aws s3api upload-part --bucket <bucket_name> --key <key_name> --part-number <part_number>
Expand All @@ -127,20 +134,27 @@ def upload_part(bucket_name, key_name, part_number, upload_id, body, end_point,
else:
ssl_param = " "
command = list_method.command(
params=[f"--bucket {bucket_name} --key {key_name} --part-number {part_number} --upload-id {upload_id}"
f" --body {body} --endpoint-url {end_point}", ssl_param]
params=[
f"--bucket {bucket_name} --key {key_name} --part-number {part_number} --upload-id {upload_id}"
f" --body {body} --endpoint-url {end_point}",
ssl_param,
]
)
try:
response = utils.exec_shell_cmd(command)
if not response:
raise Exception(f"Uploading part failed for bucket {bucket_name} with key {key_name} and upload id"
f" {upload_id}")
raise Exception(
f"Uploading part failed for bucket {bucket_name} with key {key_name} and upload id"
f" {upload_id}"
)
return response
except Exception as e:
raise AWSCommandExecError(message=str(e))


def complete_multipart_upload(bucket_name, key_name, upload_file, upload_id, end_point, ssl=None):
def complete_multipart_upload(
bucket_name, key_name, upload_file, upload_id, end_point, ssl=None
):
"""
Complete multipart uploads for given object on a given bucket
Ex: /usr/local/bin/aws s3api complete-multipart-upload --multipart-upload file://<upload_file>
Expand Down Expand Up @@ -169,14 +183,18 @@ def complete_multipart_upload(bucket_name, key_name, upload_file, upload_id, end
else:
ssl_param = " "
command = list_method.command(
params=[f"--multipart-upload file://{upload_file} --bucket {bucket_name} --key {key_name} --upload-id {upload_id} "
f"--endpoint-url {end_point}", ssl_param]
params=[
f"--multipart-upload file://{upload_file} --bucket {bucket_name} --key {key_name} --upload-id {upload_id} "
f"--endpoint-url {end_point}",
ssl_param,
]
)
try:
response = utils.exec_shell_cmd(command)
if not response:
raise Exception(f"creating multipart upload failed for bucket {bucket_name} with key {key_name} and"
f" upload id {upload_id}")
raise Exception(
f"creating multipart upload failed for bucket {bucket_name} with key {key_name} and"
f" upload id {upload_id}")
return response
except Exception as e:
raise AWSCommandExecError(message=str(e))
Expand Down
42 changes: 28 additions & 14 deletions rgw/v2/tests/aws/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,33 +71,47 @@ def test_exec(config, ssh_con):
log.info(f"bucket versioning test on bucket: {bucket_name}")
aws_reusable.put_get_bucket_versioning(bucket_name, endpoint)
if config.test_ops.get("verify_etag_for_complete_multipart_upload", False):
log.info(f"Verfying Etag element for complete multipart upload is not empty string")
log.info(
f"Verifying ETag element for complete multipart upload is not empty string"
)
log.info("Create multipart upload")
key_name = bucket_name + "_object"
create_mp_upload_resp = aws_reusable.create_multipart_upload(bucket_name, key_name, endpoint)
create_mp_upload_resp = aws_reusable.create_multipart_upload(
bucket_name, key_name, endpoint
)
upload_id = json.loads(create_mp_upload_resp)["UploadId"]
log.info(f"upload part one of object: {key_name}")
utils.exec_shell_cmd(f"fallocate -l 20m key20m")
upload_part1 = json.loads(aws_reusable.upload_part(bucket_name, key_name, 1, upload_id, "key20m", endpoint))
upload_part1 = json.loads(
aws_reusable.upload_part(
bucket_name, key_name, 1, upload_id, "key20m", endpoint
)
)
log.info(f"upload part two of object: {key_name}")
utils.exec_shell_cmd(f"fallocate -l 22m key22m")
upload_part2 = json.loads(aws_reusable.upload_part(bucket_name, key_name, 2, upload_id, "key22m", endpoint))
upload_part2 = json.loads(
aws_reusable.upload_part(
bucket_name, key_name, 2, upload_id, "key22m", endpoint
)
)

parts = [
{"ETag": upload_part1["ETag"],
"PartNumber": 1},
{"ETag": upload_part2["ETag"],
"PartNumber": 2}
]
{"ETag": upload_part1["ETag"], "PartNumber": 1},
{"ETag": upload_part2["ETag"], "PartNumber": 2}
]
mpstructure = {"Parts": parts}
os.system("touch test.json")
with open('test.json', 'w') as fd:
with open("test.json", "w") as fd:
json.dump(mpstructure, fd)
complete_multipart_upload_resp = json.loads(aws_reusable.complete_multipart_upload(bucket_name, key_name,
"test.json", upload_id,
endpoint))
complete_multipart_upload_resp = json.loads(
aws_reusable.complete_multipart_upload(
bucket_name, key_name, "test.json", upload_id, endpoint
)
)
if not complete_multipart_upload_resp["ETag"]:
raise AssertionError("Etag not generated during complete multipart upload operation")
raise AssertionError(
"Etag not generated during complete multipart upload operation"
)

if config.user_remove is True:
s3_reusable.remove_user(user)
Expand Down

0 comments on commit 6b33d56

Please sign in to comment.