Exemplo n.º 1
0
    def PUT(self, repo_group_id, distributor_id):
        params = self.params()

        distributor_config = params.get('distributor_config', None)

        if distributor_config is None:
            raise pulp_exceptions.MissingValue(['distributor_config'])

        distributor_manager = managers_factory.repo_group_distributor_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('update_distributor')
        ]

        call_request = CallRequest(distributor_manager.update_distributor_config,
                                   args=[repo_group_id, distributor_id, distributor_config],
                                   tags=tags,
                                   archive=True)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id)

        result = execution.execute(call_request)

        href = serialization.link.current_link_obj()
        result.update(href)

        return self.ok(result)
Exemplo n.º 2
0
 def DELETE(self, consumer_id, content_type):
     """
     Delete an association between the specified
     consumer and profile.  Designed to be idempotent.
     @param consumer_id: A consumer ID.
     @type consumer_id: str
     @param content_type: The content type ID.
     @type content_type: str
     @return: The deleted model object:
         {consumer_id:<str>, content_type:<str>, profile:<dict>}
         Or, None if bind does not exist.
     @rtype: dict
     """
     manager = managers.consumer_profile_manager()
     args = [
         consumer_id,
         content_type,
     ]
     tags = [
         resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
     ]
     call_request = CallRequest(manager.delete,
                                args=args,
                                tags=tags)
     call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
     return self.ok(execution.execute(call_request))
Exemplo n.º 3
0
    def POST(self, repo_group_id):
        # Params (validation will occur in the manager)
        params = self.params()
        distributor_type_id = params.get('distributor_type_id', None)
        distributor_config = params.get('distributor_config', None)
        distributor_id = params.get('distributor_id', None)

        distributor_manager = managers_factory.repo_group_distributor_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id),
                action_tag('add_distributor')]
        if distributor_id is not None:
            tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id))

        call_request = CallRequest(distributor_manager.add_distributor,
                                   [repo_group_id, distributor_type_id, distributor_config, distributor_id],
                                   weight=weight,
                                   tags=tags)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
        created = execution.execute(call_request)

        href = serialization.link.child_link_obj(created['id'])
        created.update(href)

        return self.created(href['_href'], created)
Exemplo n.º 4
0
    def POST(self, repo_id, distributor_id):
        distributor_manager = manager_factory.repo_distributor_manager()
        distributor_manager.get_distributor(repo_id, distributor_id)

        schedule_options = self.params()
        publish_options = {'override_config': schedule_options.pop('override_config', {})}

        schedule_manager = manager_factory.schedule_manager()
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
                action_tag('create_publish_schedule')]
        call_request = CallRequest(schedule_manager.create_publish_schedule,
                                   [repo_id, distributor_id, publish_options, schedule_options],
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_publish_obj(schedule)
        obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(obj['_href'], obj)
Exemplo n.º 5
0
    def POST(self):

        # Params
        params = self.params()
        login = params.get('login', None)
        resource = params.get('resource', None)
        operation_names = params.get('operations', None)
        
        _check_invalid_params({'login':login,
                               'resource':resource,
                               'operation_names':operation_names})
            
        operations = _get_operations(operation_names)
        
        # Grant permission synchronously
        permission_manager = managers.permission_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_PERMISSION_TYPE, resource),
                resource_tag(dispatch_constants.RESOURCE_USER_TYPE, login),
                action_tag('grant_permission_to_user')]

        call_request = CallRequest(permission_manager.grant,
                                   [resource, login, operations],
                                   tags=tags)
        call_request.reads_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
        call_request.updates_resource(dispatch_constants.RESOURCE_PERMISSION_TYPE, resource)
        
        return self.ok(execution.execute_sync(call_request))
Exemplo n.º 6
0
    def POST(self):
        """
        Creates an async task to regenerate content applicability data for given updated
        repositories.

        body {repo_criteria:<dict>}
        """
        body = self.params()
        repo_criteria = body.get('repo_criteria', None)
        if repo_criteria is None:
            raise exceptions.MissingValue('repo_criteria')
        try:
            repo_criteria = Criteria.from_client_input(repo_criteria)
        except:
            raise exceptions.InvalidValue('repo_criteria')

        manager = manager_factory.applicability_regeneration_manager()
        regeneration_tag = action_tag('applicability_regeneration')
        call_request = CallRequest(manager.regenerate_applicability_for_repos,
                                   [repo_criteria],
                                   tags = [regeneration_tag])
        # allow only one applicability regeneration task at a time
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_PROFILE_APPLICABILITY_TYPE,
                                      dispatch_constants.RESOURCE_ANY_ID)
        return execution.execute_async(self, call_request)
Exemplo n.º 7
0
    def POST(self, repo_id, importer_id):
        importer_manager = manager_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer_id != importer['id']:
            raise exceptions.MissingResource(importer=importer_id)

        schedule_options = self.params()
        sync_options = {'override_config': schedule_options.pop('override_config', {})}

        schedule_manager = manager_factory.schedule_manager()
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id),
                action_tag('create_sync_schedule')]
        call_request = CallRequest(schedule_manager.create_sync_schedule,
                                   [repo_id, importer_id, sync_options, schedule_options],
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id)
        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_sync_obj(schedule)
        obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(obj['_href'], obj)
