Merge "Include missing aliases in resource registry"
This commit is contained in:
commit
451f843349
|
@ -202,7 +202,8 @@ class PlansManager(object):
|
||||||
role_namespace)
|
role_namespace)
|
||||||
|
|
||||||
# Update environment file to add top level mappings, which is made
|
# 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()
|
reg_mapping = self.registry_mapping_store.list()
|
||||||
|
|
||||||
environment = deployment_plan.environment
|
environment = deployment_plan.environment
|
||||||
|
@ -401,7 +402,9 @@ class PlansManager(object):
|
||||||
# in addition to provider roles above, return non-role template files
|
# in addition to provider roles above, return non-role template files
|
||||||
reg_mapping = self.registry_mapping_store.list()
|
reg_mapping = self.registry_mapping_store.list()
|
||||||
for entry in reg_mapping:
|
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
|
# similarly, also grab extradata files for the non role templates
|
||||||
_add_template_extra_data_for(reg_mapping, self.registry_mapping_store)
|
_add_template_extra_data_for(reg_mapping, self.registry_mapping_store)
|
||||||
|
|
|
@ -20,6 +20,7 @@ from __future__ import print_function
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from tuskar.common import utils
|
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 load_file
|
||||||
from tuskar.storage.load_utils import process_role
|
from tuskar.storage.load_utils import process_role
|
||||||
from tuskar.storage.stores import MasterSeedStore
|
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]
|
role_paths = [r[1] for r in roles]
|
||||||
for entry in parsed_env.registry_entries:
|
for entry in parsed_env.registry_entries:
|
||||||
complete_path = path.join(dirname, entry.filename)
|
complete_path = path.join(dirname, entry.filename)
|
||||||
# skip adding if entry is not a filename (is another alias) or
|
# skip adding if template has already been stored as a role
|
||||||
# if template has already been stored as a role
|
if (complete_path in role_paths):
|
||||||
if (not entry.is_filename() or complete_path in role_paths):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
process_role(complete_path, entry.filename, mapping_store,
|
if (entry.is_filename()):
|
||||||
None, created, updated)
|
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
|
return all_roles, created, updated
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- encoding: utf-8 -*-
|
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# 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()
|
return role_file.read()
|
||||||
|
|
||||||
|
|
||||||
def _create_or_update(name, contents, store=None, relative_path='',
|
def create_or_update(name, contents, store=None, relative_path='',
|
||||||
registry_path=''):
|
registry_path=''):
|
||||||
if store is None:
|
if store is None:
|
||||||
store = TemplateStore()
|
store = TemplateStore()
|
||||||
try:
|
try:
|
||||||
|
@ -41,8 +40,8 @@ def process_role(role_path, role_name, store, all_roles, created, updated,
|
||||||
contents = load_file(role_path)
|
contents = load_file(role_path)
|
||||||
# if bigger than 255 chars, truncate to the last 255
|
# if bigger than 255 chars, truncate to the last 255
|
||||||
registry_path = role_path[-255:]
|
registry_path = role_path[-255:]
|
||||||
role_created, _ = _create_or_update(role_name, contents, store,
|
role_created, _ = create_or_update(role_name, contents, store,
|
||||||
relative_path, registry_path)
|
relative_path, registry_path)
|
||||||
|
|
||||||
if all_roles is not None:
|
if all_roles is not None:
|
||||||
all_roles.append(role_name)
|
all_roles.append(role_name)
|
||||||
|
|
|
@ -19,6 +19,7 @@ from tempfile import mkdtemp
|
||||||
from tuskar.storage import load_roles
|
from tuskar.storage import load_roles
|
||||||
from tuskar.storage import load_utils
|
from tuskar.storage import load_utils
|
||||||
from tuskar.storage import stores
|
from tuskar.storage import stores
|
||||||
|
from tuskar.storage.stores import ResourceRegistryMappingStore
|
||||||
from tuskar.tests.base import TestCase
|
from tuskar.tests.base import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ class LoadRoleTests(TestCase):
|
||||||
def test_import_update(self):
|
def test_import_update(self):
|
||||||
|
|
||||||
# setup
|
# setup
|
||||||
load_utils._create_or_update("role2", "contents")
|
load_utils.create_or_update("role2", "contents")
|
||||||
|
|
||||||
# test
|
# test
|
||||||
total, created, updated = load_roles.load_roles(self.roles)
|
total, created, updated = load_roles.load_roles(self.roles)
|
||||||
|
@ -93,6 +94,7 @@ class LoadRoleTests(TestCase):
|
||||||
resource_registry:
|
resource_registry:
|
||||||
OS::TripleO::Role: role1.yaml
|
OS::TripleO::Role: role1.yaml
|
||||||
OS::TripleO::Another: required_file.yaml
|
OS::TripleO::Another: required_file.yaml
|
||||||
|
OS::TripleO::SoftwareDeployment: OS::Heat::StructuredDeployment
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
|
@ -114,3 +116,11 @@ resource_registry:
|
||||||
self.assertEqual(['_master_seed', '_registry', 'required_file.yaml',
|
self.assertEqual(['_master_seed', '_registry', 'required_file.yaml',
|
||||||
'role1', 'role2'], sorted(created))
|
'role1', 'role2'], sorted(created))
|
||||||
self.assertEqual([], updated)
|
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)
|
||||||
|
|
|
@ -79,6 +79,7 @@ parameters:
|
||||||
resource_registry:
|
resource_registry:
|
||||||
Tuskar::Foo: provider-foo.yaml
|
Tuskar::Foo: provider-foo.yaml
|
||||||
Tuskar::Bar: provider-bar.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)
|
self.assertEqual('heat_key', ordered_params[2].value)
|
||||||
|
|
||||||
# Resource Registry
|
# 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)
|
ordered_entries = sorted(e.registry_entries, key=lambda x: x.alias)
|
||||||
self.assertEqual('Tuskar::Bar', ordered_entries[0].alias)
|
self.assertEqual('OS::TripleO::SoftwareDeployment',
|
||||||
self.assertEqual('provider-bar.yaml', ordered_entries[0].filename)
|
ordered_entries[0].alias)
|
||||||
self.assertEqual('Tuskar::Foo', ordered_entries[1].alias)
|
self.assertEqual('OS::Heat::StructuredDeployment',
|
||||||
self.assertEqual('provider-foo.yaml', ordered_entries[1].filename)
|
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)
|
||||||
|
|
Loading…
Reference in New Issue