How to use the pulp.server.exceptions function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulpcore / test / unit / test_repo_distributor_manager.py View on Github external
def test_add_distributor_no_distributor(self):
        """
        Tests adding a distributor that doesn't exist.
        """

        # Setup
        self.repo_manager.create_repo('real-repo')

        # Test
        try:
            self.distributor_manager.add_distributor('real-repo', 'fake-distributor', {}, True)
            self.fail('No exception thrown for an invalid distributor type')
        except exceptions.InvalidValue, e:
            print(e) # for coverage
github pulp / pulp / server / pulp / server / managers / repo / unit_association.py View on Github external
importer_instance, plugin_config = plugin_api.get_importer_by_id(dest_repo_importer['importer_type_id'])

        call_config = PluginCallConfiguration(plugin_config, dest_repo_importer['config'], import_config_override)
        login = manager_factory.principal_manager().get_principal()['login']
        conduit = ImportUnitConduit(source_repo_id, dest_repo_id, source_repo_importer['id'],
                                    dest_repo_importer['id'], RepoContentUnit.OWNER_TYPE_USER, login)

        try:
            copied_units = importer_instance.import_units(transfer_source_repo, transfer_dest_repo, conduit,
                                                          call_config, units=transfer_units)
            unit_ids = [u.to_id_dict() for u in copied_units]
            return unit_ids
        except Exception:
            _LOG.exception('Exception from importer [%s] while importing units into repository [%s]' %
                           (dest_repo_importer['importer_type_id'], dest_repo_id))
            raise exceptions.PulpExecutionException(), None, sys.exc_info()[2]
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / consumer_groups.py View on Github external
def GET(self, consumer_group_id):
        collection = ConsumerGroup.get_collection()
        group = collection.find_one({'id': consumer_group_id})
        if group is None:
            raise pulp_exceptions.MissingResource(consumer_group=consumer_group_id)
        group.update(serialization.link.current_link_obj())
        return self.ok(group)
github pulp / pulp / server / pulp / server / webservices / views / repositories.py View on Github external
:type  repo_id: str

        :raises pulp_exceptions.MissingResource: if repo does not exist.
        :raises pulp_exceptions.OperationPostponed: dispatch a ``download_repo`` task.
        """
        model.Repository.objects.get_repo_or_missing_resource(repo_id)
        verify = request.body_as_json.get('verify_all_units', False)
        if not isinstance(verify, bool):
            raise exceptions.PulpCodedValidationException(
                error_code=exceptions.error_codes.PLP1010,
                value=verify,
                field='verify_all_units',
                field_type='boolean'
            )
        async_result = repo_controller.queue_download_repo(repo_id, verify_all_units=verify)
        raise exceptions.OperationPostponed(async_result)
github pulp / pulpcore / server / pulp / server / webservices / controllers / permissions.py View on Github external
def _check_invalid_params(params):
    # Raise InvalidValue if any of the params are None
    invalid_values = []
    for key, value in params.items():
        if value is None:
            invalid_values.append(key)

    if invalid_values:
        raise exceptions.InvalidValue(invalid_values)
github pulp / pulpcore / server / pulp / server / webservices / views / users.py View on Github external
"""
        Create a new user.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing the user
        :rtype: django.http.HttpResponse
        :raises: MissingValue if login field is missing
        :raises: InvalidValue if some parameters are invalid
        """
        # Pull all the user data
        user_data = request.body_as_json
        login = user_data.pop('login', None)
        if login is None:
            raise pulp_exceptions.MissingValue(['login'])
        password = user_data.pop('password', None)
        name = user_data.pop('name', None)
        if user_data:
            raise pulp_exceptions.InvalidValue(user_data.keys())
        # Creation
        manager = factory.user_manager()
        args = [login]
        kwargs = {'password': password,
                  'name': name}

        user = manager.create_user(*args, **kwargs)

        # Add the link to the user
        link = _add_link(user)

        # Grant permissions
github pulp / pulp / platform / src / pulp / server / webservices / controllers / roles.py View on Github external
    @auth_required(UPDATE)
    def POST(self, role_id):

        # Params (validation will occur in the manager)
        params = self.params()
        login = params.get('login', None)
        if login is None:
            raise exceptions.InvalidValue(login)

        role_manager = managers.role_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
                action_tag('add_user_to_role')]

        call_request = CallRequest(role_manager.add_user_to_role,
                                   [role_id, login],
                                   tags=tags)
        call_request.updates_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
        return self.ok(execution.execute_sync(call_request))
github pulp / pulpcore / server / pulp / server / webservices / views / consumer_groups.py View on Github external
:type distributor_id: str
    :return: A dictionary of the missing resources
    :rtype: dict
    """
    missing_resources = {}
    group_manager = factory.consumer_group_query_manager()
    try:
        group_manager.get_group(group_id)
    except pulp_exceptions.MissingResource:
        missing_resources['group_id'] = group_id
    repo = model.Repository.objects(repo_id=repo_id).first()
    if repo is None:
        missing_resources['repo_id'] = repo_id
    try:
        model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id)
    except pulp_exceptions.MissingResource:
        missing_resources['distributor_id'] = distributor_id
    return missing_resources
github pulp / pulp / server / pulp / plugins / distributor.py View on Github external
    @staticmethod
    def ensure_all_units_downloaded(repo_id):
        """
        Checks the database to make sure all units in the repo have been downloaded. If not, raises
        an exception.

        :param repo_id: repository id
        :type  repo_id: basestring

        :raises exceptions.PulpCodedException:  if any unit in the repo is un-downloaded
        """
        if not repo_controller.has_all_units_downloaded(repo_id):
            raise exceptions.PulpCodedException(error_code=error_codes.PLP0045)
github pulp / pulp / server / pulp / server / webservices / controllers / consumer_groups.py View on Github external
    @auth_required(authorization.READ)
    def GET(self, consumer_group_id):
        collection = ConsumerGroup.get_collection()
        group = collection.find_one({'id': consumer_group_id})
        if group is None:
            raise pulp_exceptions.MissingResource(consumer_group=consumer_group_id)
        group.update(serialization.link.current_link_obj())
        return self.ok(group)