From 2c27382ebad541634d8dad71d06fdeffbc8c4547 Mon Sep 17 00:00:00 2001 From: Heitor Matsui Date: Tue, 19 Mar 2024 21:25:01 -0300 Subject: [PATCH] Fix upload-dir logic, return and help text Currently upload-dir logic was uploading only the files from the last directory passed as argument to the command, and it's help text and output was divergent from the similar "software upload" command. This commit fixes the logic, allowing uploading from multiple directories correctly, and fixes the help text and output to align with "software upload". Test Plan PASS: show help text for "software upload-dir" PASS: upload one directory containing patches PASS: upload one directory containing iso + patches PASS: upload multiple directories containing patches PASS: upload multiple directories containing iso + patches Story: 2010676 Task: 49693 Change-Id: I5886e8c5c55355e24ec471c4ae47e91ec3c84dfd Signed-off-by: Heitor Matsui --- software-client/software_client/v1/release.py | 22 ++++++++++++++----- .../software_client/v1/release_shell.py | 16 +++++++++----- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/software-client/software_client/v1/release.py b/software-client/software_client/v1/release.py index 1f3f248f..fdf7bd34 100644 --- a/software-client/software_client/v1/release.py +++ b/software-client/software_client/v1/release.py @@ -104,7 +104,7 @@ class ReleaseManager(base.Manager): signal.signal(signal.SIGINT, signal.SIG_IGN) to_upload_files = {} - raw_files = [] + all_raw_files = [] # Find all files that need to be uploaded in given directories for release_dir in release_dirs: @@ -114,27 +114,30 @@ class ReleaseManager(base.Manager): # Get absolute path of files raw_files = [os.path.abspath(os.path.join(release_dir, f)) for f in raw_files] + + # Append files from directory into the full list + all_raw_files.extend(raw_files) else: print("Skipping invalid directory: %s" % release_dir, file=sys.stderr) - if len(raw_files) == 0: + if len(all_raw_files) == 0: print("No file to upload") return 0 - temp_iso_files = [f for f in raw_files if f.endswith(constants.ISO_EXTENSION)] + temp_iso_files = [f for f in all_raw_files if f.endswith(constants.ISO_EXTENSION)] if len(temp_iso_files) > 1: # Verify that only one ISO file is being uploaded print("Only one ISO file can be uploaded at a time. Found: %s" % temp_iso_files, file=sys.stderr) return 1 - temp_sig_files = [f for f in raw_files if f.endswith(constants.SIG_EXTENSION)] + temp_sig_files = [f for f in all_raw_files if f.endswith(constants.SIG_EXTENSION)] if len(temp_sig_files) > 1: # Verify that only one SIG file is being uploaded print("Only one SIG file can be uploaded at a time. Found: %s" % temp_sig_files, file=sys.stderr) return 1 - for software_file in sorted(set(raw_files)): + for software_file in sorted(set(all_raw_files)): _, ext = os.path.splitext(software_file) if ext in constants.SUPPORTED_UPLOAD_FILE_EXT: to_upload_files[software_file] = (software_file, open(software_file, 'rb')) @@ -147,6 +150,15 @@ class ReleaseManager(base.Manager): utils.print_result_debug(req, data) else: utils.print_software_op_result(req, data) + data = json.loads(req.text) + data_list = [(k, v["id"]) + for d in data["upload_info"] for k, v in d.items() + if not k.endswith(".sig")] + + header_data_list = ["Uploaded File", "Id"] + has_error = 'error' in data and data["error"] + utils.print_result_list(header_data_list, data_list, has_error) + return utils.check_rc(req, data) def commit_patch(self, args): diff --git a/software-client/software_client/v1/release_shell.py b/software-client/software_client/v1/release_shell.py index 601836ef..435b4138 100644 --- a/software-client/software_client/v1/release_shell.py +++ b/software-client/software_client/v1/release_shell.py @@ -145,14 +145,13 @@ def do_is_committed(cc, args): @utils.arg('release', metavar='(iso + sig) | patch', nargs="+", # accepts a list - help='Software releases to upload') -@utils.arg('--local', - required=False, - default=False, - action='store_true', help=('pair of install iso and sig files for major release ' '(GA or patched) and/or one or more files containing a ' 'patch release. NOTE: specify at most ONE pair of (iso + sig)')) +@utils.arg('--local', + required=False, + default=False, + action='store_true') def do_upload(cc, args): """Upload a software release""" req, data = cc.release.upload(args) @@ -175,8 +174,13 @@ def do_upload(cc, args): @utils.arg('release', + metavar='directory', nargs="+", # accepts a list - help='Directory containing software releases to upload') + help=('directory containing software releases files to upload. ' + 'The release files may be either a pair of install iso and ' + 'sig files for major release (GA or patched) and/or one or ' + 'more files containing a patch release. NOTE: specify at most ' + 'ONE pair of (iso + sig)')) def do_upload_dir(cc, args): """Upload a software release dir""" return cc.release.upload_dir(args)