Fail to parse capabilities without properties

Fixed a bug that can not be parsed if properties are not defined
in the parent resource described in capabilities.
Story: #2006298
Task: #36010

Change-Id: I32e3afbd454ccaa807f7d1b049f027c97a627701
This commit is contained in:
Keiko Kuriu 2019-07-29 13:50:12 +09:00
parent 328cec62b2
commit 72823d2db9
3 changed files with 72 additions and 1 deletions

View File

@ -35,7 +35,8 @@ class CapabilityTypeDef(StatefulEntityType):
parent_properties = {}
if self.parent_capabilities:
for type, value in self.parent_capabilities.items():
parent_properties[type] = value.get('properties')
if self.PROPERTIES in value:
parent_properties[type] = value.get(self.PROPERTIES)
if self.properties:
for prop, schema in self.properties.items():
properties.append(PropertyDef(prop, None, schema))

View File

@ -0,0 +1,36 @@
tosca_definitions_version: tosca_simple_yaml_1_0
description: >
Test resources for which properties are not defined in
the parent of capabilitytype.
TestApp has capabilities->test_cap,
and the type of test_cap is TestCapabilityAA.
The parents of TestCapabilityAA is TestCapabilityA,
and TestCapabilityA has no properties.
node_types:
tosca.nodes.WebApplication.TestApp:
derived_from: tosca.nodes.WebApplication
capabilities:
test_cap:
type: tosca.capabilities.TestCapabilityAA
# Node whose parent is Root and does not have properties
tosca.capabilities.TestCapabilityA:
derived_from: tosca.capabilities.Root
tosca.capabilities.TestCapabilityAA:
derived_from: tosca.capabilities.TestCapabilityA
properties:
test:
type: integer
required: false
topology_template:
node_templates:
test_app:
type: tosca.nodes.WebApplication.TestApp
capabilities:
test_cap:
properties:
test: 1

View File

@ -439,6 +439,40 @@ class ToscaTemplateTest(TestCase):
self.assertEqual('Type "tosca.capabilities.TestCapability" is not '
'a valid type.', six.text_type(err))
def test_capability_without_properties(self):
expected_version = "tosca_simple_yaml_1_0"
expected_description = \
"Test resources for which properties are not defined in "\
"the parent of capabilitytype. "\
"TestApp has capabilities->test_cap, "\
"and the type of test_cap is TestCapabilityAA. "\
"The parents of TestCapabilityAA is TestCapabilityA, "\
"and TestCapabilityA has no properties."
expected_nodetemplates = {
"test_app": {
"type": "tosca.nodes.WebApplication.TestApp",
"capabilities": {
"test_cap": {
"properties": {
"test": 1
}
}
}
}
}
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"data/test_capability_without_properties.yaml")
tosca = ToscaTemplate(tosca_tpl)
self.assertEqual(expected_version, tosca.version)
self.assertEqual(expected_description, tosca.description)
self.assertEqual(
expected_nodetemplates,
tosca.nodetemplates[0].templates,
)
def test_local_template_with_local_relpath_import(self):
tosca_tpl = os.path.join(
os.path.dirname(os.path.abspath(__file__)),