Exemplo n.º 1
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.delete(self.schedule_id)

        mock_get_collection.assert_called_once_with()
Exemplo n.º 2
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.delete(self.schedule_id)

        mock_get_collection.assert_called_once_with()
Exemplo n.º 3
0
    def create(cls,
               repo_id,
               distributor_id,
               publish_options,
               schedule,
               failure_threshold=None,
               enabled=True):
        """
        Create a new scheduled publish for the given repository and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring
        :param publish_options: dictionary that contains the key 'override_config',
                                whose value should be passed as the 'overrides'
                                parameter to the publish 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
        """
        dist = model.Distributor.objects.get_or_404(
            repo_id=repo_id, distributor_id=distributor_id)
        utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS)
        utils.validate_initial_schedule_options(schedule, failure_threshold,
                                                enabled)

        task = repo_controller.queue_publish.name
        args = [repo_id, distributor_id]
        kwargs = {'overrides': publish_options['override_config']}
        schedule = ScheduledCall(schedule,
                                 task,
                                 args=args,
                                 kwargs=kwargs,
                                 resource=dist.resource_tag,
                                 failure_threshold=failure_threshold,
                                 enabled=enabled)
        schedule.save()

        try:
            model.Distributor.objects.get_or_404(repo_id=repo_id,
                                                 distributor_id=distributor_id)
        except exceptions.MissingResource:
            # back out of this whole thing, since the distributor disappeared
            utils.delete(schedule.id)
            raise

        return schedule
Exemplo n.º 4
0
    def test_delete(self, mock_get_collection):
        mock_remove = mock_get_collection.return_value.remove
        mock_remove.return_value = None

        utils.delete(self.schedule_id)

        self.assertEqual(mock_remove.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_remove.call_args[0]), 1)
        self.assertEqual(mock_remove.call_args[0][0], {'_id': ObjectId(self.schedule_id)})
Exemplo n.º 5
0
    def test_delete(self, mock_get_collection):
        mock_remove = mock_get_collection.return_value.remove
        mock_remove.return_value = None

        utils.delete(self.schedule_id)

        self.assertEqual(mock_remove.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_remove.call_args[0]), 1)
        self.assertEqual(mock_remove.call_args[0][0], {'_id': ObjectId(self.schedule_id)})
Exemplo n.º 6
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
Exemplo n.º 7
0
    def test_delete(self, mock_get_collection):
        mock_remove = mock_get_collection.return_value.find_and_modify
        mock_remove.return_value = 'not none'

        utils.delete(self.schedule_id)

        self.assertEqual(mock_remove.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_remove.call_args[0]), 0)
        self.assertEqual(mock_remove.call_args[1]['query'], {'_id': ObjectId(self.schedule_id)})
        self.assertEqual(mock_remove.call_args[1]['remove'], True)
Exemplo n.º 8
0
    def delete_schedule(consumer_id, schedule_id):
        """
        Permanently deletes the schedule specified

        :param consumer_id:     a unique ID for a consumer
        :type  consumer_id:     basestring
        :param schedule_id:     a unique ID for the schedule being updated
        :type  schedule_id:     basestring
        """
        ConsumerScheduleManager._validate_consumer(consumer_id)

        utils.delete(schedule_id)
Exemplo n.º 9
0
    def delete_schedule(consumer_id, schedule_id):
        """
        Permanently deletes the schedule specified

        :param consumer_id:     a unique ID for a consumer
        :type  consumer_id:     basestring
        :param schedule_id:     a unique ID for the schedule being updated
        :type  schedule_id:     basestring
        """
        ConsumerScheduleManager._validate_consumer(consumer_id)

        utils.delete(schedule_id)
Exemplo n.º 10
0
    def test_delete(self, mock_get_collection):
        mock_remove = mock_get_collection.return_value.find_and_modify
        mock_remove.return_value = 'not none'

        utils.delete(self.schedule_id)

        self.assertEqual(mock_remove.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_remove.call_args[0]), 0)
        self.assertEqual(mock_remove.call_args[1]['query'],
                         {'_id': ObjectId(self.schedule_id)})
        self.assertEqual(mock_remove.call_args[1]['remove'], True)
Exemplo n.º 11
0
    def unregister(consumer_id):
        """
        Unregisters given consumer.

        :param  consumer_id:            identifies the consumer being unregistered
        :type   consumer_id:            str
        :raises MissingResource:        if the given consumer does not exist
        :raises OperationFailed:        if any part of the unregister process fails; the exception
                                        will contain information on which sections failed
        :raises PulpExecutionException: if error during updating database collection
        """

        ConsumerManager.get_consumer(consumer_id)

        # Remove associate bind
        manager = factory.consumer_bind_manager()
        manager.consumer_deleted(consumer_id)

        # Remove associated profiles
        manager = factory.consumer_profile_manager()
        manager.consumer_deleted(consumer_id)

        # Notify agent
        agent_consumer = factory.consumer_agent_manager()
        agent_consumer.unregistered(consumer_id)

        # remove from consumer groups
        group_manager = factory.consumer_group_manager()
        group_manager.remove_consumer_from_groups(consumer_id)

        # delete any scheduled unit installs
        schedule_manager = factory.consumer_schedule_manager()
        for schedule in schedule_manager.get(consumer_id):
            # using "delete" on utils skips validation that the consumer exists.
            schedule_utils.delete(schedule.id)

        # Database Updates
        try:
            Consumer.get_collection().remove({'id': consumer_id}, safe=True)
        except Exception:
            _logger.exception(
                'Error updating database collection while removing consumer [%s]'
                % consumer_id)
            raise PulpExecutionException(
                "database-error"), None, sys.exc_info()[2]

        # remove the consumer from any groups it was a member of
        group_manager = factory.consumer_group_manager()
        group_manager.remove_consumer_from_groups(consumer_id)

        factory.consumer_history_manager().record_event(
            consumer_id, 'consumer_unregistered')
