Example #1
0
class FailTests(base.PulpServerTests):
    def setUp(self):
        self.call_request = CallRequest(fail)
        self.call_report = CallReport()
        self.task = Task(self.call_request, self.call_report)

    def tearDown(self):
        self.call_request = None
        self.call_report = None
        self.task = None

    def test_failed(self):
        self.task._run()
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_ERROR_STATE,
            self.call_report.state)
        self.assertTrue(isinstance(self.call_report.exception, RuntimeError),
                        str(type(self.call_report.exception)))
        self.assertTrue(
            isinstance(self.call_report.traceback, types.TracebackType))

    def test_error_execution_hook(self):
        hook = mock.Mock()
        self.call_request.add_life_cycle_callback(
            dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, hook)
        self.task._run()
        self.assertTrue(hook.call_count == 1)
        self.assertTrue(hook.call_args[0][0] is self.call_request)
        self.assertTrue(hook.call_args[0][1] is self.call_report)
Example #2
0
class FailTests(base.PulpServerTests):

    def setUp(self):
        self.call_request = CallRequest(fail)
        self.call_report = CallReport()
        self.task = Task(self.call_request, self.call_report)

    def tearDown(self):
        self.call_request = None
        self.call_report = None
        self.task = None

    def test_failed(self):
        self.task._run()
        self.assertTrue(self.call_report.state is dispatch_constants.CALL_ERROR_STATE,
                        self.call_report.state)
        self.assertTrue(isinstance(self.call_report.exception, RuntimeError),
                        str(type(self.call_report.exception)))
        self.assertTrue(isinstance(self.call_report.traceback, types.TracebackType))

    def test_error_execution_hook(self):
        hook = mock.Mock()
        self.call_request.add_life_cycle_callback(dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, hook)
        self.task._run()
        self.assertTrue(hook.call_count == 1)
        self.assertTrue(hook.call_args[0][0] is self.call_request)
        self.assertTrue(hook.call_args[0][1] is self.call_report)
Example #3
0
 def test_task_instantiation(self):
     call_request = CallRequest(mock.Mock())
     call_report = CallReport()
     try:
         Task(call_request)
         Task(call_request, call_report)
     except:
         self.fail(traceback.format_exc())
Example #4
0
 def test_task_archival(self):
     task = Task(CallRequest(call_without_callbacks, archive=True))
     try:
         task._run()
     except:
         self.fail(traceback.format_exc())
     collection = ArchivedCall.get_collection()
     archived_call = collection.find_one({'serialized_call_report.call_request_id': task.call_request.id})
     self.assertFalse(archived_call is None)
Example #5
0
 def test_task_archival(self):
     task = Task(CallRequest(call_without_callbacks, archive=True))
     try:
         task._run()
     except:
         self.fail(traceback.format_exc())
     collection = ArchivedCall.get_collection()
     archived_call = collection.find_one(
         {'serialized_call_report.call_request_id': task.call_request.id})
     self.assertFalse(archived_call is None)
Example #6
0
 def test_str(self):
     call = Call()
     call_request = CallRequest(call.call, call_args, call_kwargs)
     task = Task(call_request)
     try:
         str(task)
     except:
         self.fail(traceback.format_exc())
Example #7
0
    def test_find_by_call_request_id_list(self):
        call_request = call.CallRequest(find_dummy_call)
        task = Task(call_request)
        self.set_task_queue([task])

        call_report_list = self.coordinator.find_call_reports(
            call_request_id_list=[call_request.id])
        self.assertEqual(len(call_report_list), 1)
        self.assertEqual(call_report_list[0].call_request_id, call_request.id)
Example #8
0
    def test_find_by_schedule_id(self):
        schedule_id = str(ObjectId())
        call_request = call.CallRequest(find_dummy_call)
        call_report = call.CallReport.from_call_request(call_request)
        call_report.schedule_id = schedule_id
        task = Task(call_request, call_report)
        self.set_task_queue([task])

        call_report_list = self.coordinator.find_call_reports(
            schedule_id=schedule_id)
        self.assertEqual(len(call_report_list), 1)
        self.assertEqual(call_report_list[0].schedule_id, schedule_id)
