From d6335fc1cc31316e98453214e128418220d284a7 Mon Sep 17 00:00:00 2001 From: Gustavo Herzmann Date: Mon, 24 Jul 2023 15:08:44 -0300 Subject: [PATCH] Add 'subcloud deploy complete' command to dcmanager This commit adds the subcloud deploy complete command to dcmanager client. It's used to mark the subcloud deployment as 'complete', usefull when the user manually configures the subcloud and wants to finalize the deployment without running 'dcmanager subcloud deploy config'. Usage: dcmanager subcloud deploy complete subcloud-name To run the 'deploy complete' operation deploy status of the subcloud must be 'bootstrap-complete' Test Plan: 1. PASS - Verify that the dcmanager help subcloud deploy complete shows the correct help message; 2. PASS - Run 'dcmanager subcloud deploy complete' and verify that the correct API call is made; 3. PASS - Verify that the subcloud name/id parameter is required. Depends-On: https://review.opendev.org/c/starlingx/distcloud/+/889877 Story: 2010756 Task: 48454 Change-Id: I53929dcad068c93982e3381f47f4dda61b3b5d1e Signed-off-by: Gustavo Herzmann --- .../api/v1/phased_subcloud_deploy_manager.py | 4 +++ .../v1/phased_subcloud_deploy_manager.py | 30 +++++++++++++++++++ .../dcmanagerclient/shell.py | 1 + .../tests/v1/test_phased_subcloud_deploy.py | 8 +++++ 4 files changed, 43 insertions(+) diff --git a/distributedcloud-client/dcmanagerclient/api/v1/phased_subcloud_deploy_manager.py b/distributedcloud-client/dcmanagerclient/api/v1/phased_subcloud_deploy_manager.py index a131bcb..ad96148 100644 --- a/distributedcloud-client/dcmanagerclient/api/v1/phased_subcloud_deploy_manager.py +++ b/distributedcloud-client/dcmanagerclient/api/v1/phased_subcloud_deploy_manager.py @@ -61,6 +61,10 @@ class phased_subcloud_deploy_manager(base.ResourceManager): url = BASE_URL + "%s/configure" % subcloud_ref return self._deploy_operation(url, files, data, method='patch') + def subcloud_deploy_complete(self, subcloud_ref): + url = BASE_URL + "%s/complete" % subcloud_ref + return self._deploy_operation(url, {}, {}, method='patch') + def subcloud_deploy_abort(self, subcloud_ref, **kwargs): # Currently it's not passed neither data or files to abort, # so we pass an empty dict to use the _deploy_operation function diff --git a/distributedcloud-client/dcmanagerclient/commands/v1/phased_subcloud_deploy_manager.py b/distributedcloud-client/dcmanagerclient/commands/v1/phased_subcloud_deploy_manager.py index effb161..4da924a 100644 --- a/distributedcloud-client/dcmanagerclient/commands/v1/phased_subcloud_deploy_manager.py +++ b/distributedcloud-client/dcmanagerclient/commands/v1/phased_subcloud_deploy_manager.py @@ -490,3 +490,33 @@ class ConfigPhasedSubcloudDeploy(base.DCManagerShowOne): print(e) error_msg = "Unable to configure subcloud %s" % (subcloud_ref) raise exceptions.DCManagerClientException(error_msg) + + +class CompletePhasedSubcloudDeploy(base.DCManagerShowOne): + """Complete a subcloud deployment.""" + + def _get_format_function(self): + return utils.subcloud_detail_format + + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + + parser.add_argument( + 'subcloud', + help='Name or ID of the subcloud to complete the deployment.' + ) + + return parser + + def _get_resources(self, parsed_args): + subcloud_ref = parsed_args.subcloud + dcmanager_client = self.app.client_manager.\ + phased_subcloud_deploy_manager.phased_subcloud_deploy_manager + + try: + return dcmanager_client.subcloud_deploy_complete(subcloud_ref) + except Exception as e: + print(e) + error_msg = "Unable to complete the deployment of subcloud %s" % ( + subcloud_ref) + raise exceptions.DCManagerClientException(error_msg) diff --git a/distributedcloud-client/dcmanagerclient/shell.py b/distributedcloud-client/dcmanagerclient/shell.py index eac6e80..c803e8c 100644 --- a/distributedcloud-client/dcmanagerclient/shell.py +++ b/distributedcloud-client/dcmanagerclient/shell.py @@ -549,6 +549,7 @@ class DCManagerShell(app.App): 'subcloud deploy bootstrap': psdm.BootstrapPhasedSubcloudDeploy, 'subcloud deploy config': psdm.ConfigPhasedSubcloudDeploy, 'subcloud deploy install': psdm.InstallPhasedSubcloudDeploy, + 'subcloud deploy complete': psdm.CompletePhasedSubcloudDeploy, 'subcloud deploy resume': psdm.PhasedSubcloudDeployResume, 'subcloud deploy upload': sdm.SubcloudDeployUpload, 'subcloud deploy show': sdm.SubcloudDeployShow, diff --git a/distributedcloud-client/dcmanagerclient/tests/v1/test_phased_subcloud_deploy.py b/distributedcloud-client/dcmanagerclient/tests/v1/test_phased_subcloud_deploy.py index 394e686..f2bd568 100644 --- a/distributedcloud-client/dcmanagerclient/tests/v1/test_phased_subcloud_deploy.py +++ b/distributedcloud-client/dcmanagerclient/tests/v1/test_phased_subcloud_deploy.py @@ -138,6 +138,14 @@ class TestCLIPhasedSubcloudDeployManagerV1(base.BaseCommandTest): '--deploy-config', file_path]) self.assertTrue('deploy-config file does not exist' in str(e)) + def test_complete_subcloud_deployment(self): + self.client.subcloud_deploy_complete.return_value = [ + base.SUBCLOUD_RESOURCE] + actual_call = self.call( + cmd.CompletePhasedSubcloudDeploy, + app_args=[base.NAME]) + self.assertEqual(base.SUBCLOUD_FIELD_RESULT_LIST, actual_call[1]) + def test_abort_subcloud(self): self.client.subcloud_deploy_abort.return_value = [ base.SUBCLOUD_RESOURCE]