From 76739676dc97db66b5686ad06d5f41273f68b746 Mon Sep 17 00:00:00 2001 From: Bin Qian Date: Thu, 28 Mar 2024 19:20:51 +0000 Subject: [PATCH] Fix deploy show and deploy host-list output Fix software deploy show and deploy host-list not displaying information issue. Also default the deploy host state to pending when a deploy host entity is created. Story: 2010676 Task: 49645 TCs: passed: software deploy show and software deploy host-list show deploy data after deploy start command accepted. passed: display "No deploy in progress" for software deploy show when there is no deploy. Change-Id: I9dc50804c66d5cb07df7717fd6623c23d0fca522 Signed-off-by: Bin Qian --- software-client/software_client/common/utils.py | 3 +-- software-client/software_client/v1/deploy.py | 3 +-- software-client/software_client/v1/deploy_shell.py | 2 ++ software/software/api/controllers/v1/software.py | 11 ++++------- software/software/software_controller.py | 4 +++- software/software/software_entities.py | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/software-client/software_client/common/utils.py b/software-client/software_client/common/utils.py index aa49e9e6..f1b71a95 100644 --- a/software-client/software_client/common/utils.py +++ b/software-client/software_client/common/utils.py @@ -189,8 +189,7 @@ def print_result_list(header_data_list, data_list, has_error, sort_key=0): def print_software_deploy_host_list_result(req, data): - if req.status_code == 200 and data: - data = data.get("data", None) + if req.status_code == 200: if not data: print("No deploy in progress.\n") return diff --git a/software-client/software_client/v1/deploy.py b/software-client/software_client/v1/deploy.py index 30a4c53a..4aa9d2e5 100644 --- a/software-client/software_client/v1/deploy.py +++ b/software-client/software_client/v1/deploy.py @@ -122,10 +122,9 @@ class DeployManager(base.Manager): print("Respond code %d. Error: %s" % (req.status_code, req.reason)) return 1 - if not data or data.get("data"): + if not data: print("No deploy in progress.") else: - data = data.get("data") data = data[0] data["reboot_required"] = "Yes" if data.get("reboot_required") else "No" data_list = [[k, v] for k, v in data.items()] diff --git a/software-client/software_client/v1/deploy_shell.py b/software-client/software_client/v1/deploy_shell.py index 1f7787a4..06f9e48f 100644 --- a/software-client/software_client/v1/deploy_shell.py +++ b/software-client/software_client/v1/deploy_shell.py @@ -21,12 +21,14 @@ from software_client.common import utils help="List all deployments that have this state") def do_show(cc, args): """Show the software deployments states""" + # TODO(bqian) modify the cli to display with generic tabulated output return cc.deploy.show() def do_host_list(cc, args): """List of hosts for software deployment """ req, data = cc.deploy.host_list() + # TODO(bqian) modify display with generic tabulated output if args.debug: utils.print_result_debug(req, data) else: diff --git a/software/software/api/controllers/v1/software.py b/software/software/api/controllers/v1/software.py index 24c90bb1..ca8fbd33 100644 --- a/software/software/api/controllers/v1/software.py +++ b/software/software/api/controllers/v1/software.py @@ -10,7 +10,6 @@ import logging import os from pecan import expose from pecan import request -from pecan import Response import shutil from software.exceptions import SoftwareError @@ -110,9 +109,8 @@ class SoftwareAPIController(object): def deploy(self): from_release = request.GET.get("from_release") to_release = request.GET.get("to_release") - result = dict(data=sc.software_deploy_show_api(from_release, to_release)) - response_data = json.dumps(result) - return Response(body=response_data, status_code=200) + result = sc.software_deploy_show_api(from_release, to_release) + return result @expose('json') @expose('query.xml', content_type='application/xml') @@ -194,9 +192,8 @@ class SoftwareAPIController(object): @expose('json', method="GET") def host_list(self): - query_hosts = dict(data=sc.deploy_host_list()) - response_data = json.dumps(query_hosts) - return Response(body=response_data, status_code=200) + result = sc.deploy_host_list() + return result @expose(method='GET', template='json') def in_sync_controller(self): diff --git a/software/software/software_controller.py b/software/software/software_controller.py index d1d62020..92992d0a 100644 --- a/software/software/software_controller.py +++ b/software/software/software_controller.py @@ -2363,6 +2363,8 @@ class PatchController(PatchService): create_deploy_hosts() self.db_api_instance.begin_update() try: + # TODO(bqian) replace SW_VERSION below to current running sw_release + # (MM.mm.pp) self.update_and_sync_deploy_state(self.db_api_instance.create_deploy, SW_VERSION, to_release, True) self.update_and_sync_deploy_state(self.db_api_instance.update_deploy, @@ -3020,7 +3022,7 @@ class PatchController(PatchService): deploy_hosts = self.db_api_instance.get_deploy_host() deploy = self.db_api_instance.get_deploy_all() if not deploy: - return None + return [] deploy = deploy[0] deploy_host_list = [] diff --git a/software/software/software_entities.py b/software/software/software_entities.py index 2a87bd19..d3346de9 100644 --- a/software/software/software_entities.py +++ b/software/software/software_entities.py @@ -325,7 +325,7 @@ class DeployHostHandler(DeployHosts): super().__init__() self.data = get_software_filesystem_data() - def create(self, hostname, state: DEPLOY_HOST_STATES = None): + def create(self, hostname, state: DEPLOY_HOST_STATES = DEPLOY_HOST_STATES.PENDING): super().create(hostname, state) deploy = self.query(hostname) if deploy: