From bb361f47bf9bfad79af0c062fa1107386e769faa Mon Sep 17 00:00:00 2001 From: Julie Pichon Date: Thu, 16 Mar 2017 11:09:00 +0000 Subject: [PATCH] Fix return code when failing before launching the stack Until now when a configuration error was detected early during the pre-deployment verifications, the command would correctly return before attempting to create/update the Heat stack, however the return code would still show as '0', preventing scripts from picking up the problem. Conflicts: tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py tripleoclient/v1/overcloud_deploy.py Change-Id: I8bd16e9753618e4c234440d7a6626e0ce4bd9972 Closes-Bug: #1672790 (cherry picked from commit 28051613c9c1c5231140981fca76fa704af55d5d) --- ...on-predeploy-failure-bd62025646e25433.yaml | 7 ++++++ .../overcloud_deploy/test_overcloud_deploy.py | 25 +++++++++++++++++++ tripleoclient/v1/overcloud_deploy.py | 4 +-- 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/return-code-on-predeploy-failure-bd62025646e25433.yaml diff --git a/releasenotes/notes/return-code-on-predeploy-failure-bd62025646e25433.yaml b/releasenotes/notes/return-code-on-predeploy-failure-bd62025646e25433.yaml new file mode 100644 index 000000000..8261145cf --- /dev/null +++ b/releasenotes/notes/return-code-on-predeploy-failure-bd62025646e25433.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + `overcloud deploy` correctly returns an error code when failing + during the pre-deployment verifications (before the stack is + launched) (`bug 1672790 + `__). diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index eae39785a..202ba9c59 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -1507,3 +1507,28 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): {}, 1, '/tmp', {}, True) self.assertFalse(mock_deploy_and_wait.called) + + @mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True) + @mock.patch('tripleoclient.utils.write_overcloudrc', autospec=True) + @mock.patch('tripleoclient.workflows.deployment.overcloudrc', + autospec=True) + @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' + '_deploy_tripleo_heat_templates_tmpdir', autospec=True) + def test_validations_failure_raises_exception( + self, mock_deploy_tmpdir, + mock_overcloudrc, mock_write_overcloudrc, + mock_overcloud_endpoint): + clients = self.app.client_manager + orchestration_client = clients.orchestration + orchestration_client.stacks.get.return_value = mock.Mock() + self.cmd._predeploy_verify_capabilities = mock.Mock( + return_value=(1, 0)) + + arglist = ['--templates'] + verifylist = [ + ('templates', '/usr/share/openstack-tripleo-heat-templates/'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises(exceptions.InvalidConfiguration, + self.cmd.take_action, parsed_args) diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index 1eee8521d..277ab10be 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -1140,13 +1140,13 @@ class DeployOvercloud(command.Command): errors) if parsed_args.validation_warnings_fatal or \ parsed_args.validation_errors_fatal: - return + raise exceptions.InvalidConfiguration() if warnings > 0: self.log.error( "Configuration has %d warnings, fix them before proceeding. ", warnings) if parsed_args.validation_warnings_fatal: - return + raise exceptions.InvalidConfiguration() else: self.log.info("SUCCESS: No warnings or errors in deploy " "configuration, proceeding.")