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
This commit is contained in:
James Slagle 2018-06-29 16:32:00 -04:00
parent a2c3be24fb
commit ec40eb3edf
4 changed files with 40 additions and 2 deletions

View File

@ -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.

View File

@ -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,

View File

@ -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):

View File

@ -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: