Ejemplo n.º 1
0
    def put(self, request, repo_id, importer_id):
        """
        Associate an importer to a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository
        :type  repo_id: str
        :param importer_id: The id of the importer to associate
        :type  importer_id: str

        :raises exceptions.MissingValue: if required param importer_config is not in the body
        :raises exceptions.MissingResource: if importer does not match the repo's importer
        :raises exceptions.OperationPostponed: dispatch a task
        """

        importer_controller.get_valid_importer(repo_id, importer_id)
        importer_config = request.body_as_json.get('importer_config', None)

        if importer_config is None:
            raise exceptions.MissingValue(['importer_config'])

        async_result = importer_controller.queue_update_importer_config(repo_id, importer_id,
                                                                        importer_config)
        raise exceptions.OperationPostponed(async_result)
Ejemplo n.º 2
0
Archivo: repo.py Proyecto: pcreech/pulp
    def update(cls, repo_id, importer_id, schedule_id, updates):
        """
        Update an existing sync schedule.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        :param updates:         dictionary of updates to apply
        :type  updates:         dict

        :return ScheduledCall instance as it appears after the update
        :rtype  pulp.server.db.model.dispatch.ScheduledCall
        """
        importer_controller.get_valid_importer(repo_id, importer_id)

        # legacy logic that can't be explained
        if "override_config" in updates:
            updates["kwargs"] = {"overrides": updates.pop("override_config")}

        utils.validate_updated_schedule_options(updates)

        return utils.update(schedule_id, updates)
Ejemplo n.º 3
0
    def update(cls, repo_id, importer_id, schedule_id, updates):
        """
        Update an existing sync schedule.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        :param updates:         dictionary of updates to apply
        :type  updates:         dict

        :return ScheduledCall instance as it appears after the update
        :rtype  pulp.server.db.model.dispatch.ScheduledCall
        """
        importer_controller.get_valid_importer(repo_id, importer_id)

        # legacy logic that can't be explained
        if 'override_config' in updates:
            updates['kwargs'] = {'overrides': updates.pop('override_config')}

        utils.validate_updated_schedule_options(updates)

        return utils.update(schedule_id, updates)
Ejemplo n.º 4
0
    def put(self, request, repo_id, importer_id):
        """
        Associate an importer to a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository
        :type  repo_id: str
        :param importer_id: The id of the importer to associate
        :type  importer_id: str

        :raises exceptions.MissingValue: if required param importer_config is not in the body
        :raises exceptions.MissingResource: if importer does not match the repo's importer
        :raises exceptions.OperationPostponed: dispatch a task
        """

        importer_controller.get_valid_importer(repo_id, importer_id)
        importer_config = request.body_as_json.get('importer_config', None)

        if importer_config is None:
            raise exceptions.MissingValue(['importer_config'])

        async_result = importer_controller.queue_update_importer_config(repo_id, importer_id,
                                                                        importer_config)
        raise exceptions.OperationPostponed(async_result)
Ejemplo n.º 5
0
 def test_invalid_importer(self, mock_model):
     """
     Test with an extant importer that is not associated with the given repository.
     """
     mock_importer = mock_model.Importer.objects.get_or_404.return_value
     try:
         importer.get_valid_importer('mock_repo', 'mock_imp')
     except exceptions.MissingResource, result:
         pass
Ejemplo n.º 6
0
 def test_nonexisent_importer(self, mock_model):
     """
     Try to get an importer that doesn't exist.
     """
     mock_model.Importer.objects.get_or_404.side_effect = exceptions.MissingResource('foo')
     try:
         importer.get_valid_importer('mock_repo', 'mock_imp')
     except exceptions.MissingResource, result:
         pass
Ejemplo n.º 7
0
 def test_nonexisent_importer(self, mock_model):
     """
     Try to get an importer that doesn't exist.
     """
     mock_model.Importer.objects.get_or_404.side_effect = exceptions.MissingResource('foo')
     try:
         importer.get_valid_importer('mock_repo', 'mock_imp')
     except exceptions.MissingResource, result:
         pass
Ejemplo n.º 8
0
 def test_invalid_importer(self, mock_model):
     """
     Test with an extant importer that is not associated with the given repository.
     """
     mock_importer = mock_model.Importer.objects.get_or_404.return_value
     try:
         importer.get_valid_importer('mock_repo', 'mock_imp')
     except exceptions.MissingResource, result:
         pass
Ejemplo n.º 9
0
    def create(cls,
               repo_id,
               importer_id,
               sync_options,
               schedule,
               failure_threshold=None,
               enabled=True):
        """
        Create a new sync schedule for a given repository using the given importer.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        :param sync_options:    dictionary that contains the key 'override_config',
                                whose value should be passed as the 'overrides'
                                parameter to the sync task. This wasn't originally
                                documented, so it isn't clear why overrides value
                                couldn't be passed directly.
        :type  sync_options:    dict
        :param schedule_data:   dictionary that contains the key 'schedule', whose
                                value is an ISO8601 string. This wasn't originally
                                documented, so it isn't clear why the string itself
                                couldn't have been passed directly.
        :type  schedule_data:   dict

        :return:    new schedule instance
        :rtype:     pulp.server.db.model.dispatch.ScheduledCall
        """
        # validate the input
        importer_controller.get_valid_importer(repo_id, importer_id)
        utils.validate_keys(sync_options, _SYNC_OPTION_KEYS)
        utils.validate_initial_schedule_options(schedule, failure_threshold,
                                                enabled)

        task = repo_controller.queue_sync_with_auto_publish.name
        args = [repo_id]
        kwargs = {'overrides': sync_options['override_config']}
        resource = importer_controller.build_resource_tag(repo_id, importer_id)
        schedule = ScheduledCall(schedule,
                                 task,
                                 args=args,
                                 kwargs=kwargs,
                                 resource=resource,
                                 failure_threshold=failure_threshold,
                                 enabled=enabled)
        schedule.save()
        try:
            importer_controller.get_valid_importer(repo_id, importer_id)
        except exceptions.MissingResource:
            # back out of this whole thing, since the importer disappeared
            utils.delete(schedule.id)
            raise

        return schedule
Ejemplo n.º 10
0
Archivo: repo.py Proyecto: pcreech/pulp
    def create(cls, repo_id, importer_id, sync_options, schedule, failure_threshold=None, enabled=True):
        """
        Create a new sync schedule for a given repository using the given importer.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        :param sync_options:    dictionary that contains the key 'override_config',
                                whose value should be passed as the 'overrides'
                                parameter to the sync task. This wasn't originally
                                documented, so it isn't clear why overrides value
                                couldn't be passed directly.
        :type  sync_options:    dict
        :param schedule_data:   dictionary that contains the key 'schedule', whose
                                value is an ISO8601 string. This wasn't originally
                                documented, so it isn't clear why the string itself
                                couldn't have been passed directly.
        :type  schedule_data:   dict

        :return:    new schedule instance
        :rtype:     pulp.server.db.model.dispatch.ScheduledCall
        """
        # validate the input
        importer_controller.get_valid_importer(repo_id, importer_id)
        utils.validate_keys(sync_options, _SYNC_OPTION_KEYS)
        utils.validate_initial_schedule_options(schedule, failure_threshold, enabled)

        task = repo_controller.queue_sync_with_auto_publish.name
        args = [repo_id]
        kwargs = {"overrides": sync_options["override_config"]}
        resource = importer_controller.build_resource_tag(repo_id, importer_id)
        schedule = ScheduledCall(
            schedule,
            task,
            args=args,
            kwargs=kwargs,
            resource=resource,
            failure_threshold=failure_threshold,
            enabled=enabled,
        )
        schedule.save()
        try:
            importer_controller.get_valid_importer(repo_id, importer_id)
        except exceptions.MissingResource:
            # back out of this whole thing, since the importer disappeared
            utils.delete(schedule.id)
            raise

        return schedule
