From ac4cbce870aa76baa5bd30e235a53ce1299123ce Mon Sep 17 00:00:00 2001 From: Heitor Matsui Date: Thu, 15 Feb 2024 17:35:01 -0300 Subject: [PATCH] Add package listing option for "software show" As a follow-up commit for [1], this commit adds an optional argument to the "software show" command to allow the user to choose if the deb packages contained within a release should be displayed along with the release information. [1] https://review.opendev.org/c/starlingx/update/+/909046 Test Plan PASS: use "software show" with "--packages" option and verify deb packages information is displayed PASS: use "software show" without "--packages" option and verify deb packages information is not displayed Story: 2010676 Task: 49579 Change-Id: I79e63cbb24dbe085d4f5dad2f2b1718a21044631 Signed-off-by: Heitor Matsui --- .../software_client/software_client.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/software-client/software_client/software_client.py b/software-client/software_client/software_client.py index c22e8209..07fd3312 100644 --- a/software-client/software_client/software_client.py +++ b/software-client/software_client/software_client.py @@ -173,7 +173,7 @@ def print_software_op_result(req): print("Error: %s has occurred. %s" % (req.status_code, req.reason)) -def print_release_show_result(req): +def print_release_show_result(req, list_packages=False): if req.status_code == 200: data = json.loads(req.text) @@ -266,10 +266,11 @@ def print_release_show_result(req): contents[release_id]["commit%s" % (i + 1)]["commit"], width=TERM_WIDTH, subsequent_indent=' ' * 20)) - if "packages" in sd[release_id] and len(sd[release_id]["packages"]): - print(" Packages:") - for package in sorted(sd[release_id]["packages"]): - print(" " * 20 + package) + if list_packages: + if "packages" in sd[release_id] and len(sd[release_id]["packages"]): + print(" Packages:") + for package in sorted(sd[release_id]["packages"]): + print(" " * 20 + package) print("\n") @@ -680,6 +681,7 @@ def deploy_host_list_req(args): def release_show_req(args): # arg.release is a list releases = "/".join(args.release) + list_packages = args.packages url = "http://%s/v1/software/show/%s" % (api_addr, releases) @@ -691,7 +693,7 @@ def release_show_req(args): if args.debug: print_result_debug(req) else: - print_release_show_result(req) + print_release_show_result(req, list_packages=list_packages) return check_rc(req) @@ -1512,7 +1514,12 @@ def setup_argparse(): cmd.set_defaults(restricted=False) # can run non root cmd.add_argument('release', nargs="+", # accepts a list - help='Release ID to show') + help='release ID to print detailed information') + cmd.add_argument('--packages', + required=False, + default=False, + action='store_true', + help='list packages contained in the release') # --- software upload --------------- cmd = commands.add_parser(