Exemplo n.º 1
0
 def test_get_flow_state(self):
     _lb, flow_detail = p_utils.temporary_flow_detail(backend=self.backend)
     flow_detail.state = states.FAILURE
     with contextlib.closing(self.backend.get_connection()) as conn:
         flow_detail.update(conn.update_flow_details(flow_detail))
     s = self._get_storage(flow_detail)
     self.assertEqual(states.FAILURE, s.get_flow_state())
Exemplo n.º 2
0
 def test_ensure_existing_task(self):
     _lb, flow_detail = p_utils.temporary_flow_detail(self.backend)
     td = models.TaskDetail(name='my_task', uuid='42')
     flow_detail.add(td)
     s = self._get_storage(flow_detail)
     s.ensure_atom(test_utils.NoopTask('my_task'))
     self.assertEqual('42', s.get_atom_uuid('my_task'))
Exemplo n.º 3
0
    def test_transient_storage_restore(self):
        _lb, flow_detail = p_utils.temporary_flow_detail(self.backend)
        s = self._get_storage(flow_detail=flow_detail)
        s.inject([("a", "b")], transient=True)
        s.inject([("b", "c")])

        s2 = self._get_storage(flow_detail=flow_detail)
        results = s2.fetch_all()
        self.assertEqual({"b": "c"}, results)
Exemplo n.º 4
0
 def test_deregister(self):
     """Verify that register and deregister don't blow up"""
     with contextlib.closing(impl_memory.MemoryBackend()) as be:
         flow = lf.Flow("test")
         flow.add(SleepyTask("test-1", sleep_for=0.1))
         (lb, fd) = persistence_utils.temporary_flow_detail(be)
         e = self._make_engine(flow, fd, be)
         l = timing.DurationListener(e)
         l.register()
         l.deregister()
Exemplo n.º 5
0
    def test_factory_with_arg(self):
        name = 'some.test.factory'
        _lb, flow_detail = p_utils.temporary_flow_detail()
        flow_detail.meta = dict(factory=dict(name=name, args=['foo']))

        with mock.patch('oslo_utils.importutils.import_class',
                        return_value=lambda x: 'RESULT %s' % x) as mock_import:
            result = zag.engines.flow_from_detail(flow_detail)
            mock_import.assert_called_once_with(name)
        self.assertEqual('RESULT foo', result)
Exemplo n.º 6
0
 def test_ensure_task_flow_detail(self):
     _lb, flow_detail = p_utils.temporary_flow_detail(self.backend)
     s = self._get_storage(flow_detail)
     t = test_utils.NoopTask('my task')
     t.version = (3, 11)
     s.ensure_atom(t)
     td = flow_detail.find(s.get_atom_uuid('my task'))
     self.assertIsNotNone(td)
     self.assertEqual('my task', td.name)
     self.assertEqual('3.11', td.version)
     self.assertEqual(states.PENDING, td.state)
Exemplo n.º 7
0
 def test_flow_duration(self):
     with contextlib.closing(impl_memory.MemoryBackend()) as be:
         flow = lf.Flow("test")
         flow.add(SleepyTask("test-1", sleep_for=0.1))
         (lb, fd) = persistence_utils.temporary_flow_detail(be)
         e = self._make_engine(flow, fd, be)
         with timing.DurationListener(e):
             e.run()
         self.assertIsNotNone(fd)
         self.assertIsNotNone(fd.meta)
         self.assertIn('duration', fd.meta)
         self.assertGreaterEqual(0.1, fd.meta['duration'])
Exemplo n.º 8
0
 def test_storage_progress(self):
     with contextlib.closing(impl_memory.MemoryBackend({})) as be:
         flo = lf.Flow("test")
         flo.add(ProgressTask("test", 3))
         b, fd = p_utils.temporary_flow_detail(be)
         e = self._make_engine(flo, flow_detail=fd, backend=be)
         e.run()
         end_progress = e.storage.get_task_progress("test")
         self.assertEqual(1.0, end_progress)
         task_uuid = e.storage.get_atom_uuid("test")
         td = fd.find(task_uuid)
         self.assertEqual(1.0, td.meta['progress'])
         self.assertFalse(td.meta['progress_details'])
Exemplo n.º 9
0
 def test_record_ending_exception(self, mocked_warning):
     with contextlib.closing(impl_memory.MemoryBackend()) as be:
         flow = lf.Flow("test")
         flow.add(test_utils.TaskNoRequiresNoReturns("test-1"))
         (lb, fd) = persistence_utils.temporary_flow_detail(be)
         e = self._make_engine(flow, fd, be)
         duration_listener = timing.DurationListener(e)
         with mock.patch.object(duration_listener._engine.storage,
                                'update_atom_metadata') as mocked_uam:
             mocked_uam.side_effect = exc.StorageFailure('Woot!')
             with duration_listener:
                 e.run()
     mocked_warning.assert_called_once_with(mock.ANY,
                                            mock.ANY,
                                            'task',
                                            'test-1',
                                            exc_info=True)
Exemplo n.º 10
0
    def test_dual_storage_progress(self):
        fired_events = []

        def notify_me(event_type, details):
            fired_events.append(details.pop('progress'))

        with contextlib.closing(impl_memory.MemoryBackend({})) as be:
            t = ProgressTask("test", 5)
            t.notifier.register(task.EVENT_UPDATE_PROGRESS, notify_me)
            flo = lf.Flow("test")
            flo.add(t)
            b, fd = p_utils.temporary_flow_detail(be)
            e = self._make_engine(flo, flow_detail=fd, backend=be)
            e.run()

            end_progress = e.storage.get_task_progress("test")
            self.assertEqual(1.0, end_progress)
            task_uuid = e.storage.get_atom_uuid("test")
            td = fd.find(task_uuid)
            self.assertEqual(1.0, td.meta['progress'])
            self.assertFalse(td.meta['progress_details'])
            self.assertEqual(6, len(fired_events))
Exemplo n.º 11
0
 def test_get_without_save(self):
     _lb, flow_detail = p_utils.temporary_flow_detail(self.backend)
     td = models.TaskDetail(name='my_task', uuid='42')
     flow_detail.add(td)
     s = self._get_storage(flow_detail)
     self.assertEqual('42', s.get_atom_uuid('my_task'))
Exemplo n.º 12
0
 def test_non_saving_storage(self):
     _lb, flow_detail = p_utils.temporary_flow_detail(self.backend)
     s = storage.Storage(flow_detail=flow_detail)
     s.ensure_atom(test_utils.NoopTask('my_task'))
     self.assertTrue(uuidutils.is_uuid_like(s.get_atom_uuid('my_task')))
Exemplo n.º 13
0
 def _get_storage(self, flow_detail=None):
     if flow_detail is None:
         _lb, flow_detail = p_utils.temporary_flow_detail(self.backend)
     return storage.Storage(flow_detail=flow_detail, backend=self.backend)
Exemplo n.º 14
0
 def test_no_importable_function(self):
     _lb, flow_detail = p_utils.temporary_flow_detail()
     flow_detail.meta = dict(factory=dict(
         name='you can not import me, i contain spaces'))
     self.assertRaisesRegex(ImportError, '^Could not import factory',
                            zag.engines.flow_from_detail, flow_detail)
Exemplo n.º 15
0
 def test_no_factory_in_meta(self):
     _lb, flow_detail = p_utils.temporary_flow_detail()
     self.assertRaisesRegex(ValueError,
                            '^Cannot .* no factory information saved.$',
                            zag.engines.flow_from_detail, flow_detail)