From de872dd3dec645b853d86f0a8e6751efd1ae3b0d Mon Sep 17 00:00:00 2001 From: James Slagle Date: Fri, 31 Mar 2017 16:13:52 -0400 Subject: [PATCH] Add skip_deploy_identifier Add a new action argument, skip_deploy_identifier to DeployStackAction. The argument will disable setting a unique value for the DeployIdentifier parameter, which means the SoftwareDeployment resources in the templates will only be triggered if there is an actual change to their configuration. This argument can be used to avoid always applying configuration, such as during node scale out. Change-Id: Idb901a841846fec33d189b3c95f669b0380498ce Closes-Bug: #1688387 (cherry picked from commit 9d158874301eaa9444811f2c21cc9d86c2eaad7a) (cherry picked from commit 320960c804fcdcaa1458a7dec1fbbe70f77900ee) --- ...ip-deploy-identifier-d5abb0d4e6af0ecd.yaml | 10 +++ tripleo_common/actions/deployment.py | 7 +- .../tests/actions/test_deployment.py | 66 +++++++++++++++++++ workbooks/deployment.yaml | 3 + 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/skip-deploy-identifier-d5abb0d4e6af0ecd.yaml diff --git a/releasenotes/notes/skip-deploy-identifier-d5abb0d4e6af0ecd.yaml b/releasenotes/notes/skip-deploy-identifier-d5abb0d4e6af0ecd.yaml new file mode 100644 index 000000000..f80315d7f --- /dev/null +++ b/releasenotes/notes/skip-deploy-identifier-d5abb0d4e6af0ecd.yaml @@ -0,0 +1,10 @@ +--- +features: + - Add a new action argument, skip_deploy_identifier to DeployStackAction. The + argument will disable setting a unique value for the DeployIdentifier + parameter, which means the SoftwareDeployment resources in the templates + will only be triggered if there is an actual change to their configuration. + This argument can be used to avoid always applying configuration, such as + during node scale out. This option should be used with Caution, and only if + there is confidence that the software configuration does not need to be + run, such as when scaling out certain roles. diff --git a/tripleo_common/actions/deployment.py b/tripleo_common/actions/deployment.py index e0c831fb2..269b28c7b 100644 --- a/tripleo_common/actions/deployment.py +++ b/tripleo_common/actions/deployment.py @@ -130,9 +130,11 @@ class OrchestrationDeployAction(base.TripleOAction): class DeployStackAction(templates.ProcessTemplatesAction): """Deploys a heat stack.""" - def __init__(self, timeout, container=constants.DEFAULT_CONTAINER_NAME): + def __init__(self, timeout, container=constants.DEFAULT_CONTAINER_NAME, + skip_deploy_identifier=False): super(DeployStackAction, self).__init__(container) self.timeout_mins = timeout + self.skip_deploy_identifier = skip_deploy_identifier def run(self): # check to see if the stack exists @@ -149,7 +151,8 @@ class DeployStackAction(templates.ProcessTemplatesAction): wf_env = wc.environments.get(self.container) parameters = dict() - parameters['DeployIdentifier'] = int(time.time()) + if not self.skip_deploy_identifier: + parameters['DeployIdentifier'] = int(time.time()) parameters['UpdateIdentifier'] = '' parameters['StackAction'] = 'CREATE' if stack_is_new else 'UPDATE' diff --git a/tripleo_common/tests/actions/test_deployment.py b/tripleo_common/tests/actions/test_deployment.py index 646671bcf..44a5bc3d8 100644 --- a/tripleo_common/tests/actions/test_deployment.py +++ b/tripleo_common/tests/actions/test_deployment.py @@ -261,6 +261,72 @@ class DeployStackActionTest(base.TestCase): timeout_mins=1, ) + @mock.patch('tripleo_common.actions.deployment.time') + @mock.patch('heatclient.common.template_utils.' + 'process_multiple_environments_and_files') + @mock.patch('heatclient.common.template_utils.get_template_contents') + @mock.patch('tripleo_common.actions.base.TripleOAction.' + '_get_workflow_client') + @mock.patch('tripleo_common.actions.base.TripleOAction._get_object_client') + @mock.patch( + 'tripleo_common.actions.base.TripleOAction._get_orchestration_client') + @mock.patch('mistral.context.ctx') + def test_run_skip_deploy_identifier( + self, mock_ctx, get_orchestration_client_mock, + mock_get_object_client, mock_get_workflow_client, + mock_get_template_contents, + mock_process_multiple_environments_and_files, + mock_time): + + mock_ctx.return_value = mock.MagicMock() + # setup swift + swift = mock.MagicMock(url="http://test.com") + swift.get_object.side_effect = swiftexceptions.ClientException( + 'atest2') + mock_get_object_client.return_value = swift + + heat = mock.MagicMock() + heat.stacks.get.return_value = None + get_orchestration_client_mock.return_value = heat + + mock_mistral = mock.MagicMock() + mock_env = mock.MagicMock() + mock_env.variables = { + 'temp_environment': 'temp_environment', + 'template': 'template', + 'environments': [{u'path': u'environments/test.yaml'}], + 'parameter_defaults': {'random_existing_data': 'a_value'}, + } + mock_mistral.environments.get.return_value = mock_env + mock_get_workflow_client.return_value = mock_mistral + + mock_get_template_contents.return_value = ({}, { + 'heat_template_version': '2016-04-30' + }) + mock_process_multiple_environments_and_files.return_value = ({}, {}) + + # freeze time at datetime.datetime(2016, 9, 8, 16, 24, 24) + mock_time.time.return_value = 1473366264 + + action = deployment.DeployStackAction(1, 'overcloud', + skip_deploy_identifier=True) + action.run() + + # verify parameters are as expected + expected_defaults = {'StackAction': 'CREATE', + 'UpdateIdentifier': '', + 'random_existing_data': 'a_value'} + self.assertEqual(expected_defaults, + mock_env.variables['parameter_defaults']) + + heat.stacks.create.assert_called_once_with( + environment={}, + files={}, + stack_name='overcloud', + template={'heat_template_version': '2016-04-30'}, + timeout_mins=1, + ) + class OvercloudRcActionTestCase(base.TestCase): diff --git a/workbooks/deployment.yaml b/workbooks/deployment.yaml index 93fdd4a41..af03c3f0e 100644 --- a/workbooks/deployment.yaml +++ b/workbooks/deployment.yaml @@ -104,6 +104,7 @@ workflows: input: - container - timeout: 240 + - skip_deploy_identifier: False - queue_name: tripleo tasks: @@ -123,6 +124,8 @@ workflows: deploy: action: tripleo.deployment.deploy timeout=<% $.timeout %> container=<% $.container %> + input: + skip_deploy_identifier: <% $.skip_deploy_identifier %> on-success: send_message on-error: set_deployment_failed