Merge "Refactor jinja rendering of templates"
This commit is contained in:
commit
d8f96230d8
|
@ -79,7 +79,8 @@ class TestUndercloudInstall(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--heat-native', '-e',
|
'--heat-native', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'undercloud.yaml', '-e',
|
'undercloud.yaml', '-e',
|
||||||
|
@ -151,7 +152,7 @@ class TestUndercloudInstall(TestPluginV1):
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usertht',
|
'--templates=/usertht',
|
||||||
'--roles-file=foo/roles.yaml',
|
'--roles-file=foo/roles.yaml',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usertht/network_data_undercloud.yaml',
|
||||||
'--heat-native=False', '-e',
|
'--heat-native=False', '-e',
|
||||||
'/usertht/environments/undercloud.yaml', '-e',
|
'/usertht/environments/undercloud.yaml', '-e',
|
||||||
'/usertht/environments/use-dns-for-vips.yaml', '-e',
|
'/usertht/environments/use-dns-for-vips.yaml', '-e',
|
||||||
|
@ -307,7 +308,8 @@ class TestUndercloudInstall(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--heat-native', '-e',
|
'--heat-native', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'undercloud.yaml', '-e',
|
'undercloud.yaml', '-e',
|
||||||
|
@ -379,7 +381,8 @@ class TestUndercloudInstall(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--heat-native', '-e',
|
'--heat-native', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'undercloud.yaml', '-e',
|
'undercloud.yaml', '-e',
|
||||||
|
@ -444,7 +447,8 @@ class TestUndercloudInstall(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--heat-native', '-e',
|
'--heat-native', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'undercloud.yaml', '-e',
|
'undercloud.yaml', '-e',
|
||||||
|
@ -506,7 +510,8 @@ class TestUndercloudInstall(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--heat-native', '-e',
|
'--heat-native', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'undercloud.yaml', '-e',
|
'undercloud.yaml', '-e',
|
||||||
|
@ -655,7 +660,8 @@ class TestUndercloudUpgrade(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--upgrade', '-e',
|
'--upgrade', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'lifecycle/undercloud-upgrade-prepare.yaml',
|
'lifecycle/undercloud-upgrade-prepare.yaml',
|
||||||
|
@ -723,7 +729,8 @@ class TestUndercloudUpgrade(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--upgrade', '-e',
|
'--upgrade', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'lifecycle/undercloud-upgrade-prepare.yaml',
|
'lifecycle/undercloud-upgrade-prepare.yaml',
|
||||||
|
@ -791,7 +798,8 @@ class TestUndercloudUpgrade(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--upgrade', '-e',
|
'--upgrade', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'lifecycle/undercloud-upgrade-prepare.yaml',
|
'lifecycle/undercloud-upgrade-prepare.yaml',
|
||||||
|
@ -857,7 +865,8 @@ class TestUndercloudUpgrade(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'-y', '--upgrade', '-e',
|
'-y', '--upgrade', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'lifecycle/undercloud-upgrade-prepare.yaml',
|
'lifecycle/undercloud-upgrade-prepare.yaml',
|
||||||
|
@ -929,7 +938,8 @@ class TestUndercloudUpgrade(TestPluginV1):
|
||||||
'undercloud', '--local-domain=localdomain',
|
'undercloud', '--local-domain=localdomain',
|
||||||
'--local-ip=192.168.24.1/24',
|
'--local-ip=192.168.24.1/24',
|
||||||
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
'--templates=/usr/share/openstack-tripleo-heat-templates/',
|
||||||
'--networks-file=network_data_undercloud.yaml',
|
'--networks-file=/usr/share/openstack-tripleo-heat-templates/'
|
||||||
|
'network_data_undercloud.yaml',
|
||||||
'--upgrade', '-e',
|
'--upgrade', '-e',
|
||||||
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
'/usr/share/openstack-tripleo-heat-templates/environments/'
|
||||||
'lifecycle/undercloud-upgrade-prepare.yaml',
|
'lifecycle/undercloud-upgrade-prepare.yaml',
|
||||||
|
|
|
@ -1651,6 +1651,37 @@ def build_stack_data(clients, stack_name, template,
|
||||||
return stack_data
|
return stack_data
|
||||||
|
|
||||||
|
|
||||||
|
def jinja_render_files(log, templates, working_dir,
|
||||||
|
roles_file=None, networks_file=None,
|
||||||
|
base_path=None, output_dir=None):
|
||||||
|
python_version = sys.version_info[0]
|
||||||
|
python_cmd = "python{}".format(python_version)
|
||||||
|
process_templates = os.path.join(
|
||||||
|
templates, 'tools/process-templates.py')
|
||||||
|
args = [python_cmd, process_templates]
|
||||||
|
|
||||||
|
if roles_file:
|
||||||
|
roles_file_path = get_roles_file_path(
|
||||||
|
roles_file, base_path)
|
||||||
|
args.extend(['--roles-data', roles_file_path])
|
||||||
|
|
||||||
|
if networks_file:
|
||||||
|
networks_file_path = get_networks_file_path(
|
||||||
|
networks_file, base_path)
|
||||||
|
args.extend(['--network-data', networks_file_path])
|
||||||
|
|
||||||
|
if base_path:
|
||||||
|
args.extend(['-p', base_path])
|
||||||
|
|
||||||
|
if output_dir:
|
||||||
|
args.extend(['-o', output_dir])
|
||||||
|
|
||||||
|
if run_command_and_log(log, args, working_dir) != 0:
|
||||||
|
msg = _("Problems generating templates.")
|
||||||
|
log.error(msg)
|
||||||
|
raise exceptions.DeploymentError(msg)
|
||||||
|
|
||||||
|
|
||||||
def process_multiple_environments(created_env_files, tht_root,
|
def process_multiple_environments(created_env_files, tht_root,
|
||||||
user_tht_root,
|
user_tht_root,
|
||||||
env_files_tracker=None,
|
env_files_tracker=None,
|
||||||
|
|
|
@ -25,7 +25,6 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
import six
|
import six
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import yaml
|
import yaml
|
||||||
|
@ -287,33 +286,18 @@ class DeployOvercloud(command.Command):
|
||||||
self.log)
|
self.log)
|
||||||
|
|
||||||
def _deploy_tripleo_heat_templates_tmpdir(self, stack, parsed_args):
|
def _deploy_tripleo_heat_templates_tmpdir(self, stack, parsed_args):
|
||||||
# copy tht_root to temporary directory because we need to
|
|
||||||
# download any missing (e.g j2 rendered) files from the plan
|
|
||||||
tht_root = os.path.abspath(parsed_args.templates)
|
tht_root = os.path.abspath(parsed_args.templates)
|
||||||
tht_tmp = tempfile.mkdtemp(prefix='tripleoclient-')
|
tht_tmp = tempfile.mkdtemp(prefix='tripleoclient-')
|
||||||
new_tht_root = "%s/tripleo-heat-templates" % tht_tmp
|
new_tht_root = "%s/tripleo-heat-templates" % tht_tmp
|
||||||
self.log.debug("Creating temporary templates tree in %s"
|
self.log.debug("Creating temporary templates tree in %s"
|
||||||
% new_tht_root)
|
% new_tht_root)
|
||||||
python_version = sys.version_info[0]
|
|
||||||
python_cmd = "python{}".format(python_version)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shutil.copytree(tht_root, new_tht_root, symlinks=True)
|
shutil.copytree(tht_root, new_tht_root, symlinks=True)
|
||||||
process_templates = os.path.join(
|
utils.jinja_render_files(self.log, parsed_args.templates,
|
||||||
parsed_args.templates, 'tools/process-templates.py')
|
new_tht_root,
|
||||||
roles_file_path = utils.get_roles_file_path(
|
parsed_args.roles_file,
|
||||||
parsed_args.roles_file, new_tht_root)
|
parsed_args.networks_file,
|
||||||
networks_file_path = utils.get_networks_file_path(
|
new_tht_root)
|
||||||
parsed_args.networks_file, new_tht_root)
|
|
||||||
args = [python_cmd, process_templates, '--roles-data',
|
|
||||||
roles_file_path, '--network-data', networks_file_path,
|
|
||||||
'-p', new_tht_root]
|
|
||||||
|
|
||||||
if utils.run_command_and_log(
|
|
||||||
self.log, args, new_tht_root) != 0:
|
|
||||||
msg = _("Problems generating templates.")
|
|
||||||
self.log.error(msg)
|
|
||||||
raise exceptions.DeploymentError(msg)
|
|
||||||
self._deploy_tripleo_heat_templates(stack, parsed_args,
|
self._deploy_tripleo_heat_templates(stack, parsed_args,
|
||||||
new_tht_root, tht_root)
|
new_tht_root, tht_root)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -659,16 +659,11 @@ class Deploy(command.Command):
|
||||||
|
|
||||||
# generate jinja templates by its work dir location
|
# generate jinja templates by its work dir location
|
||||||
self.log.debug(_("Using roles file %s") % roles_file_path)
|
self.log.debug(_("Using roles file %s") % roles_file_path)
|
||||||
process_templates = os.path.join(parsed_args.templates,
|
utils.jinja_render_files(self.log, parsed_args.templates,
|
||||||
'tools/process-templates.py')
|
working_dir=self.tht_render,
|
||||||
args = [self.python_cmd, process_templates, '--roles-data',
|
roles_file=roles_file_path,
|
||||||
roles_file_path, '--network-data', networks_file_path,
|
networks_file=networks_file_path,
|
||||||
'--output-dir', self.tht_render]
|
output_dir=self.tht_render)
|
||||||
if utils.run_command_and_log(self.log, args, cwd=self.tht_render) != 0:
|
|
||||||
# TODO(aschultz): improve error messaging
|
|
||||||
msg = _("Problems generating templates.")
|
|
||||||
self.log.error(msg)
|
|
||||||
raise exceptions.DeploymentError(msg)
|
|
||||||
|
|
||||||
# NOTE(aschultz): the next set of environment files are system included
|
# NOTE(aschultz): the next set of environment files are system included
|
||||||
# so we have to include them at the front of our environment list so a
|
# so we have to include them at the front of our environment list so a
|
||||||
|
|
|
@ -563,7 +563,8 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
|
||||||
deploy_args.append('--networks-file=%s' % CONF['networks_file'])
|
deploy_args.append('--networks-file=%s' % CONF['networks_file'])
|
||||||
else:
|
else:
|
||||||
deploy_args.append('--networks-file=%s' %
|
deploy_args.append('--networks-file=%s' %
|
||||||
constants.UNDERCLOUD_NETWORKS_FILE)
|
os.path.join(tht_templates,
|
||||||
|
constants.UNDERCLOUD_NETWORKS_FILE))
|
||||||
|
|
||||||
if yes:
|
if yes:
|
||||||
deploy_args += ['-y']
|
deploy_args += ['-y']
|
||||||
|
|
Loading…
Reference in New Issue