Resolve template extra-data relative to the template prefix if any
When generating overcloud templates, tuskar includes non role templates that are read from the resource registry (environment.yaml) These templates typically include a path in their name, like 'puppet/compute-post-puppet.yaml'. The resource registry templates can also include extra-data and so when these are resolved, include the prefix path from the name. Change-Id: I43b6aa5eb96c7bcade501b01f0ce93353e65af64
This commit is contained in:
parent
cf604be22e
commit
f2365f33cc
|
@ -11,6 +11,8 @@
|
|||
# under the License.
|
||||
|
||||
import logging
|
||||
from os import path as os_path
|
||||
|
||||
|
||||
from tuskar.common import exception
|
||||
from tuskar.common import utils
|
||||
|
@ -372,6 +374,7 @@ class PlansManager(object):
|
|||
}
|
||||
|
||||
plan_roles = self._find_roles(environment)
|
||||
|
||||
manager = RoleManager()
|
||||
for role in plan_roles:
|
||||
contents = composer.compose_template(role.template)
|
||||
|
@ -384,10 +387,11 @@ class PlansManager(object):
|
|||
template_extra_data = manager.retrieve_db_role_extra()
|
||||
for template in templates:
|
||||
db_template = template_store.retrieve_by_name(template.name)
|
||||
prefix = os_path.split(db_template.name)[0]
|
||||
template_extra_paths = utils.resolve_template_extra_data(
|
||||
db_template, template_extra_data)
|
||||
extra_data_output = manager.template_extra_data_for_output(
|
||||
template_extra_paths)
|
||||
template_extra_paths, prefix)
|
||||
files_dict.update(extra_data_output)
|
||||
|
||||
# also grab any extradata files for the role
|
||||
|
@ -397,7 +401,6 @@ class PlansManager(object):
|
|||
reg_mapping = self.registry_mapping_store.list()
|
||||
for entry in reg_mapping:
|
||||
files_dict[entry.name] = entry.contents
|
||||
|
||||
# similarly, also grab extradata files for the non role templates
|
||||
_add_template_extra_data_for(reg_mapping, self.registry_mapping_store)
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from os import path as os_path
|
||||
|
||||
from tuskar.manager import models
|
||||
from tuskar.storage.stores import TemplateExtraStore
|
||||
from tuskar.storage.stores import TemplateStore
|
||||
|
@ -54,12 +56,15 @@ class RoleManager(object):
|
|||
def retrieve_db_role_extra(self):
|
||||
return self.template_extra_store.list(only_latest=False)
|
||||
|
||||
def template_extra_data_for_output(self, template_extra_paths):
|
||||
def template_extra_data_for_output(self, template_extra_paths, prefix=''):
|
||||
"""Compile and return role-extra data for output as a string
|
||||
|
||||
:param template_extra_paths: a list of {k,v} (name=>path)
|
||||
:type template_extra_paths: list of dict
|
||||
|
||||
:param prefix: a prefix path
|
||||
:type prefix: string
|
||||
|
||||
:return: a dict of path=>contents
|
||||
:rtype: dict
|
||||
|
||||
|
@ -81,6 +86,18 @@ class RoleManager(object):
|
|||
"hieradata/object.yaml": "CONTENTS"
|
||||
}
|
||||
|
||||
In those cases that the template_extra_paths were generated for a
|
||||
non Role template (i.e. those templates read from the resource
|
||||
registry), include their path prefix - so that the extra data files
|
||||
are created relative to the template. For example the template
|
||||
'path/to/some_template.yaml' has a reference to the extra-data file
|
||||
'hieradata/common.yaml'. The resulting extra-data file returned by
|
||||
tuskar must then be:
|
||||
|
||||
{
|
||||
"path/to/hieradata/common.yaml": "CONTENTS",
|
||||
}
|
||||
|
||||
"""
|
||||
res = {}
|
||||
for path in template_extra_paths:
|
||||
|
@ -88,6 +105,7 @@ class RoleManager(object):
|
|||
role_extra_path = path[role_extra_name]
|
||||
db_role_extra = self.template_extra_store.retrieve_by_name(
|
||||
role_extra_name)
|
||||
role_extra_path = os_path.join(prefix, role_extra_path)
|
||||
res[role_extra_path] = db_role_extra.contents
|
||||
return res
|
||||
|
||||
|
|
Loading…
Reference in New Issue