Exemple #1
0
    def _create_router(self, router_id, router):
        # TODO(Carl) We need to support a router that is both HA and DVR.  The
        # patch that enables it will replace these lines.  See bug #1365473.
        if router.get('distributed') and router.get('ha'):
            raise n_exc.DvrHaRouterNotSupported(router_id=router_id)

        args = []
        kwargs = {
            'router_id': router_id,
            'router': router,
            'use_ipv6': self.use_ipv6,
            'agent_conf': self.conf,
            'interface_driver': self.driver,
        }

        if router.get('distributed'):
            kwargs['agent'] = self
            kwargs['host'] = self.host
            if self.conf.agent_mode == l3_constants.L3_AGENT_MODE_DVR_SNAT:
                return dvr_router.DvrEdgeRouter(*args, **kwargs)
            else:
                return dvr_local_router.DvrLocalRouter(*args, **kwargs)

        if router.get('ha'):
            kwargs['state_change_callback'] = self.enqueue_state_change
            return ha_router.HaRouter(*args, **kwargs)

        return legacy_router.LegacyRouter(*args, **kwargs)
Exemple #2
0
    def _create_router(self, router_id, router):
        args = []
        kwargs = {
            'agent': self,
            'router_id': router_id,
            'router': router,
            'use_ipv6': self.use_ipv6,
            'agent_conf': self.conf,
            'interface_driver': self.driver,
        }

        if router.get('distributed'):
            kwargs['host'] = self.host

        if router.get('distributed') and router.get('ha'):
            if self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT:
                kwargs['state_change_callback'] = self.enqueue_state_change
                return dvr_edge_ha_router.DvrEdgeHaRouter(*args, **kwargs)

        if router.get('distributed'):
            if self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT:
                return dvr_router.DvrEdgeRouter(*args, **kwargs)
            else:
                return dvr_local_router.DvrLocalRouter(*args, **kwargs)

        if router.get('ha'):
            kwargs['state_change_callback'] = self.enqueue_state_change
            return ha_router.HaRouter(*args, **kwargs)

        return legacy_router.LegacyRouter(*args, **kwargs)
Exemple #3
0
 def _make_router_info_for_test(self):
     self.router = legacy_router.LegacyRouter(FAKE_ROUTER_ID,
                                              **self.ri_kwargs)
     self.router.router['distributed'] = False
     self.router.iptables_manager.ipv4['nat'] = self.iptables
     self.router.iptables_manager.apply = self.apply_mock
     self.driver.routers[FAKE_ROUTER_ID] = self.router
Exemple #4
0
    def _create_router(self, router_id, router):
        # TODO(Carl) We need to support a router that is both HA and DVR.  The
        # patch that enables it will replace these lines.  See bug #1365473.
        if router.get('distributed') and router.get('ha'):
            raise n_exc.DvrHaRouterNotSupported(router_id=router_id)

        ns_name = (self.get_ns_name(router_id)
                   if self.conf.use_namespaces else None)
        args = []
        kwargs = {
            'router_id': router_id,
            'router': router,
            'use_ipv6': self.use_ipv6,
            'ns_name': ns_name,
            'agent_conf': self.conf,
            'interface_driver': self.driver,
        }

        if router.get('distributed'):
            kwargs['host'] = self.host
            return dvr_router.DvrRouter(*args, **kwargs)

        if router.get('ha'):
            return ha_router.HaRouter(*args, **kwargs)

        return legacy_router.LegacyRouter(*args, **kwargs)
    def setUp(self):
        super(TestStrongSwanDeviceDriver, self).setUp()
        self.conf = cfg.CONF
        self.conf.register_opts(l3_config.OPTS)
        self.conf.register_opts(ipsec.ipsec_opts, 'ipsec')
        self.conf.register_opts(strongswan_ipsec.strongswan_opts,
                                'strongswan')
        self.conf.set_override('state_path', '/tmp')

        ri_kwargs = {'router': {'id': FAKE_ROUTER_ID},
                     'agent_conf': self.conf,
                     'interface_driver': mock.sentinel.interface_driver}
        self.router = legacy_router.LegacyRouter(router_id=FAKE_ROUTER_ID,
                                                 agent=mock.Mock(),
                                                 **ri_kwargs)
        self.router.router['distributed'] = False
        self.router_id = FAKE_VPN_SERVICE['router_id']

        looping_call_p = mock.patch(
            'oslo_service.loopingcall.FixedIntervalLoopingCall')
        looping_call_p.start()

        vpn_service = mock.Mock()
        vpn_service.conf = self.conf
        self.driver = strongswan_ipsec.StrongSwanDriver(
            vpn_service, host=mock.sentinel.host)
        self.driver.routers[FAKE_ROUTER_ID] = self.router
        self.driver.agent_rpc = mock.Mock()
        self.driver._update_nat = mock.Mock()
        self.driver.agent_rpc.get_vpn_services_on_host.return_value = [
            FAKE_VPN_SERVICE]
        self.addCleanup(self.driver.destroy_router, self.router_id)

        self.router.router_namespace.create()
        self.addCleanup(self.router.router_namespace.delete)
 def test_router_updated_actions(self):
     ri = legacy_router.LegacyRouter(FAKE_ROUTER_ID, **self.ri_kwargs)
     vpn_service.router_updated_actions(mock.Mock(),
                                        mock.Mock(),
                                        self.l3_agent,
                                        router=ri)
     self.device_driver.sync.assert_called_once_with(
         self.l3_agent.context, [ri.router])
 def test_router_removed_actions(self):
     ri = legacy_router.LegacyRouter(FAKE_ROUTER_ID, **self.ri_kwargs)
     vpn_service.router_removed_actions(mock.Mock(),
                                        mock.Mock(),
                                        self.l3_agent,
                                        router=ri)
     self.device_driver.destroy_router.assert_called_once_with(
         FAKE_ROUTER_ID)
