Esempio n. 1
0
    def delete_by_importer_id(repo_id, importer_id):
        """
        Delete all schedules for the specified repo and importer.

        :param importer_id:     unique ID for an importer
        :type  importer_id:     basestring
        """
        utils.delete_by_resource(RepoImporter.build_resource_tag(repo_id, importer_id))
Esempio n. 2
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
        cls.validate_importer(repo_id, importer_id)
        utils.validate_keys(sync_options, _SYNC_OPTION_KEYS)
        utils.validate_initial_schedule_options(schedule, failure_threshold,
                                                enabled)

        task = sync_with_auto_publish.name
        args = [repo_id]
        kwargs = {'overrides': sync_options['override_config']}
        resource = RepoImporter.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:
            cls.validate_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
Esempio n. 3
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
        """
        cls.validate_importer(repo_id, importer_id)

        return utils.get_by_resource(RepoImporter.build_resource_tag(repo_id, importer_id))
Esempio n. 4
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
        cls.validate_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 = RepoImporter.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:
            cls.validate_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
Esempio n. 5
0
    def test_list(self, mock_get_by_resource, mock_validate_importer):
        ret = RepoSyncScheduleManager.list('repo1', 'importer1')

        mock_get_by_resource.assert_called_once_with(
            RepoImporter.build_resource_tag('repo1', 'importer1'))
        self.assertTrue(ret is mock_get_by_resource.return_value)
Esempio n. 6
0
    def test_calls_delete_resource(self, mock_delete_by):
        resource = RepoImporter.build_resource_tag(self.repo, self.importer)

        RepoSyncScheduleManager.delete_by_importer_id(self.repo, self.importer)

        mock_delete_by.assert_called_once_with(resource)
Esempio n. 7
0
    def test_list(self, mock_get_by_resource, mock_validate_importer):
        ret = RepoSyncScheduleManager.list("repo1", "importer1")

        mock_get_by_resource.assert_called_once_with(RepoImporter.build_resource_tag("repo1", "importer1"))
        self.assertTrue(ret is mock_get_by_resource.return_value)
Esempio n. 8
0
    def test_calls_delete_resource(self, mock_delete_by):
        resource = RepoImporter.build_resource_tag(self.repo, self.importer)

        RepoSyncScheduleManager.delete_by_importer_id(self.repo, self.importer)

        mock_delete_by.assert_called_once_with(resource)