Exemplo n.º 8
0
    def PUT(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        install_options = None
        units = schedule_data.pop('units', None)

        if 'options' in schedule_data:
            install_options = {'options': schedule_data.pop('options')}

        schedule_manager = managers.schedule_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id),
                action_tag('update_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.update_unit_uninstall_schedule,
                                   [consumer_id, schedule_id, units, install_options, schedule_data],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
        call_request.updates_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)

        execution.execute(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.current_link_obj())
        return self.ok(scheduled_obj)
Exemplo n.º 9
0
    def POST(self):
        body = self.params()
        id = body.get('id')
        display_name = body.get('display_name')
        description = body.get('description')
        notes = body.get('notes')

        manager = managers.consumer_manager()
        args = [id, display_name, description, notes]
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, id),
                action_tag('create')]

        call_request = CallRequest(manager.register,
                                   args,
                                   weight=weight,
                                   tags=tags)
        call_request.creates_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, id)

        call_report = CallReport.from_call_request(call_request)
        call_report.serialize_result = False

        consumer = execution.execute_sync(call_request, call_report)
        consumer.update({'_href': serialization.link.child_link_obj(consumer['id'])})
        return self.created(consumer['_href'], consumer)
Exemplo n.º 10
0
class FailTests(base.PulpServerTests):

    def setUp(self):
        self.call_request = CallRequest(fail)
        self.call_report = CallReport()
        self.task = Task(self.call_request, self.call_report)

    def tearDown(self):
        self.call_request = None
        self.call_report = None
        self.task = None

    def test_failed(self):
        self.task._run()
        self.assertTrue(self.call_report.state is dispatch_constants.CALL_ERROR_STATE,
                        self.call_report.state)
        self.assertTrue(isinstance(self.call_report.exception, RuntimeError),
                        str(type(self.call_report.exception)))
        self.assertTrue(isinstance(self.call_report.traceback, types.TracebackType))

    def test_error_execution_hook(self):
        hook = mock.Mock()
        self.call_request.add_life_cycle_callback(dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, hook)
        self.task._run()
        self.assertTrue(hook.call_count == 1)
        self.assertTrue(hook.call_args[0][0] is self.call_request)
        self.assertTrue(hook.call_args[0][1] is self.call_report)
Exemplo n.º 11
0
Arquivo: cud.py Projeto: ehelms/pulp
    def create_unit_install_schedule(self, consumer_id, units, install_options, schedule_data ):
        """
        Create a schedule for installing content units on a consumer.
        @param consumer_id: unique id for the consumer
        @param units: list of unit type and unit key dicts
        @param install_options: options to pass to the install manager
        @param schedule_data: scheduling data
        @return: schedule id
        """
        self._validate_consumer(consumer_id)
        self._validate_keys(install_options, _UNIT_INSTALL_OPTION_KEYS)
        if 'schedule' not in schedule_data:
            raise pulp_exceptions.MissingValue(['schedule'])

        manager = managers_factory.consumer_agent_manager()
        args = [consumer_id]
        kwargs = {'units': units,
                  'options': install_options.get('options', {})}
        weight = pulp_config.config.getint('tasks', 'consumer_content_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                action_tag('unit_install'), action_tag('scheduled_unit_install')]
        call_request = CallRequest(manager.install_content, args, kwargs, weight=weight, tags=tags, archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)

        scheduler = dispatch_factory.scheduler()
        schedule_id = scheduler.add(call_request, **schedule_data)
        return schedule_id
Exemplo n.º 12
0
    def POST(self):
        group_data = self.params()
        group_id = group_data.pop('id', None)
        if group_id is None:
            raise pulp_exceptions.MissingValue(['id'])
        display_name = group_data.pop('display_name', None)
        description = group_data.pop('description', None)
        repo_ids = group_data.pop('repo_ids', None)
        notes = group_data.pop('notes', None)
        distributors = group_data.pop('distributors', None)
        if group_data:
            raise pulp_exceptions.InvalidValue(group_data.keys())

        # Create the repo group
        manager = managers_factory.repo_group_manager()
        args = [group_id, display_name, description, repo_ids, notes]
        kwargs = {'distributor_list': distributors}
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, group_id)]

        call_request = CallRequest(manager.create_and_configure_repo_group, args, kwargs, weight=weight,
                                   tags=tags)
        call_request.creates_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, group_id)
        group = execution.execute_sync(call_request)
        group.update(serialization.link.child_link_obj(group['id']))
        group['distributors'] = distributors or []
        return self.created(group['_href'], group)
Exemplo n.º 13
0
    def POST(self):

        # Pull all the user data
        user_data = self.params()
        login = user_data.get('login', None)
        password = user_data.get('password', None)
        name = user_data.get('name', None)

        # Creation
        manager = managers.user_manager()
        args = [login]
        kwargs = {'password': password,
                  'name': name}
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_USER_TYPE, login),
                action_tag('create')]
        call_request = CallRequest(manager.create_user,
                                   args,
                                   kwargs,
                                   weight=weight,
                                   tags=tags,
                                   kwarg_blacklist=['password'])
        call_request.creates_resource(dispatch_constants.RESOURCE_USER_TYPE, login)
        user = execution.execute_sync(call_request)
        user_link = serialization.link.child_link_obj(login)
        user.update(user_link)

        # Grant permissions
        permission_manager = managers.permission_manager()
        permission_manager.grant_automatic_permissions_for_resource(user_link['_href'])

        return self.created(login, user)
