From ec40eb3edf1bc7b56d3698c18adf37fc79fb548c Mon Sep 17 00:00:00 2001 From: James Slagle Date: Fri, 29 Jun 2018 16:32:00 -0400 Subject: [PATCH] git integration for GetOvercloudConfig action Override the default git commit message so that it's clear that the config-download commit was run from the Mistral action. Also, first download the existing config container if one exists. Since the config-download dir is now managed as a git repo, we want to preserve the git history, so we need to first reuse the existing contents of the config container. Change-Id: I0246918d89dfb564e3d472d4b2f517b5beaf4372 --- ...-git-repo-commit-msg-9a550daaae1fc55e.yaml | 10 +++++++ tripleo_common/actions/config.py | 28 +++++++++++++++++-- tripleo_common/tests/actions/test_config.py | 2 ++ workbooks/deployment.yaml | 2 ++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/config-download-git-repo-commit-msg-9a550daaae1fc55e.yaml diff --git a/releasenotes/notes/config-download-git-repo-commit-msg-9a550daaae1fc55e.yaml b/releasenotes/notes/config-download-git-repo-commit-msg-9a550daaae1fc55e.yaml new file mode 100644 index 000000000..208eddd99 --- /dev/null +++ b/releasenotes/notes/config-download-git-repo-commit-msg-9a550daaae1fc55e.yaml @@ -0,0 +1,10 @@ +--- +features: + - The GetOvercloudConfig action now sets a commit message that indicates the + config was downloaded by the Mistral action and what user/project were used + to execute the action. + - Since the config download directory is now managed by git, the + GetOvercloudConfig action will now first download the existing config + container (default of overcloud-config), so that the git history is + preserved and new changes will reuse the same git repo. Each new change to + the config-download directory creates a new git commit. diff --git a/tripleo_common/actions/config.py b/tripleo_common/actions/config.py index ca0b1eee4..9481c3ec1 100644 --- a/tripleo_common/actions/config.py +++ b/tripleo_common/actions/config.py @@ -17,6 +17,8 @@ import os import shutil import tempfile +from swiftclient import exceptions as swiftexceptions + from tripleo_common.actions import templates from tripleo_common import constants from tripleo_common.utils import config as ooo_config @@ -49,11 +51,33 @@ class GetOvercloudConfig(templates.ProcessTemplatesAction): def run(self, context): heat = self.get_orchestration_client(context) + swift = self.get_object_client(context) + + # Since the config-download directory is now a git repo, first download + # the existing config container if it exists so we can reuse the + # existing git repo. + try: + swiftutils.download_container(swift, self.container_config, + self.config_dir) + # Delete the existing container before we re-upload, otherwise + # files may not be fully overwritten. + swiftutils.delete_container(swift, self.container_config) + except swiftexceptions.ClientException as err: + if err.http_status != 404: + raise + config = ooo_config.Config(heat) - config_path = config.download_config(self.container, self.config_dir) + message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n' + 'User: {user}\n' + 'Project: {project}'.format(user=context.user_name, + project=context.project_name)) + config_path = config.download_config(self.container, self.config_dir, + preserve_config_dir=True, + commit_message=message) with tempfile.NamedTemporaryFile() as tmp_tarball: - tarball.create_tarball(config_path, tmp_tarball.name) + tarball.create_tarball(config_path, tmp_tarball.name, + excludes=['.tox', '*.pyc', '*.pyo']) tarball.tarball_extract_to_swift_container( self.get_object_client(context), tmp_tarball.name, diff --git a/tripleo_common/tests/actions/test_config.py b/tripleo_common/tests/actions/test_config.py index 1e93f6d10..80cb998e7 100644 --- a/tripleo_common/tests/actions/test_config.py +++ b/tripleo_common/tests/actions/test_config.py @@ -76,6 +76,8 @@ class GetOvercloudConfigActionTest(base.TestCase): self.swift.put_object.assert_called_once() mock_create_tarball.assert_called_once() + self.assertEqual(dict(excludes=['.tox', '*.pyc', '*.pyo']), + mock_create_tarball.call_args[1]) class DownloadConfigActionTest(base.TestCase): diff --git a/workbooks/deployment.yaml b/workbooks/deployment.yaml index a722b9e30..aa998c132 100644 --- a/workbooks/deployment.yaml +++ b/workbooks/deployment.yaml @@ -374,6 +374,7 @@ workflows: action: tripleo.config.get_overcloud_config input: container: <% $.get('plan_name') %> + container_config: <% $.get('plan_name') %>-config on-success: download_config on-error: send_message publish-on-error: @@ -385,6 +386,7 @@ workflows: action: tripleo.config.download_config input: work_dir: <% $.get('work_dir') %>/<% execution().id %> + container_config: <% $.get('plan_name') %>-config on-success: send_msg_config_download on-error: send_message publish-on-error: