Example #1
0
def _evaluate_target_func(target_dep_func, source_dep_id):
    if is_function(target_dep_func):
        evaluated_func = evaluate_intrinsic_functions(
            {'target_deployment': target_dep_func}, source_dep_id)
        return evaluated_func.get('target_deployment')

    return target_dep_func
Example #2
0
def validate_input_value(input_name, input_constraints, input_value):
    if input_constraints and functions.is_function(input_value):
        raise exceptions.DSLParsingException(
            exceptions.ERROR_INPUT_WITH_FUNCS_AND_CONSTRAINTS,
            'Input value {0}, of input {1}, cannot contain an intrinsic '
            'function and also have '
            'constraints.'.format(input_value, input_name))
    for c in input_constraints:
        if not c.predicate(input_value):
            raise exceptions.ConstraintException(
                "Value {0} of input {1} violates constraint "
                "{2}.".format(input_value, input_name, c))
Example #3
0
def validate_args(constraint_cls, args, ancestor):
    """Validates the given constraint class arguments.

    :param constraint_cls: a Constraint class.
    :param args: the constraint operator arguments.
    :param ancestor: ancestor element of this constraint.
    :raises DSLParsingFormatException: in case of a violation.
    """
    if functions.is_function(args) \
            or not VALIDATION_FUNCTIONS[
                constraint_cls.constraint_data_type](args):
        raise exceptions.DSLParsingLogicException(
            exceptions.ERROR_INVALID_CONSTRAINT_ARGUMENT,
            'Invalid constraint operator argument "{0}", for constraint '
            'operator "{1}" in '
            '"{2}".'.format(args, constraint_cls.name, ancestor))
Example #4
0
 def _assert_initial_compute_node_dependencies(self,
                                               dependencies):
     for dependency in dependencies:
         self.assertEqual(dependency.source_deployment_id, MAIN_DEPLOYMENT)
         if 'property_static' in dependency.dependency_creator:
             self.assertEqual(dependency.target_deployment_id,
                              SR_DEPLOYMENT)
         elif 'property_function' in dependency.dependency_creator:
             self.assertEqual(dependency.target_deployment_id,
                              SR_DEPLOYMENT)
             secret_func = {'get_secret': 'shared_resource_deployment_key'}
             assert is_function(dependency['target_deployment_func'])
             self.assertEqual(dependency['target_deployment_func'],
                              secret_func)
         else:
             self.fail('Unexpected dependency creator "{0}"'
                       ''.format(dependency.dependency_creator))
Example #5
0
def parse_value(value,
                type_name,
                data_types,
                undefined_property_error_message,
                missing_property_error_message,
                node_name,
                path,
                derived_value=None,
                raise_on_missing_property=True):
    if type_name is None:
        return value
    elif functions.is_function(value):
        # intrinsic function - not validated at the moment
        return value
    elif type_name == 'integer':
        if isinstance(value, numbers.Integral) and not isinstance(value, bool):
            return value
    elif type_name == 'float':
        if isinstance(value, numbers.Number) and not isinstance(value, bool):
            return value
    elif type_name == 'boolean':
        if isinstance(value, bool):
            return value
    elif type_name == 'string':
        return value
    elif type_name == 'regex':
        if isinstance(value, text_type):
            try:
                re.compile(value)
                return value
            except re.error:
                pass
    elif type_name == 'list':
        if isinstance(value, (list, tuple)):
            return value
    elif type_name == 'dict':
        if isinstance(value, dict):
            return value
    elif type_name in data_types:
        if isinstance(value, dict):
            data_schema = data_types[type_name]['properties']
            flattened_data_schema = flatten_schema(data_schema)
            if isinstance(derived_value, dict):
                flattened_data_schema.update(derived_value)
            undef_msg = undefined_property_error_message
            return _merge_flattened_schema_and_instance_properties(
                instance_properties=value,
                schema_properties=data_schema,
                flattened_schema_properties=flattened_data_schema,
                data_types=data_types,
                undefined_property_error_message=undef_msg,
                missing_property_error_message=missing_property_error_message,
                node_name=node_name,
                path=path,
                raise_on_missing_property=raise_on_missing_property)
    else:
        raise RuntimeError(
            "Unexpected type defined in property schema for property '{0}'"
            " - unknown type is '{1}'".format(_property_description(path),
                                              type_name))

    prop_path = _property_description(path)
    if not prop_path:
        err_msg = "Property type validation failed in '{0}': the defined " \
                  "type is '{1}', yet it was assigned with the " \
                  "value '{2}'".format(node_name, type_name, value)
    else:
        err_msg = "Property type validation failed in '{0}': property " \
                  "'{1}' type is '{2}', yet it was assigned with the " \
                  "value '{3}'".format(node_name,
                                       _property_description(path),
                                       type_name,
                                       value)

    raise exceptions.DSLParsingLogicException(
        exceptions.ERROR_VALUE_DOES_NOT_MATCH_TYPE, err_msg)