Esempio n. 1
0
 def __init__(self, consumer):
     context = Context(consumer)
     # replyto
     context.replyto = dict(systemid='pulp',
                            method='POST',
                            path='/v2/agent/%s/reply/' % context.uuid)
     # context
     self.context = context
Esempio n. 2
0
 def __init__(self, consumer):
     context = Context(consumer)
     # replyto
     context.replyto = dict(
         systemid='pulp',
         method='POST',
         path='/v2/agent/%s/reply/' % context.uuid)
     # context
     self.context = context
Esempio n. 3
0
    def bind(consumer_id, repo_id, distributor_id, options):
        """
        Request the agent to perform the specified bind. This method will be called
        after the server-side representation of the binding has been created.

        :param consumer_id: The 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: The options are handler specific.
        :type options: dict
        :return: The task created by the bind
        :rtype: dict
        """
        # track agent operations using a pseudo task
        task_id = str(uuid4())
        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONSUMER_TYPE, consumer_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
            tags.action_tag(tags.ACTION_AGENT_BIND)
        ]
        task = TaskStatus(task_id, 'agent', tags=task_tags).save()

        # agent request
        consumer_manager = managers.consumer_manager()
        binding_manager = managers.consumer_bind_manager()
        consumer = consumer_manager.get_consumer(consumer_id)
        binding = binding_manager.get_bind(consumer_id, repo_id, distributor_id)
        agent_bindings = AgentManager._bindings([binding])
        context = Context(
            consumer,
            task_id=task_id,
            action='bind',
            consumer_id=consumer_id,
            repo_id=repo_id,
            distributor_id=distributor_id)
        agent = PulpAgent()
        agent.consumer.bind(context, agent_bindings, options)

        # bind action tracking
        consumer_manager = managers.consumer_bind_manager()
        consumer_manager.action_pending(
            consumer_id,
            repo_id,
            distributor_id,
            Bind.Action.BIND,
            task_id)

        return task
Esempio n. 4
0
 def cancel_request(self, consumer_id, task_id):
     """
     Cancel an agent request associated with the specified task ID.
     :param consumer_id: The consumer ID.
     :type consumer_id: str
     :param: task_id: The task ID associated with the request.
     :type: str
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     context = Context(consumer)
     agent = PulpAgent()
     agent.cancel(context, task_id)
Esempio n. 5
0
 def unregistered(self, consumer_id):
     """
     Notification that a consumer (agent) has
     been unregistered.  This ensure that all registration
     artifacts have been cleaned up.
     :param consumer_id: The consumer ID.
     :type consumer_id: str
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     context = Context(consumer)
     agent = PulpAgent()
     agent.consumer.unregistered(context)
Esempio n. 6
0
    def unbind(consumer_id, repo_id, distributor_id, options):
        """
        Request the agent to perform the specified unbind.
        :param consumer_id: The 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: The options are handler specific.
        :type options: dict
        :return: A task ID that may be used to track the agent request.
        :rtype: str
        """
        # track agent operations using a pseudo task
        task_id = str(uuid4())
        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONSUMER_TYPE, consumer_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id),
            tags.resource_tag(tags.RESOURCE_REPOSITORY_DISTRIBUTOR_TYPE, distributor_id),
            tags.action_tag(tags.ACTION_AGENT_UNBIND)
        ]
        task = TaskStatus(task_id, 'agent', tags=task_tags).save()

        # agent request
        manager = managers.consumer_manager()
        consumer = manager.get_consumer(consumer_id)
        binding = dict(repo_id=repo_id, distributor_id=distributor_id)
        bindings = AgentManager._unbindings([binding])
        context = Context(
            consumer,
            task_id=task_id,
            action='unbind',
            consumer_id=consumer_id,
            repo_id=repo_id,
            distributor_id=distributor_id)
        agent = PulpAgent()
        agent.consumer.unbind(context, bindings, options)

        # unbind action tracking
        manager = managers.consumer_bind_manager()
        manager.action_pending(
            consumer_id,
            repo_id,
            distributor_id,
            Bind.Action.UNBIND,
            task_id)

        return task
Esempio n. 7
0
    def test_enter_exit(self, queue, add_connector, load, get_url):
        _id = 'test-db_id'
        consumer = {'_id': _id, 'id': 'test-consumer'}
        details = {'task_id': '3456'}

        get_url.return_value = 'amqp://host'
        load.return_value = None

        # test context
        with Context(consumer, **details) as connector:
            pass

        # validation
        add_connector.assert_called_once_with()
        queue.assert_called_once_with(connector.address, connector.url)
        queue.return_value.declare.assert_called_once_with()
