예제 #1
0
    def test_d1_worker_cleanup(self):
        # Worker1 subscribes to RT1
        worker1 = self._new_worker("worker.Worker-1", worker.Worker)
        self._worker_subscriptions(worker1, [t.RT1])
        # Worker2 subscribes to RT2
        worker2 = self._new_worker("worker.Worker-2", worker.Worker)
        self._worker_subscriptions(worker2, [t.RT2])
        # BGPPeerWorker1 subscribes to RT1 and RT2
        bgp_peer_worker1 = self._new_worker("BGPWorker1", bpw.BGPPeerWorker)
        self._worker_subscriptions(bgp_peer_worker1, [t.RT1, t.RT2])
        # BGPPeerWorker1 advertises a route for RT1 and RT2
        evt1 = self._new_route_event(engine.RouteEvent.ADVERTISE, t.NLRI1,
                                     [t.RT1, t.RT2], bgp_peer_worker1, t.NH1)
        # BGPPeerWorker1 advertises an other route for RT2
        evt2 = self._new_route_event(engine.RouteEvent.ADVERTISE, t.NLRI2,
                                     [t.RT2], bgp_peer_worker1, t.NH1)
        # Cleanup Worker1
        self.rtm.enqueue(engine.WorkerCleanupEvent(bgp_peer_worker1))
        # Waiting for RouteTableManager thread finishes to process the
        # subscriptions
        self._wait()

        self.assertEqual(
            0,
            self.rtm.last_local_subscriber_callback.call_count,
            "last_local_subscriber_callback should not have been called "
            " (non local worker)")

        # check unsubscriptions
        self._check_unsubscriptions(bgp_peer_worker1, [MATCH1, MATCH2])
        # Check route synthesize to Worker1 and Worker2
        self.assertEqual(2, worker1.enqueue.call_count,
                         "2 routes should be advert/withdraw to Worker1")
        self._check_events_calls(worker1.enqueue.call_args_list,
                                 [evt1.route_entry], [evt1.route_entry.nlri])
        self.assertEqual(4, worker2.enqueue.call_count,
                         "4 routes should be advert/withdraw to Worker2")
        self._check_events_calls(worker2.enqueue.call_args_list,
                                 [evt1.route_entry, evt2.route_entry],
                                 [evt1.route_entry.nlri,
                                  evt2.route_entry.nlri])
        # Check route entries have been removed for BGPPeerWorker1
        self.assertNotIn(evt1.route_entry, bgp_peer_worker1._rtm_route_entries,
                         "Route entry found")
        self.assertNotIn(evt2.route_entry, bgp_peer_worker1._rtm_route_entries,
                         "Route entry found")

        # Cleanup Worker1
        self.rtm.enqueue(engine.WorkerCleanupEvent(worker1))

        self._wait()
        # check that last local subscriber callback for RT1 is called
        self.assertEqual(1, self.rtm.last_local_subscriber_callback.call_count)
예제 #2
0
 def _cleanup(self):
     self.rtm.enqueue(engine.WorkerCleanupEvent(self))