Merge "Fix populate templates dir for mixed UC/OC cases"

This commit is contained in:
Zuul 2018-07-14 02:36:20 +00:00 committed by Gerrit Code Review
commit f6303ec5b9
2 changed files with 39 additions and 16 deletions

View File

@ -107,25 +107,35 @@ class TestDeployUndercloud(TestPluginV1):
mock_data.return_value = [{'name': 'Bar'}, {'name': 'Foo'}]
self.assertEqual(self.cmd._get_primary_role_name(), 'Bar')
@mock.patch('os.path.exists', side_effect=[True, False])
@mock.patch('os.path.exists', return_value=True)
@mock.patch('shutil.copytree')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_create_working_dirs')
def test_populate_templates_dir(self, mock_workingdirs, mock_copy,
mock_exists):
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_set_data_rights')
def test_populate_templates_dir(self, mock_rights, mock_workingdirs,
mock_copy, mock_exists):
self.cmd.tht_render = '/foo'
self.cmd._populate_templates_dir('/bar')
mock_workingdirs.assert_called_once()
mock_copy.assert_called_once_with('/bar', '/foo', symlinks=True)
@mock.patch('os.path.exists', return_value=False)
@mock.patch('shutil.copytree')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_create_working_dirs')
def test_populate_templates_dir_bad_source(self, mock_workingdirs,
mock_exists):
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_set_data_rights')
def test_populate_templates_dir_no_source(self, mock_rights,
mock_workingdirs, mock_copy,
mock_exists):
self.cmd.tht_render = '/foo'
self.assertRaises(exceptions.NotFound,
self.cmd._populate_templates_dir, '/foo')
self.cmd._populate_templates_dir('/bar')
mock_workingdirs.assert_called_once()
mock_copy.assert_has_calls([
mock.call(constants.TRIPLEO_HEAT_TEMPLATES,
'/bar', symlinks=True),
mock.call('/bar', '/foo', symlinks=True)])
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('getpass.getuser', return_value='stack')

View File

@ -221,22 +221,34 @@ class Deploy(command.Command):
self.tmp_ansible_dir = tempfile.mkdtemp(
prefix='undercloud-ansible-', dir=self.output_dir)
def _populate_templates_dir(self, source_templates_dir):
"""Creates template dir with templates
def _populate_templates_dir(self, source_templates_dir, user=None):
"""Creates templates dir containing TripleO Heat Templates
* Copy --templates content into a working dir
* If source_templates_dir does not exist, create it and populate from
the t-h-t system directory (installed from RPM). This may be the
case for mixed UC/OC deployments or upgrades, which require different
versions of t-h-t.
* Always copy source_templates_dir into the working dir
created as 'output_dir/tripleo-heat-installer-templates'.
:param source_templates_dir: string to a directory containing our
source templates
"""
# NOTE(bogdando): this ensures self.tht_render defined and its target
# directory is purged for a new clear run of _populate_templates_dir
self._create_working_dirs()
if not os.path.exists(source_templates_dir):
raise exceptions.NotFound("%s template director does not exists" %
source_templates_dir)
if not os.path.exists(self.tht_render):
shutil.copytree(source_templates_dir, self.tht_render,
symlinks=True)
self.log.warning(
_("%s template directory does not exists. "
"A new directory will be populated from the "
"TripleO Heat Templates system directory.") %
source_templates_dir)
shutil.copytree(constants.TRIPLEO_HEAT_TEMPLATES,
source_templates_dir, symlinks=True)
self._set_data_rights(source_templates_dir, user=user, mode=0o700)
shutil.copytree(source_templates_dir, self.tht_render,
symlinks=True)
def _cleanup_working_dirs(self, cleanup=False, user=None):
"""Cleanup temporary working directories
@ -987,7 +999,8 @@ class Deploy(command.Command):
self._configure_puppet()
# copy the templates dir in place
self._populate_templates_dir(parsed_args.templates)
self._populate_templates_dir(parsed_args.templates,
parsed_args.deployment_user)
# configure our roles data
self._set_roles_file(parsed_args.roles_file, self.tht_render)