Exemple #8
0
 def test_add_update_legacy_router(self):
     l3_agent = mock.Mock()
     l3_agent.pd.routers = {}
     router_id = '1'
     ri = legacy_router.LegacyRouter(router_id, mock.Mock(), mock.Mock(),
                                     mock.Mock())
     ns_name = ri.ns_name
     self._test_add_update_pd(l3_agent, ri, ns_name)
Exemple #9
0
 def _create_router(self, router=None, **kwargs):
     if not router:
         router = mock.MagicMock()
     self.agent_conf = mock.Mock()
     self.driver = mock.Mock()
     self.router_id = _uuid()
     return legacy_router.LegacyRouter(self.router_id, router,
                                       self.agent_conf, self.driver,
                                       **kwargs)
 def _create_router(self, router=None, **kwargs):
     if not router:
         router = mock.MagicMock()
     self.agent_conf = mock.Mock()
     self.driver = mock.Mock()
     return legacy_router.LegacyRouter(mock.sentinel.router_id,
                                       router,
                                       self.agent_conf,
                                       self.driver,
                                       ns_name=mock.sentinel.namespace,
                                       **kwargs)
Exemple #11
0
    def _create_router(self, router_id, router):
        args = []
        kwargs = {
            'agent': self,
            'router_id': router_id,
            'router': router,
            'use_ipv6': self.use_ipv6,
            'agent_conf': self.conf,
            'interface_driver': self.driver,
        }

        if router.get('distributed'):
            kwargs['host'] = self.host

        if router.get('distributed') and router.get('ha'):
            # Case 1: If the router contains information about the HA interface
            # and if the requesting agent is a DVR_SNAT agent then go ahead
            # and create a HA router.
            # Case 2: If the router does not contain information about the HA
            # interface this means that this DVR+HA router needs to host only
            # the edge side of it, typically because it's landing on a node
            # that needs to provision a router namespace because of a DVR
            # service port (e.g. DHCP). So go ahead and create a regular DVR
            # edge router.
            if (self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT
                    and router.get(lib_const.HA_INTERFACE_KEY) is not None):
                kwargs['state_change_callback'] = self.enqueue_state_change
                return dvr_edge_ha_router.DvrEdgeHaRouter(*args, **kwargs)

        if router.get('distributed'):
            if self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT:
                return dvr_router.DvrEdgeRouter(*args, **kwargs)
            else:
                return dvr_local_router.DvrLocalRouter(*args, **kwargs)

        if router.get('ha'):
            kwargs['state_change_callback'] = self.enqueue_state_change
            return ha_router.HaRouter(*args, **kwargs)

        return legacy_router.LegacyRouter(*args, **kwargs)