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)
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())
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'))
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')
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'))
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'))
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')
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'))
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())
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')))
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())
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'))
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'))
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)
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'))
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)
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')))
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')))
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)
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)
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'))
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')
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')))
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'))
def ensure_my_task(): s.ensure_atom(test_utils.NoopTask('my_task'))
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())
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())
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')
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'))
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'))