Exemplo n.º 14
0
 def test_control_hooks(self):
     call_request = CallRequest(function)
     for key in dispatch_constants.CALL_CONTROL_HOOKS:
         self.assertTrue(call_request.control_hooks[key] is None)
     for key in dispatch_constants.CALL_CONTROL_HOOKS:
         call_request.add_control_hook(key, function)
         self.assertTrue(call_request.control_hooks[key] is function)
Exemplo n.º 15
0
def consumer_content_update_itinerary(consumer_id, units, options):
    """
    Create an itinerary for consumer content update.
    @param consumer_id: unique id of the consumer
    @type consumer_id: str
    @param units: units to update
    @type units: list or tuple
    @param options: options to pass to the update manager
    @type options: dict or None
    @return: list of call requests
    @rtype: list
    """
    manager = managers_factory.consumer_agent_manager()
    args = [consumer_id]
    kwargs = {'units': units, 'options': options}
    weight = pulp_config.config.getint('tasks', 'consumer_content_weight')
    tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
            action_tag('unit_update')]
    call_request = CallRequest(
        manager.update_content,
        args,
        kwargs,
        weight=weight,
        tags=tags,
        archive=True,
        asynchronous=True,
        kwarg_blacklist=['options'])
    call_request.add_control_hook(dispatch_constants.CALL_CANCEL_CONTROL_HOOK, cancel_agent_request)
    call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
    return [call_request]
Exemplo n.º 16
0
    def POST(self, repo_id):
        """
        Import an uploaded unit into the given repository.

        :param repo_id: The id of the repository the upload should be imported into
        :type  repo_id: basestring
        :return:        A json serialized dictionary with two keys. 'success_flag' indexes a boolean
                        value that indicates whether the import was successful, and 'summary' will
                        contain the summary as reported by the Importer.
        :rtype:         basestring
        """
        # Collect user input
        params = self.params()
        upload_id = params['upload_id']
        unit_type_id = params['unit_type_id']
        unit_key = params['unit_key']
        unit_metadata = params.pop('unit_metadata', None)

        # Coordinator configuration
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                action_tag('import_upload')]

        upload_manager = manager_factory.content_upload_manager()
        call_request = CallRequest(upload_manager.import_uploaded_unit,
            [repo_id, unit_type_id, unit_key, unit_metadata, upload_id],
            tags=tags, archive=True)
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)

        report = execution.execute(call_request)
        return self.ok(report)
Exemplo n.º 17
0
    def POST(self, repo_id):
        # Params
        params = self.params()
        query = params.get('criteria', {})
        options = params.get('options', {})
        timeout = params.get('timeout', 60)

        try:
            criteria = UnitAssociationCriteria.from_client_input(query)
        except:
            _LOG.error('Error parsing association criteria [%s]' % query)
            raise exceptions.PulpDataException(), None, sys.exc_info()[2]

        try:
            timeout = int(timeout)
        except ValueError:
            raise exceptions.InvalidValue(['timeout']), None, sys.exc_info()[2]

        # Coordinator configuration
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                action_tag('resolve_dependencies')]

        dependency_manager = manager_factory.dependency_manager()
        call_request = CallRequest(dependency_manager.resolve_dependencies_by_criteria,
                                   [repo_id, criteria, options],
                                   tags=tags, archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        return execution.execute_sync_ok(self, call_request, timeout=timedelta(seconds=timeout))
Exemplo n.º 18
0
    def POST(self):

        # Pull all the roles data
        role_data = self.params()
        role_id = role_data.get('role_id', None)
        display_name = role_data.get('display_name', None)
        description = role_data.get('description', None)

        # Creation
        manager = managers.role_manager()
        args = [role_id, display_name, description]
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
                action_tag('create')]
        call_request = CallRequest(manager.create_role,
                                   args,
                                   weight=weight,
                                   tags=tags)
        call_request.creates_resource(dispatch_constants.RESOURCE_ROLE_TYPE, role_id)

        role = execution.execute_sync(call_request)
        role_link = serialization.link.child_link_obj(role_id)
        role.update(role_link)
        
        return self.created(role_id, role)
Exemplo n.º 19
0
    def POST(self, repo_id):

        # Params (validation will occur in the manager)
        params = self.params()
        importer_type = params.get('importer_type_id', None)
        importer_config = params.get('importer_config', None)

        if importer_type is None:
            _LOG.error('Missing importer type adding importer to repository [%s]' % repo_id)
            raise exceptions.MissingValue(['importer_type'])

        # Note: If an importer exists, it's removed, so no need to handle 409s.
        # Note: If the plugin raises an exception during initialization, let it
        #  bubble up and be handled like any other 500.

        importer_manager = manager_factory.repo_importer_manager()
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                action_tag('add_importer')]

        call_request = CallRequest(importer_manager.set_importer,
                                   [repo_id, importer_type],
                                   {'repo_plugin_config': importer_config},
                                   weight=weight,
                                   tags=tags,
                                   kwarg_blacklist=['repo_plugin_config'])
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        return execution.execute_sync_created(self, call_request, 'importer')
Exemplo n.º 20
0
    def POST(self, consumer_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        units = schedule_data.pop('units', None)
        uninstall_options = {'options': schedule_data.pop('options', {})}

        if not units:
            raise MissingValue(['units'])

        schedule_manager = managers.schedule_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                action_tag('create_unit_uninstall_schedule')]

        call_request = CallRequest(schedule_manager.create_unit_uninstall_schedule,
                                   [consumer_id, units, uninstall_options, schedule_data],
                                   weight=weight,
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)

        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(scheduled_call)
        scheduled_obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(scheduled_obj['_href'], scheduled_obj)
