Merge "Simple refactor to stop passing around an unused parameter"
This commit is contained in:
commit
ad7a7cd9de
@ -760,9 +760,6 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
namespace=ri.ns_name,
|
||||
prefix=INTERNAL_DEV_PREFIX)
|
||||
|
||||
# Get IPv4 only internal CIDRs
|
||||
internal_cidrs = [p['ip_cidr'] for p in ri.internal_ports
|
||||
if netaddr.IPNetwork(p['ip_cidr']).version == 4]
|
||||
# TODO(salv-orlando): RouterInfo would be a better place for
|
||||
# this logic too
|
||||
ex_gw_port_id = (ex_gw_port and ex_gw_port['id'] or
|
||||
@ -773,11 +770,9 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
interface_name = self.get_external_device_name(ex_gw_port_id)
|
||||
if ex_gw_port and ex_gw_port != ri.ex_gw_port:
|
||||
self._set_subnet_info(ex_gw_port)
|
||||
self.external_gateway_added(ri, ex_gw_port,
|
||||
interface_name, internal_cidrs)
|
||||
self.external_gateway_added(ri, ex_gw_port, interface_name)
|
||||
elif not ex_gw_port and ri.ex_gw_port:
|
||||
self.external_gateway_removed(ri, ri.ex_gw_port,
|
||||
interface_name, internal_cidrs)
|
||||
self.external_gateway_removed(ri, ri.ex_gw_port, interface_name)
|
||||
|
||||
stale_devs = [dev for dev in existing_devices
|
||||
if dev.startswith(EXTERNAL_DEV_PREFIX)
|
||||
@ -795,6 +790,9 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
# Process SNAT rules for external gateway
|
||||
if (not ri.router['distributed'] or
|
||||
ex_gw_port and ri.router['gw_port_host'] == self.host):
|
||||
# Get IPv4 only internal CIDRs
|
||||
internal_cidrs = [p['ip_cidr'] for p in ri.internal_ports
|
||||
if netaddr.IPNetwork(p['ip_cidr']).version == 4]
|
||||
ri.perform_snat_action(self._handle_router_snat_rules,
|
||||
internal_cidrs, interface_name)
|
||||
|
||||
@ -1063,7 +1061,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
LOG.error(_('DVR: no map match_port found!'))
|
||||
|
||||
def _create_dvr_gateway(self, ri, ex_gw_port, gw_interface_name,
|
||||
internal_cidrs, snat_ports):
|
||||
snat_ports):
|
||||
"""Create SNAT namespace."""
|
||||
snat_ns_name = self.get_snat_ns_name(ri.router['id'])
|
||||
self._create_namespace(snat_ns_name)
|
||||
@ -1077,16 +1075,14 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
port['mac_address'], interface_name,
|
||||
SNAT_INT_DEV_PREFIX)
|
||||
self._external_gateway_added(ri, ex_gw_port, gw_interface_name,
|
||||
internal_cidrs, snat_ns_name,
|
||||
preserve_ips=[])
|
||||
snat_ns_name, preserve_ips=[])
|
||||
ri.snat_iptables_manager = (
|
||||
iptables_manager.IptablesManager(
|
||||
root_helper=self.root_helper, namespace=snat_ns_name
|
||||
)
|
||||
)
|
||||
|
||||
def external_gateway_added(self, ri, ex_gw_port,
|
||||
interface_name, internal_cidrs):
|
||||
def external_gateway_added(self, ri, ex_gw_port, interface_name):
|
||||
if ri.router['distributed']:
|
||||
ip_wrapr = ip_lib.IPWrapper(self.root_helper, namespace=ri.ns_name)
|
||||
ip_wrapr.netns.execute(['sysctl', '-w',
|
||||
@ -1102,9 +1098,8 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
if self.conf.agent_mode == 'dvr_snat' and (
|
||||
ri.router['gw_port_host'] == self.host):
|
||||
if snat_ports:
|
||||
self._create_dvr_gateway(ri, ex_gw_port,
|
||||
interface_name,
|
||||
internal_cidrs, snat_ports)
|
||||
self._create_dvr_gateway(ri, ex_gw_port, interface_name,
|
||||
snat_ports)
|
||||
for port in snat_ports:
|
||||
for ip in port['fixed_ips']:
|
||||
self._update_arp_entry(ri, ip['ip_address'],
|
||||
@ -1120,11 +1115,10 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
for ip in floating_ips]
|
||||
|
||||
self._external_gateway_added(ri, ex_gw_port, interface_name,
|
||||
internal_cidrs, ri.ns_name,
|
||||
preserve_ips)
|
||||
ri.ns_name, preserve_ips)
|
||||
|
||||
def _external_gateway_added(self, ri, ex_gw_port, interface_name,
|
||||
internal_cidrs, ns_name, preserve_ips):
|
||||
ns_name, preserve_ips):
|
||||
if not ip_lib.device_exists(interface_name,
|
||||
root_helper=self.root_helper,
|
||||
namespace=ns_name):
|
||||
@ -1178,8 +1172,7 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
|
||||
ip_wrapper.netns.execute(['ip', 'addr', 'add',
|
||||
ip_cidr, 'dev', interface_name])
|
||||
|
||||
def external_gateway_removed(self, ri, ex_gw_port,
|
||||
interface_name, internal_cidrs):
|
||||
def external_gateway_removed(self, ri, ex_gw_port, interface_name):
|
||||
if ri.router['distributed']:
|
||||
for p in ri.internal_ports:
|
||||
internal_interface = self.get_internal_device_name(p['id'])
|
||||
|
@ -337,7 +337,6 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
||||
ri = l3_agent.RouterInfo(router['id'], self.conf.root_helper,
|
||||
self.conf.use_namespaces, router=router)
|
||||
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
|
||||
internal_cidrs = ['100.0.1.0/24', '200.74.0.0/16']
|
||||
ex_gw_port = {'fixed_ips': [{'ip_address': '20.0.0.30',
|
||||
'subnet_id': _uuid()}],
|
||||
'subnet': {'gateway_ip': '20.0.0.1'},
|
||||
@ -355,8 +354,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
||||
'fixed_ip_address': '192.168.0.1',
|
||||
'port_id': _uuid()}]}
|
||||
router[l3_constants.FLOATINGIP_KEY] = fake_fip['floatingips']
|
||||
agent.external_gateway_added(ri, ex_gw_port,
|
||||
interface_name, internal_cidrs)
|
||||
agent.external_gateway_added(ri, ex_gw_port, interface_name)
|
||||
self.assertEqual(self.mock_driver.plug.call_count, 1)
|
||||
self.assertEqual(self.mock_driver.init_l3.call_count, 1)
|
||||
self.send_arp.assert_called_once_with(ri.ns_name, interface_name,
|
||||
@ -371,8 +369,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
||||
|
||||
elif action == 'remove':
|
||||
self.device_exists.return_value = True
|
||||
agent.external_gateway_removed(ri, ex_gw_port,
|
||||
interface_name, internal_cidrs)
|
||||
agent.external_gateway_removed(ri, ex_gw_port, interface_name)
|
||||
self.assertEqual(self.mock_driver.unplug.call_count, 1)
|
||||
else:
|
||||
raise Exception("Invalid action %s" % action)
|
||||
@ -1716,11 +1713,9 @@ class TestBasicRouterOperations(base.BaseTestCase):
|
||||
'id': _uuid(), 'device_id': _uuid()}]
|
||||
|
||||
interface_name = agent.get_snat_int_device_name(port_id)
|
||||
internal_cidrs = None
|
||||
self.device_exists.return_value = False
|
||||
|
||||
agent._create_dvr_gateway(ri, dvr_gw_port, interface_name,
|
||||
internal_cidrs, snat_ports)
|
||||
agent._create_dvr_gateway(ri, dvr_gw_port, interface_name, snat_ports)
|
||||
|
||||
# check 2 internal ports are plugged
|
||||
# check 1 ext-gw-port is plugged
|
||||
|
Loading…
x
Reference in New Issue
Block a user