示例#1
0
    def test_forced_unbind_agent_not_notified(self):

        # Setup
        self.populate()
        manager = factory.consumer_bind_manager()
        bind = manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID,
                            False, self.BINDING_CONFIG)

        # Test
        options = {}
        itinerary = forced_unbind_itinerary(
            self.CONSUMER_ID,
            self.REPO_ID,
            self.DISTRIBUTOR_ID,
            options)

        call_reports = self.coordinator.execute_multiple_calls(itinerary)

        # Verify
        self.assertEqual(len(call_reports), 1)
        self.assertEqual(call_reports[0].call_request_tags, self.UNBIND_TAGS)
        for call in call_reports:
            self.assertNotEqual(call.state, dispatch_constants.CALL_REJECTED_RESPONSE)

        # run task #1 (actual delete)
        self.run_next()

        # verify bind deleted
        collection = Bind.get_collection()
        bind = collection.find_one(self.QUERY)
        self.assertTrue(bind is None)

        # verify agent notified
        self.assertFalse(mock_agent.Consumer.unbind.called)
示例#2
0
 def DELETE(self, consumer_id, repo_id, distributor_id):
     """
     Delete a bind association between the specified
     consumer and repo-distributor.  Designed to be idempotent.
     @param consumer_id: A consumer ID.
     @type consumer_id: str
     @param repo_id: A repo ID.
     @type repo_id: str
     @param distributor_id: A distributor ID.
     @type distributor_id: str
     @return: The list of call_reports
     @rtype: list
     """
     body = self.params()
     # validate resources
     manager = managers.consumer_bind_manager()
     binding = manager.get_bind(consumer_id, repo_id, distributor_id)
     notify_agent = binding['notify_agent']
     # delete (unbind)
     forced = body.get('force', False)
     options = body.get('options', {})
     if forced or not notify_agent:
         call_requests = forced_unbind_itinerary(consumer_id, repo_id,
                                                 distributor_id, options)
     else:
         call_requests = unbind_itinerary(consumer_id, repo_id,
                                          distributor_id, options)
     execution.execute_multiple(call_requests)
示例#3
0
文件: consumers.py 项目: graco/pulp
 def DELETE(self, consumer_id, repo_id, distributor_id):
     """
     Delete a bind association between the specified
     consumer and repo-distributor.  Designed to be idempotent.
     @param consumer_id: A consumer ID.
     @type consumer_id: str
     @param repo_id: A repo ID.
     @type repo_id: str
     @param distributor_id: A distributor ID.
     @type distributor_id: str
     @return: The list of call_reports
     @rtype: list
     """
     body = self.params()
     # validate resources
     manager = managers.consumer_bind_manager()
     binding = manager.get_bind(consumer_id, repo_id, distributor_id)
     notify_agent = binding['notify_agent']
     # delete (unbind)
     forced = body.get('force', False)
     options = body.get('options', {})
     if forced or not notify_agent:
         call_requests = forced_unbind_itinerary(
             consumer_id,
             repo_id,
             distributor_id,
             options)
     else:
         call_requests = unbind_itinerary(
             consumer_id,
             repo_id,
             distributor_id,
             options)
     execution.execute_multiple(call_requests)
示例#4
0
    def test_forced_unbind(self):

        # Setup
        self.populate()
        manager = factory.consumer_bind_manager()
        bind = manager.bind(self.CONSUMER_ID, self.REPO_ID, self.DISTRIBUTOR_ID,
                            self.NOTIFY_AGENT, self.BINDING_CONFIG)

        # Test
        options = {}
        itinerary = forced_unbind_itinerary(
            self.CONSUMER_ID,
            self.REPO_ID,
            self.DISTRIBUTOR_ID,
            options)
        call_reports = self.coordinator.execute_multiple_calls(itinerary)

        # Verify
        self.assertEqual(len(call_reports), 2)
        self.assertEqual(call_reports[0].call_request_tags, self.UNBIND_TAGS)
        self.assertEqual(call_reports[1].call_request_tags, self.AGENT_UNBIND_TAGS)
        for call in call_reports:
            self.assertNotEqual(call.state, dispatch_constants.CALL_REJECTED_RESPONSE)

        # run task #1 (actual delete)
        self.run_next()

        # verify bind marked deleted
        collection = Bind.get_collection()
        bind = collection.find_one(self.QUERY)
        self.assertTrue(bind is None)

        # run task #2 (notify consumer)
        self.run_next()

        # verify agent notified
        self.assertTrue(mock_agent.Consumer.unbind.called)