Exemplo n.º 21
0
    def POST(self, repo_id):

        # Params (validation will occur in the manager)
        params = self.params()
        distributor_type = params.get('distributor_type_id', None)
        distributor_config = params.get('distributor_config', None)
        distributor_id = params.get('distributor_id', None)
        auto_publish = params.get('auto_publish', False)

        # Update the repo
        distributor_manager = manager_factory.repo_distributor_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
                action_tag('add_distributor')]
        if distributor_id is not None:
            tags.append(resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id))
        call_request = CallRequest(distributor_manager.add_distributor,
                                   [repo_id, distributor_type],
                                   {'repo_plugin_config': distributor_config, 'auto_publish': auto_publish,
                                    'distributor_id': distributor_id},
                                   weight=weight,
                                   tags=tags,
                                   kwarg_blacklist=['repo_plugin_config'])
        call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        if distributor_id is not None:
            call_request.creates_resource(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id)
        return execution.execute_created(self, call_request, distributor_id)
Exemplo n.º 22
0
    def PUT(self, consumer_id, content_type):
        """
        Update the association of a profile with a consumer by content type ID.
        @param consumer_id: A consumer ID.
        @type consumer_id: str
        @param content_type: A content unit type ID.
        @type content_type: str
        @return: The updated model object:
            {consumer_id:<str>, content_type:<str>, profile:<dict>}
        @rtype: dict
        """
        body = self.params()
        profile = body.get('profile')

        manager = managers.consumer_profile_manager()
        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_CONTENT_UNIT_TYPE, content_type),
                action_tag('profile_update')]

        call_request = CallRequest(manager.update,
                                   [consumer_id, content_type],
                                   {'profile': profile},
                                   tags=tags,
                                   weight=0,
                                   kwarg_blacklist=['profile'])
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)

        call_report = CallReport.from_call_request(call_request)
        call_report.serialize_result = False

        consumer = execution.execute_sync(call_request, call_report)
        link = serialization.link.child_link_obj(consumer_id, content_type)
        consumer.update(link)

        return self.ok(consumer)
Exemplo n.º 23
0
Arquivo: repo.py Projeto: ashcrow/pulp
def publish_itinerary(repo_id, distributor_id, overrides=None):
    """
    Create an itinerary for repo publish.
    @param repo_id: id of the repo to publish
    @type repo_id: str
    @param distributor_id: id of the distributor to use for the repo publish
    @type distributor_id: str
    @param overrides: dictionary of options to pass to the publish manager
    @type overrides: dict or None
    @return: list of call requests
    @rtype: list
    """

    repo_publish_manager = manager_factory.repo_publish_manager()
    weight = pulp_config.config.getint('tasks', 'publish_weight')
    tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            action_tag('publish')]

    call_request = CallRequest(repo_publish_manager.publish,
                               [repo_id, distributor_id],
                               {'publish_config_override': overrides},
                               weight=weight,
                               tags=tags,
                               archive=True)

    call_request.updates_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)

    return [call_request]
Exemplo n.º 24
0
    def POST(self):

        # Params
        params = self.params()
        role_id = params.get('role_id', None)
        resource = params.get('resource', None)
        operation_names = params.get('operations', None)
        
        _check_invalid_params({'role_id':role_id,
                               'resource':resource,
                               'operation_names':operation_names})

        operations = _get_operations(operation_names)
        
        # Grant permission synchronously
        role_manager = managers.role_manager()
        
        tags = [resource_tag(dispatch_constants.RESOURCE_ROLE_TYPE, role_id),
                action_tag('remove_permission_from_role')]

        call_request = CallRequest(role_manager.remove_permissions_from_role,
                                   [role_id, resource, operations],
                                   tags=tags)
        call_request.updates_resource(dispatch_constants.RESOURCE_ROLE_TYPE, role_id)
        
        return self.ok(execution.execute_sync(call_request))
Exemplo n.º 25
0
 def test_execution_hooks(self):
     call_request = CallRequest(function)
     for key in dispatch_constants.CALL_LIFE_CYCLE_CALLBACKS:
         self.assertTrue(isinstance(call_request.execution_hooks[key], list))
         self.assertTrue(len(call_request.execution_hooks[key]) == 0)
         call_request.add_life_cycle_callback(key, function)
         self.assertTrue(isinstance(call_request.execution_hooks[key], list))
         self.assertTrue(len(call_request.execution_hooks[key]) == 1)
Exemplo n.º 26
0
 def DELETE(self, repo_group_id):
     manager = managers_factory.repo_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)]
     call_request = CallRequest(manager.delete_repo_group,
                                [repo_group_id],
                                tags=tags)
     call_request.deletes_resource(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id)
     return execution.execute_ok(self, call_request)
