Use playbook for config-download export

Depends-On: https://review.opendev.org/#/c/734417/
Change-Id: I49b855ab80ebf5750dbf52f7569f681598485dd1
changes/22/734422/1
Rabi Mishra 3 years ago
parent d95ed1f819
commit a20dc2d849

@ -14,6 +14,7 @@ import mock
from osc_lib.tests import utils
from tripleoclient.tests import fakes
from tripleoclient.v1 import overcloud_config
@ -21,20 +22,12 @@ class TestOvercloudConfig(utils.TestCommand):
def setUp(self):
super(TestOvercloudConfig, self).setUp()
self.cmd = overcloud_config.DownloadConfig(self.app, None)
self.app.client_manager.workflow_engine = mock.Mock()
self.app.client_manager.orchestration = mock.Mock()
self.workflow = self.app.client_manager.workflow_engine
self.app.options = fakes.FakeOptions()
@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):
@mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True)
def test_overcloud_download_config(self, mock_playbook):
arglist = ['--name', 'overcloud', '--config-dir', '/tmp']
verifylist = [
('name', 'overcloud'),
@ -44,20 +37,15 @@ 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(
self.app.client_manager, plan='overcloud', config_type=None)
mock_rmtree.assert_not_called()
mock_open.assert_called()
mock_request.urlopen.assert_called()
mock_playbook.assert_called_once_with(
extra_vars={'plan': 'overcloud', 'config_dir': '/tmp',
'preserve_config': True},
inventory='localhost,', playbook='cli-config-download-export.yaml',
playbook_dir='/usr/share/ansible/tripleo-playbooks',
verbosity=3, workdir=mock.ANY)
@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):
@mock.patch("tripleoclient.utils.run_ansible_playbook", autospec=True)
def test_overcloud_download_config_no_preserve(self, mock_playbook):
arglist = ['--name', 'overcloud', '--config-dir', '/tmp',
'--no-preserve-config']
verifylist = [
@ -68,8 +56,9 @@ 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(
self.app.client_manager, plan='overcloud', config_type=None)
mock_rmtree.assert_called()
mock_open.assert_called()
mock_request.urlopen.assert_called()
mock_playbook.assert_called_once_with(
extra_vars={'plan': 'overcloud', 'config_dir': '/tmp',
'preserve_config': False},
inventory='localhost,', playbook='cli-config-download-export.yaml',
playbook_dir='/usr/share/ansible/tripleo-playbooks',
verbosity=3, workdir=mock.ANY)

@ -12,16 +12,12 @@
import logging
import os
import shutil
from six.moves.urllib import request
from osc_lib.i18n import _
from oslo_concurrency import processutils
from tripleoclient import command
from tripleoclient import constants
from tripleoclient import utils
from tripleoclient.workflows import deployment
class DownloadConfig(command.Command):
@ -69,20 +65,6 @@ 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)
utils.makedirs(config_dir)
def take_action(self, parsed_args):
self.log.debug("take_action(%s)" % parsed_args)
@ -90,29 +72,20 @@ class DownloadConfig(command.Command):
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
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()
f.close()
tarball_name = "%s-config.tar.gz" % name
tarball_path = os.path.join(config_dir, tarball_name)
with open(tarball_path, 'wb') as f:
f.write(tarball_contents)
extra_vars = {'plan': name,
'config_dir': config_dir,
'preserve_config': preserve_config_dir}
if config_type:
extra_vars['config_type'] = config_type
print("Extracting config-download...")
cmd = ['/usr/bin/tar', '-C', config_dir, '-xf', tarball_path]
processutils.execute(*cmd)
with utils.TempDirs() as tmp:
utils.run_ansible_playbook(
playbook='cli-config-download-export.yaml',
inventory='localhost,',
workdir=tmp,
playbook_dir=constants.ANSIBLE_TRIPLEO_PLAYBOOKS,
verbosity=utils.playbook_verbosity(self=self),
extra_vars=extra_vars)
print("The TripleO configuration has been successfully generated "
"into: {0}".format(config_dir))

@ -20,7 +20,6 @@ from heatclient.common import event_utils
from heatclient import exc as heat_exc
from openstackclient import shell
from swiftclient import exceptions as swiftexceptions
from tripleo_common.actions import config
from tripleo_common.utils import swift as swift_utils
from tripleoclient.constants import ANSIBLE_TRIPLEO_PLAYBOOKS
@ -475,39 +474,6 @@ def config_download(log, clients, stack, ssh_network='ctlplane',
)
def config_download_export(clients, plan, config_type):
"""Export a given config.
:param clients: application client object.
:type clients: Object
:param plan: Plan name.
:type plan: String
:param config_type: List of config type options.
:type config_type: List
:returns: string
"""
context = clients.tripleoclient.create_mistral_context()
container_config = '{}-config'.format(plan)
config.GetOvercloudConfig(
container=plan,
config_type=config_type,
container_config=container_config
).run(context=context)
print(
'Config Download export complete for {}. Creating temp URL.'.format(
plan
)
)
return swift_utils.get_temp_url(
clients.tripleoclient.object_store, container=container_config,
object_name='{}.tar.gz'.format(container_config))
def get_horizon_url(stack, verbosity=0):
"""Return horizon URL string.

Loading…
Cancel
Save