コード例 #1
0
 def _create_router(self, router=None, **kwargs):
     agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
     self.router_id = _uuid()
     if not router:
         router = mock.MagicMock()
     kwargs['agent'] = agent
     kwargs['router_id'] = self.router_id
     kwargs['router'] = router
     kwargs['agent_conf'] = self.conf
     kwargs['interface_driver'] = mock.Mock()
     return dvr_router.DvrLocalRouter(HOSTNAME, **kwargs)
コード例 #2
0
    def test_external_gateway_removed_ext_gw_port_and_fip(self):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        agent.conf.agent_mode = 'dvr'
        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_router.DvrLocalRouter(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.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')
コード例 #3
0
 def _create_router(self, router=None, **kwargs):
     agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
     self.router_id = _uuid()
     if not router:
         router = mock.MagicMock()
     return dvr_router.DvrLocalRouter(agent,
                                 HOSTNAME,
                                 self.router_id,
                                 router,
                                 self.conf,
                                 mock.Mock(),
                                 **kwargs)
コード例 #4
0
 def test_add_update_dvr_local_router(self, *args):
     l3_agent = mock.Mock()
     l3_agent.pd.routers = {}
     router_id = '1'
     ri = dvr_local_router.DvrLocalRouter(l3_agent,
                                          'host',
                                          router_id,
                                          mock.Mock(),
                                          mock.Mock(),
                                          mock.Mock())
     ns_name = ri.ns_name
     self._test_add_update_pd(l3_agent, ri, ns_name)
コード例 #5
0
 def _create_router(self, router=None, **kwargs):
     agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
     self.router_id = _uuid()
     if not router:
         router = mock.MagicMock()
     kwargs['agent'] = agent
     kwargs['router_id'] = self.router_id
     kwargs['router'] = router
     kwargs['agent_conf'] = self.conf
     kwargs['interface_driver'] = mock.Mock()
     with mock.patch.object(dvr_router.DvrLocalRouter,
                            'load_used_fip_information'):
         return dvr_router.DvrLocalRouter(HOSTNAME, **kwargs)
コード例 #6
0
    def test_process_router_dist_floating_ip_add(self):
        fake_floatingips = {
            'floatingips': [{
                'id': _uuid(),
                'host': HOSTNAME,
                'floating_ip_address': '15.1.2.3',
                'fixed_ip_address': '192.168.0.1',
                'floating_network_id': mock.sentinel.ext_net_id,
                'port_id': _uuid()
            }, {
                'id': _uuid(),
                'host': 'some-other-host',
                'floating_ip_address': '15.1.2.4',
                'fixed_ip_address': '192.168.0.10',
                'floating_network_id': mock.sentinel.ext_net_id,
                'port_id': _uuid()
            }]
        }

        router = l3_test_common.prepare_router_data(enable_snat=True)
        router[l3_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips']
        router['distributed'] = True
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        ri = dvr_router.DvrLocalRouter(agent, HOSTNAME, router['id'], router,
                                       **self.ri_kwargs)
        ri.iptables_manager.ipv4['nat'] = mock.MagicMock()
        ri.dist_fip_count = 0
        fip_ns = agent.get_fip_ns(mock.sentinel.ext_net_id)
        subnet_id = _uuid()
        fip_ns.agent_gateway_port = ({
            'fixed_ips': [{
                'ip_address': '20.0.0.30',
                'subnet_id': subnet_id
            }],
            'subnets': [{
                'id': subnet_id,
                'cidr': '20.0.0.0/24',
                'gateway_ip': '20.0.0.1'
            }],
            'id':
            _uuid(),
            'network_id':
            _uuid(),
            'mac_address':
            'ca:fe:de:ad:be:ef'
        })
コード例 #7
0
    def _test_ext_gw_updated_dvr_agent_mode(self, host, agent_mode,
                                            expected_call_count):
        router = l3_test_common.prepare_router_data(num_internal_ports=2)
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        ri = dvr_router.DvrLocalRouter(agent, HOSTNAME, router['id'], router,
                                       **self.ri_kwargs)

        interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(
            self, ri)
        ri._external_gateway_added = mock.Mock()

        # test agent mode = dvr (compute node)
        router['gw_port_host'] = host
        agent.conf.agent_mode = agent_mode

        ri.external_gateway_updated(ex_gw_port, interface_name)
        # no gateway should be added on dvr node
        self.assertEqual(expected_call_count,
                         ri._external_gateway_added.call_count)
コード例 #8
0
    def test__set_subnet_arp_info(self):
        agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
        router = l3_test_common.prepare_router_data(num_internal_ports=2)
        router['distributed'] = True
        self._set_ri_kwargs(agent, router['id'], router)
        ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
        ports = ri.router.get(lib_constants.INTERFACE_KEY, [])
        subnet_id = l3_test_common.get_subnet_id(ports[0])
        test_ports = [{'mac_address': '00:11:22:33:44:55',
                       'device_owner': lib_constants.DEVICE_OWNER_DHCP,
                       'fixed_ips': [{'ip_address': '1.2.3.4',
                                      'prefixlen': 24,
                                      'subnet_id': subnet_id}]},
                      {'mac_address': '11:22:33:44:55:66',
                       'device_owner': lib_constants.DEVICE_OWNER_LOADBALANCER,
                       'fixed_ips': [{'ip_address': '1.2.3.5',
                                      'prefixlen': 24,
                                      'subnet_id': subnet_id}]},
                      {'mac_address': '22:33:44:55:66:77',
                       'device_owner':
                           lib_constants.DEVICE_OWNER_LOADBALANCERV2,
                       'fixed_ips': [{'ip_address': '1.2.3.6',
                                      'prefixlen': 24,
                                      'subnet_id': subnet_id}]}]

        self.plugin_api.get_ports_by_subnet.return_value = test_ports

        # Test basic case
        ports[0]['subnets'] = [{'id': subnet_id,
                                'cidr': '1.2.3.0/24'}]
        with mock.patch.object(ri,
                               '_process_arp_cache_for_internal_port') as parp:
            ri._set_subnet_arp_info(subnet_id)
        self.assertEqual(1, parp.call_count)
        self.mock_ip_dev.neigh.add.assert_called_once_with(
            '1.2.3.4', '00:11:22:33:44:55')

        # Test negative case
        router['distributed'] = False
        ri._set_subnet_arp_info(subnet_id)
        self.mock_ip_dev.neigh.add.never_called()
コード例 #9
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)
コード例 #10
0
ファイル: test_ndp_proxy.py プロジェクト: stackhpc/neutron
 def setUp(self):
     super(NDPProxyExtensionDVRTestCase, self).setUp()
     self.conf.host = HOSTNAME
     self.conf.agent_mode = lib_const.L3_AGENT_MODE_DVR
     self.agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
     self.add_route = mock.MagicMock()
     self.delete_route = mock.MagicMock()
     mock_route_cmd = mock.MagicMock()
     mock_route_cmd.add_route = self.add_route
     mock_route_cmd.delete_route = self.delete_route
     self.mock_ip_dev.route = mock_route_cmd
     self.lladdr = "fe80::f816:3eff:fe5f:9d67"
     get_ipv6_lladdr = mock.patch("neutron.agent.linux.ip_lib."
                                  "get_ipv6_lladdr").start()
     get_ipv6_lladdr.return_value = "%s/64" % self.lladdr
     self.router = {
         'id': self.fake_router_id,
         'gw_port': self.ex_gw_port,
         'ha': False,
         'distributed': True,
         'enable_ndp_proxy': True
     }
     kwargs = {
         'agent': self.agent,
         'router_id': self.fake_router_id,
         'router': self.router,
         'agent_conf': self.conf,
         'interface_driver': mock.Mock()
     }
     self.router_info = dvr_router.DvrLocalRouter(HOSTNAME, **kwargs)
     self.get_router_info = mock.patch(
         'neutron.agent.l3.l3_agent_extension_api.'
         'L3AgentExtensionAPI.get_router_info').start()
     self.get_router_info.return_value = self.router_info
     self.router_info.fip_ns = self.agent.get_fip_ns(self.ex_net_id)
     agent_ext_port_id = _uuid()
     self.router_info.fip_ns.agent_gateway_port = {'id': agent_ext_port_id}
     self.namespace = "fip-%s" % self.ex_net_id
     self.agent_ext_dvice = "fg-%s" % agent_ext_port_id[:11]
     self.ip_wrapper.reset_mock()