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 e1556486c5)
This commit is contained in:
James Slagle 2018-07-25 10:42:14 -04:00
parent d22cb3ed82
commit 792bc26fb8
5 changed files with 86 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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