コード例 #1
0
    def test_reverting_flow(self):
        wf = lw.Flow("the-test-action")
        wf.add(utils.make_reverting_task(1))
        wf.add(utils.make_reverting_task(2, True))

        capture_func, captured = self._capture_states()
        e = self._make_engine(wf)
        e.task_notifier.register('*', capture_func)

        self.assertRaises(Exception, e.run)

        run_context = e.storage.fetch('context')
        self.assertEquals('reverted', run_context[1])
        self.assertEquals(1, len(run_context))

        blowup_id = e.storage.get_uuid_by_name('blowup_2')
        happy_id = e.storage.get_uuid_by_name('do_apply_1')
        self.assertEquals(2, len(captured))
        self.assertIn(blowup_id, captured)

        expected_states = [states.RUNNING, states.FAILURE, states.REVERTING,
                           states.REVERTED, states.PENDING]
        self.assertEquals(expected_states, captured[blowup_id])

        expected_states = [states.RUNNING, states.SUCCESS, states.REVERTING,
                           states.REVERTED, states.PENDING]
        self.assertIn(happy_id, captured)
        self.assertEquals(expected_states, captured[happy_id])
コード例 #2
0
    def test_sad_flow_state_changes(self):
        changes = []
        task_changes = []

        def listener(state, details):
            changes.append(state)

        def task_listener(state, details):
            if details.get('task_name') == 'blowup_1':
                task_changes.append(state)

        wf = lw.Flow("the-test-action")
        wf.add(utils.make_reverting_task(2, False))
        wf.add(utils.make_reverting_task(1, True))

        e = self._make_engine(wf)
        e.notifier.register('*', listener)
        e.task_notifier.register('*', task_listener)
        self.assertRaises(Exception, e.run)

        expected_states = [
            states.RUNNING,
            states.REVERTING,
            states.REVERTED,
            states.FAILURE,
        ]
        self.assertEquals(expected_states, changes)
        expected_states = [
            states.RUNNING,
            states.FAILURE,
            states.REVERTING,
            states.REVERTED,
            states.PENDING,
        ]
        self.assertEquals(expected_states, task_changes)
        context = e.storage.fetch('context')

        # Only 2 should have been reverted (which should have been
        # marked in the context as occuring).
        self.assertIn(2, context)
        self.assertEquals('reverted', context[2])
        self.assertNotIn(1, context)
コード例 #3
0
    def test_happy_flow_state_changes(self):
        changes = []

        def listener(state, details):
            changes.append(state)

        wf = lw.Flow("the-test-action")
        wf.add(utils.make_reverting_task(1))

        e = self._make_engine(wf)
        e.notifier.register('*', listener)
        e.run()

        self.assertEquals([states.RUNNING, states.SUCCESS], changes)
コード例 #4
0
    def test_happy_flow(self):
        wf = lw.Flow("the-test-action")
        for i in range(0, 10):
            wf.add(utils.make_reverting_task(i))

        e = self._make_engine(wf)
        capture_func, captured = self._capture_states()
        e.task_notifier.register('*', capture_func)
        e.run()

        context = e.storage.fetch('context')
        self.assertEquals(10, len(context))
        self.assertEquals(10, len(captured))
        for _k, v in context.items():
            self.assertEquals('passed', v)
        for _uuid, u_states in captured.items():
            self.assertEquals([states.RUNNING, states.SUCCESS], u_states)
コード例 #5
0
 def test_reverting_flow(self):
     wf = uf.Flow("the-test-action")
     wf.add(utils.make_reverting_task('1'))
     wf.add(utils.make_reverting_task('2', blowup=True))
     e = self._make_engine(wf)
     self.assertRaises(Exception, e.run)
コード例 #6
0
 def test_reverting_flow(self):
     wf = uf.Flow("the-test-action")
     wf.add(utils.make_reverting_task('1'))
     wf.add(utils.make_reverting_task('2', blowup=True))
     e = self._make_engine(wf)
     self.assertRaisesRegexp(RuntimeError, '^I blew up', e.run)
コード例 #7
0
 def test_reverting_flow(self):
     wf = uf.Flow("the-test-action")
     wf.add(utils.make_reverting_task('1'))
     wf.add(utils.make_reverting_task('2', blowup=True))
     e = self._make_engine(wf)
     self.assertRaises(Exception, e.run)
コード例 #8
0
 def test_reverting_flow(self):
     wf = uf.Flow("the-test-action")
     wf.add(utils.make_reverting_task('1'))
     wf.add(utils.make_reverting_task('2', blowup=True))
     e = self._make_engine(wf)
     self.assertRaisesRegexp(RuntimeError, '^I blew up', e.run)