Exemplo n.º 27
0
 def test_serialize_deserialize(self):
     args = ["fee", "fie", "foe", "foo"]
     kwargs = {"one": "foo", "two": "bar", "three": "baz"}
     call_request = CallRequest(function, args, kwargs)
     data = call_request.serialize()
     self.assertTrue(isinstance(data, dict))
     call_request_2 = CallRequest.deserialize(data)
     self.assertTrue(isinstance(call_request_2, CallRequest), str(type(call_request_2)))
Exemplo n.º 28
0
 def test_serialize_deserialize(self):
     args = ['fee', 'fie', 'foe', 'foo']
     kwargs = {'one': 'foo', 'two': 'bar', 'three': 'baz'}
     call_request = CallRequest(function, args, kwargs)
     data = call_request.serialize()
     self.assertTrue(isinstance(data, dict))
     call_request_2 = CallRequest.deserialize(data)
     self.assertTrue(isinstance(call_request_2, CallRequest), str(type(call_request_2)))
Exemplo n.º 29
0
 def DELETE(self, consumer_group_id):
     manager = managers_factory.consumer_group_manager()
     tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)]
     call_request = CallRequest(manager.delete_consumer_group,
                                [consumer_group_id],
                                tags=tags)
     call_request.deletes_resource(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, consumer_group_id)
     return execution.execute_ok(self, call_request)
Exemplo n.º 30
0
 def test_serialize_deserialize_with_execution_hook(self):
     key = dispatch_constants.CALL_CANCEL_LIFE_CYCLE_CALLBACK
     call_request = CallRequest(function)
     call_request.add_life_cycle_callback(key, function)
     data = call_request.serialize()
     self.assertTrue(isinstance(data, dict))
     call_request_2 = CallRequest.deserialize(data)
     self.assertTrue(isinstance(call_request_2, CallRequest))
     self.assertTrue(call_request_2.execution_hooks[key][0] == function)
Exemplo n.º 31
0
    def PUT(self, repo_id, importer_id):

        # Params (validation will occur in the manager)
        params = self.params()
        importer_config = params.get('importer_config', None)

        if importer_config is None:
            _LOG.error(
                'Missing configuration updating importer for repository [%s]' %
                repo_id)
            raise exceptions.MissingValue(['importer_config'])

        importer_manager = manager_factory.repo_importer_manager()
        resources = {
            dispatch_constants.RESOURCE_REPOSITORY_TYPE: {
                repo_id: dispatch_constants.RESOURCE_UPDATE_OPERATION
            },
            dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE: {
                importer_id: dispatch_constants.RESOURCE_UPDATE_OPERATION
            }
        }
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE,
                         importer_id),
            action_tag('update_importer')
        ]
        call_request = CallRequest(importer_manager.update_importer_config,
                                   [repo_id],
                                   {'importer_config': importer_config},
                                   resources=resources,
                                   tags=tags,
                                   archive=True,
                                   kwarg_blacklist=['importer_config'])
        result = execution.execute(call_request)
        return self.ok(result)
Exemplo n.º 32
0
    def DELETE(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_manager = managers.schedule_manager()

        tags = [resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
                resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id),
                action_tag('delete_unit_install_schedule')]

        call_request = CallRequest(schedule_manager.delete_unit_install_schedule,
                                   [consumer_id, schedule_id],
                                   tags=tags,
                                   archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id)
        call_request.deletes_resource(dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)

        result = execution.execute(call_request)
        return self.ok(result)
Exemplo n.º 33
0
    def PUT(self, consumer_id, schedule_id):
        consumer_manager = managers.consumer_manager()
        consumer_manager.get_consumer(consumer_id)

        schedule_data = self.params()
        install_options = None
        units = schedule_data.pop('units', None)

        if 'options' in schedule_data:
            install_options = {'options': schedule_data.pop('options')}

        schedule_manager = managers.schedule_manager()

        tags = [
            resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                         consumer_id),
            resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE,
                         schedule_id),
            action_tag('update_unit_update_schedule')
        ]

        call_request = CallRequest(
            schedule_manager.update_unit_update_schedule,
            [consumer_id, schedule_id, units, install_options, schedule_data],
            tags=tags,
            archive=True)
        call_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                                    consumer_id)
        call_request.updates_resource(
            dispatch_constants.RESOURCE_SCHEDULE_TYPE, schedule_id)

        execution.execute(call_request)

        scheduler = dispatch_factory.scheduler()
        scheduled_call = scheduler.get(schedule_id)

        scheduled_obj = serialization.dispatch.scheduled_unit_management_obj(
            scheduled_call)
        scheduled_obj.update(serialization.link.current_link_obj())
        return self.ok(scheduled_obj)
