Drop swift cruft from config-download

We've already removed swift from undercloud.

Change-Id: I6c1ad6fea4c7e21c01c9b495314c67fce69f771d
This commit is contained in:
ramishra 2021-03-08 14:50:52 +05:30
parent 9190b7dc98
commit 816582dace
2 changed files with 9 additions and 156 deletions

View File

@ -914,122 +914,23 @@ class OvercloudConfigTest(base.TestCase):
def setUp(self,):
super(OvercloudConfigTest, self).setUp()
self.plan = 'overcloud'
self.delete_after = 3600
self.config_container = 'config-overcloud'
# setup swift
self.template_files = (
'some-name.yaml',
'some-other-name.yaml',
'yet-some-other-name.yaml',
'finally-another-name.yaml'
)
self.swift = mock.MagicMock()
self.swift.get_container.return_value = (
{'x-container-meta-usage-tripleo': 'plan'}, [
{
'name': tf,
'last_modified': '2018-11-05'
} for tf in self.template_files
]
)
self.swift.get_object.return_value = ({}, RESOURCES_YAML_CONTENTS)
@mock.patch('tripleo_common.utils.swift.delete_container')
@mock.patch('tripleo_common.utils.swift.download_container')
@mock.patch('tripleo_common.utils.config.Config.download_config')
@mock.patch('tripleo_common.utils.tarball.create_tarball')
def test_get_overcloud_config(self, mock_create_tarball,
mock_config,
mock_swift_download,
mock_swift_delete):
def test_get_overcloud_config(self, mock_config):
heat = mock.MagicMock()
heat.stacks.get.return_value = mock.MagicMock(
stack_name='stack', id='stack_id')
mock_config.return_value = '/tmp/fake-path'
ooo_config.get_overcloud_config(
self.swift, heat,
None, heat,
self.plan,
self.config_container,
'/tmp/fake-path')
mock_swift_download.assert_called_once_with(self.swift,
self.config_container,
'/tmp/fake-path')
mock_swift_delete.assert_called_once_with(self.swift,
self.config_container)
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][0][2]), # closed file call
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])
@mock.patch('tripleo_common.utils.config.os.unlink')
@mock.patch('tripleo_common.utils.config.os.path.exists')
@mock.patch('tripleo_common.utils.config.os.symlink')
@mock.patch('tripleo_common.utils.swift.download_container')
@mock.patch('tempfile.mkdtemp')
def test_download_config(self, mock_mkdtemp,
mock_swiftutils,
mock_os_symlink,
mock_os_path_exists,
mock_os_unlink):
mock_mkdtemp.return_value = '/tmp/tripleo-foo-config'
ooo_config.download_overcloud_config(self.swift,
self.config_container)
mock_swiftutils.assert_called_once_with(self.swift,
self.config_container,
'/tmp/tripleo-foo-config')
@mock.patch('tripleo_common.utils.config.os.path.exists')
@mock.patch('tripleo_common.utils.config.os.symlink')
@mock.patch('tripleo_common.utils.swift.download_container')
@mock.patch('tempfile.mkdtemp')
def test_download_create_latest_symlink(
self, mock_mkdtemp,
mock_swiftutils,
mock_os_symlink,
mock_os_path_exists):
mock_mkdtemp.return_value = '/var/lib/mistral/uuid'
mock_os_path_exists.return_value = False
ooo_config.download_overcloud_config(self.swift,
self.config_container)
mock_swiftutils.assert_called_once_with(self.swift,
self.config_container,
mock_mkdtemp())
mock_os_symlink.assert_called_once_with(
'/var/lib/mistral/uuid',
os.path.join(os.path.dirname('/var/lib/mistral/uuid'),
'config-download-latest'))
@mock.patch('tripleo_common.utils.config.os.unlink')
@mock.patch('tripleo_common.utils.config.os.path.exists')
@mock.patch('tripleo_common.utils.config.os.symlink')
@mock.patch('tripleo_common.utils.swift.download_container')
@mock.patch('tempfile.mkdtemp')
def test_download_update_latest_symlink(
self, mock_mkdtemp,
mock_swiftutils,
mock_os_symlink,
mock_os_path_exists,
mock_os_unlink):
mock_mkdtemp.return_value = '/var/lib/mistral/uuid'
mock_os_path_exists.return_value = True
ooo_config.download_overcloud_config(self.swift,
self.config_container)
mock_swiftutils.assert_called_once_with(self.swift,
self.config_container,
mock_mkdtemp())
mock_os_symlink.assert_called_once_with(
'/var/lib/mistral/uuid',
os.path.join(os.path.dirname('/var/lib/mistral/uuid'),
'config-download-latest'))
mock_os_unlink.assert_called_once_with(
'/var/lib/mistral/config-download-latest')
mock_config.assert_called_once_with('overcloud', '/tmp/fake-path',
None, commit_message=mock.ANY,
preserve_config_dir=True)
@patch.object(ooo_config.Config, '_open_file')
def test_overcloud_config__write_tasks_per_step(self, mock_open_file):