Example #9
0
 def test_run_task_async(self):
     task = Task(call.CallRequest(dummy_call))
     self.coordinator._process_tasks([task])
     self.assertTrue(
         len(task.call_request.execution_hooks[
             dispatch_constants.CALL_ENQUEUE_LIFE_CYCLE_CALLBACK]) == 1)
     self.assertTrue(
         len(task.call_request.execution_hooks[
             dispatch_constants.CALL_DEQUEUE_LIFE_CYCLE_CALLBACK]) == 2)
     self.assertTrue(
         coordinator.coordinator_dequeue_callback in
         task.call_request.execution_hooks[
             dispatch_constants.CALL_DEQUEUE_LIFE_CYCLE_CALLBACK])
Example #10
0
    def _create_task(self,
                     call_request,
                     call_report=None,
                     call_request_group_id=None):
        """
        Create the task for the given call request.
        @param call_request: call request to encapsulate in a task
        @type  call_request: L{call.CallRequest} instance
        @param call_report: call report for call request
        @type  call_report: L{call.CallReport} instance or None
        @param call_request_group_id: optional call request group id
        @type  call_request_group_id: None or str
        @return: task that encapsulates the call request
        @rtype:  L{Task} instance
        """
        if call_request_group_id is not None:
            call_request.group_id = call_request_group_id

        if not call_request.asynchronous:
            task = Task(call_request, call_report)
        else:
            task = AsyncTask(call_request, call_report)

        return task
Example #11
0
 def gen_task(self, call=call):
     return Task(CallRequest(call))
Example #12
0
 def test_run_task_sync_timeout(self):
     task = Task(call.CallRequest(dummy_call))
     timeout = datetime.timedelta(seconds=0.001)
     self.assertRaises(OperationTimedOut, self.coordinator._run_task, task,
                       timeout)
Example #13
0
 def test_run_task_sync(self):
     task = Task(call.CallRequest(dummy_call))
     self.coordinator._process_tasks([task])
     self.coordinator._run_task(task)
     self.assertTrue(coordinator.wait_for_task.call_count == 2,
                     coordinator.wait_for_task.call_count)
Example #14
0
 def setUp(self):
     super(TaskTests, self).setUp()
     self.call_request = CallRequest(Call(), call_args, call_kwargs)
     self.call_report = CallReport()
     self.task = Task(self.call_request, self.call_report)
Example #15
0
class TaskTests(base.PulpServerTests):

    def setUp(self):
        super(TaskTests, self).setUp()
        self.call_request = CallRequest(Call(), call_args, call_kwargs)
        self.call_report = CallReport()
        self.task = Task(self.call_request, self.call_report)

    def tearDown(self):
        super(TaskTests, self).tearDown()
        self.call_request = None
        self.call_report = None
        self.task = None

    def test_run(self):
        self.assertTrue(self.call_report.state is dispatch_constants.CALL_WAITING_STATE)
        self.task._run()
        self.assertTrue(self.call_request.call.call_count == 1)
        self.assertTrue(self.call_request.call.call_args[0] == call_args,
                        '%s != %s' % (str(self.call_request.call.call_args[0]), str(call_args)))
        self.assertTrue(self.call_request.call.call_args[1] == call_kwargs)
        self.assertTrue(self.call_report.state is dispatch_constants.CALL_FINISHED_STATE)

    def test_complete(self):
        now = datetime.datetime.now(dateutils.utc_tz())
        self.task._run()
        self.assertTrue(self.call_report.finish_time > now)

    def test_complete_callback(self):
        callback = mock.Mock()
        self.task.complete_callback = callback
        self.task._run()
        self.assertTrue(callback.call_count == 1)
        self.assertTrue(callback.call_args[0][0] is self.task)

    def test_cancel_control_hook(self):
        callback = mock.Mock()
        self.call_request.add_control_hook(dispatch_constants.CALL_CANCEL_CONTROL_HOOK, callback)
        self.call_report.state = dispatch_constants.CALL_RUNNING_STATE
        try:
            self.task.cancel()
        except:
            self.fail(traceback.format_exc())
        self.assertTrue(callback.call_count == 1)
        self.assertTrue(callback.call_args[0][0] is self.call_request)
        self.assertTrue(callback.call_args[0][1] is self.call_report)
        self.assertTrue(self.call_report.state is dispatch_constants.CALL_CANCELED_STATE,
                        self.call_report.state)

    def test_finish_execution_hook(self):
        hooks = [mock.Mock(), mock.Mock()]
        for h in hooks:
            self.call_request.add_life_cycle_callback(dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, h)
        self.task._run()
        for h in hooks:
            self.assertTrue(h.call_count == 1)
            self.assertTrue(h.call_args[0][0] is self.call_request)
            self.assertTrue(h.call_args[0][1] is self.call_report)

    def test_complete_execution_hook(self):
        hooks = [mock.Mock(), mock.Mock()]
        for h in hooks:
            self.call_request.add_life_cycle_callback(dispatch_constants.CALL_COMPLETE_LIFE_CYCLE_CALLBACK, h)
        self.task._run()
        for h in hooks:
            self.assertTrue(h.call_count == 1)
