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):
|
||||
'''TOSCA built-in interfaces type.'''
|
||||
|
||||
def __init__(self, node_type, interfacetype,
|
||||
def __init__(self, node_type, interfacename,
|
||||
node_template=None, name=None, value=None):
|
||||
self.ntype = node_type
|
||||
self.node_template = node_template
|
||||
self.type = interfacetype
|
||||
self.type = interfacename
|
||||
self.interfacename = interfacename
|
||||
self.name = name
|
||||
self.value = value
|
||||
self.implementation = None
|
||||
self.inputs = None
|
||||
self.defs = {}
|
||||
if interfacetype == LIFECYCLE_SHORTNAME:
|
||||
interfacetype = LIFECYCLE
|
||||
if interfacetype == CONFIGURE_SHORTNAME:
|
||||
interfacetype = CONFIGURE
|
||||
if hasattr(self.ntype, 'interfaces') \
|
||||
and self.ntype.interfaces \
|
||||
and interfacetype in self.ntype.interfaces:
|
||||
interfacetype = self.ntype.interfaces[interfacetype]['type']
|
||||
if interfacename == LIFECYCLE_SHORTNAME:
|
||||
self.interfacetype = LIFECYCLE
|
||||
elif interfacename == CONFIGURE_SHORTNAME:
|
||||
self.interfacetype = CONFIGURE
|
||||
elif hasattr(self.ntype, 'interfaces') \
|
||||
and self.ntype.interfaces \
|
||||
and interfacename in self.ntype.interfaces:
|
||||
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 self.node_template and self.node_template.custom_def \
|
||||
and interfacetype in self.node_template.custom_def:
|
||||
self.defs = self.node_template.custom_def[interfacetype]
|
||||
else:
|
||||
self.defs = self.TOSCA_DEF[interfacetype]
|
||||
and self.interfacetype in self.node_template.custom_def:
|
||||
self.defs = self.node_template.custom_def[self.interfacetype]
|
||||
elif self.interfacetype in self.TOSCA_DEF:
|
||||
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 isinstance(self.value, dict):
|
||||
for i, j in self.value.items():
|
||||
|
@ -312,7 +312,7 @@ class EntityTemplate(object):
|
||||
for interface_type, value in type_interfaces.items():
|
||||
for op, op_def in value.items():
|
||||
iface = InterfacesDef(self.type_definition,
|
||||
interfacetype=interface_type,
|
||||
interfacename=interface_type,
|
||||
node_template=self,
|
||||
name=op,
|
||||
value=op_def)
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
|
||||
import abc
|
||||
import toscaparser.elements.interfaces
|
||||
|
||||
from toscaparser.common.exception import ExceptionCollector
|
||||
from toscaparser.common.exception import UnknownInputError
|
||||
@ -667,9 +666,36 @@ class GetProperty(Function):
|
||||
class GetOperationOutput(Function):
|
||||
def validate(self):
|
||||
if len(self.args) == 4:
|
||||
self._find_node_template(self.args[0])
|
||||
interface_name = self._find_interface_name(self.args[1])
|
||||
self._find_operation_name(interface_name, self.args[2])
|
||||
template_name = self.args[0]
|
||||
interface_name = self.args[1]
|
||||
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:
|
||||
ExceptionCollector.appendException(
|
||||
ValueError(_('Illegal arguments for function "{0}". Expected '
|
||||
@ -678,16 +704,8 @@ class GetOperationOutput(Function):
|
||||
).format(GET_OPERATION_OUTPUT)))
|
||||
return
|
||||
|
||||
def _find_interface_name(self, interface_name):
|
||||
if interface_name in toscaparser.elements.interfaces.SECTIONS:
|
||||
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):
|
||||
def _find_operation_name(self, interface_name, operation_name,
|
||||
interfaces=None):
|
||||
if(interface_name == 'Configure' or
|
||||
interface_name == 'tosca.interfaces.node.relationship.Configure'):
|
||||
if(operation_name in
|
||||
@ -709,6 +727,11 @@ class GetOperationOutput(Function):
|
||||
ValueError(_('Enter an operation of Standard interface'
|
||||
).format(GET_OPERATION_OUTPUT)))
|
||||
return
|
||||
elif interfaces:
|
||||
for interface_obj in interfaces:
|
||||
if interface_obj.name == operation_name and \
|
||||
interface_obj.type == interface_name:
|
||||
return operation_name
|
||||
else:
|
||||
ExceptionCollector.appendException(
|
||||
ValueError(_('Enter a valid operation name'
|
||||
@ -737,10 +760,11 @@ class GetOperationOutput(Function):
|
||||
for node_template in self.tosca_tpl.nodetemplates:
|
||||
if node_template.name == name:
|
||||
return node_template
|
||||
ExceptionCollector.appendException(
|
||||
KeyError(_(
|
||||
'Node template "{0}" was not found.'
|
||||
).format(node_template_name)))
|
||||
|
||||
def _find_relationship_template(self, relationship_template_name):
|
||||
for rel_template in self.tosca_tpl.relationship_templates:
|
||||
if rel_template.name == relationship_template_name:
|
||||
return rel_template
|
||||
|
||||
def result(self):
|
||||
return self
|
||||
|
@ -142,7 +142,9 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
|
||||
err = self.assertRaises(ValueError,
|
||||
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__())
|
||||
# test case 2
|
||||
tpl_snippet2 = '''
|
||||
@ -162,7 +164,8 @@ class ToscaTemplateValidationTest(TestCase):
|
||||
tpl2 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet2))
|
||||
err2 = self.assertRaises(KeyError,
|
||||
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__())
|
||||
# test case 3
|
||||
tpl_snippet3 = '''
|
||||
|
Loading…
Reference in New Issue
Block a user