Exemplo n.º 12
0
Arquivo: repo.py Projeto: pcreech/pulp
    def delete(cls, repo_id, distributor_id, schedule_id):
        """
        Delete an existing scheduled publish from the given repository and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        """
        model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id)
        utils.delete(schedule_id)
Exemplo n.º 13
0
Arquivo: repo.py Projeto: 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
Exemplo n.º 14
0
    def delete(cls, repo_id, distributor_id, schedule_id):
        """
        Delete an existing scheduled publish from the given repository and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        """
        model.Distributor.objects.get_or_404(repo_id=repo_id,
                                             distributor_id=distributor_id)
        utils.delete(schedule_id)
Exemplo n.º 15
0
Arquivo: repo.py Projeto: pcreech/pulp
    def create(cls, repo_id, distributor_id, publish_options, schedule, failure_threshold=None, enabled=True):
        """
        Create a new scheduled publish for the given repository and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring
        :param publish_options: dictionary that contains the key 'override_config',
                                whose value should be passed as the 'overrides'
                                parameter to the publish 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
        """
        dist = model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id)
        utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS)
        utils.validate_initial_schedule_options(schedule, failure_threshold, enabled)

        task = repo_controller.queue_publish.name
        args = [repo_id, distributor_id]
        kwargs = {"overrides": publish_options["override_config"]}
        schedule = ScheduledCall(
            schedule,
            task,
            args=args,
            kwargs=kwargs,
            resource=dist.resource_tag,
            failure_threshold=failure_threshold,
            enabled=enabled,
        )
        schedule.save()

        try:
            model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=distributor_id)
        except exceptions.MissingResource:
            # back out of this whole thing, since the distributor disappeared
            utils.delete(schedule.id)
            raise

        return schedule
Exemplo n.º 16
0
Arquivo: cud.py Projeto: credativ/pulp
    def unregister(consumer_id):
        """
        Unregisters given consumer.

        :param  consumer_id:            identifies the consumer being unregistered
        :type   consumer_id:            str
        :raises MissingResource:        if the given consumer does not exist
        :raises OperationFailed:        if any part of the unregister process fails; the exception
                                        will contain information on which sections failed
        :raises PulpExecutionException: if error during updating database collection
        """

        ConsumerManager.get_consumer(consumer_id)

        # Remove associate bind
        manager = factory.consumer_bind_manager()
        manager.consumer_deleted(consumer_id)

        # Remove associated profiles
        manager = factory.consumer_profile_manager()
        manager.consumer_deleted(consumer_id)

        # Notify agent
        agent_consumer = factory.consumer_agent_manager()
        agent_consumer.unregister(consumer_id)

        # remove from consumer groups
        group_manager = factory.consumer_group_manager()
        group_manager.remove_consumer_from_groups(consumer_id)

        # delete any scheduled unit installs
        schedule_manager = factory.consumer_schedule_manager()
        for schedule in schedule_manager.get(consumer_id):
            # using "delete" on utils skips validation that the consumer exists.
            schedule_utils.delete(schedule.id)

        # Database Updates
        try:
            Consumer.get_collection().remove({'id': consumer_id}, safe=True)
        except Exception:
            _logger.exception(
                'Error updating database collection while removing consumer [%s]' % consumer_id)
            raise PulpExecutionException("database-error"), None, sys.exc_info()[2]

        # remove the consumer from any groups it was a member of
        group_manager = factory.consumer_group_manager()
        group_manager.remove_consumer_from_groups(consumer_id)

        factory.consumer_history_manager().record_event(consumer_id, 'consumer_unregistered')
Exemplo n.º 17
0
    def delete(cls, repo_id, distributor_id, schedule_id):
        """
        Delete an existing scheduled publish from the given repository and distributor.

        :param repo_id:         unique ID for a repository
        :type  repo_id:         basestring
        :param distributor_id:  unique ID for a distributor
        :type  distributor_id:  basestring
        :param schedule_id:     unique ID for a schedule
        :type  schedule_id:     basestring
        """
        # validate the input
        cls.validate_distributor(repo_id, distributor_id)

        # remove from the scheduler
        utils.delete(schedule_id)
Exemplo n.º 18
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
        cls.validate_importer(repo_id, importer_id)

        # remove from the scheduler
        utils.delete(schedule_id)