Update validation of function get_operation_output
Function `get_operation_output` takes Node or Relationship Template as first argument. Change-Id: Ifb9ddf2c021408bdc9f2da18a8c7f3958056709e Closes-Bug: #1901051
This commit is contained in:
parent
df16f011f0
commit
5860c6f0b0
@ -29,30 +29,41 @@ INTERFACE_DEF_RESERVED_WORDS = ['type', 'inputs', 'derived_from', 'version',
|
|||||||
class InterfacesDef(StatefulEntityType):
|
class InterfacesDef(StatefulEntityType):
|
||||||
'''TOSCA built-in interfaces type.'''
|
'''TOSCA built-in interfaces type.'''
|
||||||
|
|
||||||
def __init__(self, node_type, interfacetype,
|
def __init__(self, node_type, interfacename,
|
||||||
node_template=None, name=None, value=None):
|
node_template=None, name=None, value=None):
|
||||||
self.ntype = node_type
|
self.ntype = node_type
|
||||||
self.node_template = node_template
|
self.node_template = node_template
|
||||||
self.type = interfacetype
|
self.type = interfacename
|
||||||
|
self.interfacename = interfacename
|
||||||
self.name = name
|
self.name = name
|
||||||
self.value = value
|
self.value = value
|
||||||
self.implementation = None
|
self.implementation = None
|
||||||
self.inputs = None
|
self.inputs = None
|
||||||
self.defs = {}
|
self.defs = {}
|
||||||
if interfacetype == LIFECYCLE_SHORTNAME:
|
if interfacename == LIFECYCLE_SHORTNAME:
|
||||||
interfacetype = LIFECYCLE
|
self.interfacetype = LIFECYCLE
|
||||||
if interfacetype == CONFIGURE_SHORTNAME:
|
elif interfacename == CONFIGURE_SHORTNAME:
|
||||||
interfacetype = CONFIGURE
|
self.interfacetype = CONFIGURE
|
||||||
if hasattr(self.ntype, 'interfaces') \
|
elif hasattr(self.ntype, 'interfaces') \
|
||||||
and self.ntype.interfaces \
|
and self.ntype.interfaces \
|
||||||
and interfacetype in self.ntype.interfaces:
|
and interfacename in self.ntype.interfaces:
|
||||||
interfacetype = self.ntype.interfaces[interfacetype]['type']
|
self.interfacetype = self.ntype.interfaces[interfacename]['type']
|
||||||
|
if not self.interfacetype:
|
||||||
|
ExceptionCollector.appendException(
|
||||||
|
TypeError("Interface type for interface \"{0}\" not found"
|
||||||
|
.format(self.interfacename))
|
||||||
|
)
|
||||||
if node_type:
|
if node_type:
|
||||||
if self.node_template and self.node_template.custom_def \
|
if self.node_template and self.node_template.custom_def \
|
||||||
and interfacetype in self.node_template.custom_def:
|
and self.interfacetype in self.node_template.custom_def:
|
||||||
self.defs = self.node_template.custom_def[interfacetype]
|
self.defs = self.node_template.custom_def[self.interfacetype]
|
||||||
else:
|
elif self.interfacetype in self.TOSCA_DEF:
|
||||||
self.defs = self.TOSCA_DEF[interfacetype]
|
self.defs = self.TOSCA_DEF[self.interfacetype]
|
||||||
|
if not self.defs:
|
||||||
|
ExceptionCollector.appendException(
|
||||||
|
TypeError("Interface type definition for interface \"{0}\" "
|
||||||
|
"not found".format(self.interfacetype))
|
||||||
|
)
|
||||||
if value:
|
if value:
|
||||||
if isinstance(self.value, dict):
|
if isinstance(self.value, dict):
|
||||||
for i, j in self.value.items():
|
for i, j in self.value.items():
|
||||||
|
@ -312,7 +312,7 @@ class EntityTemplate(object):
|
|||||||
for interface_type, value in type_interfaces.items():
|
for interface_type, value in type_interfaces.items():
|
||||||
for op, op_def in value.items():
|
for op, op_def in value.items():
|
||||||
iface = InterfacesDef(self.type_definition,
|
iface = InterfacesDef(self.type_definition,
|
||||||
interfacetype=interface_type,
|
interfacename=interface_type,
|
||||||
node_template=self,
|
node_template=self,
|
||||||
name=op,
|
name=op,
|
||||||
value=op_def)
|
value=op_def)
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import toscaparser.elements.interfaces
|
|
||||||
|
|
||||||
from toscaparser.common.exception import ExceptionCollector
|
from toscaparser.common.exception import ExceptionCollector
|
||||||
from toscaparser.common.exception import UnknownInputError
|
from toscaparser.common.exception import UnknownInputError
|
||||||
@ -667,9 +666,36 @@ class GetProperty(Function):
|
|||||||
class GetOperationOutput(Function):
|
class GetOperationOutput(Function):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
if len(self.args) == 4:
|
if len(self.args) == 4:
|
||||||
self._find_node_template(self.args[0])
|
template_name = self.args[0]
|
||||||
interface_name = self._find_interface_name(self.args[1])
|
interface_name = self.args[1]
|
||||||
self._find_operation_name(interface_name, self.args[2])
|
operation_name = self.args[2]
|
||||||
|
template = None
|
||||||
|
node_template = self._find_node_template(template_name)
|
||||||
|
if node_template:
|
||||||
|
template = node_template
|
||||||
|
else:
|
||||||
|
relationship_template = \
|
||||||
|
self._find_relationship_template(template_name)
|
||||||
|
if relationship_template:
|
||||||
|
template = relationship_template
|
||||||
|
if not template:
|
||||||
|
ExceptionCollector.appendException(
|
||||||
|
KeyError(_(
|
||||||
|
'Node or relationship template "{0}" was not found.'
|
||||||
|
).format(template_name)))
|
||||||
|
return
|
||||||
|
if hasattr(template, template.INTERFACES):
|
||||||
|
operation = self._find_operation_name(interface_name,
|
||||||
|
operation_name,
|
||||||
|
template.interfaces)
|
||||||
|
if operation:
|
||||||
|
return
|
||||||
|
ExceptionCollector.appendException(
|
||||||
|
ValueError(_(
|
||||||
|
'Node or relationship template "{0}" has not '
|
||||||
|
'interface "{1}" or operation "{2}".'
|
||||||
|
).format(template_name, interface_name, operation_name)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ExceptionCollector.appendException(
|
ExceptionCollector.appendException(
|
||||||
ValueError(_('Illegal arguments for function "{0}". Expected '
|
ValueError(_('Illegal arguments for function "{0}". Expected '
|
||||||
@ -678,16 +704,8 @@ class GetOperationOutput(Function):
|
|||||||
).format(GET_OPERATION_OUTPUT)))
|
).format(GET_OPERATION_OUTPUT)))
|
||||||
return
|
return
|
||||||
|
|
||||||
def _find_interface_name(self, interface_name):
|
def _find_operation_name(self, interface_name, operation_name,
|
||||||
if interface_name in toscaparser.elements.interfaces.SECTIONS:
|
interfaces=None):
|
||||||
return interface_name
|
|
||||||
else:
|
|
||||||
ExceptionCollector.appendException(
|
|
||||||
ValueError(_('Enter a valid interface name'
|
|
||||||
).format(GET_OPERATION_OUTPUT)))
|
|
||||||
return
|
|
||||||
|
|
||||||
def _find_operation_name(self, interface_name, operation_name):
|
|
||||||
if(interface_name == 'Configure' or
|
if(interface_name == 'Configure' or
|
||||||
interface_name == 'tosca.interfaces.node.relationship.Configure'):
|
interface_name == 'tosca.interfaces.node.relationship.Configure'):
|
||||||
if(operation_name in
|
if(operation_name in
|
||||||
@ -709,6 +727,11 @@ class GetOperationOutput(Function):
|
|||||||
ValueError(_('Enter an operation of Standard interface'
|
ValueError(_('Enter an operation of Standard interface'
|
||||||
).format(GET_OPERATION_OUTPUT)))
|
).format(GET_OPERATION_OUTPUT)))
|
||||||
return
|
return
|
||||||
|
elif interfaces:
|
||||||
|
for interface_obj in interfaces:
|
||||||
|
if interface_obj.name == operation_name and \
|
||||||
|
interface_obj.type == interface_name:
|
||||||
|
return operation_name
|
||||||
else:
|
else:
|
||||||
ExceptionCollector.appendException(
|
ExceptionCollector.appendException(
|
||||||
ValueError(_('Enter a valid operation name'
|
ValueError(_('Enter a valid operation name'
|
||||||
@ -737,10 +760,11 @@ class GetOperationOutput(Function):
|
|||||||
for node_template in self.tosca_tpl.nodetemplates:
|
for node_template in self.tosca_tpl.nodetemplates:
|
||||||
if node_template.name == name:
|
if node_template.name == name:
|
||||||
return node_template
|
return node_template
|
||||||
ExceptionCollector.appendException(
|
|
||||||
KeyError(_(
|
def _find_relationship_template(self, relationship_template_name):
|
||||||
'Node template "{0}" was not found.'
|
for rel_template in self.tosca_tpl.relationship_templates:
|
||||||
).format(node_template_name)))
|
if rel_template.name == relationship_template_name:
|
||||||
|
return rel_template
|
||||||
|
|
||||||
def result(self):
|
def result(self):
|
||||||
return self
|
return self
|
||||||
|
@ -142,7 +142,9 @@ class ToscaTemplateValidationTest(TestCase):
|
|||||||
tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
|
tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
|
||||||
err = self.assertRaises(ValueError,
|
err = self.assertRaises(ValueError,
|
||||||
TopologyTemplate, tpl, None)
|
TopologyTemplate, tpl, None)
|
||||||
expectedmessage = _('Enter a valid interface name')
|
expectedmessage = _('Node or relationship template "front_end" '
|
||||||
|
'has not interface "Standard1" '
|
||||||
|
'or operation "create".')
|
||||||
self.assertEqual(expectedmessage, err.__str__())
|
self.assertEqual(expectedmessage, err.__str__())
|
||||||
# test case 2
|
# test case 2
|
||||||
tpl_snippet2 = '''
|
tpl_snippet2 = '''
|
||||||
@ -162,7 +164,8 @@ class ToscaTemplateValidationTest(TestCase):
|
|||||||
tpl2 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet2))
|
tpl2 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet2))
|
||||||
err2 = self.assertRaises(KeyError,
|
err2 = self.assertRaises(KeyError,
|
||||||
TopologyTemplate, tpl2, None)
|
TopologyTemplate, tpl2, None)
|
||||||
expectedmessage2 = _('\'Node template "front_end1" was not found.\'')
|
expectedmessage2 = _('\'Node or relationship template "front_end1" '
|
||||||
|
'was not found.\'')
|
||||||
self.assertEqual(expectedmessage2, err2.__str__())
|
self.assertEqual(expectedmessage2, err2.__str__())
|
||||||
# test case 3
|
# test case 3
|
||||||
tpl_snippet3 = '''
|
tpl_snippet3 = '''
|
||||||
|
Loading…
Reference in New Issue
Block a user