예제 #1
0
 def class_(value, name, default_name=None, version_spec=None):
     object_store = None if this is None else this.object_store
     if not default_name:
         default_name = name
     murano_class = name.type
     if value is None:
         return None
     if isinstance(value, dsl_types.MuranoObject):
         obj = value
     elif isinstance(value, dsl_types.MuranoObjectInterface):
         obj = value.object
     elif isinstance(value, utils.MappingType):
         obj = helpers.instantiate(
             value, owner, object_store, root_context,
             calling_type, default_name)
     elif isinstance(value, six.string_types) and object_store:
         obj = object_store.get(value)
         if obj is None:
             if not object_store.initializing:
                 raise exceptions.NoObjectFoundError(value)
             else:
                 return TypeScheme.ObjRef(value)
     else:
         raise exceptions.ContractViolationException(
             'Value {0} cannot be represented as class {1}'.format(
                 format_scalar(value), name))
     if not helpers.is_instance_of(
             obj, murano_class.name,
             version_spec or helpers.get_type(root_context)):
         raise exceptions.ContractViolationException(
             'Object of type {0} is not compatible with '
             'requested type {1}'.format(obj.type.name, name))
     return obj
예제 #2
0
def _get_all_test_methods(exc, package):
    """Initiate objects of package classes and get test methods.

       Check, if test class and test case name are valid.
       Return class mappings to objects and test methods.
    """
    class_to_obj = {}
    class_to_methods = {}
    for pkg_class_name in package.classes:
        class_obj = package.find_class(pkg_class_name, False)

        obj = class_obj.new(None, exc.object_store)(None)
        if not helpers.is_instance_of(obj, BASE_CLASS, '*'):
            LOG.debug('Class {0} is not inherited from {1}. '
                      'Skipping it.'.format(pkg_class_name, BASE_CLASS))
            continue

        class_to_obj[pkg_class_name] = obj
        # Exclude methods, that are not test cases.
        tests = []
        valid_test_name = TEST_CASE_NAME

        for m in class_obj.methods:
            if valid_test_name.match(m):
                tests.append(m)
        class_to_methods[pkg_class_name] = tests
    return class_to_methods, class_to_obj
예제 #3
0
        def template(engine,
                     value,
                     type_,
                     exclude_properties=None,
                     default_type=None,
                     version_spec=None):
            object_store = helpers.get_object_store()
            passkey = None
            if not default_type:
                default_type = type_
            murano_class = type_.type
            if value is None:
                return None
            if isinstance(value, dsl_types.MuranoObject):
                obj = value
            elif isinstance(value, dsl_types.MuranoObjectInterface):
                obj = value.object
            elif isinstance(value, utils.MappingType):
                passkey = utils.create_marker('<Contract Passkey>')
                if exclude_properties:
                    parsed = helpers.parse_object_definition(
                        value, calling_type, context)
                    props = dsl.to_mutable(parsed['properties'], engine)
                    for p in exclude_properties:
                        helpers.patch_dict(props, p, passkey)
                    parsed['properties'] = props
                    value = helpers.assemble_object_definition(parsed)
                with helpers.thread_local_attribute(
                        constants.TL_CONTRACT_PASSKEY, passkey):
                    with helpers.thread_local_attribute(
                            constants.TL_OBJECTS_DRY_RUN, True):
                        obj = object_store.load(value,
                                                owner,
                                                context=context,
                                                default_type=default_type,
                                                scope_type=calling_type)
            else:
                raise exceptions.ContractViolationException(
                    'Value {0} cannot be represented as class {1}'.format(
                        format_scalar(value), type_))
            if not helpers.is_instance_of(
                    obj, murano_class.name, version_spec
                    or helpers.get_type(root_context)):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, type_))

            with helpers.thread_local_attribute(constants.TL_CONTRACT_PASSKEY,
                                                passkey):
                result = serializer.serialize(obj.real_this,
                                              object_store.executor,
                                              dsl_types.DumpTypes.Mixed)
                if exclude_properties:
                    for p in exclude_properties:
                        helpers.patch_dict(result, p, utils.NO_VALUE)
                return result
