Exemplo n.º 1
0
 def test_new_with_ownership(self):
     obj = serializer.serialize(self._runner.testNewWithOwnership(),
                                self._runner.executor)
     self.assertEqual('STRING', obj.get('property1'))
     self.assertIsNotNone('string', obj.get('xxx'))
     self.assertEqual('STR', obj['xxx'].get('property1'))
     self.assertEqual('QQQ', obj['xxx']['?'].get('name'))
Exemplo n.º 2
0
 def execute(self):
     with package_loader.CombinedPackageLoader(self._session) as pkg_loader:
         get_plugin_loader().register_in_loader(pkg_loader)
         executor = dsl_executor.MuranoDslExecutor(pkg_loader,
                                                   ContextManager())
         action_result = self._invoke(executor)
         action_result = serializer.serialize(action_result, executor)
         return action_result
Exemplo n.º 3
0
def dump(obj, serialization_type=serializer.DumpTypes.Serializable,
         ignore_upcasts=True):
    if serialization_type not in serializer.DumpTypes.All:
        raise ValueError('Invalid Serialization Type')
    executor = helpers.get_executor()
    if ignore_upcasts:
        obj = obj.real_this
    return serializer.serialize(obj, executor, serialization_type)
Exemplo n.º 4
0
    def _execute(self, pkg_loader):
        get_plugin_loader().register_in_loader(pkg_loader)

        executor = dsl_executor.MuranoDslExecutor(
            pkg_loader, ContextManager(), self.environment)
        try:
            obj = executor.load(self.model)
        except Exception as e:
            return self.exception_result(e, None, '<load>')

        if obj is not None:
            try:
                self._validate_model(obj.object, pkg_loader)
            except Exception as e:
                return self.exception_result(e, obj, '<validate>')

        try:
            LOG.debug('Invoking pre-cleanup hooks')
            self.environment.start()
            executor.cleanup(self._model)
        except Exception as e:
            return self.exception_result(e, obj, '<GC>')
        finally:
            LOG.debug('Invoking post-cleanup hooks')
            self.environment.finish()
        self._model['ObjectsCopy'] = copy.deepcopy(self._model.get('Objects'))

        action_result = None
        if self.action:
            try:
                LOG.debug('Invoking pre-execution hooks')
                self.environment.start()
                try:
                    action_result = self._invoke(executor)
                finally:
                    try:
                        self._model = serializer.serialize_model(obj, executor)
                    except Exception as e:
                        return self.exception_result(e, None, '<model>')
            except Exception as e:
                return self.exception_result(e, obj, self.action['method'])
            finally:
                LOG.debug('Invoking post-execution hooks')
                self.environment.finish()

        try:
            action_result = serializer.serialize(action_result)
        except Exception as e:
            return self.exception_result(e, None, '<result>')

        return {
            'action': {
                'result': action_result,
                'isException': False
            }
        }
Exemplo n.º 5
0
 def finalize(self):
     if self.value is None:
         return None
     object_store = helpers.get_object_store()
     passkey = getattr(self.value, '__passkey__', None)
     with helpers.thread_local_attribute(constants.TL_CONTRACT_PASSKEY,
                                         passkey):
         result = serializer.serialize(self.value.real_this,
                                       object_store.executor,
                                       dsl_types.DumpTypes.Mixed)
         if self.exclude_properties:
             for p in self.exclude_properties:
                 helpers.patch_dict(result, p, utils.NO_VALUE)
         return result
    def test_value_deserialization(self):
        """Test serialization of arbitrary values that can be returned
        from action methods
        """

        runner = self.new_runner(self._class2)
        result = runner.testMethod()
        self.assertEqual(
            {
                'key1': 'abc',
                'key2': ['a', 'b', 'c'],
                'key3': None,
                'key4': False,
                'key5': {'x': 'y'},
                'key6': [{'w': 'q'}]
            },
            serializer.serialize(result))
    def test_value_deserialization(self):
        """Test serialization of arbitrary values

        Test serialization of arbitrary values that can be returned
        from action methods
        """

        runner = self.new_runner(self._class2)
        result = runner.testMethod()
        self.assertEqual(
            {
                'key1': 'abc',
                'key2': ['a', 'b', 'c'],
                'key3': None,
                'key4': False,
                'key5': {'x': 'y'},
                'key6': [{'w': 'q'}]
            },
            serializer.serialize(result, runner.executor))
Exemplo n.º 8
0
    def _execute(self, pkg_loader):
        get_plugin_loader().register_in_loader(pkg_loader)

        executor = dsl_executor.MuranoDslExecutor(
            pkg_loader, ContextManager(), self.session)
        try:
            obj = executor.load(self.model)
        except Exception as e:
            return self.exception_result(e, None, '<load>')

        if obj is not None:
            try:
                self._validate_model(obj.object, pkg_loader)
            except Exception as e:
                return self.exception_result(e, obj, '<validate>')

        try:
            LOG.debug('Invoking pre-cleanup hooks')
            self.session.start()
            executor.cleanup(self._model)
        except Exception as e:
            return self.exception_result(e, obj, '<GC>')
        finally:
            LOG.debug('Invoking post-cleanup hooks')
            self.session.finish()
        self._model['ObjectsCopy'] = copy.deepcopy(self._model.get('Objects'))

        action_result = None
        if self.action:
            try:
                LOG.debug('Invoking pre-execution hooks')
                self.session.start()
                try:
                    action_result = self._invoke(executor)
                finally:
                    try:
                        self._model, alive_object_ids = \
                            serializer.serialize_model(obj, executor)
                        LOG.debug('Cleaning up orphan objects')
                        n = executor.cleanup_orphans(alive_object_ids)
                        LOG.debug('{} orphan objects were destroyed'.format(n))

                    except Exception as e:
                        return self.exception_result(e, None, '<model>')
            except Exception as e:
                return self.exception_result(e, obj, self.action['method'])
            finally:
                LOG.debug('Invoking post-execution hooks')
                self.session.finish()

        try:
            action_result = serializer.serialize(action_result, executor)
        except Exception as e:
            return self.exception_result(e, None, '<result>')

        pkg_loader.compact_fixation_table()
        return {
            'action': {
                'result': action_result,
                'isException': False
            }
        }