Exemplo n.º 34
0
    def POST(self, repo_id):

        # Params (validation will occur in the manager)
        params = self.params()
        distributor_type = params.get('distributor_type_id', None)
        distributor_config = params.get('distributor_config', None)
        distributor_id = params.get('distributor_id', None)
        auto_publish = params.get('auto_publish', False)

        # Update the repo
        distributor_manager = manager_factory.repo_distributor_manager()

        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            action_tag('add_distributor')
        ]
        if distributor_id is not None:
            tags.append(
                resource_tag(
                    dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                    distributor_id))
        call_request = CallRequest(
            distributor_manager.add_distributor, [repo_id, distributor_type], {
                'repo_plugin_config': distributor_config,
                'auto_publish': auto_publish,
                'distributor_id': distributor_id
            },
            weight=weight,
            tags=tags,
            kwarg_blacklist=['repo_plugin_config'])
        call_request.updates_resource(
            dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        if distributor_id is not None:
            call_request.creates_resource(
                dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                distributor_id)
        return execution.execute_created(self, call_request, distributor_id)
Exemplo n.º 35
0
    def POST(self, repo_id, importer_id):
        importer_manager = manager_factory.repo_importer_manager()
        importer = importer_manager.get_importer(repo_id)
        if importer_id != importer['id']:
            raise exceptions.MissingResource(importer=importer_id)

        schedule_options = self.params()
        sync_options = {
            'override_config': schedule_options.pop('override_config', {})
        }

        schedule_manager = manager_factory.schedule_manager()
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE,
                         importer_id),
            action_tag('create_sync_schedule')
        ]
        call_request = CallRequest(
            schedule_manager.create_sync_schedule,
            [repo_id, importer_id, sync_options, schedule_options],
            weight=weight,
            tags=tags,
            archive=True)
        call_request.reads_resource(
            dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.updates_resource(
            dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id)
        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_sync_obj(schedule)
        obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(obj['_href'], obj)
Exemplo n.º 36
0
    def POST(self, repo_id, distributor_id):
        distributor_manager = manager_factory.repo_distributor_manager()
        distributor_manager.get_distributor(repo_id, distributor_id)

        schedule_options = self.params()
        publish_options = {
            'override_config': schedule_options.pop('override_config', {})
        }

        schedule_manager = manager_factory.schedule_manager()
        weight = pulp_config.config.getint('tasks', 'create_weight')
        tags = [
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(
                dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                distributor_id),
            action_tag('create_publish_schedule')
        ]
        call_request = CallRequest(
            schedule_manager.create_publish_schedule,
            [repo_id, distributor_id, publish_options, schedule_options],
            weight=weight,
            tags=tags,
            archive=True)
        call_request.reads_resource(
            dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id)
        call_request.updates_resource(
            dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
            distributor_id)
        schedule_id = execution.execute_sync(call_request)

        scheduler = dispatch_factory.scheduler()
        schedule = scheduler.get(schedule_id)
        obj = serialization.dispatch.scheduled_publish_obj(schedule)
        obj.update(serialization.link.child_link_obj(schedule_id))
        return self.created(obj['_href'], obj)
Exemplo n.º 37
0
 def setUp(self):
     self.call_request = CallRequest(Call(), call_args, call_kwargs)
     self.call_report = CallReport()
     self.task = AsyncTask(self.call_request, self.call_report)
Exemplo n.º 38
0
 def test__instantiation(self):
     call = Functor()
     try:
         call_request = CallRequest(call)
     except Exception, e:
         self.fail(e.message)
Exemplo n.º 39
0
 def setUp(self):
     super(TaskTests, self).setUp()
     self.call_request = CallRequest(Call(), call_args, call_kwargs)
     self.call_report = CallReport()
     self.task = Task(self.call_request, self.call_report)
Exemplo n.º 40
0
def _sync_schedules(v1_database, v2_database, report):
    v1_repo_collection = v1_database.repos
    v2_repo_importer_collection = v2_database.repo_importers
    v2_scheduled_call_collection = v2_database.scheduled_calls

    # ugly hack to find out which repos have already been scheduled
    # necessary because $size is not a meta-query and doesn't support $gt, etc
    repos_without_schedules = v2_repo_importer_collection.find(
        {'scheduled_syncs': {
            '$size': 0
        }}, fields=['repo_id'])

    repo_ids_without_schedules = [
        r['repo_id'] for r in repos_without_schedules
    ]

    repos_with_schedules = v2_repo_importer_collection.find(
        {'repo_id': {
            '$nin': repo_ids_without_schedules
        }}, fields=['repo_id'])

    repo_ids_with_schedules = [r['repo_id'] for r in repos_with_schedules]

    repos_to_schedule = v1_repo_collection.find(
        {
            'id': {
                '$nin': repo_ids_with_schedules
            },
            'sync_schedule': {
                '$ne': None
            }
        },
        fields=['id', 'sync_schedule', 'sync_options', 'last_sync'])

    for repo in repos_to_schedule:

        if repo['id'] not in repo_ids_without_schedules:
            report.error('Repository [%s] not found in the v2 database.'
                         'sync scheduling being canceled.' % repo['id'])
            return False

        args = [repo['id']]
        kwargs = {'overrides': {}}
        call_request = CallRequest(sync_with_auto_publish_itinerary,
                                   args,
                                   kwargs,
                                   principal=SystemUser())

        scheduled_call_document = {
            '_id': ObjectId(),
            'id': None,
            'serialized_call_request': None,
            'schedule': repo['sync_schedule'],
            'failure_threshold': None,
            'consecutive_failures': 0,
            'first_run': None,
            'last_run': None,
            'next_run': None,
            'remaining_runs': None,
            'enabled': True
        }

        scheduled_call_document['id'] = str(scheduled_call_document['_id'])

        schedule_tag = resource_tag(dispatch_constants.RESOURCE_SCHEDULE_TYPE,
                                    scheduled_call_document['id'])
        call_request.tags.append(schedule_tag)

        scheduled_call_document[
            'serialized_call_request'] = call_request.serialize()

        if isinstance(repo['sync_options'], dict):
            scheduled_call_document['failure_threshold'] = repo[
                'sync_options'].get('failure_threshold', None)

        interval, start, recurrences = dateutils.parse_iso8601_interval(
            scheduled_call_document['schedule'])

        scheduled_call_document['first_run'] = start or datetime.utcnow()
        scheduled_call_document['remaining_runs'] = recurrences
        scheduled_call_document['next_run'] = _calculate_next_run(
            scheduled_call_document)

        if repo['last_sync'] is not None:
            scheduled_call_document[
                'last_run'] = dateutils.to_naive_utc_datetime(
                    dateutils.parse_iso8601_datetime(repo['last_sync']))

        v2_scheduled_call_collection.insert(scheduled_call_document, safe=True)
        v2_repo_importer_collection.update(
            {'repo_id': repo['id']},
            {'$push': {
                'scheduled_syncs': scheduled_call_document['id']
            }},
            safe=True)

    return True
Exemplo n.º 41
0
def unbind_itinerary(consumer_id, repo_id, distributor_id, options):
    """
    Get the unbind itinerary.
    The tasks in the itinerary are as follows:
      1. Mark the binding as (deleted) on the server.
      2. Request that the consumer (agent) perform the unbind.
      3. Delete the binding on the server.
    @param consumer_id: A consumer ID.
    @type consumer_id: str
    @param repo_id: A repository ID.
    @type repo_id: str
    @param distributor_id: A distributor ID.
    @type distributor_id: str
    @param options: Unbind options passed to the agent handler.
    @type options: dict
    @return: A list of call_requests.
    @rtype list
    """

    call_requests = []
    bind_manager = managers.consumer_bind_manager()
    agent_manager = managers.consumer_agent_manager()

    # unbind

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
    ]

    unbind_request = CallRequest(bind_manager.unbind, args=args, tags=tags)
    unbind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                                  consumer_id)
    call_requests.append(unbind_request)

    # notify agent

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_AGENT_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        options,
    ]

    agent_request = CallRequest(agent_manager.unbind,
                                args,
                                weight=0,
                                asynchronous=True,
                                archive=True,
                                tags=tags)

    agent_request.add_life_cycle_callback(
        dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, unbind_succeeded)

    agent_request.add_life_cycle_callback(
        dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, unbind_failed)

    call_requests.append(agent_request)

    agent_request.depends_on(unbind_request.id)

    # delete the binding

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_DELETE_BINDING)
    ]

    args = [consumer_id, repo_id, distributor_id]

    delete_request = CallRequest(bind_manager.delete, args=args, tags=tags)
    unbind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                                  consumer_id)
    call_requests.append(delete_request)

    delete_request.depends_on(agent_request.id)

    return call_requests