예제 #4
0
 def validate(self):
     if self.value is None or helpers.is_instance_of(
             self.value, self.type.name, self.version_spec
             or helpers.get_names_scope(self.root_context)):
         return self.value
     if not isinstance(
             self.value,
         (dsl_types.MuranoObject, dsl_types.MuranoObjectInterface)):
         raise exceptions.ContractViolationException(
             'Value is not an object')
     raise exceptions.ContractViolationException(
         'Object of type {0} is not compatible with '
         'requested type {1}'.format(self.value.type, self.type))
예제 #5
0
        def template(value,
                     type_,
                     exclude_properties=None,
                     default_type=None,
                     version_spec=None):

            if value is None or isinstance(value, utils.MappingType):
                return value

            if helpers.is_instance_of(
                    value, type_.type.name, version_spec
                    or helpers.get_names_scope(root_context)):
                return value
            raise exceptions.ContractViolationException()
예제 #6
0
 def check(self, value, context, *args, **kwargs):
     if not super(MuranoType, self).check(value, context, *args, **kwargs):
         return False
     if isinstance(value, MuranoObjectInterface):
         value = value.object
     if value is None or isinstance(value, yaql_expressions.Expression):
         return True
     murano_class = self.murano_class
     if isinstance(murano_class, types.StringTypes):
         murano_class_name = murano_class
     else:
         murano_class_name = murano_class.name
     return helpers.is_instance_of(
         value, murano_class_name, self.version_spec
         or helpers.get_type(context))
예제 #7
0
파일: dsl.py 프로젝트: Magic-Mirror/murano
 def check(self, value, context, *args, **kwargs):
     if not super(MuranoType, self).check(
             value, context, *args, **kwargs):
         return False
     if isinstance(value, MuranoObjectInterface):
         value = value.object
     if value is None or isinstance(value, yaql_expressions.Expression):
         return True
     murano_class = self.murano_class
     if isinstance(murano_class, six.string_types):
         murano_class_name = murano_class
     else:
         murano_class_name = murano_class.name
     return helpers.is_instance_of(
         value, murano_class_name,
         self.version_spec or helpers.get_type(context))
예제 #8
0
        def class_(value, name, default_name=None, version_spec=None):
            object_store = this.object_store
            if not default_name:
                default_name = name
            murano_class = name.murano_class
            if value is None:
                return None
            if isinstance(value, dsl_types.MuranoObject):
                obj = value
            elif isinstance(value, dsl_types.MuranoObjectInterface):
                obj = value.object
            elif isinstance(value, utils.MappingType):
                if '?' not in value:
                    new_value = {
                        '?': {
                            'id': uuid.uuid4().hex,
                            'type': default_name.murano_class.name,
                            'classVersion':
                            str(default_name.murano_class.version)
                        }
                    }
                    new_value.update(value)
                    value = new_value

                obj = object_store.load(value,
                                        owner,
                                        root_context,
                                        defaults=default)
            elif isinstance(value, types.StringTypes):
                obj = object_store.get(value)
                if obj is None:
                    if not object_store.initializing:
                        raise exceptions.NoObjectFoundError(value)
                    else:
                        return TypeScheme.ObjRef(value)
            else:
                raise exceptions.ContractViolationException(
                    'Value {0} cannot be represented as class {1}'.format(
                        format_scalar(value), name))
            if not helpers.is_instance_of(
                    obj, murano_class.name, version_spec
                    or helpers.get_type(root_context)):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, name))
            return obj
예제 #9
0
파일: dsl.py 프로젝트: Aqsamm/murano
 def check(self, value, context, *args, **kwargs):
     if not super(MuranoObjectParameter, self).check(
             value, context, *args, **kwargs):
         return False
     if value is None or isinstance(value, yaql_expressions.Expression):
         return True
     if isinstance(value, MuranoObjectInterface):
         value = value.object
     if not isinstance(value, dsl_types.MuranoObject):
         return False
     if self.murano_class:
         murano_class = self.murano_class
         if isinstance(murano_class, six.string_types):
             return helpers.is_instance_of(
                 value, murano_class,
                 self.version_spec or helpers.get_type(context))
         else:
             return murano_class.is_compatible(value)
     else:
         return True
예제 #10
0
 def check(self, value, context, *args, **kwargs):
     if not super(MuranoObjectParameter, self).check(
             value, context, *args, **kwargs):
         return False
     if value is None or isinstance(value, yaql_expressions.Expression):
         return True
     if isinstance(value, MuranoObjectInterface):
         value = value.object
     if not isinstance(value, dsl_types.MuranoObject):
         return False
     if self.murano_class:
         murano_class = self.murano_class
         if isinstance(murano_class, six.string_types):
             return helpers.is_instance_of(
                 value, murano_class,
                 self.version_spec or helpers.get_type(context))
         else:
             return murano_class.is_compatible(value)
     else:
         return True
예제 #11
0
        def class_(value, name, default_name=None, version_spec=None):
            object_store = this.object_store
            if not default_name:
                default_name = name
            murano_class = name.murano_class
            if value is None:
                return None
            if isinstance(value, dsl_types.MuranoObject):
                obj = value
            elif isinstance(value, dsl_types.MuranoObjectInterface):
                obj = value.object
            elif isinstance(value, utils.MappingType):
                if '?' not in value:
                    new_value = {'?': {
                        'id': uuid.uuid4().hex,
                        'type': default_name.murano_class.name,
                        'classVersion': str(default_name.murano_class.version)
                    }}
                    new_value.update(value)
                    value = new_value

                obj = object_store.load(
                    value, owner, root_context, defaults=default)
            elif isinstance(value, types.StringTypes):
                obj = object_store.get(value)
                if obj is None:
                    if not object_store.initializing:
                        raise exceptions.NoObjectFoundError(value)
                    else:
                        return TypeScheme.ObjRef(value)
            else:
                raise exceptions.ContractViolationException(
                    'Value {0} cannot be represented as class {1}'.format(
                        value, name))
            if not helpers.is_instance_of(
                    obj, murano_class.name,
                    version_spec or helpers.get_type(root_context)):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, name))
            return obj
예제 #12
0
파일: dsl.py 프로젝트: Magic-Mirror/murano
 def is_instance_of(self, murano_class, version_spec=None):
     return helpers.is_instance_of(
         self.__object, murano_class,
         version_spec or helpers.get_type())
예제 #13
0
 def test_create(self):
     logger_instance = self._runner.testCreate()
     self.assertTrue(
         helpers.is_instance_of(logger_instance, 'io.murano.system.Logger'),
         'Function should return io.murano.system.Logger instance')
예제 #14
0
 def is_instance_of(self, murano_class, version_spec=None):
     return helpers.is_instance_of(
         self.object, murano_class,
         version_spec or helpers.get_type())
예제 #15
0
 def class_(value, type, version_spec=None):
     if helpers.is_instance_of(
             value, type.type.name,
             version_spec or helpers.get_names_scope(root_context)):
         return value
     raise exceptions.ContractViolationException()
예제 #16
0
 def test_create(self):
     logger_instance = self._runner.testCreate()
     self.assertTrue(
         helpers.is_instance_of(logger_instance, 'io.murano.system.Logger'),
         'Function should return io.murano.system.Logger instance')
예제 #17
0
 def class_(value, type, version_spec=None):
     if value is None or helpers.is_instance_of(
             value, type.type.name, version_spec
             or helpers.get_names_scope(root_context)):
         return value
     raise exceptions.ContractViolationException()