Beispiel #1
0
def delete(repo_id, distributor_id):
    """
    Get the itinerary for deleting a repository distributor.
      1. Delete the distributor on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor id
    :type distributor_id: str
    :return: Any errors that may have occurred and the list of tasks spawned for each consumer
    :rtype TaskResult
    """
    manager = managers.repo_distributor_manager()
    manager.remove_distributor(repo_id, distributor_id)

    # append unbind itineraries foreach bound consumer

    unbind_errors = []
    additional_tasks = []
    options = {}
    manager = managers.consumer_bind_manager()
    for bind in manager.find_by_distributor(repo_id, distributor_id):
        try:
            report = consumer.unbind(bind['consumer_id'],
                                     bind['repo_id'],
                                     bind['distributor_id'],
                                     options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            unbind_errors.append(e)
Beispiel #2
0
def delete(repo_id, distributor_id):
    """
    Get the itinerary for deleting a repository distributor.
      1. Delete the distributor on the sever.
      2. Unbind any bound consumers.
    :param repo_id: A repository ID.
    :type repo_id: str
    :param distributor_id: A distributor id
    :type distributor_id: str
    :return: Any errors that may have occurred and the list of tasks spawned for each consumer
    :rtype TaskResult
    """
    manager = managers.repo_distributor_manager()
    manager.remove_distributor(repo_id, distributor_id)

    # append unbind itineraries foreach bound consumer

    unbind_errors = []
    additional_tasks = []
    options = {}
    manager = managers.consumer_bind_manager()
    for bind in manager.find_by_distributor(repo_id, distributor_id):
        try:
            report = consumer.unbind(bind['consumer_id'], bind['repo_id'],
                                     bind['distributor_id'], options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            unbind_errors.append(e)
Beispiel #3
0
 def test_unbind_with_agent_notification(self, mock_bind_manager):
     binding_config = {'notify_agent': True}
     agent_options = {'bar': 'baz'}
     mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config
     mock_bind_manager.consumer_agent_manager.return_value.unbind.return_value = \
         {'task_id': 'foo-request-id', 'other_task_detail': 'abc123'}
     result = consumer.unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id',
                              agent_options)
     mock_bind_manager.consumer_bind_manager.return_value.unbind.assert_called_once_with(
         'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id')
     mock_bind_manager.consumer_agent_manager.return_value.unbind.assert_called_once_with(
         'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', agent_options)
     self.assertTrue(isinstance(result, TaskResult))
     self.assertEquals(result.spawned_tasks, [{'task_id': 'foo-request-id'}])
Beispiel #4
0
    def test_unbind_no_agent_notification(self, mock_bind_manager):
        binding_config = {'notify_agent': False}
        agent_options = {'bar': 'baz'}
        mock_bind_manager.consumer_bind_manager.return_value.get_bind.return_value = binding_config
        result = consumer.unbind('foo_consumer_id', 'foo_repo_id', 'foo_distributor_id',
                                 agent_options)

        mock_bind_manager.consumer_bind_manager.return_value.delete.assert_called_once_with(
            'foo_consumer_id', 'foo_repo_id', 'foo_distributor_id', True)

        self.assertEqual(result.error, None)
        self.assertEqual(result.return_value, {'notify_agent': False})
        self.assertEqual(result.spawned_tasks, [])

        # Make sure we didn't process the agent
        self.assertFalse(mock_bind_manager.consumer_agent_manager.called)
Beispiel #5
0
    def delete(self, request, consumer_id, repo_id, distributor_id):
        """
        Delete a bind association between the specified
        consumer and repo-distributor.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str
        :param repo_id: A repo ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str

        :raises OperationPostponed: will dispatch a task if 'notify_agent' is set to True
        :raises InvalidValue: if some parameters are invalid

        :return: Response representing the deleted binding(in case 'notify agent' is set to False)
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        forced = body.get('force', False)
        if not isinstance(forced, bool):
            raise InvalidValue(['force'])
        options = body.get('options', {})
        if not isinstance(options, dict):
            raise InvalidValue(['options'])
        if forced:
            call_report = consumer_controller.force_unbind(
                consumer_id, repo_id, distributor_id, options)
        else:
            call_report = consumer_controller.unbind(consumer_id, repo_id,
                                                     distributor_id, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return generate_json_response_with_pulp_encoder(
                call_report.serialize())
Beispiel #6
0
    def delete(self, request, consumer_id, repo_id, distributor_id):
        """
        Delete a bind association between the specified
        consumer and repo-distributor.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str
        :param repo_id: A repo ID.
        :type repo_id: str
        :param distributor_id: A distributor ID.
        :type distributor_id: str

        :raises OperationPostponed: will dispatch a task if 'notify_agent' is set to True
        :raises InvalidValue: if some parameters are invalid

        :return: Response representing the deleted binding(in case 'notify agent' is set to False)
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        forced = body.get('force', False)
        if not isinstance(forced, bool):
            raise InvalidValue(['force'])
        options = body.get('options', {})
        if not isinstance(options, dict):
            raise InvalidValue(['options'])
        if forced:
            call_report = consumer_controller.force_unbind(consumer_id, repo_id, distributor_id,
                                                           options)
        else:
            call_report = consumer_controller.unbind(consumer_id, repo_id, distributor_id, options)

        if call_report.spawned_tasks:
            raise OperationPostponed(call_report)
        else:
            return generate_json_response_with_pulp_encoder(call_report.serialize())
Beispiel #7
0
    group_manager.remove_repo_from_groups(repo_id)

    if len(error_tuples) > 0:
        pe = pulp_exceptions.PulpExecutionException()
        pe.child_exceptions = error_tuples
        raise pe

    # append unbind itineraries foreach bound consumer
    options = {}
    consumer_bind_manager = manager_factory.consumer_bind_manager()

    additional_tasks = []
    errors = []
    for bind in consumer_bind_manager.find_by_repo(repo_id):
        try:
            report = consumer_controller.unbind(bind['consumer_id'], bind['repo_id'],
                                                bind['distributor_id'], options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            errors.append(e)

    error = None
    if len(errors) > 0:
        error = pulp_exceptions.PulpCodedException(error_codes.PLP0007, repo_id=repo_id)
        error.child_exceptions = errors

    return TaskResult(error=error, spawned_tasks=additional_tasks)


def update_repo_and_plugins(repo, repo_delta, importer_config, distributor_configs):
    """
Beispiel #8
0
    if len(error_tuples) > 0:
        pe = pulp_exceptions.PulpExecutionException()
        pe.child_exceptions = error_tuples
        raise pe

    # append unbind itineraries foreach bound consumer
    options = {}
    consumer_bind_manager = manager_factory.consumer_bind_manager()

    additional_tasks = []
    errors = []
    for bind in consumer_bind_manager.find_by_repo(repo_id):
        try:
            report = consumer_controller.unbind(bind['consumer_id'],
                                                bind['repo_id'],
                                                bind['distributor_id'],
                                                options)
            if report:
                additional_tasks.extend(report.spawned_tasks)
        except Exception, e:
            errors.append(e)

    error = None
    if len(errors) > 0:
        error = pulp_exceptions.PulpCodedException(error_codes.PLP0007,
                                                   repo_id=repo_id)
        error.child_exceptions = errors

    return TaskResult(error=error, spawned_tasks=additional_tasks)