Exemple #1
0
 def __init__(self, *args, **kwargs):
     """Initialize a BaseDistributionViewSet and emit deprecation warnings"""
     deprecation_logger.warn(
         _("BaseDistributionViewSet is deprecated and could be removed as early as "
           "pulpcore==3.13; use pulpcore.plugin.viewsets.DistributionViewset instead."
           ))
     return super().__init__(*args, **kwargs)
Exemple #2
0
 def __init__(self, *args, **kwargs):
     """Initialize a DistributionFilter and emit deprecation warnings"""
     deprecation_logger.warn(
         _("DistributionFilter is deprecated and could be removed as early as "
           "pulpcore==3.13; use pulpcore.plugin.serializers.NewDistributionFilter instead."
           ))
     return super().__init__(*args, **kwargs)
Exemple #3
0
 def __init__(self, *args, **kwargs):
     """Initialize a RepositoryVersionDistributionSerializer and emit deprecation warnings"""
     deprecation_logger.warn(
         _("PublicationDistributionSerializer is deprecated and could be removed as early as "
           "pulpcore==3.13; use pulpcore.plugin.serializers.DistributionSerializer instead. "
           "See its docstring for more details."))
     return super().__init__(*args, **kwargs)
Exemple #4
0
 def default(self, obj):
     try:
         return json.JSONEncoder.default(self, obj)
     except TypeError:
         deprecation_logger.warn(
             _("The argument {obj} is of type {type}, which is not JSON serializable. The use "
               "of non JSON serializable objects for `args` and `kwargs` to tasks is "
               "deprecated as of pulpcore==3.12. See the traceback below for more info."
               ).format(obj=obj, type=type(obj)))
         return None
Exemple #5
0
 def default(self, obj):
     if isinstance(obj, uuid.UUID):
         return str(obj)
     try:
         return json.JSONEncoder.default(self, obj)
     except TypeError:
         deprecation_logger.warn(
             _(
                 "The argument {obj} is of type {type}, which is not JSON serializable. The use "
                 "of non JSON serializable objects for `args` and `kwargs` to tasks is "
                 "deprecated as of pulpcore==3.12."
             ).format(obj=obj, type=type(obj))
         )
         return None
Exemple #6
0
    def __init__(
        self,
        url,
        custom_file_object=None,
        expected_digests=None,
        expected_size=None,
        semaphore=None,
        *args,
        **kwargs,
    ):
        """
        Create a BaseDownloader object. This is expected to be called by all subclasses.

        Args:
            url (str): The url to download.
            custom_file_object (file object): An open, writable file object that downloaded data
                can be written to by
                :meth:`~pulpcore.plugin.download.BaseDownloader.handle_data`.
            expected_digests (dict): Keyed on the algorithm name provided by hashlib and stores the
                value of the expected digest. e.g. {'md5': '912ec803b2ce49e4a541068d495ab570'}
            expected_size (int): The number of bytes the download is expected to have.
            semaphore (asyncio.Semaphore): A semaphore the downloader must acquire before running.
                Useful for limiting the number of outstanding downloaders in various ways.
        """
        if custom_file_object:
            deprecation_logger.warn(
                "The 'custom_file_object' argument to 'BaseDownloader' is"
                "deprecated and will be removed in pulpcore==3.20; stop using it."
            )

        self.url = url
        self._writer = custom_file_object
        self.path = None
        self.expected_digests = expected_digests
        self.expected_size = expected_size
        if semaphore:
            self.semaphore = semaphore
        else:
            self.semaphore = asyncio.Semaphore(
            )  # This will always be acquired
        self._digests = {}
        self._size = 0
        if self.expected_digests:
            if not set(self.expected_digests).intersection(
                    set(Artifact.DIGEST_FIELDS)):
                raise UnsupportedDigestValidationError(
                    _("Content at the url {} does not contain at least one trusted hasher which"
                      " is specified in 'ALLOWED_CONTENT_CHECKSUMS' setting.").
                    format(self.url))
