Fix deploy upload invalid arg exit
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) <arg> does not exist: <file>” Closes-Bug: 2032970 Change-Id: I53da00a1ba4562aae4345ea1182ca923d227d0e8 Signed-off-by: Salman Rana <salman.rana@windriver.com>
This commit is contained in:
parent
eee5c7cedf
commit
db6d32fdf7
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue