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

If the dir doesn't exist, we should exit with an error,
not log a warning and use some completely different path.

IMHO this is breaking a long established interface, e.g

1. --templates (no args, we use the /usr/share default templates)

2. --templates foo (foo must exist, we use foo)

The --templates argument should be explicit, and point to a path that exists.

This reverts commit cf6fc69e55.
Change-Id: I291babbbfc091ffe6e815298301a60dd1f047de1
This commit is contained in:
Steven Hardy 2018-07-18 14:07:38 +01:00
parent c4eed20b62
commit f357393629
2 changed files with 16 additions and 39 deletions

View File

@ -107,35 +107,25 @@ 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', return_value=True)
@mock.patch('os.path.exists', side_effect=[True, False])
@mock.patch('shutil.copytree')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_create_working_dirs')
@mock.patch('tripleoclient.v1.tripleo_deploy.Deploy.'
'_set_data_rights')
def test_populate_templates_dir(self, mock_rights, mock_workingdirs,
mock_copy, mock_exists):
def test_populate_templates_dir(self, 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')
@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):
def test_populate_templates_dir_bad_source(self, mock_workingdirs,
mock_exists):
self.cmd.tht_render = '/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)])
self.assertRaises(exceptions.NotFound,
self.cmd._populate_templates_dir, '/foo')
# TODO(cjeanner) drop once we have proper oslo.privsep
@mock.patch('getpass.getuser', return_value='stack')

View File

@ -220,34 +220,22 @@ 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, user=None):
"""Creates templates dir containing TripleO Heat Templates
def _populate_templates_dir(self, source_templates_dir):
"""Creates template dir with templates
* 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
* Copy --templates content into a 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):
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)
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)
def _set_default_plan(self):
"""Populate default plan-environment.yaml and capabilities-map.yaml."""
@ -1016,8 +1004,7 @@ class Deploy(command.Command):
self._configure_puppet()
# copy the templates dir in place
self._populate_templates_dir(parsed_args.templates,
parsed_args.deployment_user)
self._populate_templates_dir(parsed_args.templates)
# Set default plan if not specified by user
self._set_default_plan()