Exemplo n.º 42
0
def forced_unbind_itinerary(consumer_id, repo_id, distributor_id, options):
    """
    Get the unbind itinerary.
    A forced unbind immediately deletes the binding instead
    of marking it deleted and going through that lifecycle.
    It is intended to be used to clean up orphaned bindings
    caused by failed/unconfirmed unbind actions on the consumer.
    The itinerary is:
      1. Delete the binding on the server.
      2. Request that the consumer (agent) perform the unbind.
    @param consumer_id: A consumer ID.
    @type consumer_id: str
    @param repo_id: A repository ID.
    @type repo_id: str
    @param distributor_id: A distributor ID.
    @type distributor_id: str
    @param options: Unbind options passed to the agent handler.
    @type options: dict
    @return: A list of call_requests
    @rtype list
    """

    call_requests = []
    bind_manager = managers.consumer_bind_manager()
    agent_manager = managers.consumer_agent_manager()

    # unbind

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        True,
    ]

    delete_request = CallRequest(bind_manager.delete, args=args, tags=tags)

    delete_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                                  consumer_id)

    call_requests.append(delete_request)

    # notify agent

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_AGENT_UNBIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        options,
    ]

    agent_request = CallRequest(agent_manager.unbind,
                                args,
                                weight=0,
                                asynchronous=True,
                                archive=True,
                                tags=tags)

    call_requests.append(agent_request)

    agent_request.depends_on(delete_request.id)

    return call_requests
Exemplo n.º 43
0
 def gen_async_task(self, call=call):
     return AsyncTask(CallRequest(call))
Exemplo n.º 44
0
 def setUp(self):
     self.call_request = CallRequest(fail)
     self.call_report = CallReport()
     self.task = Task(self.call_request, self.call_report)
