-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added simple test tool to perform object upload, download, verify #12
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a399fbf
Added simple test tool to perform object upload, download, verify
grandsuri 68aca0d
Fixed warning messages from sonar cloud and pycodestyle
grandsuri 8b49838
Fixed few issues related to path joining and arguments
grandsuri bcc50dd
Added DEL support to the tool
grandsuri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import argparse | ||
import dss | ||
import hashlib | ||
import os | ||
|
||
data_hash_map = dict() | ||
|
||
|
||
def command_line_parser(): | ||
parser = argparse.ArgumentParser(description='Distributed version of S3 CLI to perform Data integrity') | ||
parser.add_argument("--count", "-c", type=int, default=1, required=False, action='store', | ||
help='Number of files (Default: 1)') | ||
parser.add_argument("--debug", "-d", required=False, action='store_true', | ||
help='Debug flag (Default: False)') | ||
parser.add_argument("--endpoint", "-e", type=str, required=True, action='store', | ||
help='Cluster endpoint IP address (Default: <minio_ip_addr>:<port>)') | ||
parser.add_argument("--file_name_prefix", "-f", type=str, default="testfile", required=False, action='store', | ||
help='File name prefix(Default: testfile)') | ||
parser.add_argument("--path_prefix", "-p", type=str, default="/samsung/s3test/", required=False, action='store', | ||
help='Prefix path for the files to be uploaded. Creates dir if not present' | ||
'(Default: /samsung/s3test/)') | ||
parser.add_argument("--password", "-pw", type=str, default="minio123", required=False, action='store', | ||
help='Minio endpoint password (Default: minio123)') | ||
parser.add_argument("--size", "-s", type=int, default=1, required=False, action='store', | ||
help='Size in MB (Default: 1)') | ||
parser.add_argument("--user", "-u", type=str, default="minio", required=False, action='store', | ||
help='Minio endpoint admin (Default: minio)') | ||
return parser | ||
|
||
|
||
def create_client_connection(endpoint, user='minio', pw='minio123'): | ||
c = dss.createClient(endpoint, user, pw) | ||
return c | ||
|
||
|
||
def get_object(client_handle, filename, size, print_enable=False): | ||
buffer = bytearray(size) | ||
content_length = client_handle.getObjectBuffer(filename, buffer) | ||
mv = memoryview(buffer) | ||
data_out = mv[:content_length] | ||
data_out_chksum = hashlib.sha512(data_out).hexdigest() | ||
if print_enable: | ||
print(f"GetObject: {filename} length: {content_length} chksum: {data_out_chksum}") | ||
return data_out_chksum | ||
|
||
|
||
def put_object(client_handle, filename, size, print_enable=False): | ||
buffer = os.urandom(size) | ||
client_handle.putObjectBuffer(filename, buffer, size) | ||
data_in_chksum = hashlib.sha512(buffer).hexdigest() | ||
if print_enable: | ||
print(f"PutObject: {filename} length: {size} chksum: {data_in_chksum}") | ||
return data_in_chksum | ||
|
||
|
||
def del_object(client_handle, filename, print_enable=False): | ||
ret = client_handle.deleteObject(filename) | ||
if print_enable: | ||
print(f"DeleteObject: {filename} return val: {ret}") | ||
return ret | ||
|
||
|
||
def data_integrity_check(endpoint, user, password, prefix, file_name_prefix, size, file_count, debug=False): | ||
try: | ||
c = create_client_connection(endpoint, user, password) | ||
print(f"Uploading objects with the name {prefix + file_name_prefix}") | ||
print("-" * 64) | ||
os.makedirs(prefix, 0o755, True) | ||
full_filename_prefix = os.path.join(prefix, file_name_prefix) | ||
for i in range(file_count): | ||
filename = full_filename_prefix + str(i) | ||
if debug: | ||
print(f"Uploading file {filename}") | ||
object_data = os.urandom(size) | ||
with open(filename, 'wb') as f: | ||
f.write(object_data) | ||
data_in_md5 = put_object(c, filename, size, debug) | ||
data_hash_map[filename] = data_in_md5 | ||
print("-" * 64) | ||
|
||
print(f"Downloading objects with the name {full_filename_prefix} and verifying") | ||
print("-" * 64) | ||
for i in range(file_count): | ||
filename = full_filename_prefix + str(i) | ||
if debug: | ||
print(f"Downloading file {filename}") | ||
data_out_chksum = get_object(c, filename, size, debug) | ||
if data_out_chksum != data_hash_map[filename]: | ||
print(f"File {filename} contents mismatched") | ||
print("-" * 64) | ||
|
||
print(f"Deleting objects with the name {full_filename_prefix}") | ||
print("-" * 64) | ||
for i in range(file_count): | ||
filename = full_filename_prefix + str(i) | ||
if debug: | ||
print(f"Deleting file {filename}") | ||
ret = del_object(c, filename, debug) | ||
if ret == 0: | ||
print(f"File {filename} deleted successfully") | ||
else: | ||
print(f"Failure in deleting the file {filename}") | ||
print("-" * 64) | ||
|
||
print(f"Cleaning up objects with the name {full_filename_prefix} on local disk") | ||
print("-" * 64) | ||
for i in range(file_count): | ||
filename = full_filename_prefix + str(i) | ||
os.unlink(filename) | ||
print("-" * 64) | ||
|
||
except Exception as e: | ||
print(f"Exception {e}") | ||
|
||
|
||
if __name__ == '__main__': | ||
p = command_line_parser() | ||
args = p.parse_args() | ||
data_integrity_check(args.endpoint, args.user, args.password, args.path_prefix, args.file_name_prefix, args.size * 1024 * 1024, | ||
args.count, args.debug) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want the user/pass exposed here?