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