View File

@ -24,12 +24,9 @@ import warnings
import yaml
import jinja2
from swiftclient import exceptions as swiftexceptions
from tripleo_common import constants
from tripleo_common.utils.safe_import import git
from tripleo_common.utils import swift as swiftutils
from tripleo_common.utils import tarball
LOG = logging.getLogger(__name__)
@ -595,36 +592,18 @@ class Config(object):
return config_dir
def get_overcloud_config(swift, heat,
def get_overcloud_config(swift=None, heat=None,
container=constants.DEFAULT_CONTAINER_NAME,
container_config=constants.CONFIG_CONTAINER_NAME,
config_dir=None, config_type=None,
preserve_config=False):
if heat is None:
raise RuntimeError('Should provide orchestration client to fetch '
' TripleO config')
if not config_dir:
config_dir = tempfile.mkdtemp(prefix='tripleo-',
suffix='-config')
if swift:
# 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, container_config,
config_dir)
# Delete the existing container before we re-upload, otherwise
# files may not be fully overwritten.
swiftutils.delete_container(swift, container_config)
except swiftexceptions.ClientException as err:
if err.http_status != 404:
raise
# Delete downloaded tarball as it will be recreated later and we don't
# want to include the old tarball in the new tarball.
old_tarball_path = os.path.join(
config_dir, '%s.tar.gz' % container_config)
if os.path.exists(old_tarball_path):
os.unlink(old_tarball_path)
config = Config(heat)
message = "Automatic commit with fresh config download\n\n"
@ -633,33 +612,6 @@ def get_overcloud_config(swift, heat,
preserve_config_dir=True,
commit_message=message)
if swift:
with tempfile.NamedTemporaryFile() as tmp_tarball:
tarball.create_tarball(config_path, tmp_tarball.name,
excludes=['.tox', '*.pyc', '*.pyo'])
tarball.tarball_extract_to_swift_container(
swift,
tmp_tarball.name,
container_config)
# Also upload the tarball to the container for use by export later
with open(tmp_tarball.name, 'rb') as t:
swift.put_object(container_config,
'%s.tar.gz' % container_config, t)
if not preserve_config:
if os.path.exists(config_path):
shutil.rmtree(config_path)
def download_overcloud_config(swift,
container_config=constants.CONFIG_CONTAINER_NAME,
work_dir=None):
if not work_dir:
work_dir = tempfile.mkdtemp(prefix='tripleo-', suffix='-config')
swiftutils.download_container(swift, container_config, work_dir)
symlink_path = os.path.join(
os.path.dirname(work_dir), 'config-download-latest')
if os.path.exists(symlink_path):
os.unlink(symlink_path)
os.symlink(work_dir, symlink_path)
return work_dir