Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def test_add_update_dvr_edge_router(self):
     l3_agent = mock.Mock()
     l3_agent.pd.routers = {}
     router_id = '1'
     ri = dvr_edge_router.DvrEdgeRouter(l3_agent, 'host', router_id,
                                        mock.Mock(), mock.Mock(),
                                        mock.Mock())
     ns_name = ri.snat_namespace.name
     self._test_add_update_pd(l3_agent, ri, ns_name)
Ejemplo n.º 4
0
    def test_external_gateway_removed_ext_gw_port_and_fip(self):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
        router = l3_test_common.prepare_router_data(num_internal_ports=2)
        router['gw_port_host'] = HOSTNAME
        self.mock_driver.unplug.reset_mock()

        external_net_id = router['gw_port']['network_id']
        self._set_ri_kwargs(agent, router['id'], router)
        ri = dvr_edge_rtr.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
        ri.remove_floating_ip = mock.Mock()
        agent._fetch_external_net_id = mock.Mock(return_value=external_net_id)
        ri.ex_gw_port = ri.router['gw_port']
        del ri.router['gw_port']
        ri.external_gateway_added(
            ri.ex_gw_port, ri.get_external_device_name(ri.ex_gw_port['id']))
        ri.fip_ns = None
        nat = ri.iptables_manager.ipv4['nat']
        nat.clear_rules_by_tag = mock.Mock()
        nat.add_rule = mock.Mock()

        ri.fip_ns = agent.get_fip_ns(external_net_id)
        subnet_id = _uuid()
        ri.fip_ns.agent_gateway_port = {
            'fixed_ips': [{
                'ip_address': '20.0.0.30',
                'prefixlen': 24,
                'subnet_id': subnet_id
            }],
            'subnets': [{
                'id': subnet_id,
                'cidr': '20.0.0.0/24',
                'gateway_ip': '20.0.0.1'
            }],
            'id':
            _uuid(),
            'network_id':
            external_net_id,
            'mac_address':
            'ca:fe:de:ad:be:ef'
        }

        vm_floating_ip = '19.4.4.2'
        ri.floating_ips_dict[vm_floating_ip] = FIP_PRI
        ri.rtr_fip_subnet = ri.fip_ns.local_subnets.allocate(ri.router_id)
        _, fip_to_rtr = ri.rtr_fip_subnet.get_pair()
        self.mock_ip.get_devices.return_value = [
            l3_test_common.FakeDev(ri.fip_ns.get_ext_device_name(_uuid()))
        ]
        ri.get_router_cidrs = mock.Mock(
            return_value={vm_floating_ip + '/32', '19.4.4.1/24'})
        self.device_exists.return_value = True
        ri.external_gateway_removed(
            ri.ex_gw_port, ri.get_external_device_name(ri.ex_gw_port['id']))
        ri.remove_floating_ip.assert_called_once_with(self.mock_ip_dev,
                                                      '19.4.4.2/32')
Ejemplo n.º 5
0
 def _make_dvr_edge_router_info_for_test(self):
     router = dvr_edge_router.DvrEdgeRouter(mock.sentinel.agent,
                                            mock.sentinel.myhost,
                                            FAKE_ROUTER_ID,
                                            **self.ri_kwargs)
     router.router['distributed'] = True
     router.snat_namespace = dvr_snat_ns.SnatNamespace(
         router.router['id'], mock.sentinel.agent, self.driver, mock.ANY)
     router.snat_namespace.create()
     router.snat_iptables_manager = iptables_manager.IptablesManager(
         namespace='snat-' + FAKE_ROUTER_ID, use_ipv6=mock.ANY)
     router.snat_iptables_manager.ipv4['nat'] = self.iptables
     router.snat_iptables_manager.apply = self.apply_mock
     self.driver.routers[FAKE_ROUTER_ID] = router
Ejemplo n.º 6
0
    def test_handle_snat_rule_for_centralized_fip(self, _add_snat_rules,
                                                  _handle_router_snat_rules):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        agent.conf.agent_mode = lib_constants.L3_AGENT_MODE_DVR_SNAT
        self.mock_driver.unplug.reset_mock()

        router = l3_test_common.prepare_router_data(enable_floating_ip=True)
        router['gw_port_host'] = HOSTNAME
        self._set_ri_kwargs(agent, router['id'], router)
        ri = dvr_edge_rtr.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
        ri.snat_iptables_manager = mock.MagicMock()
        ipv4_nat = ri.snat_iptables_manager.ipv4['nat']
        interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(
            self, ri)
        ri._handle_router_snat_rules(ex_gw_port, interface_name)
        ipv4_nat.add_rule.assert_called_once_with('snat', '-j $float-snat')
Ejemplo n.º 7
0
 def setUp(self):
     super(NDPProxyExtensionLegacyDVRNoExternalTestCaseBase, self).setUp()
     self.conf.host = HOSTNAME
     self.conf.agent_mode = lib_const.L3_AGENT_MODE_DVR_SNAT
     self.agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
     self.ext_device_name = 'qg-%s' % self.ext_port_id[0:11]
     self.internal_ports = [{'subnets': [{'cidr': '2001::1:0/112'}]}]
     self.router = {
         'id': self.fake_router_id,
         'gw_port': self.ex_gw_port,
         'gw_port_host': HOSTNAME,
         'ha': False,
         'distributed': True,
         'enable_ndp_proxy': True
     }
     interface_driver = mock.Mock()
     interface_driver.DEV_NAME_LEN = 14
     kwargs = {
         'agent': self.agent,
         'router_id': self.fake_router_id,
         'router': self.router,
         'agent_conf': self.conf,
         'interface_driver': interface_driver
     }
     self._mock_load_fip = mock.patch.object(
         dvr_edge_router.DvrEdgeRouter,
         '_load_used_fip_information').start()
     self.router_info = dvr_edge_router.DvrEdgeRouter(HOSTNAME, **kwargs)
     self.iptables_manager = iptables_manager.IptablesManager(
         namespace=self.router_info.snat_namespace.name,
         use_ipv6=self.router_info.use_ipv6)
     self.router_info.snat_iptables_manager = self.iptables_manager
     self.router_info.internal_ports = self.internal_ports
     self.router_info.ex_gw_port = self.ex_gw_port
     self.iptables_manager.ipv6['filter'].chains = []
     self.iptables_manager.ipv6['filter'].rules = []
     self.agent.router_info[self.router['id']] = self.router_info
     self.wrap_name = self.iptables_manager.wrap_name
     self.namespace = "snat-" + self.fake_router_id
     self._mock_iptables_actions()
     self.ip_wrapper.reset_mock()
Ejemplo n.º 8
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)