From 792bc26fb8446ede0475d99ec6e3e51a074eaee5 Mon Sep 17 00:00:00 2001 From: James Slagle Date: Wed, 25 Jul 2018 10:42:14 -0400 Subject: [PATCH] Add workflow for config-download export Add a new workflow, config_download_export, to export the config_download files by providing a swift tempurl of the generated tarball. The CLI will be migrated to using this workflow. Partial-Bug: #1783646 Change-Id: Ic3d3667a7e2d0b445a4ace4d9aa8643062eb9cf3 (cherry picked from commit e1556486c57f839c39171f92de2279c41f6577a2) --- ...nfig-download-export-d22f3eb958b8c97a.yaml | 5 ++ tripleo_common/actions/config.py | 11 +++- tripleo_common/tests/actions/test_config.py | 5 +- tripleo_common/utils/config.py | 10 ++++ workbooks/deployment.yaml | 57 +++++++++++++++++++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/workflow-config-download-export-d22f3eb958b8c97a.yaml diff --git a/releasenotes/notes/workflow-config-download-export-d22f3eb958b8c97a.yaml b/releasenotes/notes/workflow-config-download-export-d22f3eb958b8c97a.yaml new file mode 100644 index 000000000..3803ed96e --- /dev/null +++ b/releasenotes/notes/workflow-config-download-export-d22f3eb958b8c97a.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - A new workflow, config_download_export, for exporting the config-download + files via a Swift tempurl is added so that the openstack overcloud config + download tripleoclient command can use the API. diff --git a/tripleo_common/actions/config.py b/tripleo_common/actions/config.py index 9481c3ec1..c442d7408 100644 --- a/tripleo_common/actions/config.py +++ b/tripleo_common/actions/config.py @@ -40,10 +40,13 @@ class GetOvercloudConfig(templates.ProcessTemplatesAction): def __init__(self, container=constants.DEFAULT_CONTAINER_NAME, config_dir=None, - container_config=constants.CONFIG_CONTAINER_NAME): + container_config=constants.CONFIG_CONTAINER_NAME, + config_type=None): super(GetOvercloudConfig, self).__init__(container) self.container = container self.config_dir = config_dir + self.config_type = config_type + if not self.config_dir: self.config_dir = tempfile.mkdtemp(prefix='tripleo-', suffix='-config') @@ -72,6 +75,7 @@ class GetOvercloudConfig(templates.ProcessTemplatesAction): 'Project: {project}'.format(user=context.user_name, project=context.project_name)) config_path = config.download_config(self.container, self.config_dir, + self.config_type, preserve_config_dir=True, commit_message=message) @@ -82,6 +86,11 @@ class GetOvercloudConfig(templates.ProcessTemplatesAction): self.get_object_client(context), tmp_tarball.name, self.container_config) + # Also upload the tarball to the container for use by export later + with open(tmp_tarball.name) as t: + swift.put_object(self.container_config, + '%s.tar.gz' % self.container_config, + t.read()) if os.path.exists(config_path): shutil.rmtree(config_path) diff --git a/tripleo_common/tests/actions/test_config.py b/tripleo_common/tests/actions/test_config.py index 80cb998e7..a82512954 100644 --- a/tripleo_common/tests/actions/test_config.py +++ b/tripleo_common/tests/actions/test_config.py @@ -74,7 +74,10 @@ class GetOvercloudConfigActionTest(base.TestCase): self.config_container) action.run(self.ctx) - self.swift.put_object.assert_called_once() + self.assertEqual(2, self.swift.put_object.call_count) + self.assertEqual(mock.call('config-overcloud', + 'config-overcloud.tar.gz', ''), + self.swift.put_object.call_args_list[1]) mock_create_tarball.assert_called_once() self.assertEqual(dict(excludes=['.tox', '*.pyc', '*.pyo']), mock_create_tarball.call_args[1]) diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index 6d831e699..8d16495d0 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -135,6 +135,16 @@ class Config(object): def initialize_git_repo(self, dirname): repo = git.Repo.init(dirname) + gitignore_path = os.path.join(dirname, '.gitignore') + + # Ignore tarballs, which we use for the export process + if not os.path.exists(gitignore_path): + with open(gitignore_path, 'w') as f: + f.write('*.tar.gz\n') + # For some reason using repo.index.add is not working, so go + # directly to the GitCmd interface. + repo.git.add('.gitignore') + return repo def snapshot_config_dir(self, repo, commit_message): diff --git a/workbooks/deployment.yaml b/workbooks/deployment.yaml index 394bfb716..4bd22d774 100644 --- a/workbooks/deployment.yaml +++ b/workbooks/deployment.yaml @@ -524,6 +524,63 @@ workflows: plan_name: <% $.plan_name %> deployment_status: <% $.deployment_status %> + config_download_export: + + description: Creates an export tarball and an associated Swift tempurl for config-download for the given plan. + + input: + - plan + - queue_name: tripleo + - config_type: "" + + tags: + - tripleo-common-managed + + tasks: + + get_config: + action: tripleo.config.get_overcloud_config + input: + container: <% $.plan %> + container_config: <% $.plan %>-config + config_type: <% $.config_type %> + on-success: create_tempurl + on-error: send_message + publish-on-error: + status: FAILED + message: <% task().result %> + + create_tempurl: + action: tripleo.swift.tempurl + on-success: set_status_success + on-error: send_message + input: + container: <% $.plan %>-config + obj: "<% $.plan %>-config.tar.gz" + valid: 3600 + publish-on-error: + status: FAILED + message: <% task().result %> + + set_status_success: + on-success: send_message + publish: + status: SUCCESS + message: "config-download export successful" + tempurl: <% task(create_tempurl).result %> + + send_message: + workflow: tripleo.messaging.v1.send + input: + queue_name: <% $.queue_name %> + type: <% execution().name %> + status: <% $.status %> + execution: <% execution() %> + plan_name: <% $.plan %> + message: <% $.get('message', '') %> + payload: + tempurl: <% $.get('tempurl', '') %> + undeploy_plan: description: >