コード例 #1
0
 def test_get_tasks_states(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.ensure_atom(test_utils.NoopTask('my task2'))
     s.save('my task', 'foo')
     expected = {
         'my task': (states.SUCCESS, states.EXECUTE),
         'my task2': (states.PENDING, states.EXECUTE),
     }
     self.assertEqual(s.get_atoms_states(['my task', 'my task2']), expected)
コード例 #2
0
 def test_fetch_by_name(self):
     s = self._get_storage()
     name = 'my result'
     s.ensure_atom(test_utils.NoopTask('my task', provides=name))
     s.save('my task', 5)
     self.assertEqual(5, s.fetch(name))
     self.assertEqual({name: 5}, s.fetch_all())
コード例 #3
0
    def test_task_progress_erase(self):
        s = self._get_storage()
        s.ensure_atom(test_utils.NoopTask('my task'))

        s.set_task_progress('my task', 0.8, {})
        self.assertEqual(0.8, s.get_task_progress('my task'))
        self.assertEqual(None, s.get_task_progress_details('my task'))
コード例 #4
0
 def test_reset(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', 5)
     s.reset('my task')
     self.assertEqual(states.PENDING, s.get_atom_state('my task'))
     self.assertRaises(exceptions.NotFound, s.get, 'my task')
コード例 #5
0
 def test_save_and_get(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', 5)
     self.assertEqual(5, s.get('my task'))
     self.assertEqual({}, s.fetch_all())
     self.assertEqual(states.SUCCESS, s.get_atom_state('my task'))
コード例 #6
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'))
コード例 #7
0
 def test_short_result_is_checked(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task', provides=['a', 'b']))
     s.save('my task', ['result'])
     self.assertEqual('result', s.fetch('a'))
     self.assertRaisesRegexp(exceptions.NotFound, '^Unable to find result',
                             s.fetch, 'b')
コード例 #8
0
    def test_task_progress(self):
        s = self._get_storage()
        s.ensure_atom(test_utils.NoopTask('my task'))

        s.set_task_progress('my task', 0.5, {'test_data': 11})
        self.assertEqual(0.5, s.get_task_progress('my task'))
        self.assertEqual({
            'at_progress': 0.5,
            'details': {
                'test_data': 11
            }
        }, s.get_task_progress_details('my task'))

        s.set_task_progress('my task', 0.7, {'test_data': 17})
        self.assertEqual(0.7, s.get_task_progress('my task'))
        self.assertEqual({
            'at_progress': 0.7,
            'details': {
                'test_data': 17
            }
        }, s.get_task_progress_details('my task'))

        s.set_task_progress('my task', 0.99)
        self.assertEqual(0.99, s.get_task_progress('my task'))
        self.assertEqual({
            'at_progress': 0.7,
            'details': {
                'test_data': 17
            }
        }, s.get_task_progress_details('my task'))
コード例 #9
0
 def test_save_multiple_results(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task', provides=['foo', 'bar']))
     s.save('my task', ('spam', 'eggs'))
     self.assertEqual({
         'foo': 'spam',
         'bar': 'eggs',
     }, s.fetch_all())
コード例 #10
0
 def test_save_and_get_non_cached_failure(self):
     a_failure = failure.Failure.from_exception(RuntimeError('Woot!'))
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', a_failure, states.FAILURE)
     self.assertEqual(a_failure, s.get('my task'))
     s._failures['my task'] = {}
     self.assertTrue(a_failure.matches(s.get('my task')))
コード例 #11
0
 def test_save_and_get_cached_failure(self):
     a_failure = failure.Failure.from_exception(RuntimeError('Woot!'))
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', a_failure, states.FAILURE)
     self.assertEqual(a_failure, s.get('my task'))
     self.assertEqual(states.FAILURE, s.get_atom_state('my task'))
     self.assertTrue(s.has_failures())
     self.assertEqual({'my task': a_failure}, s.get_failures())
コード例 #12
0
 def test_task_metadata_update_with_none(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.update_atom_metadata('my task', None)
     self.assertEqual(0.0, s.get_task_progress('my task'))
     s.set_task_progress('my task', 0.5)
     self.assertEqual(0.5, s.get_task_progress('my task'))
     s.update_atom_metadata('my task', None)
     self.assertEqual(0.5, s.get_task_progress('my task'))
コード例 #13
0
 def test_get_failure_after_reload(self):
     a_failure = failure.Failure.from_exception(RuntimeError('Woot!'))
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', a_failure, states.FAILURE)
     s2 = self._get_storage(s._flowdetail)
     self.assertTrue(s2.has_failures())
     self.assertEqual(1, len(s2.get_failures()))
     self.assertTrue(a_failure.matches(s2.get('my task')))
     self.assertEqual(states.FAILURE, s2.get_atom_state('my task'))
コード例 #14
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)
コード例 #15
0
    def test_get_failure_from_reverted_task(self):
        a_failure = failure.Failure.from_exception(RuntimeError('Woot!'))

        s = self._get_storage()
        s.ensure_atom(test_utils.NoopTask('my task'))
        s.save('my task', a_failure, states.FAILURE)

        s.set_atom_state('my task', states.REVERTING)
        self.assertEqual(a_failure, s.get('my task'))

        s.set_atom_state('my task', states.REVERTED)
        self.assertEqual(a_failure, s.get('my task'))
コード例 #16
0
 def test_save_and_get_other_state(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', 5, states.FAILURE)
     self.assertEqual(s.get('my task'), 5)
     self.assertEqual(s.get_atom_state('my task'), states.FAILURE)
コード例 #17
0
 def test_ensure_task(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     self.assertEqual(states.PENDING, s.get_atom_state('my task'))
     self.assertTrue(uuidutils.is_uuid_like(s.get_atom_uuid('my task')))
コード例 #18
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')))
コード例 #19
0
 def test_save_retry_intention(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my retry'))
     s.set_atom_intention('my retry', states.RETRY)
     intention = s.get_atom_intention('my retry')
     self.assertEqual(states.RETRY, intention)
コード例 #20
0
 def test_save_task_intention(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.set_atom_intention('my task', states.REVERT)
     intention = s.get_atom_intention('my task')
     self.assertEqual(states.REVERT, intention)
コード例 #21
0
 def test_ensure_retry_and_task_with_same_name(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my retry'))
     self.assertRaisesRegexp(exceptions.Duplicate,
                             '^Atom detail', s.ensure_atom,
                             test_utils.NoopRetry('my retry'))
コード例 #22
0
 def test_empty_result_is_checked(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task', provides=['a']))
     s.save('my task', ())
     self.assertRaisesRegex(exceptions.NotFound, '^Unable to find result',
                            s.fetch, 'a')
コード例 #23
0
 def test_task_by_name(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     self.assertTrue(uuidutils.is_uuid_like(s.get_atom_uuid('my task')))
コード例 #24
0
 def test_set_and_get_task_state(self):
     s = self._get_storage()
     state = states.PENDING
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.set_atom_state('my task', state)
     self.assertEqual(state, s.get_atom_state('my task'))
コード例 #25
0
 def ensure_my_task():
     s.ensure_atom(test_utils.NoopTask('my_task'))
コード例 #26
0
 def test_mapping_none(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     s.save('my task', 5)
     self.assertEqual({}, s.fetch_all())
コード例 #27
0
 def test_fetch_result_not_ready(self):
     s = self._get_storage()
     name = 'my result'
     s.ensure_atom(test_utils.NoopTask('my task', provides=name))
     self.assertRaises(exceptions.NotFound, s.get, name)
     self.assertEqual({}, s.fetch_all())
コード例 #28
0
 def test_get_non_existing_var(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     self.assertRaises(exceptions.NotFound, s.get, 'my task')
コード例 #29
0
 def test_reset_unknown_task(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     self.assertEqual(None, s.reset('my task'))
コード例 #30
0
 def test_default_task_progress(self):
     s = self._get_storage()
     s.ensure_atom(test_utils.NoopTask('my task'))
     self.assertEqual(0.0, s.get_task_progress('my task'))
     self.assertEqual(None, s.get_task_progress_details('my task'))