From 7f16d103560bf6d915ac717e9d5b092295bc0eae Mon Sep 17 00:00:00 2001 From: Dougal Matthews Date: Thu, 17 Nov 2016 11:43:36 +0000 Subject: [PATCH] Only start the deploy if the Heat stack isn't already in progress At the moment the deploy command will take a number of steps, including updating the plan and setting parameters in Mistral. Then when it gets to the deploy, the workflow will fail. This change stops it earlier in the process, which will be quicker and cleaner. Change-Id: I09e40e3f27b9ba3b0f3dad97cece6afbe28bd6b9 Partial-Bug: #1640249 --- tripleoclient/exceptions.py | 4 +++ .../tests/v1/overcloud_deploy/fakes.py | 1 + .../overcloud_deploy/test_overcloud_deploy.py | 28 +++++++++++++++---- tripleoclient/v1/overcloud_deploy.py | 5 ++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/tripleoclient/exceptions.py b/tripleoclient/exceptions.py index 8e7538cbf..6ec957e27 100644 --- a/tripleoclient/exceptions.py +++ b/tripleoclient/exceptions.py @@ -33,6 +33,10 @@ class DeploymentError(RuntimeError): """Deployment failed""" +class StackInProgress(RuntimeError): + """Unable to deploy as the stack is busy""" + + class RootUserExecution(Exception): """Command was executed by a root user""" diff --git a/tripleoclient/tests/v1/overcloud_deploy/fakes.py b/tripleoclient/tests/v1/overcloud_deploy/fakes.py index 4a256ac58..6cc740c06 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/fakes.py +++ b/tripleoclient/tests/v1/overcloud_deploy/fakes.py @@ -28,6 +28,7 @@ FAKE_STACK = { 'CephStorageCount': 0, }, 'stack_name': 'overcloud', + 'stack_status': "CREATE_COMPLETE", 'outputs': [{ 'output_key': 'KeystoneURL', 'output_value': 'http://0.0.0.0:8000', diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index 378837348..57ca94ca3 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -1483,12 +1483,12 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): @mock.patch('os.path.relpath', autospec=True) @mock.patch('tripleo_common.update.add_breakpoints_cleanup_into_env', autospec=True) - def test__heat_deploy_update_plan_only(self, mock_breakpoints_cleanup, - mock_relpath, - mock_get_template_contents, - mock_upload_missing_files, - mock_process_and_upload_env, - mock_deploy_and_wait): + def test_heat_deploy_update_plan_only(self, mock_breakpoints_cleanup, + mock_relpath, + mock_get_template_contents, + mock_upload_missing_files, + mock_process_and_upload_env, + mock_deploy_and_wait): clients = self.app.client_manager orchestration_client = clients.orchestration mock_stack = fakes.create_tht_stack() @@ -1511,3 +1511,19 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): {}, 1, '/tmp', {}, True) self.assertFalse(mock_deploy_and_wait.called) + + def test_heat_stack_busy(self): + + clients = self.app.client_manager + orchestration_client = clients.orchestration + mock_stack = fakes.create_tht_stack(stack_status="IN_PROGRESS") + orchestration_client.stacks.get.return_value = mock_stack + + arglist = ['--templates', ] + verifylist = [ + ('templates', '/usr/share/openstack-tripleo-heat-templates/'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises(exceptions.StackInProgress, + self.cmd.take_action, parsed_args) diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index bd6bd2dca..95e2b1a68 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -1136,6 +1136,11 @@ class DeployOvercloud(command.Command): stack = utils.get_stack(orchestration_client, parsed_args.stack) + if stack and stack.stack_status == 'IN_PROGRESS': + raise exceptions.StackInProgress( + "Unable to deploy as the stack '{}' status is '{}'".format( + stack.stack_name, stack.stack_status)) + parameters = self._update_parameters( parsed_args, clients.network, stack)