Instead of having a pretty restrictive module based api for saving logbook objects it is much more friendly and extensible to move toward a more ceilometer-influenced engine and connection based storage backend using stevedore to do the backend loading instead of a custom registration/fetching mechanism. This allows us to provide a base object oriented backend api that can be easily inherited from to allow for customized & pluggable backend storage modules. Implements blueprint stevedore-based-backends Implements blueprint ceilometer-influenced-backends Change-Id: Ib5868d3d9018b7aa1a3354858dcb90ca1a04055d
		
			
				
	
	
		
			137 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			137 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
# -*- coding: utf-8 -*-
 | 
						|
 | 
						|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 | 
						|
 | 
						|
#    Copyright (C) 2012-2013 Yahoo! Inc. All Rights Reserved.
 | 
						|
#
 | 
						|
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 | 
						|
#    not use this file except in compliance with the License. You may obtain
 | 
						|
#    a copy of the License at
 | 
						|
#
 | 
						|
#         http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
#
 | 
						|
#    Unless required by applicable law or agreed to in writing, software
 | 
						|
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 | 
						|
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 | 
						|
#    License for the specific language governing permissions and limitations
 | 
						|
#    under the License.
 | 
						|
 | 
						|
from taskflow import decorators
 | 
						|
from taskflow.patterns import linear_flow
 | 
						|
from taskflow import test
 | 
						|
 | 
						|
from taskflow.engines.action_engine import engine as eng
 | 
						|
 | 
						|
 | 
						|
class WrapableObjectsTest(test.TestCase):
 | 
						|
    def _make_engine(self, flow):
 | 
						|
        e = eng.SingleThreadedActionEngine(flow)
 | 
						|
        e.compile()
 | 
						|
        return e
 | 
						|
 | 
						|
    def test_simple_function(self):
 | 
						|
        values = []
 | 
						|
 | 
						|
        def revert_one(*args, **kwargs):
 | 
						|
            values.append('revert one')
 | 
						|
 | 
						|
        @decorators.task(revert=revert_one)
 | 
						|
        def run_one(*args, **kwargs):
 | 
						|
            values.append('one')
 | 
						|
 | 
						|
        @decorators.task
 | 
						|
        def run_fail(*args, **kwargs):
 | 
						|
            values.append('fail')
 | 
						|
            raise RuntimeError('Woot!')
 | 
						|
 | 
						|
        flow = linear_flow.Flow('test')
 | 
						|
        flow.add(
 | 
						|
            run_one,
 | 
						|
            run_fail
 | 
						|
        )
 | 
						|
        with self.assertRaisesRegexp(RuntimeError, '^Woot'):
 | 
						|
            e = self._make_engine(flow)
 | 
						|
            e.run()
 | 
						|
        self.assertEquals(values, ['one', 'fail', 'revert one'])
 | 
						|
 | 
						|
    def test_simple_method(self):
 | 
						|
        class MyTasks(object):
 | 
						|
            def __init__(self):
 | 
						|
                # NOTE(imelnikov): that's really *bad thing* to pass
 | 
						|
                # data between task like this; though, its good enough
 | 
						|
                # for our testing here
 | 
						|
                self.values = []
 | 
						|
 | 
						|
            @decorators.task
 | 
						|
            def run_one(self, *args, **kwargs):
 | 
						|
                self.values.append('one')
 | 
						|
 | 
						|
            @decorators.task
 | 
						|
            def run_fail(self, *args, **kwargs):
 | 
						|
                self.values.append('fail')
 | 
						|
                raise RuntimeError('Woot!')
 | 
						|
 | 
						|
        tasks = MyTasks()
 | 
						|
        flow = linear_flow.Flow('test')
 | 
						|
        flow.add(
 | 
						|
            tasks.run_one,
 | 
						|
            tasks.run_fail
 | 
						|
        )
 | 
						|
        with self.assertRaisesRegexp(RuntimeError, '^Woot'):
 | 
						|
            e = self._make_engine(flow)
 | 
						|
            e.run()
 | 
						|
        self.assertEquals(tasks.values, ['one', 'fail'])
 | 
						|
 | 
						|
    def test_static_method(self):
 | 
						|
        values = []
 | 
						|
 | 
						|
        class MyTasks(object):
 | 
						|
            @decorators.task
 | 
						|
            @staticmethod
 | 
						|
            def run_one(*args, **kwargs):
 | 
						|
                values.append('one')
 | 
						|
 | 
						|
            # NOTE(imelnikov): decorators should work in any order:
 | 
						|
            @staticmethod
 | 
						|
            @decorators.task
 | 
						|
            def run_fail(*args, **kwargs):
 | 
						|
                values.append('fail')
 | 
						|
                raise RuntimeError('Woot!')
 | 
						|
 | 
						|
        flow = linear_flow.Flow('test')
 | 
						|
        flow.add(
 | 
						|
            MyTasks.run_one,
 | 
						|
            MyTasks.run_fail
 | 
						|
        )
 | 
						|
        with self.assertRaisesRegexp(RuntimeError, '^Woot'):
 | 
						|
            e = self._make_engine(flow)
 | 
						|
            e.run()
 | 
						|
        self.assertEquals(values, ['one', 'fail'])
 | 
						|
 | 
						|
    def test_class_method(self):
 | 
						|
 | 
						|
        class MyTasks(object):
 | 
						|
            values = []
 | 
						|
 | 
						|
            @decorators.task
 | 
						|
            @classmethod
 | 
						|
            def run_one(cls, *args, **kwargs):
 | 
						|
                cls.values.append('one')
 | 
						|
 | 
						|
            # NOTE(imelnikov): decorators should work in any order:
 | 
						|
            @classmethod
 | 
						|
            @decorators.task
 | 
						|
            def run_fail(cls, *args, **kwargs):
 | 
						|
                cls.values.append('fail')
 | 
						|
                raise RuntimeError('Woot!')
 | 
						|
 | 
						|
        flow = linear_flow.Flow('test')
 | 
						|
        flow.add(
 | 
						|
            MyTasks.run_one,
 | 
						|
            MyTasks.run_fail
 | 
						|
        )
 | 
						|
        with self.assertRaisesRegexp(RuntimeError, '^Woot'):
 | 
						|
            e = self._make_engine(flow)
 | 
						|
            e.run()
 | 
						|
        self.assertEquals(MyTasks.values, ['one', 'fail'])
 |