def validate(self): if len(self.args) < 2: ExceptionCollector.appendException( ValueError( _('Illegal arguments for function "{0}". Expected ' 'arguments: "node-template-name", "req-or-cap"' '(optional), "property name"').format(GET_ATTRIBUTE))) return elif len(self.args) == 2: self._find_node_template_containing_attribute() else: node_tpl = self._find_node_template(self.args[0]) index = 2 attrs = node_tpl.type_definition.get_attributes_def() found = [attrs[self.args[1]]] if self.args[1] in attrs else [] if found: attr = found[0] else: index = 3 # then check the req or caps attr = self._find_req_or_cap_attribute(self.args[1], self.args[2]) value_type = attr.schema['type'] if len(self.args) > index: for elem in self.args[index:]: if value_type == "list": if not isinstance(elem, int): ExceptionCollector.appendException( ValueError( _('Illegal arguments for function' ' "{0}". "{1}" Expected positive' ' integer argument').format( GET_ATTRIBUTE, elem))) value_type = attr.schema['entry_schema']['type'] elif value_type == "map": value_type = attr.schema['entry_schema']['type'] elif value_type in Schema.PROPERTY_TYPES: ExceptionCollector.appendException( ValueError( _('Illegal arguments for function' ' "{0}". Unexpected attribute/' 'index value "{1}"').format( GET_ATTRIBUTE, elem))) return else: # It is a complex type data_type = DataType(value_type) props = data_type.get_all_properties() found = [props[elem]] if elem in props else [] if found: prop = found[0] value_type = prop.schema['type'] else: ExceptionCollector.appendException( KeyError( _('Illegal arguments for function' ' "{0}". Attribute name "{1}" not' ' found in "{2}"').format( GET_ATTRIBUTE, elem, value_type)))
def test_built_in_datatype_without_properties(self): value_snippet = ''' 2 ''' value = yamlparser.simple_parse(value_snippet) datatype = DataType('PortDef') self.assertEqual('integer', datatype.value_type) data = DataEntity('PortDef', value) self.assertIsNotNone(data.validate())
def __init__(self, datatypename, value_dict, custom_def=None, prop_name=None): self.custom_def = custom_def self.datatype = DataType(datatypename, custom_def) self.schema = self.datatype.get_all_properties() self.value = value_dict self.property_name = prop_name
def __init__(self, datatypename, value, custom_def=None, prop_name=None): self.custom_def = custom_def self.type = datatypename if datatypename in Schema.PROPERTY_TYPES: self.datatype = ValueDataType(datatypename) self.schema = {} else: self.datatype = DataType(datatypename, custom_def) if self.datatype.value_type: # "type" and "properties" are mutually exclusive self.schema = {} else: self.schema = self.datatype.get_properties_def() self.value = value self.property_name = prop_name self._properties = None