Esempio n. 8
0
    def test_context(self, load, get_url):
        _id = 'test-db_id'
        consumer = {'_id': _id, 'id': 'test-consumer'}
        details = {'task_id': '3456'}

        # test context

        context = Context(consumer, **details)

        # validation
        load.assert_called_once_with()

        self.assertEqual(context.address, 'pulp.agent.%s' % consumer['id'])
        self.assertEqual(context.url, get_url.return_value)
        self.assertEqual(context.secret, _id)
        self.assertEqual(context.details, details)
        self.assertEqual(context.reply_queue, ReplyHandler.REPLY_QUEUE)
        self.assertTrue(isinstance(context.authenticator, Authenticator))
        self.assertTrue(load.called)
Esempio n. 9
0
    def uninstall_content(consumer_id, units, options):
        """
        Uninstall content units on a consumer.
        :param consumer_id: The consumer ID.
        :type consumer_id: str
        :param units: A list of content units to be uninstalled.
        :type units: list of:
            { type_id:<str>, type_id:<dict> }
        :param options: Uninstall options; based on unit type.
        :type options: dict
        :return: A task ID that may be used to track the agent request.
        :rtype: dict
        """
        # track agent operations using a pseudo task
        task_id = str(uuid4())
        task_tags = [
            tags.resource_tag(tags.RESOURCE_CONSUMER_TYPE, consumer_id),
            tags.action_tag(tags.ACTION_AGENT_UNIT_UNINSTALL)
        ]
        task = TaskStatus(task_id, 'agent', tags=task_tags).save()

        # agent request
        manager = managers.consumer_manager()
        consumer = manager.get_consumer(consumer_id)
        conduit = ProfilerConduit()
        collated = Units(units)
        for typeid, units in collated.items():
            pc = AgentManager._profiled_consumer(consumer_id)
            profiler, cfg = AgentManager._profiler(typeid)
            units = AgentManager._invoke_plugin(
                profiler.uninstall_units,
                pc,
                units,
                options,
                cfg,
                conduit)
            collated[typeid] = units
        units = collated.join()
        context = Context(consumer, task_id=task_id, consumer_id=consumer_id)
        agent = PulpAgent()
        agent.content.uninstall(context, units, options)
        return task
Esempio n. 10
0
    def test_context(self, mock_load):
        _id = 'test-db_id'
        consumer = {'_id': _id, 'id': 'test-consumer', 'certificate': 'XXX'}
        details = {'task_id': '3456'}

        # test context

        context = Context(consumer, **details)

        # validation

        agent_id = 'pulp.agent.%s' % consumer['id']

        self.assertEqual(context.agent_id, agent_id)
        self.assertEqual(context.url, pulp_conf.get('messaging', 'url'))
        self.assertEqual(context.secret, _id)
        self.assertEqual(context.details, details)
        self.assertEqual(context.reply_queue, Services.REPLY_QUEUE)
        self.assertTrue(isinstance(context.authenticator, Authenticator))
        self.assertTrue(mock_load.called)
Esempio n. 11
0
 def unregister(consumer_id):
     """
     Notification that a consumer (agent) has
     been unregistered.  This ensure that all registration
     artifacts have been cleaned up.  Then, we fire off a task to lazily
     delete the agent queue.
     :param consumer_id: The consumer ID.
     :type consumer_id: str
     """
     manager = managers.consumer_manager()
     consumer = manager.get_consumer(consumer_id)
     context = Context(consumer)
     agent = PulpAgent()
     agent.consumer.unregister(context)
     url = context.url
     name = context.address.split('/')[-1]
     task_tags = [
         tags.resource_tag(tags.ACTION_AGENT_QUEUE_DELETE, consumer_id)
     ]
     delete_queue.apply_async(args=[url, name, consumer_id],
                              countdown=QUEUE_DELETE_DELAY,
                              tags=task_tags)
Esempio n. 12
0
    def test_context(self, mock_load, get_url, queue):
        _id = 'test-db_id'
        consumer = {'_id': _id, 'id': 'test-consumer', 'certificate': 'XXX'}
        details = {'task_id': '3456'}

        # test context

        context = Context(consumer, **details)

        # validation

        route = 'pulp.agent.%s' % consumer['id']

        queue.assert_called_once_with(route)
        queue.return_value.declare.assert_called_once_with(context.url)

        self.assertEqual(context.route, route)
        self.assertEqual(context.url, get_url.return_value)
        self.assertEqual(context.secret, _id)
        self.assertEqual(context.details, details)
        self.assertEqual(context.reply_queue, ReplyHandler.REPLY_QUEUE)
        self.assertTrue(isinstance(context.authenticator, Authenticator))
        self.assertTrue(mock_load.called)
Esempio n. 13
0
 def __init__(self, consumer):
     context = Context(consumer)
     context.watchdog = Services.watchdog
     context.ctag = Services.CTAG
     self.context = context
Esempio n. 14
0
 def __init__(self, consumer):
     context = Context(consumer)
     context.watchdog = Services.watchdog
     context.ctag = Services.CTAG
     self.context = context