Merge "Include missing aliases in resource registry"

This commit is contained in:
Jenkins 2015-03-31 14:38:42 +00:00 committed by Gerrit Code Review
commit 451f843349
5 changed files with 39 additions and 18 deletions

View File

@ -202,7 +202,8 @@ class PlansManager(object):
role_namespace)
# Update environment file to add top level mappings, which is made
# up of all non-role files present in the resource registry
# up of all non-role files present in the resource registry, plus
# required aliases
reg_mapping = self.registry_mapping_store.list()
environment = deployment_plan.environment
@ -401,7 +402,9 @@ class PlansManager(object):
# in addition to provider roles above, return non-role template files
reg_mapping = self.registry_mapping_store.list()
for entry in reg_mapping:
files_dict[entry.name] = entry.contents
if os_path.splitext(entry.name)[1] in ('.yaml', '.yml'):
# if entry is an alias, don't include it
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)

View File

@ -20,6 +20,7 @@ from __future__ import print_function
from os import path
from tuskar.common import utils
from tuskar.storage.load_utils import create_or_update
from tuskar.storage.load_utils import load_file
from tuskar.storage.load_utils import process_role
from tuskar.storage.stores import MasterSeedStore
@ -119,12 +120,15 @@ def load_roles(roles, seed_file=None, resource_registry_path=None,
role_paths = [r[1] for r in roles]
for entry in parsed_env.registry_entries:
complete_path = path.join(dirname, entry.filename)
# skip adding if entry is not a filename (is another alias) or
# if template has already been stored as a role
if (not entry.is_filename() or complete_path in role_paths):
# skip adding if template has already been stored as a role
if (complete_path in role_paths):
continue
process_role(complete_path, entry.filename, mapping_store,
None, created, updated)
if (entry.is_filename()):
process_role(complete_path, entry.filename, mapping_store,
None, created, updated)
else:
# if entry is not a filename, (is an alias) add to mappings
create_or_update(entry.filename, entry.alias, mapping_store)
return all_roles, created, updated

View File

@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -21,8 +20,8 @@ def load_file(role_path):
return role_file.read()
def _create_or_update(name, contents, store=None, relative_path='',
registry_path=''):
def create_or_update(name, contents, store=None, relative_path='',
registry_path=''):
if store is None:
store = TemplateStore()
try:
@ -41,8 +40,8 @@ def process_role(role_path, role_name, store, all_roles, created, updated,
contents = load_file(role_path)
# if bigger than 255 chars, truncate to the last 255
registry_path = role_path[-255:]
role_created, _ = _create_or_update(role_name, contents, store,
relative_path, registry_path)
role_created, _ = create_or_update(role_name, contents, store,
relative_path, registry_path)
if all_roles is not None:
all_roles.append(role_name)

View File

@ -19,6 +19,7 @@ from tempfile import mkdtemp
from tuskar.storage import load_roles
from tuskar.storage import load_utils
from tuskar.storage import stores
from tuskar.storage.stores import ResourceRegistryMappingStore
from tuskar.tests.base import TestCase
@ -64,7 +65,7 @@ class LoadRoleTests(TestCase):
def test_import_update(self):
# setup
load_utils._create_or_update("role2", "contents")
load_utils.create_or_update("role2", "contents")
# test
total, created, updated = load_roles.load_roles(self.roles)
@ -93,6 +94,7 @@ class LoadRoleTests(TestCase):
resource_registry:
OS::TripleO::Role: role1.yaml
OS::TripleO::Another: required_file.yaml
OS::TripleO::SoftwareDeployment: OS::Heat::StructuredDeployment
"""
# Setup
@ -114,3 +116,11 @@ resource_registry:
self.assertEqual(['_master_seed', '_registry', 'required_file.yaml',
'role1', 'role2'], sorted(created))
self.assertEqual([], updated)
# Check resource registry
registry_list = ResourceRegistryMappingStore().list()
ordered_list = sorted(registry_list, key=lambda x: x.name)
self.assertEqual('OS::Heat::StructuredDeployment',
ordered_list[0].name)
self.assertEqual('required_file.yaml',
ordered_list[1].name)

View File

@ -79,6 +79,7 @@ parameters:
resource_registry:
Tuskar::Foo: provider-foo.yaml
Tuskar::Bar: provider-bar.yaml
OS::TripleO::SoftwareDeployment: OS::Heat::StructuredDeployment
"""
@ -186,9 +187,13 @@ class ParserTests(unittest.TestCase):
self.assertEqual('heat_key', ordered_params[2].value)
# Resource Registry
self.assertEqual(2, len(e.registry_entries))
self.assertEqual(3, len(e.registry_entries))
ordered_entries = sorted(e.registry_entries, key=lambda x: x.alias)
self.assertEqual('Tuskar::Bar', ordered_entries[0].alias)
self.assertEqual('provider-bar.yaml', ordered_entries[0].filename)
self.assertEqual('Tuskar::Foo', ordered_entries[1].alias)
self.assertEqual('provider-foo.yaml', ordered_entries[1].filename)
self.assertEqual('OS::TripleO::SoftwareDeployment',
ordered_entries[0].alias)
self.assertEqual('OS::Heat::StructuredDeployment',
ordered_entries[0].filename)
self.assertEqual('Tuskar::Bar', ordered_entries[1].alias)
self.assertEqual('provider-bar.yaml', ordered_entries[1].filename)
self.assertEqual('Tuskar::Foo', ordered_entries[2].alias)
self.assertEqual('provider-foo.yaml', ordered_entries[2].filename)