Ejemplo n.º 1
0
 def test_router_auto_schedule_with_candidates(self):
     l3_hosta = {
         'binary': 'quantum-l3-agent',
         'host': L3_HOSTA,
         'topic': 'L3_AGENT',
         'configurations': {
             'use_namespaces': False,
             'router_id': None,
             'handle_internal_only_routers': True,
             'gateway_external_network_id': None,
             'interface_driver': 'interface_driver',
         },
         'agent_type': constants.AGENT_TYPE_L3
     }
     with contextlib.nested(self.router(),
                            self.router()) as (router1, router2):
         l3_rpc = l3_rpc_base.L3RpcCallbackMixin()
         l3_hosta['configurations']['router_id'] = router1['router']['id']
         self._register_one_agent_state(l3_hosta)
         hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3, L3_HOSTA)
         l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA)
         hosta_routers = self._list_routers_hosted_by_l3_agent(hosta_id)
         num_hosta_routers = len(hosta_routers['routers'])
         l3_agents_1 = self._list_l3_agents_hosting_router(
             router1['router']['id'])
         l3_agents_2 = self._list_l3_agents_hosting_router(
             router2['router']['id'])
     # L3 agent will host only the compatible router.
     self.assertEqual(1, num_hosta_routers)
     self.assertEqual(1, len(l3_agents_1['agents']))
     self.assertEqual(0, len(l3_agents_2['agents']))
Ejemplo n.º 2
0
 def test_router_auto_schedule_with_hosted(self):
     with self.router() as router:
         l3_rpc = l3_rpc_base.L3RpcCallbackMixin()
         self._register_agent_states()
         l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA)
         l3_rpc.sync_routers(self.adminContext, host=L3_HOSTB)
         l3_agents = self._list_l3_agents_hosting_router(
             router['router']['id'])
     self.assertEqual(1, len(l3_agents['agents']))
     self.assertEqual(L3_HOSTA, l3_agents['agents'][0]['host'])
Ejemplo n.º 3
0
 def test_router_auto_schedule_with_disabled(self):
     with contextlib.nested(self.router(), self.router()):
         l3_rpc = l3_rpc_base.L3RpcCallbackMixin()
         self._register_agent_states()
         hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3, L3_HOSTA)
         hostb_id = self._get_agent_id(constants.AGENT_TYPE_L3, L3_HOSTB)
         self._disable_agent(hosta_id)
         # first agent will not host router since it is disabled
         l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA)
         # second agent will host all the routers since first is disabled.
         l3_rpc.sync_routers(self.adminContext, host=L3_HOSTB)
         hostb_routers = self._list_routers_hosted_by_l3_agent(hostb_id)
         num_hostb_routers = len(hostb_routers['routers'])
         hosta_routers = self._list_routers_hosted_by_l3_agent(hosta_id)
         num_hosta_routers = len(hosta_routers['routers'])
     self.assertEqual(2, num_hostb_routers)
     self.assertEqual(0, num_hosta_routers)
Ejemplo n.º 4
0
    def test_router_auto_schedule_with_hosted_2(self):
        # one agent hosts one router
        l3_rpc = l3_rpc_base.L3RpcCallbackMixin()
        l3_hosta = {
            'binary': 'quantum-l3-agent',
            'host': L3_HOSTA,
            'topic': 'L3_AGENT',
            'configurations': {'use_namespaces': True,
                               'router_id': None,
                               'handle_internal_only_routers':
                               True,
                               'gateway_external_network_id':
                               None,
                               'interface_driver': 'interface_driver',
                               },
            'agent_type': constants.AGENT_TYPE_L3}
        l3_hostb = copy.deepcopy(l3_hosta)
        l3_hostb['host'] = L3_HOSTB
        with self.router() as router1:
            self._register_one_agent_state(l3_hosta)
            l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA)
            hosta_id = self._get_agent_id(constants.AGENT_TYPE_L3,
                                          L3_HOSTA)
            self._disable_agent(hosta_id, admin_state_up=False)
            with self.router() as router2:
                self._register_one_agent_state(l3_hostb)
                l3_rpc.sync_routers(self.adminContext, host=L3_HOSTB)
                l3_agents_1 = self._list_l3_agents_hosting_router(
                    router1['router']['id'])
                l3_agents_2 = self._list_l3_agents_hosting_router(
                    router2['router']['id'])
                hosta_routers = self._list_routers_hosted_by_l3_agent(hosta_id)
                num_hosta_routers = len(hosta_routers['routers'])
                hostb_id = self._get_agent_id(
                    constants.AGENT_TYPE_L3,
                    L3_HOSTB)
                hostb_routers = self._list_routers_hosted_by_l3_agent(hostb_id)
                num_hostc_routers = len(hostb_routers['routers'])

        self.assertEqual(1, num_hosta_routers)
        self.assertEqual(1, num_hostc_routers)
        self.assertEqual(1, len(l3_agents_1['agents']))
        self.assertEqual(1, len(l3_agents_2['agents']))
        self.assertEqual(L3_HOSTA, l3_agents_1['agents'][0]['host'])
        self.assertEqual(L3_HOSTB, l3_agents_2['agents'][0]['host'])