Use workflow config_download_export

Update openstack overcloud config download to go through the API and use
the workflow added in the depends-on patch.

Change-Id: I65b45c00df65ec910b4fd620c475d4ee1d691e30
Closes-Bug: #1783646
Depends-On: Ic3d3667a7e2d0b445a4ace4d9aa8643062eb9cf3
This commit is contained in:
James Slagle 2018-07-25 18:15:56 -04:00
parent a33b1499d7
commit 611cf819a9
3 changed files with 92 additions and 13 deletions

View File

@ -27,8 +27,14 @@ class TestOvercloudConfig(utils.TestCommand):
self.app.client_manager.orchestration = mock.Mock()
self.workflow = self.app.client_manager.workflow_engine
@mock.patch('tripleo_common.utils.config.Config.download_config')
def test_overcloud_download_config(self, mock_config):
@mock.patch('tripleoclient.v1.overcloud_config.processutils.execute')
@mock.patch('tripleoclient.v1.overcloud_config.open')
@mock.patch('tripleoclient.v1.overcloud_config.request')
@mock.patch('shutil.rmtree')
@mock.patch('tripleoclient.workflows.deployment.config_download_export')
def test_overcloud_download_config(
self, mock_config, mock_rmtree, mock_request,
mock_open, mock_execute):
arglist = ['--name', 'overcloud', '--config-dir', '/tmp']
verifylist = [
('name', 'overcloud'),
@ -38,10 +44,20 @@ class TestOvercloudConfig(utils.TestCommand):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
mock_config.assert_called_once_with('overcloud', '/tmp', None, True)
mock_config.assert_called_once_with(
self.app.client_manager, plan='overcloud', config_type=None)
mock_rmtree.assert_not_called()
mock_open.assert_called()
mock_request.urlopen.assert_called()
@mock.patch('tripleo_common.utils.config.Config.download_config')
def test_overcloud_download_config_no_preserve(self, mock_config):
@mock.patch('tripleoclient.v1.overcloud_config.processutils.execute')
@mock.patch('tripleoclient.v1.overcloud_config.open')
@mock.patch('tripleoclient.v1.overcloud_config.request')
@mock.patch('shutil.rmtree')
@mock.patch('tripleoclient.workflows.deployment.config_download_export')
def test_overcloud_download_config_no_preserve(
self, mock_config, mock_rmtree, mock_request,
mock_open, mock_execute):
arglist = ['--name', 'overcloud', '--config-dir', '/tmp',
'--no-preserve-config']
verifylist = [
@ -52,4 +68,8 @@ class TestOvercloudConfig(utils.TestCommand):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
mock_config.assert_called_once_with('overcloud', '/tmp', None, False)
mock_config.assert_called_once_with(
self.app.client_manager, plan='overcloud', config_type=None)
mock_rmtree.assert_called()
mock_open.assert_called()
mock_request.urlopen.assert_called()

View File

@ -12,11 +12,14 @@
import logging
import os
import shutil
from six.moves.urllib import request
from osc_lib.i18n import _
from tripleo_common.utils import config as ooo_config
from oslo_concurrency import processutils
from tripleoclient import command
from tripleoclient.workflows import deployment
class DownloadConfig(command.Command):
@ -61,18 +64,50 @@ class DownloadConfig(command.Command):
)
return parser
def create_config_dir(self, config_dir, preserve_config_dir=True):
# Create config directory
if os.path.exists(config_dir) and preserve_config_dir is False:
try:
self.log.info("Directory %s already exists, removing"
% config_dir)
shutil.rmtree(config_dir)
except OSError as e:
message = 'Failed to remove: %s, error: %s' % (config_dir,
str(e))
raise OSError(message)
if not os.path.exists(config_dir):
os.makedirs(config_dir)
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
# Get clients
clients = self.app.client_manager
name = parsed_args.name
config_dir = parsed_args.config_dir
config_type = parsed_args.config_type
preserve_config_dir = parsed_args.preserve_config_dir
self.create_config_dir(config_dir, preserve_config_dir)
# Get config
config = ooo_config.Config(clients.orchestration)
config_path = config.download_config(name, config_dir, config_type,
preserve_config_dir)
print("Starting config-download export...")
tempurl = deployment.config_download_export(
self.app.client_manager,
plan=name,
config_type=config_type
)
print("Finished config-download export.")
self.log.debug("config-download tempurl: %s" % tempurl)
f = request.urlopen(tempurl)
tarball_contents = f.read()
tarball_name = "%s-config.tar.gz" % name
tarball_path = os.path.join(config_dir, tarball_name)
with open(tarball_path, 'w') as f:
f.write(tarball_contents)
print("Extracting config-download...")
cmd = ['/usr/bin/tar', '-C', config_dir, '-xf', tarball_path]
processutils.execute(*cmd)
print("The TripleO configuration has been successfully generated "
"into: {0}".format(config_path))
"into: {0}".format(config_dir))

View File

@ -271,6 +271,30 @@ def config_download(log, clients, stack, templates,
raise exceptions.DeploymentError("Overcloud configuration failed.")
def config_download_export(clients, **workflow_input):
workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient
execution = base.start_workflow(
workflow_client,
'tripleo.deployment.v1.config_download_export',
workflow_input=workflow_input
)
with tripleoclients.messaging_websocket() as ws:
for payload in base.wait_for_messages(workflow_client, ws, execution,
_WORKFLOW_TIMEOUT):
if 'message' in payload:
print(payload['message'])
if payload['status'] == 'SUCCESS':
return payload['tempurl']
else:
raise exceptions.WorkflowServiceError(
'Exception exporting config-download: {}'.format(
payload['message']))
def get_horizon_url(clients, **workflow_input):
workflow_client = clients.workflow_engine
tripleoclients = clients.tripleoclient