Beispiel #1
0
    def test_unbind_failed(self, mock_task_failed, mock_unbind_failed):
        task_id = 'task_1'
        consumer_id = 'consumer_1'
        repo_id = 'repo_1'
        dist_id = 'dist_1'
        call_context = {
            'action': 'unbind',
            'task_id': task_id,
            'consumer_id': consumer_id,
            'repo_id': repo_id,
            'distributor_id': dist_id
        }
        raised = dict(
            exval='Boom',
            xmodule='foo.py',
            xclass=ValueError,
            xstate={'trace': 'stack-trace'},
            xargs=[]
        )
        envelope = Envelope(routing=['A', 'B'], result=raised, any=call_context)
        reply = Failed(envelope)
        handler = ReplyHandler('')
        handler.failed(reply)

        # validate task updated
        mock_task_failed.assert_called_with(task_id, 'stack-trace')
        # validate bind action updated
        mock_unbind_failed.assert_called_with(task_id, call_context)
Beispiel #2
0
    def test_progress_reported(self, mock_update_task_status):
        task_id = 'task_1'
        call_context = {'task_id': task_id}
        progress_report = {'step': 'step-1'}
        envelope = Envelope(routing=['A', 'B'], any=call_context, details=progress_report)
        reply = Progress(envelope)
        handler = ReplyHandler('')
        handler.progress(reply)

        # validate task updated
        delta = {'progress_report': progress_report}
        mock_update_task_status.assert_called_with(task_id, delta)
Beispiel #3
0
 def test_construction(self, mock_consumer, mock_queue, mock_auth):
     url = 'http://broker'
     transport = pulp_conf.get('messaging', 'transport')
     handler = ReplyHandler(url, transport)
     mock_queue.assert_called_with(Services.REPLY_QUEUE, transport=transport)
     mock_consumer.assert_called_with(
         mock_queue(), url=url, transport=transport, authenticator=mock_auth())
     self.assertEqual(handler.consumer, mock_consumer())
Beispiel #4
0
 def test__unbind_failed(self, mock_get_manager):
     bind_manager = Mock()
     mock_get_manager.return_value = bind_manager
     task_id = 'task_1'
     consumer_id = 'consumer_1'
     repo_id = 'repo_1'
     dist_id = 'dist_1'
     call_context = {
         'action': 'bind',
         'task_id': task_id,
         'consumer_id': consumer_id,
         'repo_id': repo_id,
         'distributor_id': dist_id
     }
     # handler report: failed
     ReplyHandler._unbind_failed(task_id, call_context)
     bind_manager.action_failed.assert_called_with(consumer_id, repo_id, dist_id, task_id)
Beispiel #5
0
 def test__unbind_succeeded(self, mock_get_manager):
     bind_manager = Mock()
     mock_get_manager.return_value = bind_manager
     task_id = 'task_1'
     consumer_id = 'consumer_1'
     repo_id = 'repo_1'
     dist_id = 'dist_1'
     call_context = {
         'action': 'unbind',
         'task_id': task_id,
         'consumer_id': consumer_id,
         'repo_id': repo_id,
         'distributor_id': dist_id
     }
     # handler report: succeeded
     ReplyHandler._unbind_succeeded(call_context)
     bind_manager.delete.assert_called_with(consumer_id, repo_id, dist_id, force=True)
Beispiel #6
0
 def test__unbind_failed(self, mock_get_manager):
     bind_manager = Mock()
     mock_get_manager.return_value = bind_manager
     task_id = 'task_1'
     consumer_id = 'consumer_1'
     repo_id = 'repo_1'
     dist_id = 'dist_1'
     call_context = {
         'action': 'bind',
         'task_id': task_id,
         'consumer_id': consumer_id,
         'repo_id': repo_id,
         'distributor_id': dist_id
     }
     # handler report: failed
     ReplyHandler._unbind_failed(task_id, call_context)
     bind_manager.action_failed.assert_called_with(consumer_id, repo_id, dist_id, task_id)
Beispiel #7
0
 def test__unbind_succeeded(self, mock_get_manager):
     bind_manager = Mock()
     mock_get_manager.return_value = bind_manager
     task_id = 'task_1'
     consumer_id = 'consumer_1'
     repo_id = 'repo_1'
     dist_id = 'dist_1'
     call_context = {
         'action': 'unbind',
         'task_id': task_id,
         'consumer_id': consumer_id,
         'repo_id': repo_id,
         'distributor_id': dist_id
     }
     # handler report: succeeded
     ReplyHandler._unbind_succeeded(call_context)
     bind_manager.delete.assert_called_with(consumer_id, repo_id, dist_id, force=True)
Beispiel #8
0
 def test_construction(self, mock_consumer, mock_queue, mock_auth):
     url = 'http://broker'
     handler = ReplyHandler(url)
     mock_queue.assert_called_with(ReplyHandler.REPLY_QUEUE)
     mock_queue.return_value.declare.assert_called_with(url)
     self.assertTrue(mock_queue.return_value.durable)
     mock_consumer.assert_called_with(mock_queue(),
                                      url=url,
                                      authenticator=mock_auth())
     self.assertEqual(handler.consumer, mock_consumer())
Beispiel #9
0
    def test_started(self, mock_task_started):
        dispatch_report = dict(succeeded=True)
        task_id = 'task_1'
        consumer_id = 'consumer_1'
        repo_id = 'repo_1'
        dist_id = 'dist_1'
        call_context = {
            'task_id': task_id,
            'consumer_id': consumer_id,
            'repo_id': repo_id,
            'distributor_id': dist_id
        }
        envelope = Envelope(routing=['A', 'B'], any=call_context)
        reply = Started(envelope)
        handler = ReplyHandler('')
        handler.started(reply)

        # validate task updated
        mock_task_started.assert_called_with(task_id)
Beispiel #10
0
    def test_unbind_succeeded_with_error_report(self, mock_task_succeeded, mock_unbind_failed):
        task_id = 'task_1'
        consumer_id = 'consumer_1'
        repo_id = 'repo_1'
        dist_id = 'dist_1'
        call_context = {
            'action': 'unbind',
            'task_id': task_id,
            'consumer_id': consumer_id,
            'repo_id': repo_id,
            'distributor_id': dist_id
        }
        dispatch_report = dict(succeeded=False)
        result = Envelope(retval=dispatch_report)
        envelope = Envelope(routing=['A', 'B'], result=result, any=call_context)
        reply = Succeeded(envelope)
        handler = ReplyHandler('')
        handler.succeeded(reply)

        # validate task updated
        mock_task_succeeded.assert_called_with(task_id, dispatch_report)
        # validate bind action updated
        mock_unbind_failed.assert_called_with(task_id, call_context)
Beispiel #11
0
 def reply_handler(self):
     return ReplyHandler('')
Beispiel #12
0
 def test_start(self, mock_start):
     url = 'http://broker'
     handler = ReplyHandler(url)
     watchdog = Mock()
     handler.start(watchdog)
     mock_start.assert_called_with(handler, watchdog=watchdog)