From db6d32fdf773d56e4adee15674a0bcdd3522ef30 Mon Sep 17 00:00:00 2001 From: Salman Rana Date: Thu, 24 Aug 2023 12:04:36 -0400 Subject: [PATCH] Fix deploy upload invalid arg exit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Raise a DCManagerClientException to exit from the deploy upload command handler when an invalid file arg is encountered. Otherwise, exiting the method with a simple return results in: - an exit code of 0 (a non-zero exit code is expected) - Output of an empty deploy table (SubcloudDeployUpload is a subclass of DCManagerShowOne. A simple return is interpreted as success, hence a console output of an empty result is displayed) Overall, this behavior is misleading as it indicates success despite the failure. This behavior is specific to the file arg check (client-side validation done prior to the endpoint call). Backend errors have been verified to be handled properly, with a non-zero exit code. Test Plan: Using deploy upload (dcmanager subcloud-deploy upload): 1. PASS: Execute the command with valid arguments (correct file references); verify a zero exit code (“echo $?”) and console output displaying the deploy table. 2. PASS: Execute the command with an invalid argument (missing reference file); verify a non-zero exit code (“echo $?”), no deploy table console output and an error message “ERROR (app) does not exist: ” Closes-Bug: 2032970 Change-Id: I53da00a1ba4562aae4345ea1182ca923d227d0e8 Signed-off-by: Salman Rana --- .../commands/v1/subcloud_deploy_manager.py | 9 +++------ .../tests/v1/test_subcloud_deploy_manager.py | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_deploy_manager.py b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_deploy_manager.py index d1b41a0..a56eeb5 100644 --- a/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_deploy_manager.py +++ b/distributedcloud-client/dcmanagerclient/commands/v1/subcloud_deploy_manager.py @@ -119,12 +119,9 @@ class SubcloudDeployUpload(base.DCManagerShowOne): if val is None: continue elif not os.path.isfile(val): - error_msg = "error: argument --%s directory %s not valid" \ - % (key, val) - print(error_msg) - return - else: - files[key] = val + error_msg = f"{key} file does not exist: {val}" + raise exceptions.DCManagerClientException(error_msg) + files[key] = val if parsed_args.release is not None: data['release'] = parsed_args.release diff --git a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_deploy_manager.py b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_deploy_manager.py index 20f9965..5e3806d 100644 --- a/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_deploy_manager.py +++ b/distributedcloud-client/dcmanagerclient/tests/v1/test_subcloud_deploy_manager.py @@ -19,6 +19,7 @@ import tempfile from dcmanagerclient.api.v1 import subcloud_deploy_manager as sdm from dcmanagerclient.commands.v1 \ import subcloud_deploy_manager as subcloud_deploy_cmd +from dcmanagerclient.exceptions import DCManagerClientException from dcmanagerclient.tests import base @@ -249,12 +250,13 @@ class TestCLISubcloudDeployManagerV1(base.BaseCommandTest): tempfile.NamedTemporaryFile() as f3: file_path_2 = os.path.abspath(f2.name) file_path_3 = os.path.abspath(f3.name) - self.call( - subcloud_deploy_cmd.SubcloudDeployUpload, - app_args=[ - '--deploy-playbook', file_path_1, - '--deploy-overrides', file_path_2, - '--deploy-chart', file_path_3]) - mock_print.assert_called_with('error: argument --deploy_playbook' - ' directory not_a_valid_path not valid') + e = self.assertRaises(DCManagerClientException, + self.call, + subcloud_deploy_cmd.SubcloudDeployUpload, + app_args=['--deploy-playbook', file_path_1, + '--deploy-overrides', file_path_2, + '--deploy-chart', file_path_3]) + + self.assertTrue('deploy_playbook file does not exist: not_a_valid_path' + in str(e))