Included namespace_prefix logic in toscaparser
if namespace_prefix is provided in imports, the full name will be namespace_prefix.type while importing type definition from namespace. Partially Implements: blueprint tosca-namespaces Change-Id: I8fb43a6db2fc040713f41c75a80e27abbe451ea1
This commit is contained in:
parent
17feff6ca5
commit
0a4c6a0503
@ -73,20 +73,34 @@ class ImportsLoader(object):
|
|||||||
|
|
||||||
custom_type = self._load_import_template(import_name,
|
custom_type = self._load_import_template(import_name,
|
||||||
import_uri)
|
import_uri)
|
||||||
self._update_custom_def(custom_type)
|
namespace_prefix = None
|
||||||
|
if isinstance(import_uri, dict):
|
||||||
|
namespace_prefix = import_uri.get(
|
||||||
|
self.NAMESPACE_PREFIX)
|
||||||
|
|
||||||
|
self._update_custom_def(custom_type, namespace_prefix)
|
||||||
else: # old style of imports
|
else: # old style of imports
|
||||||
custom_type = self._load_import_template(None,
|
custom_type = self._load_import_template(None,
|
||||||
import_def)
|
import_def)
|
||||||
if custom_type:
|
if custom_type:
|
||||||
self._update_custom_def(custom_type)
|
self._update_custom_def(custom_type, None)
|
||||||
|
|
||||||
def _update_custom_def(self, custom_type):
|
def _update_custom_def(self, custom_type, namespace_prefix):
|
||||||
outer_custom_types = {}
|
outer_custom_types = {}
|
||||||
for type_def in self.type_definition_list:
|
for type_def in self.type_definition_list:
|
||||||
outer_custom_types = custom_type.get(type_def)
|
outer_custom_types = custom_type.get(type_def)
|
||||||
if outer_custom_types:
|
if outer_custom_types:
|
||||||
if type_def == "imports":
|
if type_def == "imports":
|
||||||
self.custom_defs.update({'imports': outer_custom_types})
|
self.custom_defs.update({'imports': outer_custom_types})
|
||||||
|
else:
|
||||||
|
if namespace_prefix:
|
||||||
|
prefix_custom_types = {}
|
||||||
|
for type_def_key in outer_custom_types.keys():
|
||||||
|
namespace_prefix_to_key = (namespace_prefix +
|
||||||
|
"." + type_def_key)
|
||||||
|
prefix_custom_types[namespace_prefix_to_key] = \
|
||||||
|
outer_custom_types[type_def_key]
|
||||||
|
self.custom_defs.update(prefix_custom_types)
|
||||||
else:
|
else:
|
||||||
self.custom_defs.update(outer_custom_types)
|
self.custom_defs.update(outer_custom_types)
|
||||||
|
|
||||||
@ -133,9 +147,6 @@ class ImportsLoader(object):
|
|||||||
file_name = import_uri_def.get(self.FILE)
|
file_name = import_uri_def.get(self.FILE)
|
||||||
repository = import_uri_def.get(self.REPOSITORY)
|
repository = import_uri_def.get(self.REPOSITORY)
|
||||||
namespace_uri = import_uri_def.get(self.NAMESPACE_URI)
|
namespace_uri = import_uri_def.get(self.NAMESPACE_URI)
|
||||||
# TODO(anyone) : will be extended this namespace_prefix in
|
|
||||||
# the next patch after design discussion with PTL.
|
|
||||||
# namespace_prefix = import_uri_def.get(self.NAMESPACE_PREFIX)
|
|
||||||
else:
|
else:
|
||||||
file_name = import_uri_def
|
file_name = import_uri_def
|
||||||
namespace_uri = None
|
namespace_uri = None
|
||||||
|
@ -8,7 +8,7 @@ imports:
|
|||||||
file: custom_types/logstash.yaml
|
file: custom_types/logstash.yaml
|
||||||
|
|
||||||
node_types:
|
node_types:
|
||||||
tosca.nodes.SoftwareComponent.Rsyslog:
|
Rsyslog:
|
||||||
derived_from: tosca.nodes.SoftwareComponent
|
derived_from: tosca.nodes.SoftwareComponent
|
||||||
requirements:
|
requirements:
|
||||||
- log_endpoint:
|
- log_endpoint:
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
tosca_definitions_version: tosca_simple_yaml_1_0
|
tosca_definitions_version: tosca_simple_yaml_1_0
|
||||||
imports:
|
imports:
|
||||||
- rsyslog: custom_types/nested_rsyslog.yaml
|
- test_prefix_defs:
|
||||||
|
file: custom_types/nested_rsyslog.yaml
|
||||||
|
namespace_prefix: test_namespace_prefix
|
||||||
|
- test_second_time_with_another_prefix:
|
||||||
|
file: custom_types/nested_rsyslog.yaml
|
||||||
|
namespace_prefix: test_2nd_namespace_prefix
|
||||||
|
|
||||||
node_types:
|
node_types:
|
||||||
tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType:
|
tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType:
|
||||||
derived_from: tosca.nodes.SoftwareComponent.Rsyslog
|
derived_from: test_namespace_prefix.Rsyslog
|
||||||
|
|
||||||
|
Test2ndRsyslogType:
|
||||||
|
derived_from: test_2nd_namespace_prefix.Rsyslog
|
||||||
|
|
||||||
tosca.nodes.WebApplication.WordPress:
|
tosca.nodes.WebApplication.WordPress:
|
||||||
derived_from: tosca.nodes.WebApplication
|
derived_from: tosca.nodes.WebApplication
|
||||||
|
@ -16,7 +16,7 @@ topology_template:
|
|||||||
type: tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType
|
type: tosca.nodes.SoftwareComponent.Rsyslog.TestRsyslogType
|
||||||
|
|
||||||
rsyslog:
|
rsyslog:
|
||||||
type: tosca.nodes.SoftwareComponent.Rsyslog
|
type: Test2ndRsyslogType
|
||||||
|
|
||||||
logstash:
|
logstash:
|
||||||
type: tosca.nodes.SoftwareComponent.Logstash
|
type: tosca.nodes.SoftwareComponent.Logstash
|
||||||
|
@ -443,7 +443,9 @@ class ToscaTemplateTest(TestCase):
|
|||||||
"data/test_instance_nested_imports.yaml")
|
"data/test_instance_nested_imports.yaml")
|
||||||
tosca = ToscaTemplate(tosca_tpl)
|
tosca = ToscaTemplate(tosca_tpl)
|
||||||
expected_custom_types = ['tosca.nodes.WebApplication.WordPress',
|
expected_custom_types = ['tosca.nodes.WebApplication.WordPress',
|
||||||
'tosca.nodes.SoftwareComponent.Rsyslog',
|
'test_namespace_prefix.Rsyslog',
|
||||||
|
'Test2ndRsyslogType',
|
||||||
|
'test_2nd_namespace_prefix.Rsyslog',
|
||||||
'tosca.nodes.SoftwareComponent.Logstash',
|
'tosca.nodes.SoftwareComponent.Logstash',
|
||||||
'tosca.nodes.SoftwareComponent.Rsyslog.'
|
'tosca.nodes.SoftwareComponent.Rsyslog.'
|
||||||
'TestRsyslogType']
|
'TestRsyslogType']
|
||||||
|
@ -132,8 +132,21 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
|||||||
custom_defs = self._imports_content_test(tpl_snippet,
|
custom_defs = self._imports_content_test(tpl_snippet,
|
||||||
path,
|
path,
|
||||||
"node_types")
|
"node_types")
|
||||||
self.assertTrue(custom_defs.get("tosca.nodes."
|
self.assertTrue(custom_defs.get("single_instance_wordpress.tosca."
|
||||||
"WebApplication.WordPress"))
|
"nodes.WebApplication.WordPress"))
|
||||||
|
|
||||||
|
def test_imports_wth_namespace_prefix(self):
|
||||||
|
tpl_snippet = '''
|
||||||
|
imports:
|
||||||
|
- more_definitions:
|
||||||
|
file: custom_types/nested_rsyslog.yaml
|
||||||
|
namespace_prefix: testprefix
|
||||||
|
'''
|
||||||
|
path = 'toscaparser/tests/data/tosca_elk.yaml'
|
||||||
|
custom_defs = self._imports_content_test(tpl_snippet,
|
||||||
|
path,
|
||||||
|
"node_types")
|
||||||
|
self.assertTrue(custom_defs.get("testprefix.Rsyslog"))
|
||||||
|
|
||||||
def test_imports_with_no_main_template(self):
|
def test_imports_with_no_main_template(self):
|
||||||
tpl_snippet = '''
|
tpl_snippet = '''
|
||||||
@ -187,7 +200,6 @@ tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
|||||||
- more_definitions:
|
- more_definitions:
|
||||||
file: https://raw.githubusercontent.com/openstack/\
|
file: https://raw.githubusercontent.com/openstack/\
|
||||||
tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
|
||||||
namespace_prefix: mycompany
|
|
||||||
'''
|
'''
|
||||||
path = 'https://raw.githubusercontent.com/openstack/\
|
path = 'https://raw.githubusercontent.com/openstack/\
|
||||||
tosca-parser/master/toscaparser/tests/data/\
|
tosca-parser/master/toscaparser/tests/data/\
|
||||||
@ -211,7 +223,7 @@ custom_types/wordpress.yaml
|
|||||||
custom_defs = self._imports_content_test(tpl_snippet,
|
custom_defs = self._imports_content_test(tpl_snippet,
|
||||||
path,
|
path,
|
||||||
"node_types")
|
"node_types")
|
||||||
self.assertTrue(custom_defs.get("tosca.nodes."
|
self.assertTrue(custom_defs.get("mycompany.tosca.nodes."
|
||||||
"WebApplication.WordPress"))
|
"WebApplication.WordPress"))
|
||||||
|
|
||||||
def test_import_error_namespace_uri(self):
|
def test_import_error_namespace_uri(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user