Example #16
0
 def test_set_principal(self):
     user = User('test-user', 'test-password')
     task = Task(CallRequest(self.principal_manager.get_principal, principal=user))
     task._run()
     self.assertEqual(user, task.call_report.result)
Example #17
0
 def setUp(self):
     self.call_request = CallRequest(fail)
     self.call_report = CallReport()
     self.task = Task(self.call_request, self.call_report)
Example #18
0
 def setUp(self):
     self.call_request = CallRequest(fail)
     self.call_report = CallReport()
     self.task = Task(self.call_request, self.call_report)
Example #19
0
 def setUp(self):
     super(TaskTests, self).setUp()
     self.call_request = CallRequest(Call(), call_args, call_kwargs)
     self.call_report = CallReport()
     self.task = Task(self.call_request, self.call_report)
Example #20
0
class TaskTests(base.PulpServerTests):
    def setUp(self):
        super(TaskTests, self).setUp()
        self.call_request = CallRequest(Call(), call_args, call_kwargs)
        self.call_report = CallReport()
        self.task = Task(self.call_request, self.call_report)

    def tearDown(self):
        super(TaskTests, self).tearDown()
        self.call_request = None
        self.call_report = None
        self.task = None

    def test_run(self):
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_WAITING_STATE)
        self.task._run()
        self.assertTrue(self.call_request.call.call_count == 1)
        self.assertTrue(
            self.call_request.call.call_args[0] == call_args, '%s != %s' %
            (str(self.call_request.call.call_args[0]), str(call_args)))
        self.assertTrue(self.call_request.call.call_args[1] == call_kwargs)
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_FINISHED_STATE)

    def test_complete(self):
        now = datetime.datetime.now(dateutils.utc_tz())
        self.task._run()
        self.assertTrue(self.call_report.finish_time > now)

    def test_complete_callback(self):
        callback = mock.Mock()
        self.task.complete_callback = callback
        self.task._run()
        self.assertTrue(callback.call_count == 1)
        self.assertTrue(callback.call_args[0][0] is self.task)

    def test_cancel_control_hook(self):
        callback = mock.Mock()
        self.call_request.add_control_hook(
            dispatch_constants.CALL_CANCEL_CONTROL_HOOK, callback)
        self.call_report.state = dispatch_constants.CALL_RUNNING_STATE
        try:
            self.task.cancel()
        except:
            self.fail(traceback.format_exc())
        self.assertTrue(callback.call_count == 1)
        self.assertTrue(callback.call_args[0][0] is self.call_request)
        self.assertTrue(callback.call_args[0][1] is self.call_report)
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_CANCELED_STATE,
            self.call_report.state)

    def test_finish_execution_hook(self):
        hooks = [mock.Mock(), mock.Mock()]
        for h in hooks:
            self.call_request.add_life_cycle_callback(
                dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, h)
        self.task._run()
        for h in hooks:
            self.assertTrue(h.call_count == 1)
            self.assertTrue(h.call_args[0][0] is self.call_request)
            self.assertTrue(h.call_args[0][1] is self.call_report)

    def test_complete_execution_hook(self):
        hooks = [mock.Mock(), mock.Mock()]
        for h in hooks:
            self.call_request.add_life_cycle_callback(
                dispatch_constants.CALL_COMPLETE_LIFE_CYCLE_CALLBACK, h)
        self.task._run()
        for h in hooks:
            self.assertTrue(h.call_count == 1)
Example #21
0
 def test_eq(self):
     call_request = CallRequest(mock.Mock())
     task_1 = Task(call_request)
     task_2 = Task(call_request)
     self.assertTrue(task_1 == task_1)
     self.assertTrue(task_1 == task_2)
Example #22
0
 def test_set_principal(self):
     user = User('test-user', 'test-password')
     task = Task(
         CallRequest(self.principal_manager.get_principal, principal=user))
     task._run()
     self.assertEqual(user, task.call_report.result)