Ejemplo n.º 11
0
Archivo: repo.py Proyecto: pcreech/pulp
    def list(cls, repo_id, importer_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and importer.

        :param repo_id:     unique ID for a repository
        :type  repo_id:     basestring
        :param importer_id: unique ID for an importer
        :type  importer_id: basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        return utils.get_by_resource(importer_controller.build_resource_tag(repo_id, importer_id))
Ejemplo n.º 12
0
    def delete(cls, repo_id, importer_id, schedule_id):
        """
        Delete a scheduled sync from a given repository and importer.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        """
        # validate the input
        importer_controller.get_valid_importer(repo_id, importer_id)

        # remove from the scheduler
        utils.delete(schedule_id)
Ejemplo n.º 13
0
 def test_as_expected(self, mock_model):
     """
     Get an importer with a valid importer_type_id that is associated to the given repo.
     """
     mock_importer = mock_model.Importer.objects.get_or_404.return_value
     result = importer.get_valid_importer('mock_repo', mock_importer.importer_type_id)
     self.assertTrue(result is mock_importer)
Ejemplo n.º 14
0
    def delete(self, request, repo_id, importer_id):
        """
        Dispatch a task to remove an importer from a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository to remove the importer from
        :type  repo_id: str
        :param importer_id: The id of the importer to remove from the given repository
        :type  importer_id: str

        :raises exceptions.OperationPostponed: to dispatch a task to delete the importer
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        async_result = importer_controller.queue_remove_importer(repo_id, importer_id)
        raise exceptions.OperationPostponed(async_result)
Ejemplo n.º 15
0
    def delete(self, request, repo_id, importer_id):
        """
        Dispatch a task to remove an importer from a repository.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: The id of the repository to remove the importer from
        :type  repo_id: str
        :param importer_id: The id of the importer to remove from the given repository
        :type  importer_id: str

        :raises exceptions.OperationPostponed: to dispatch a task to delete the importer
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        async_result = importer_controller.queue_remove_importer(repo_id, importer_id)
        raise exceptions.OperationPostponed(async_result)
Ejemplo n.º 16
0
    def list(cls, repo_id, importer_id):
        """
        Returns an iterator of ScheduledCall instances that represent schedules
        for the specified repo and importer.

        :param repo_id:     unique ID for a repository
        :type  repo_id:     basestring
        :param importer_id: unique ID for an importer
        :type  importer_id: basestring

        :return:    iterator of ScheduledCall instances
        :rtype:     iterator
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        return utils.get_by_resource(
            importer_controller.build_resource_tag(repo_id, importer_id))
Ejemplo n.º 17
0
Archivo: repo.py Proyecto: pcreech/pulp
    def delete(cls, repo_id, importer_id, schedule_id):
        """
        Delete a scheduled sync from a given repository and importer.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        """
        # validate the input
        importer_controller.get_valid_importer(repo_id, importer_id)

        # remove from the scheduler
        utils.delete(schedule_id)
Ejemplo n.º 18
0
 def test_as_expected(self, mock_model):
     """
     Get an importer with a valid importer_type_id that is associated to the given repo.
     """
     mock_importer = mock_model.Importer.objects.get_or_404.return_value
     result = importer.get_valid_importer('mock_repo', mock_importer.importer_type_id)
     self.assertTrue(result is mock_importer)
Ejemplo n.º 19
0
    def get(self, request, repo_id, importer_id, schedule_id):
        """
        Retrieve information about a scheduled sync.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param importer_id: id of the importer
        :type  importer_id: str
        :param schedule_id: id of the requested scheduled repository sync
        :type  schedule)id: str

        :return: information about the requested scheduled sync
        :rtype: django.http.HttpResponse
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        resource_href = reverse('repo_sync_schedule_resource',
                                kwargs={'repo_id': repo_id, 'importer_id': importer_id,
                                        'schedule_id': schedule_id})
        return self._get(schedule_id, resource_href)
Ejemplo n.º 20
0
    def get(self, request, repo_id, importer_id, schedule_id):
        """
        Retrieve information about a scheduled sync.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param importer_id: id of the importer
        :type  importer_id: str
        :param schedule_id: id of the requested scheduled repository sync
        :type  schedule)id: str

        :return: information about the requested scheduled sync
        :rtype: django.http.HttpResponse
        """
        importer_controller.get_valid_importer(repo_id, importer_id)
        resource_href = reverse('repo_sync_schedule_resource',
                                kwargs={'repo_id': repo_id, 'importer_id': importer_id,
                                        'schedule_id': schedule_id})
        return self._get(schedule_id, resource_href)
Ejemplo n.º 21
0
    def get(self, request, repo_id, importer_id):
        """
        Retrieve the importer for a repo.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: request the importer of this repository
        :type  repo_id: str
        :param importer_id: (unused) id of the requested importer
        :type  importer_id: str

        :return: Response containing a dict reporesenting the importer of the repo
        :rtype : django.http.HttpResponse
        :raises exceptions.MissingResource: if importer_id does not match importer for repo
        """
        importer = importer_controller.get_valid_importer(repo_id, importer_id)
        serialized_importer = model.Importer.serializer(importer).data
        return generate_json_response_with_pulp_encoder(serialized_importer)
Ejemplo n.º 22
0
    def get(self, request, repo_id, importer_id):
        """
        Retrieve the importer for a repo.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: request the importer of this repository
        :type  repo_id: str
        :param importer_id: (unused) id of the requested importer
        :type  importer_id: str

        :return: Response containing a dict reporesenting the importer of the repo
        :rtype : django.http.HttpResponse
        :raises exceptions.MissingResource: if importer_id does not match importer for repo
        """
        importer = importer_controller.get_valid_importer(repo_id, importer_id)
        serialized_importer = model.Importer.SERIALIZER(importer).data
        return generate_json_response_with_pulp_encoder(serialized_importer)