Exemple #7
0
 def _handle_creation_hooks(self, access_policy):
     if access_policy.creation_hooks is not None:
         for creation_hook in access_policy.creation_hooks:
             function = self.REGISTERED_CREATION_HOOKS.get(creation_hook["function"])
             if function is not None:
                 kwargs = creation_hook.get("parameters") or {}
                 function(**kwargs)
             else:
                 # Old interface deprecated for removal in 3.20
                 function = getattr(self, creation_hook["function"])
                 deprecation_logger.warn(
                     "Calling unregistered creation hooks from the access policy is deprecated"
                     " and may be removed with pulpcore 3.20 "
                     f"[hook={creation_hook}, viewset={access_policy.viewset_name}]."
                 )
                 function(creation_hook.get("permissions"), creation_hook.get("parameters"))
def worker(resource_manager, pid):
    """A Pulp worker."""

    if pid:
        with open(os.path.expanduser(pid), "w") as fp:
            fp.write(str(os.getpid()))

    if resource_manager:
        _logger.warn("Attempting to start a resource-manager with the distributed tasking system")
        deprecation_logger.warn(
            "The `--resource-manager` option of the pulpcore-worker entrypoint is deprecated and"
            " will be removed in pulpcore 3.17."
        )
        select.select([], [], [])
    _logger.info("Starting distributed type worker")

    NewPulpWorker().run_forever()
Exemple #9
0
def _rename_permissions_assignment_workaround(access_policy, viewset):
    from pulpcore.app.loggers import deprecation_logger

    if "permissions_assignment" in access_policy:
        deprecation_logger.warn(
            f"In AccessPolicy for {viewset}, "
            "the field 'permissions_assignment' has been renamed to 'creation_hooks'. This "
            "workaround may be removed with pulpcore 3.20."
        )
        access_policy["creation_hooks"] = access_policy.pop("permissions_assignment")
    if "creation_hooks" in access_policy:
        if any(hook.get("permissions") is not None for hook in access_policy["creation_hooks"]):
            deprecation_logger.warn(
                f"In AccessPolicy for {viewset}, "
                "the 'permissions' field in 'creation_hooks' is deprecated and may be removed "
                "with pulpcore 3.20. Use the 'parameters' field instead."
            )
Exemple #10
0
def enqueue_with_reservation(func,
                             resources,
                             args=None,
                             kwargs=None,
                             options=None,
                             task_group=None):
    """
    Enqueue a message to Pulp workers with a reservation.

    This method provides normal enqueue functionality, while also requesting necessary locks for
    serialized urls. No two tasks that claim the same resource can execute concurrently. It
    accepts resources which it transforms into a list of urls (one for each resource).

    This does not dispatch the task directly, but instead promises to dispatch it later by
    encapsulating the desired task through a call to a :func:`_queue_reserved_task` task. See
    the docblock on :func:`_queue_reserved_task` for more information on this.

    This method creates a :class:`pulpcore.app.models.Task` object. Pulp expects to poll on a
    task just after calling this method, so a Task entry needs to exist for it
    before it returns.

    Args:
        func (callable): The function to be run by RQ when the necessary locks are acquired.
        resources (list): A list of resources to reserve guaranteeing that only one task reserves
                          these resources. Each resource can be either a (str) resource URL or a
                          (django.models.Model) resource instance.
        args (tuple): The positional arguments to pass on to the task.
        kwargs (dict): The keyword arguments to pass on to the task.
        options (dict): The options to be passed on to the task.
        task_group (pulpcore.app.models.TaskGroup): A TaskGroup to add the created Task to.

    Returns (rq.job.job): An RQ Job instance as returned by RQ's enqueue function

    Raises:
        ValueError: When `resources` is an unsupported type.
    """
    deprecation_logger.warn(
        _("`enqueue_with_reservation` is deprecated and could be removed as early as "
          "pulpcore==3.13; use pulpcore.plugin.tasking.dispatch instead."))
    return _enqueue_with_reservation(func,
                                     resources,
                                     args=args,
                                     kwargs=kwargs,
                                     options=options,
                                     task_group=task_group)