Ejemplo n.º 1
0
    def test_run_background(self, mock_publish, mock_search, mock_poll):
        """
        Test run() with the --bg flag is set.
        """
        repo_id = 'test-repo'
        data = {
            options.OPTION_REPO_ID.keyword: repo_id,
            polling.FLAG_BACKGROUND.keyword: False
        }
        # No tasks are running
        mock_search.return_value = []
        # responses.Response from the sync call
        task_data = copy.copy(CALL_REPORT_TEMPLATE)
        task = responses.Task(task_data)
        mock_publish.return_value = responses.Response(202, task)

        self.command.run(**data)

        mock_publish.assert_called_once_with(repo_id,
                                             self.command.distributor_id, None)
        expected_search_query = {
            'state': {
                '$nin': responses.COMPLETED_STATES
            },
            'tags': {
                '$all': [
                    tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
                    tags.action_tag(tags.ACTION_PUBLISH_TYPE)
                ]
            }
        }
        mock_search.assert_called_once_with(filters=expected_search_query)
        mock_poll.assert_called_once_with([task], data)
Ejemplo n.º 2
0
    def test_run(self, mock_sync, mock_search, poll):
        """
        Test the run() method when there is not an existing sync Task on the server.
        """
        repo_id = 'test-repo'
        data = {
            options.OPTION_REPO_ID.keyword: repo_id,
            polling.FLAG_BACKGROUND.keyword: False
        }
        # No tasks are running
        mock_search.return_value = []
        # responses.Response from the sync call
        task_data = copy.copy(CALL_REPORT_TEMPLATE)
        task = responses.Task(task_data)
        mock_sync.return_value = responses.Response(202, task)

        self.command.run(**data)

        mock_sync.assert_called_once_with(repo_id, None)
        sync_tasks = poll.mock_calls[0][1][0]
        poll.assert_called_once_with(sync_tasks, data)
        expected_search_query = {
            'state': {
                '$nin': responses.COMPLETED_STATES
            },
            'tags': {
                '$all': [
                    tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
                    tags.action_tag(tags.ACTION_SYNC_TYPE)
                ]
            }
        }
        mock_search.assert_called_once_with(filters=expected_search_query)
        self.assertEqual(self.prompt.get_write_tags(), [TAG_TITLE])
Ejemplo n.º 3
0
def create_fake_task_response():
    """
    Returns a Response object that can be used as a mock return from a bindings call
    that is expected to return a task. The values for the task will be the same as
    those found in TASK_TEMPLATE.

    :return: response object with the parsed Task object in its response_body
    :rtype:  Response
    """
    task = responses.Task(TASK_TEMPLATE)
    response = responses.Response('202', task)
    return response
Ejemplo n.º 4
0
    def get_task(self, task_id):
        """
        Returns the next state for the given task.

        :return: response object as if the bindings had contacted the server
        :rtype:  pulp.bindings.response.Response

        :raises ValueError: if no states are defined for the given task ID
        """
        if task_id not in self.tasks_by_id:
            raise ValueError('No task states configured for task ID [%s]' % task_id)

        # Wrap the task in a response to simulate what comes out of the bindings
        task = self.tasks_by_id[task_id].pop()
        response = responses.Response('200', task)

        return response
Ejemplo n.º 5
0
    def get_all_tasks(self, tags=()):
        """
        Returns the next state for all tasks that match the given tags, if any. The index
        counters will be incremented such that on the next call to get_task, the state
        following what is returned from this call will be returned.

        This implementation currently does not use the tags parameter but should be
        enhanced to do so in the future.

        :return: response object as if the bindings had contacted the server
        :rtype:  pulp.bindings.response.Response
        """

        task_list = []
        for task_id in self.ordered_task_ids:
            next_task = self.tasks_by_id[task_id].pop()
            task_list.append(next_task)

        # Package the task list into the response object like the bindings would
        response = responses.Response('200', task_list)

        return response