Exemplo n.º 45
0
def bind_itinerary(consumer_id, repo_id, distributor_id, notify_agent,
                   binding_config, agent_options):
    """
    Get the bind itinerary:
      1. Create the binding on the server.
      2. Request that the consumer (agent) perform the bind.
    @param consumer_id: A consumer ID.
    @type consumer_id: str
    @param repo_id: A repository ID.
    @type repo_id: str
    @param distributor_id: A distributor ID.
    @type distributor_id: str
    @param agent_options: Bind options passed to the agent handler.
    @type agent_options: dict
    @param notify_agent: indicates if the agent should be sent a message about the new binding
    @type  notify_agent: bool
    @param binding_config: configuration options to use when generating the payload for this binding

    @return: A list of call_requests.
    @rtype list
    """

    call_requests = []
    bind_manager = managers.consumer_bind_manager()
    agent_manager = managers.consumer_agent_manager()

    # bind

    tags = [
        resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE, consumer_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
        resource_tag(dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                     distributor_id),
        action_tag(ACTION_BIND)
    ]

    args = [
        consumer_id,
        repo_id,
        distributor_id,
        notify_agent,
        binding_config,
    ]

    bind_request = CallRequest(bind_manager.bind, args, weight=0, tags=tags)

    bind_request.reads_resource(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                                consumer_id)
    bind_request.reads_resource(dispatch_constants.RESOURCE_REPOSITORY_TYPE,
                                repo_id)
    bind_request.reads_resource(
        dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
        distributor_id)

    call_requests.append(bind_request)

    # notify agent

    if notify_agent:
        tags = [
            resource_tag(dispatch_constants.RESOURCE_CONSUMER_TYPE,
                         consumer_id),
            resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id),
            resource_tag(
                dispatch_constants.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE,
                distributor_id),
            action_tag(ACTION_AGENT_BIND)
        ]

        args = [consumer_id, repo_id, distributor_id, agent_options]

        agent_request = CallRequest(agent_manager.bind,
                                    args,
                                    weight=0,
                                    asynchronous=True,
                                    archive=True,
                                    tags=tags)

        agent_request.add_life_cycle_callback(
            dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK,
            bind_succeeded)

        agent_request.add_life_cycle_callback(
            dispatch_constants.CALL_FAILURE_LIFE_CYCLE_CALLBACK, bind_failed)

        call_requests.append(agent_request)

        agent_request.depends_on(bind_request.id)

    return call_requests
Exemplo n.º 46
0
 def gen_task(self, call=call):
     return Task(CallRequest(call))
Exemplo n.º 47
0
 def test_set_principal(self):
     user = User('test-user', 'test-password')
     task = Task(
         CallRequest(self.principal_manager.get_principal, principal=user))
     task._run()
     self.assertEqual(user, task.call_report.result)
Exemplo n.º 48
0
 def test_eq(self):
     call_request = CallRequest(mock.Mock())
     task_1 = Task(call_request)
     task_2 = Task(call_request)
     self.assertTrue(task_1 == task_1)
     self.assertTrue(task_1 == task_2)
Exemplo n.º 49
0
class TaskTests(base.PulpServerTests):
    def setUp(self):
        super(TaskTests, self).setUp()
        self.call_request = CallRequest(Call(), call_args, call_kwargs)
        self.call_report = CallReport()
        self.task = Task(self.call_request, self.call_report)

    def tearDown(self):
        super(TaskTests, self).tearDown()
        self.call_request = None
        self.call_report = None
        self.task = None

    def test_run(self):
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_WAITING_STATE)
        self.task._run()
        self.assertTrue(self.call_request.call.call_count == 1)
        self.assertTrue(
            self.call_request.call.call_args[0] == call_args, '%s != %s' %
            (str(self.call_request.call.call_args[0]), str(call_args)))
        self.assertTrue(self.call_request.call.call_args[1] == call_kwargs)
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_FINISHED_STATE)

    def test_complete(self):
        now = datetime.datetime.now(dateutils.utc_tz())
        self.task._run()
        self.assertTrue(self.call_report.finish_time > now)

    def test_complete_callback(self):
        callback = mock.Mock()
        self.task.complete_callback = callback
        self.task._run()
        self.assertTrue(callback.call_count == 1)
        self.assertTrue(callback.call_args[0][0] is self.task)

    def test_cancel_control_hook(self):
        callback = mock.Mock()
        self.call_request.add_control_hook(
            dispatch_constants.CALL_CANCEL_CONTROL_HOOK, callback)
        self.call_report.state = dispatch_constants.CALL_RUNNING_STATE
        try:
            self.task.cancel()
        except:
            self.fail(traceback.format_exc())
        self.assertTrue(callback.call_count == 1)
        self.assertTrue(callback.call_args[0][0] is self.call_request)
        self.assertTrue(callback.call_args[0][1] is self.call_report)
        self.assertTrue(
            self.call_report.state is dispatch_constants.CALL_CANCELED_STATE,
            self.call_report.state)

    def test_finish_execution_hook(self):
        hooks = [mock.Mock(), mock.Mock()]
        for h in hooks:
            self.call_request.add_life_cycle_callback(
                dispatch_constants.CALL_SUCCESS_LIFE_CYCLE_CALLBACK, h)
        self.task._run()
        for h in hooks:
            self.assertTrue(h.call_count == 1)
            self.assertTrue(h.call_args[0][0] is self.call_request)
            self.assertTrue(h.call_args[0][1] is self.call_report)

    def test_complete_execution_hook(self):
        hooks = [mock.Mock(), mock.Mock()]
        for h in hooks:
            self.call_request.add_life_cycle_callback(
                dispatch_constants.CALL_COMPLETE_LIFE_CYCLE_CALLBACK, h)
        self.task._run()
        for h in hooks:
            self.assertTrue(h.call_count == 1)
Exemplo n.º 50
0
 def test_method_str(self):
     name = 'Class.method'
     instance = Class()
     call_request = CallRequest(instance.method)
     self.assertTrue(call_request.callable_name() == name)
Exemplo n.º 51
0
 def test_function_str(self):
     name = 'function'
     call_request = CallRequest(function)
     self.assertTrue(call_request.callable_name() == name)