Merge "Add agent object in router info"

This commit is contained in:
Jenkins 2017-01-10 12:03:05 +00:00 committed by Gerrit Code Review
commit eb5871535c
19 changed files with 259 additions and 264 deletions

View File

@ -308,6 +308,7 @@ class L3NATAgent(ha.AgentMixin,
def _create_router(self, router_id, router): def _create_router(self, router_id, router):
args = [] args = []
kwargs = { kwargs = {
'agent': self,
'router_id': router_id, 'router_id': router_id,
'router': router, 'router': router,
'use_ipv6': self.use_ipv6, 'use_ipv6': self.use_ipv6,
@ -316,7 +317,6 @@ class L3NATAgent(ha.AgentMixin,
} }
if router.get('distributed'): if router.get('distributed'):
kwargs['agent'] = self
kwargs['host'] = self.host kwargs['host'] = self.host
if router.get('distributed') and router.get('ha'): if router.get('distributed') and router.get('ha'):
@ -368,7 +368,7 @@ class L3NATAgent(ha.AgentMixin,
registry.notify(resources.ROUTER, events.BEFORE_DELETE, registry.notify(resources.ROUTER, events.BEFORE_DELETE,
self, router=ri) self, router=ri)
ri.delete(self) ri.delete()
del self.router_info[router_id] del self.router_info[router_id]
registry.notify(resources.ROUTER, events.AFTER_DELETE, self, router=ri) registry.notify(resources.ROUTER, events.AFTER_DELETE, self, router=ri)
@ -443,7 +443,7 @@ class L3NATAgent(ha.AgentMixin,
self._router_added(router['id'], router) self._router_added(router['id'], router)
ri = self.router_info[router['id']] ri = self.router_info[router['id']]
ri.router = router ri.router = router
ri.process(self) ri.process()
registry.notify(resources.ROUTER, events.AFTER_CREATE, self, router=ri) registry.notify(resources.ROUTER, events.AFTER_CREATE, self, router=ri)
self.l3_ext_manager.add_router(self.context, router) self.l3_ext_manager.add_router(self.context, router)
@ -452,7 +452,7 @@ class L3NATAgent(ha.AgentMixin,
ri.router = router ri.router = router
registry.notify(resources.ROUTER, events.BEFORE_UPDATE, registry.notify(resources.ROUTER, events.BEFORE_UPDATE,
self, router=ri) self, router=ri)
ri.process(self) ri.process()
registry.notify(resources.ROUTER, events.AFTER_UPDATE, self, router=ri) registry.notify(resources.ROUTER, events.AFTER_UPDATE, self, router=ri)
self.l3_ext_manager.update_router(self.context, router) self.l3_ext_manager.update_router(self.context, router)

View File

@ -26,8 +26,8 @@ class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter,
DVR router with HA capabilities. DVR router with HA capabilities.
""" """
def __init__(self, agent, host, *args, **kwargs): def __init__(self, host, *args, **kwargs):
super(DvrEdgeHaRouter, self).__init__(agent, host, super(DvrEdgeHaRouter, self).__init__(host,
*args, **kwargs) *args, **kwargs)
self.enable_snat = None self.enable_snat = None

View File

@ -27,8 +27,8 @@ LOG = logging.getLogger(__name__)
class DvrEdgeRouter(dvr_local_router.DvrLocalRouter): class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
def __init__(self, agent, host, *args, **kwargs): def __init__(self, host, *args, **kwargs):
super(DvrEdgeRouter, self).__init__(agent, host, *args, **kwargs) super(DvrEdgeRouter, self).__init__(host, *args, **kwargs)
self.snat_namespace = dvr_snat_ns.SnatNamespace( self.snat_namespace = dvr_snat_ns.SnatNamespace(
self.router_id, self.agent_conf, self.driver, self.use_ipv6) self.router_id, self.agent_conf, self.driver, self.use_ipv6)
self.snat_iptables_manager = None self.snat_iptables_manager = None
@ -211,8 +211,8 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
"the router."), ns_name) "the router."), ns_name)
super(DvrEdgeRouter, self).update_routing_table(operation, route) super(DvrEdgeRouter, self).update_routing_table(operation, route)
def delete(self, agent): def delete(self):
super(DvrEdgeRouter, self).delete(agent) super(DvrEdgeRouter, self).delete()
if self.snat_namespace.exists(): if self.snat_namespace.exists():
self.snat_namespace.delete() self.snat_namespace.delete()

View File

@ -39,8 +39,8 @@ Arp_entry = collections.namedtuple(
class DvrLocalRouter(dvr_router_base.DvrRouterBase): class DvrLocalRouter(dvr_router_base.DvrRouterBase):
def __init__(self, agent, host, *args, **kwargs): def __init__(self, host, *args, **kwargs):
super(DvrLocalRouter, self).__init__(agent, host, *args, **kwargs) super(DvrLocalRouter, self).__init__(host, *args, **kwargs)
self.floating_ips_dict = {} self.floating_ips_dict = {}
# Linklocal subnet for router and floating IP namespace link # Linklocal subnet for router and floating IP namespace link
@ -505,11 +505,11 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
ext_scope_mark) ext_scope_mark)
return ports_scopemark return ports_scopemark
def process_external(self, agent): def process_external(self):
ex_gw_port = self.get_ex_gw_port() ex_gw_port = self.get_ex_gw_port()
if ex_gw_port: if ex_gw_port:
self.create_dvr_fip_interfaces(ex_gw_port) self.create_dvr_fip_interfaces(ex_gw_port)
super(DvrLocalRouter, self).process_external(agent) super(DvrLocalRouter, self).process_external()
def create_dvr_fip_interfaces(self, ex_gw_port): def create_dvr_fip_interfaces(self, ex_gw_port):
floating_ips = self.get_floating_ips() floating_ips = self.get_floating_ips()
@ -562,10 +562,10 @@ class DvrLocalRouter(dvr_router_base.DvrRouterBase):
return {common_utils.ip_to_cidr(route['cidr']) return {common_utils.ip_to_cidr(route['cidr'])
for route in exist_routes} for route in exist_routes}
def process(self, agent): def process(self):
ex_gw_port = self.get_ex_gw_port() ex_gw_port = self.get_ex_gw_port()
if ex_gw_port: if ex_gw_port:
self.fip_ns = agent.get_fip_ns(ex_gw_port['network_id']) self.fip_ns = self.agent.get_fip_ns(ex_gw_port['network_id'])
self.fip_ns.scan_fip_ports(self) self.fip_ns.scan_fip_ports(self)
super(DvrLocalRouter, self).process(agent) super(DvrLocalRouter, self).process()

View File

@ -20,15 +20,14 @@ LOG = logging.getLogger(__name__)
class DvrRouterBase(router.RouterInfo): class DvrRouterBase(router.RouterInfo):
def __init__(self, agent, host, *args, **kwargs): def __init__(self, host, *args, **kwargs):
super(DvrRouterBase, self).__init__(*args, **kwargs) super(DvrRouterBase, self).__init__(*args, **kwargs)
self.agent = agent
self.host = host self.host = host
self.snat_ports = None self.snat_ports = None
def process(self, agent): def process(self):
super(DvrRouterBase, self).process(agent) super(DvrRouterBase, self).process()
# NOTE: Keep a copy of the interfaces around for when they are removed # NOTE: Keep a copy of the interfaces around for when they are removed
self.snat_ports = self.get_snat_interfaces() self.snat_ports = self.get_snat_interfaces()

View File

@ -401,14 +401,14 @@ class HaRouter(router.RouterInfo):
namespace=self.ns_name, namespace=self.ns_name,
prefix=router.EXTERNAL_DEV_PREFIX) prefix=router.EXTERNAL_DEV_PREFIX)
def delete(self, agent): def delete(self):
self.destroy_state_change_monitor(self.process_monitor) self.destroy_state_change_monitor(self.process_monitor)
self.disable_keepalived() self.disable_keepalived()
self.ha_network_removed() self.ha_network_removed()
super(HaRouter, self).delete(agent) super(HaRouter, self).delete()
def process(self, agent): def process(self):
super(HaRouter, self).process(agent) super(HaRouter, self).process()
self.ha_port = self.router.get(n_consts.HA_INTERFACE_KEY) self.ha_port = self.router.get(n_consts.HA_INTERFACE_KEY)
if (self.ha_port and if (self.ha_port and

View File

@ -43,11 +43,13 @@ DEFAULT_ADDRESS_SCOPE = "noscope"
class RouterInfo(object): class RouterInfo(object):
def __init__(self, def __init__(self,
agent,
router_id, router_id,
router, router,
agent_conf, agent_conf,
interface_driver, interface_driver,
use_ipv6=False): use_ipv6=False):
self.agent = agent
self.router_id = router_id self.router_id = router_id
self.ex_gw_port = None self.ex_gw_port = None
self._snat_enabled = None self._snat_enabled = None
@ -374,11 +376,11 @@ class RouterInfo(object):
fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ERROR fip_statuses[fip['id']] = lib_constants.FLOATINGIP_STATUS_ERROR
return fip_statuses return fip_statuses
def delete(self, agent): def delete(self):
self.router['gw_port'] = None self.router['gw_port'] = None
self.router[lib_constants.INTERFACE_KEY] = [] self.router[lib_constants.INTERFACE_KEY] = []
self.router[lib_constants.FLOATINGIP_KEY] = [] self.router[lib_constants.FLOATINGIP_KEY] = []
self.process_delete(agent) self.process_delete()
self.disable_radvd() self.disable_radvd()
self.router_namespace.delete() self.router_namespace.delete()
@ -493,7 +495,7 @@ class RouterInfo(object):
return '-o %s -m mark ! --mark %s -j DROP' % ( return '-o %s -m mark ! --mark %s -j DROP' % (
device_name, mark_mask) device_name, mark_mask)
def _process_internal_ports(self, pd): def _process_internal_ports(self):
existing_port_ids = set(p['id'] for p in self.internal_ports) existing_port_ids = set(p['id'] for p in self.internal_ports)
internal_ports = self.router.get(lib_constants.INTERFACE_KEY, []) internal_ports = self.router.get(lib_constants.INTERFACE_KEY, [])
@ -516,7 +518,7 @@ class RouterInfo(object):
for subnet in p['subnets']: for subnet in p['subnets']:
if ipv6_utils.is_ipv6_pd_enabled(subnet): if ipv6_utils.is_ipv6_pd_enabled(subnet):
interface_name = self.get_internal_device_name(p['id']) interface_name = self.get_internal_device_name(p['id'])
pd.enable_subnet(self.router_id, subnet['id'], self.agent.pd.enable_subnet(self.router_id, subnet['id'],
subnet['cidr'], subnet['cidr'],
interface_name, p['mac_address']) interface_name, p['mac_address'])
@ -527,7 +529,7 @@ class RouterInfo(object):
enable_ra = enable_ra or self._port_has_ipv6_subnet(p) enable_ra = enable_ra or self._port_has_ipv6_subnet(p)
for subnet in p['subnets']: for subnet in p['subnets']:
if ipv6_utils.is_ipv6_pd_enabled(subnet): if ipv6_utils.is_ipv6_pd_enabled(subnet):
pd.disable_subnet(self.router_id, subnet['id']) self.agent.pd.disable_subnet(self.router_id, subnet['id'])
updated_cidrs = [] updated_cidrs = []
if updated_ports: if updated_ports:
@ -547,7 +549,8 @@ class RouterInfo(object):
if p['id'] in (set(current_port_ids) & set(existing_port_ids)): if p['id'] in (set(current_port_ids) & set(existing_port_ids)):
for subnet in p.get('subnets', []): for subnet in p.get('subnets', []):
if ipv6_utils.is_ipv6_pd_enabled(subnet): if ipv6_utils.is_ipv6_pd_enabled(subnet):
old_prefix = pd.update_subnet(self.router_id, old_prefix = self.agent.pd.update_subnet(
self.router_id,
subnet['id'], subnet['id'],
subnet['cidr']) subnet['cidr'])
if old_prefix: if old_prefix:
@ -570,7 +573,7 @@ class RouterInfo(object):
for stale_dev in stale_devs: for stale_dev in stale_devs:
LOG.debug('Deleting stale internal router device: %s', LOG.debug('Deleting stale internal router device: %s',
stale_dev) stale_dev)
pd.remove_stale_ri_ifname(self.router_id, stale_dev) self.agent.pd.remove_stale_ri_ifname(self.router_id, stale_dev)
self.driver.unplug(stale_dev, self.driver.unplug(stale_dev,
namespace=self.ns_name, namespace=self.ns_name,
prefix=INTERNAL_DEV_PREFIX) prefix=INTERNAL_DEV_PREFIX)
@ -681,11 +684,13 @@ class RouterInfo(object):
def external_gateway_added(self, ex_gw_port, interface_name): def external_gateway_added(self, ex_gw_port, interface_name):
preserve_ips = self._list_floating_ip_cidrs() preserve_ips = self._list_floating_ip_cidrs()
preserve_ips.extend(self.agent.pd.get_preserve_ips(self.router_id))
self._external_gateway_added( self._external_gateway_added(
ex_gw_port, interface_name, self.ns_name, preserve_ips) ex_gw_port, interface_name, self.ns_name, preserve_ips)
def external_gateway_updated(self, ex_gw_port, interface_name): def external_gateway_updated(self, ex_gw_port, interface_name):
preserve_ips = self._list_floating_ip_cidrs() preserve_ips = self._list_floating_ip_cidrs()
preserve_ips.extend(self.agent.pd.get_preserve_ips(self.router_id))
self._external_gateway_added( self._external_gateway_added(
ex_gw_port, interface_name, self.ns_name, preserve_ips) ex_gw_port, interface_name, self.ns_name, preserve_ips)
@ -708,7 +713,7 @@ class RouterInfo(object):
def _gateway_ports_equal(port1, port2): def _gateway_ports_equal(port1, port2):
return port1 == port2 return port1 == port2
def _process_external_gateway(self, ex_gw_port, pd): def _process_external_gateway(self, ex_gw_port):
# TODO(Carl) Refactor to clarify roles of ex_gw_port vs self.ex_gw_port # TODO(Carl) Refactor to clarify roles of ex_gw_port vs self.ex_gw_port
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
self.ex_gw_port and self.ex_gw_port['id']) self.ex_gw_port and self.ex_gw_port['id'])
@ -719,12 +724,13 @@ class RouterInfo(object):
if ex_gw_port: if ex_gw_port:
if not self.ex_gw_port: if not self.ex_gw_port:
self.external_gateway_added(ex_gw_port, interface_name) self.external_gateway_added(ex_gw_port, interface_name)
pd.add_gw_interface(self.router['id'], interface_name) self.agent.pd.add_gw_interface(self.router['id'],
interface_name)
elif not self._gateway_ports_equal(ex_gw_port, self.ex_gw_port): elif not self._gateway_ports_equal(ex_gw_port, self.ex_gw_port):
self.external_gateway_updated(ex_gw_port, interface_name) self.external_gateway_updated(ex_gw_port, interface_name)
elif not ex_gw_port and self.ex_gw_port: elif not ex_gw_port and self.ex_gw_port:
self.external_gateway_removed(self.ex_gw_port, interface_name) self.external_gateway_removed(self.ex_gw_port, interface_name)
pd.remove_gw_interface(self.router['id']) self.agent.pd.remove_gw_interface(self.router['id'])
elif not ex_gw_port and not self.ex_gw_port: elif not ex_gw_port and not self.ex_gw_port:
for p in self.internal_ports: for p in self.internal_ports:
interface_name = self.get_internal_device_name(p['id']) interface_name = self.get_internal_device_name(p['id'])
@ -736,7 +742,7 @@ class RouterInfo(object):
and dev != interface_name] and dev != interface_name]
for stale_dev in stale_devs: for stale_dev in stale_devs:
LOG.debug('Deleting stale external router device: %s', stale_dev) LOG.debug('Deleting stale external router device: %s', stale_dev)
pd.remove_gw_interface(self.router['id']) self.agent.pd.remove_gw_interface(self.router['id'])
self.driver.unplug(stale_dev, self.driver.unplug(stale_dev,
bridge=self.agent_conf.external_network_bridge, bridge=self.agent_conf.external_network_bridge,
namespace=self.ns_name, namespace=self.ns_name,
@ -820,11 +826,11 @@ class RouterInfo(object):
self.iptables_manager, self.iptables_manager,
interface_name) interface_name)
def _process_external_on_delete(self, agent): def _process_external_on_delete(self):
fip_statuses = {} fip_statuses = {}
try: try:
ex_gw_port = self.get_ex_gw_port() ex_gw_port = self.get_ex_gw_port()
self._process_external_gateway(ex_gw_port, agent.pd) self._process_external_gateway(ex_gw_port)
if not ex_gw_port: if not ex_gw_port:
return return
@ -837,14 +843,14 @@ class RouterInfo(object):
LOG.exception(_LE("Failed to process floating IPs.")) LOG.exception(_LE("Failed to process floating IPs."))
fip_statuses = self.put_fips_in_error_state() fip_statuses = self.put_fips_in_error_state()
finally: finally:
self.update_fip_statuses(agent, fip_statuses) self.update_fip_statuses(fip_statuses)
def process_external(self, agent): def process_external(self):
fip_statuses = {} fip_statuses = {}
try: try:
with self.iptables_manager.defer_apply(): with self.iptables_manager.defer_apply():
ex_gw_port = self.get_ex_gw_port() ex_gw_port = self.get_ex_gw_port()
self._process_external_gateway(ex_gw_port, agent.pd) self._process_external_gateway(ex_gw_port)
if not ex_gw_port: if not ex_gw_port:
return return
@ -863,9 +869,9 @@ class RouterInfo(object):
LOG.exception(_LE("Failed to process floating IPs.")) LOG.exception(_LE("Failed to process floating IPs."))
fip_statuses = self.put_fips_in_error_state() fip_statuses = self.put_fips_in_error_state()
finally: finally:
self.update_fip_statuses(agent, fip_statuses) self.update_fip_statuses(fip_statuses)
def update_fip_statuses(self, agent, fip_statuses): def update_fip_statuses(self, fip_statuses):
# Identify floating IPs which were disabled # Identify floating IPs which were disabled
existing_floating_ips = self.floating_ips existing_floating_ips = self.floating_ips
self.floating_ips = set(fip_statuses.keys()) self.floating_ips = set(fip_statuses.keys())
@ -878,8 +884,8 @@ class RouterInfo(object):
return return
LOG.debug('Sending floating ip statuses: %s', fip_statuses) LOG.debug('Sending floating ip statuses: %s', fip_statuses)
# Update floating IP status on the neutron server # Update floating IP status on the neutron server
agent.plugin_rpc.update_floatingip_statuses( self.agent.plugin_rpc.update_floatingip_statuses(
agent.context, self.router_id, fip_statuses) self.agent.context, self.router_id, fip_statuses)
def initialize_address_scope_iptables(self): def initialize_address_scope_iptables(self):
self._initialize_address_scope_iptables(self.iptables_manager) self._initialize_address_scope_iptables(self.iptables_manager)
@ -1035,7 +1041,7 @@ class RouterInfo(object):
self.process_floating_ip_address_scope_rules() self.process_floating_ip_address_scope_rules()
@common_utils.exception_logger() @common_utils.exception_logger()
def process_delete(self, agent): def process_delete(self):
"""Process the delete of this router """Process the delete of this router
This method is the point where the agent requests that this router This method is the point where the agent requests that this router
@ -1047,15 +1053,15 @@ class RouterInfo(object):
""" """
LOG.debug("process router delete") LOG.debug("process router delete")
if self.router_namespace.exists(): if self.router_namespace.exists():
self._process_internal_ports(agent.pd) self._process_internal_ports()
agent.pd.sync_router(self.router['id']) self.agent.pd.sync_router(self.router['id'])
self._process_external_on_delete(agent) self._process_external_on_delete()
else: else:
LOG.warning(_LW("Can't gracefully delete the router %s: " LOG.warning(_LW("Can't gracefully delete the router %s: "
"no router namespace found."), self.router['id']) "no router namespace found."), self.router['id'])
@common_utils.exception_logger() @common_utils.exception_logger()
def process(self, agent): def process(self):
"""Process updates to this router """Process updates to this router
This method is the point where the agent requests that updates be This method is the point where the agent requests that updates be
@ -1064,9 +1070,9 @@ class RouterInfo(object):
:param agent: Passes the agent in order to send RPC messages. :param agent: Passes the agent in order to send RPC messages.
""" """
LOG.debug("process router updates") LOG.debug("process router updates")
self._process_internal_ports(agent.pd) self._process_internal_ports()
agent.pd.sync_router(self.router['id']) self.agent.pd.sync_router(self.router['id'])
self.process_external(agent) self.process_external()
self.process_address_scope() self.process_address_scope()
# Process static routes for router # Process static routes for router
self.routes_updated(self.routes, self.router['routes']) self.routes_updated(self.routes, self.router['routes'])

View File

@ -158,6 +158,15 @@ class PrefixDelegation(object):
router['gw_interface'] = None router['gw_interface'] = None
self.delete_router_pd(router) self.delete_router_pd(router)
@utils.synchronized("l3-agent-pd")
def get_preserve_ips(self, router_id):
preserve_ips = []
router = self.routers.get(router_id)
if router is not None:
for subnet_id, pd_info in router['subnets'].items():
preserve_ips.append(pd_info.get_bind_lla_with_mask())
return preserve_ips
@utils.synchronized("l3-agent-pd") @utils.synchronized("l3-agent-pd")
def sync_router(self, router_id): def sync_router(self, router_id):
router = self.routers.get(router_id) router = self.routers.get(router_id)

View File

@ -135,7 +135,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
clean_fips(router) clean_fips(router)
self._add_fip(router, client_address, fixed_address=server_address) self._add_fip(router, client_address, fixed_address=server_address)
router.process(self.agent) router.process()
router_ns = ip_lib.IPWrapper(namespace=router.ns_name) router_ns = ip_lib.IPWrapper(namespace=router.ns_name)
netcat = net_helpers.NetcatTester( netcat = net_helpers.NetcatTester(
@ -159,7 +159,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
assert_num_of_conntrack_rules(1) assert_num_of_conntrack_rules(1)
clean_fips(router) clean_fips(router)
router.process(self.agent) router.process()
assert_num_of_conntrack_rules(0) assert_num_of_conntrack_rules(0)
with testtools.ExpectedException(RuntimeError): with testtools.ExpectedException(RuntimeError):
@ -237,7 +237,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
count=2, count=2,
ip_version=6, ip_version=6,
ipv6_subnet_modes=subnet_modes) ipv6_subnet_modes=subnet_modes)
router.process(self.agent) router.process()
if enable_ha: if enable_ha:
port = router.get_ex_gw_port() port = router.get_ex_gw_port()

View File

@ -1042,7 +1042,7 @@ class TestDvrRouter(framework.L3AgentTestFramework):
subnet['gateway_ip'] = None subnet['gateway_ip'] = None
router.router[n_const.FLOATINGIP_AGENT_INTF_KEY] = [new_fg_port] router.router[n_const.FLOATINGIP_AGENT_INTF_KEY] = [new_fg_port]
router.process(self.agent) router.process()
self.assertIsNone(ex_gw_device.route.get_gateway()) self.assertIsNone(ex_gw_device.route.get_gateway())
self.assertIsNone(fg_device.route.get_gateway()) self.assertIsNone(fg_device.route.get_gateway())
@ -1133,7 +1133,7 @@ class TestDvrRouter(framework.L3AgentTestFramework):
fixed_address=machine_diff_scope.ip, fixed_address=machine_diff_scope.ip,
host=self.agent.conf.host, host=self.agent.conf.host,
fixed_ip_address_scope='scope2') fixed_ip_address_scope='scope2')
router.process(self.agent) router.process()
br_ex = framework.get_ovs_bridge( br_ex = framework.get_ovs_bridge(
self.agent.conf.external_network_bridge) self.agent.conf.external_network_bridge)

View File

@ -112,7 +112,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
_ext_dev_name, ex_port = l3_test_common.prepare_ext_gw_test( _ext_dev_name, ex_port = l3_test_common.prepare_ext_gw_test(
mock.Mock(), router) mock.Mock(), router)
router_info['gw_port'] = ex_port router_info['gw_port'] = ex_port
router.process(self.agent) router.process()
self._assert_ipv6_accept_ra(router) self._assert_ipv6_accept_ra(router)
def test_keepalived_configuration(self): def test_keepalived_configuration(self):
@ -138,7 +138,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
router.router['gw_port']['subnets'] = subnets router.router['gw_port']['subnets'] = subnets
router.router['gw_port']['fixed_ips'] = fixed_ips router.router['gw_port']['fixed_ips'] = fixed_ips
router.process(self.agent) router.process()
# Get the updated configuration and assert that both FIPs are in, # Get the updated configuration and assert that both FIPs are in,
# and that the GW IP address was updated. # and that the GW IP address was updated.
@ -220,7 +220,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
self._add_internal_interface_by_subnet(router.router, count=1, self._add_internal_interface_by_subnet(router.router, count=1,
ip_version=6, ipv6_subnet_modes=[slaac_mode], ip_version=6, ipv6_subnet_modes=[slaac_mode],
interface_id=interface_id) interface_id=interface_id)
router.process(self.agent) router.process()
common_utils.wait_until_true(lambda: router.ha_state == 'master') common_utils.wait_until_true(lambda: router.ha_state == 'master')
# Verify that router internal interface is present and is configured # Verify that router internal interface is present and is configured
@ -240,7 +240,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
subnets.append(interfaces[0]['subnets'][0]) subnets.append(interfaces[0]['subnets'][0])
interfaces[0].update({'fixed_ips': fixed_ips, 'subnets': subnets}) interfaces[0].update({'fixed_ips': fixed_ips, 'subnets': subnets})
router.router[constants.INTERFACE_KEY] = interfaces router.router[constants.INTERFACE_KEY] = interfaces
router.process(self.agent) router.process()
# Verify that router internal interface has a single ipaddress # Verify that router internal interface has a single ipaddress
internal_iface = router.router[constants.INTERFACE_KEY][0] internal_iface = router.router[constants.INTERFACE_KEY][0]
@ -269,7 +269,7 @@ class L3HATestCase(framework.L3AgentTestFramework):
interface_name = router.get_external_device_interface_name(ex_gw_port) interface_name = router.get_external_device_interface_name(ex_gw_port)
common_utils.wait_until_true(lambda: router.ha_state == 'master') common_utils.wait_until_true(lambda: router.ha_state == 'master')
self._add_fip(router, '172.168.1.20', fixed_address='10.0.0.3') self._add_fip(router, '172.168.1.20', fixed_address='10.0.0.3')
router.process(self.agent) router.process()
router.router[constants.FLOATINGIP_KEY] = [] router.router[constants.FLOATINGIP_KEY] = []
# The purpose of the test is to simply make sure no exception is raised # The purpose of the test is to simply make sure no exception is raised
# Because router.process will consume the FloatingIpSetupException, # Because router.process will consume the FloatingIpSetupException,

View File

@ -93,7 +93,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
router.ex_gw_port = copy.deepcopy(router.ex_gw_port) router.ex_gw_port = copy.deepcopy(router.ex_gw_port)
for subnet in gw_port['subnets']: for subnet in gw_port['subnets']:
subnet['gateway_ip'] = None subnet['gateway_ip'] = None
router.process(self.agent) router.process()
self.assertIsNone(device.route.get_gateway()) self.assertIsNone(device.route.get_gateway())
@ -267,7 +267,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
dst_fip = '19.4.4.10' dst_fip = '19.4.4.10'
router.router[lib_constants.FLOATINGIP_KEY] = [] router.router[lib_constants.FLOATINGIP_KEY] = []
self._add_fip(router, dst_fip, fixed_address=dst_machine.ip) self._add_fip(router, dst_fip, fixed_address=dst_machine.ip)
router.process(self.agent) router.process()
return src_machine, dst_machine, dst_fip return src_machine, dst_machine, dst_fip
@ -365,7 +365,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
self._add_fip(router, fip_diff_scope, self._add_fip(router, fip_diff_scope,
fixed_address=machine_diff_scope.ip, fixed_address=machine_diff_scope.ip,
fixed_ip_address_scope='scope2') fixed_ip_address_scope='scope2')
router.process(self.agent) router.process()
br_ex = framework.get_ovs_bridge( br_ex = framework.get_ovs_bridge(
self.agent.conf.external_network_bridge) self.agent.conf.external_network_bridge)
@ -403,7 +403,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
self._add_fip(router, fip, self._add_fip(router, fip,
fixed_address=machine_diff_scope.ip, fixed_address=machine_diff_scope.ip,
fixed_ip_address_scope='scope2') fixed_ip_address_scope='scope2')
router.process(self.agent) router.process()
# For the internal networks that are in the same address scope as # For the internal networks that are in the same address scope as
# external network, they should be able to reach the floating ip # external network, they should be able to reach the floating ip

View File

@ -181,7 +181,7 @@ class BasicRouterOperationsFramework(base.BaseTestCase):
agent.process_monitor, agent.process_monitor,
ri.get_internal_device_name, ri.get_internal_device_name,
self.conf) self.conf)
ri.process(agent) ri.process()
class TestBasicRouterOperations(BasicRouterOperationsFramework): class TestBasicRouterOperations(BasicRouterOperationsFramework):
@ -281,7 +281,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_router_info_create(self): def test_router_info_create(self):
id = _uuid() id = _uuid()
ri = l3router.RouterInfo(id, {}, **self.ri_kwargs) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(agent, id, {}, **self.ri_kwargs)
self.assertTrue(ri.ns_name.endswith(id)) self.assertTrue(ri.ns_name.endswith(id))
@ -301,7 +302,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'enable_snat': True, 'enable_snat': True,
'routes': [], 'routes': [],
'gw_port': ex_gw_port} 'gw_port': ex_gw_port}
ri = l3router.RouterInfo(ns_id, router, **self.ri_kwargs) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(agent, ns_id, router, **self.ri_kwargs)
self.assertTrue(ri.ns_name.endswith(ns_id)) self.assertTrue(ri.ns_name.endswith(ns_id))
self.assertEqual(router, ri.router) self.assertEqual(router, ri.router)
@ -311,7 +313,9 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def _test_internal_network_action(self, action): def _test_internal_network_action(self, action):
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
router_id = router['id'] router_id = router['id']
ri = l3router.RouterInfo(router_id, router, **self.ri_kwargs) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(agent, router_id,
router, **self.ri_kwargs)
port = {'network_id': _uuid(), port = {'network_id': _uuid(),
'id': _uuid(), 'id': _uuid(),
'mac_address': 'ca:fe:de:ad:be:ef', 'mac_address': 'ca:fe:de:ad:be:ef',
@ -342,10 +346,9 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def _test_internal_network_action_dist(self, action): def _test_internal_network_action_dist(self, action):
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
router_id = router['id']
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router_id, router, **self.ri_kwargs) ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
subnet_id = _uuid() subnet_id = _uuid()
port = {'network_id': _uuid(), port = {'network_id': _uuid(),
'id': _uuid(), 'id': _uuid(),
@ -472,6 +475,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
ri._create_dvr_gateway.assert_called_once_with( ri._create_dvr_gateway.assert_called_once_with(
ex_gw_port, interface_name) ex_gw_port, interface_name)
def _set_ri_kwargs(self, agent, router_id, router):
self.ri_kwargs['agent'] = agent
self.ri_kwargs['router_id'] = router_id
self.ri_kwargs['router'] = router
def _test_external_gateway_action(self, action, router, dual_stack=False): def _test_external_gateway_action(self, action, router, dual_stack=False):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ex_net_id = _uuid() ex_net_id = _uuid()
@ -480,11 +488,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
if router.get('distributed'): if router.get('distributed'):
agent.conf.agent_mode = 'dvr_snat' agent.conf.agent_mode = 'dvr_snat'
agent.host = HOSTNAME agent.host = HOSTNAME
ri = dvr_router.DvrEdgeRouter(agent, self._set_ri_kwargs(agent, router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
ri._create_dvr_gateway = mock.Mock() ri._create_dvr_gateway = mock.Mock()
ri.get_snat_interfaces = mock.Mock(return_value=self.snat_ports) ri.get_snat_interfaces = mock.Mock(return_value=self.snat_ports)
ri.snat_ports = self.snat_ports ri.snat_ports = self.snat_ports
@ -493,7 +498,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
ri.internal_ports = self.snat_ports ri.internal_ports = self.snat_ports
else: else:
ri = l3router.RouterInfo( ri = l3router.RouterInfo(
router['id'], router, agent, router['id'], router,
**self.ri_kwargs) **self.ri_kwargs)
ri.use_ipv6 = False ri.use_ipv6 = False
@ -577,8 +582,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
raise Exception("Invalid action %s" % action) raise Exception("Invalid action %s" % action)
def _test_external_gateway_updated(self, dual_stack=False): def _test_external_gateway_updated(self, dual_stack=False):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'],
router, **self.ri_kwargs)
ri.use_ipv6 = False ri.use_ipv6 = False
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test( interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(
self, ri, dual_stack=dual_stack) self, ri, dual_stack=dual_stack)
@ -619,11 +626,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_dvr_edge_router_init_for_snat_namespace_object(self): def test_dvr_edge_router_init_for_snat_namespace_object(self):
router = {'id': _uuid()} router = {'id': _uuid()}
ri = dvr_router.DvrEdgeRouter(mock.Mock(), self._set_ri_kwargs(mock.Mock(), router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
# Make sure that ri.snat_namespace object is created when the # Make sure that ri.snat_namespace object is created when the
# router is initialized # router is initialized
self.assertIsNotNone(ri.snat_namespace) self.assertIsNotNone(ri.snat_namespace)
@ -637,11 +641,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
snat_namespace when the gw_port_host mismatches or none. snat_namespace when the gw_port_host mismatches or none.
""" """
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
ri = dvr_router.DvrEdgeRouter(mock.Mock(), self._set_ri_kwargs(mock.Mock(), router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
with mock.patch.object(dvr_snat_ns.SnatNamespace, with mock.patch.object(dvr_snat_ns.SnatNamespace,
'delete') as snat_ns_delete: 'delete') as snat_ns_delete:
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test( interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(
@ -666,11 +667,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
it tries to delete. it tries to delete.
""" """
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
ri = dvr_router.DvrEdgeRouter(mock.Mock(), self._set_ri_kwargs(mock.Mock(), router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
# Make sure we set a return value to emulate the non existence # Make sure we set a return value to emulate the non existence
# of the namespace. # of the namespace.
self.mock_ip.netns.exists.return_value = False self.mock_ip.netns.exists.return_value = False
@ -691,11 +689,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
snat for the router snat for the router
""" """
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
ri = dvr_router.DvrEdgeRouter(mock.Mock(), self._set_ri_kwargs(mock.Mock(), router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
if snat_hosted_before: if snat_hosted_before:
ri._create_snat_namespace() ri._create_snat_namespace()
snat_ns_name = ri.snat_namespace.name snat_ns_name = ri.snat_namespace.name
@ -830,11 +825,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_get_snat_port_for_internal_port(self): def test_get_snat_port_for_internal_port(self):
router = l3_test_common.prepare_router_data(num_internal_ports=4) router = l3_test_common.prepare_router_data(num_internal_ports=4)
ri = dvr_router.DvrEdgeRouter(mock.sentinel.agent, self._set_ri_kwargs(mock.Mock(), router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
test_port = { test_port = {
'mac_address': '00:12:23:34:45:56', 'mac_address': '00:12:23:34:45:56',
'fixed_ips': [{'subnet_id': l3_test_common.get_subnet_id( 'fixed_ips': [{'subnet_id': l3_test_common.get_subnet_id(
@ -855,17 +847,15 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_cent_router(self): def test_process_cent_router(self):
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'],
router, **self.ri_kwargs)
self._test_process_router(ri, agent) self._test_process_router(ri, agent)
def test_process_dist_router(self): def test_process_dist_router(self):
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter(agent, self._set_ri_kwargs(agent, router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
subnet_id = l3_test_common.get_subnet_id( subnet_id = l3_test_common.get_subnet_id(
router[lib_constants.INTERFACE_KEY][0]) router[lib_constants.INTERFACE_KEY][0])
ri.router['distributed'] = True ri.router['distributed'] = True
@ -893,7 +883,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'fixed_ip_address': '7.7.7.7', 'fixed_ip_address': '7.7.7.7',
'port_id': _uuid(), 'port_id': _uuid(),
'host': HOSTNAME}]} 'host': HOSTNAME}]}
ri.process(agent) ri.process()
ri.process_floating_ip_addresses.assert_called_with(mock.ANY) ri.process_floating_ip_addresses.assert_called_with(mock.ANY)
ri.process_floating_ip_addresses.reset_mock() ri.process_floating_ip_addresses.reset_mock()
ri.process_floating_ip_nat_rules.assert_called_with() ri.process_floating_ip_nat_rules.assert_called_with()
@ -905,7 +895,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
fake_floatingips2['floatingips'][0]['fixed_ip_address'] = '7.7.7.8' fake_floatingips2['floatingips'][0]['fixed_ip_address'] = '7.7.7.8'
router[lib_constants.FLOATINGIP_KEY] = fake_floatingips2['floatingips'] router[lib_constants.FLOATINGIP_KEY] = fake_floatingips2['floatingips']
ri.process(agent) ri.process()
ri.process_floating_ip_addresses.assert_called_with(mock.ANY) ri.process_floating_ip_addresses.assert_called_with(mock.ANY)
ri.process_floating_ip_addresses.reset_mock() ri.process_floating_ip_addresses.reset_mock()
ri.process_floating_ip_nat_rules.assert_called_with() ri.process_floating_ip_nat_rules.assert_called_with()
@ -922,7 +912,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
['fixed_ips'][0]['ip_address'])) ['fixed_ips'][0]['ip_address']))
ri.router['gw_port']['fixed_ips'][0]['ip_address'] = str(old_ip + 1) ri.router['gw_port']['fixed_ips'][0]['ip_address'] = str(old_ip + 1)
ri.process(agent) ri.process()
ri.process_floating_ip_addresses.reset_mock() ri.process_floating_ip_addresses.reset_mock()
ri.process_floating_ip_nat_rules.reset_mock() ri.process_floating_ip_nat_rules.reset_mock()
self.assertEqual(0, ri.external_gateway_added.call_count) self.assertEqual(0, ri.external_gateway_added.call_count)
@ -930,7 +920,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# remove just the floating ips # remove just the floating ips
del router[lib_constants.FLOATINGIP_KEY] del router[lib_constants.FLOATINGIP_KEY]
ri.process(agent) ri.process()
ri.process_floating_ip_addresses.assert_called_with(mock.ANY) ri.process_floating_ip_addresses.assert_called_with(mock.ANY)
ri.process_floating_ip_addresses.reset_mock() ri.process_floating_ip_addresses.reset_mock()
ri.process_floating_ip_nat_rules.assert_called_with() ri.process_floating_ip_nat_rules.assert_called_with()
@ -939,7 +929,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# now no ports so state is torn down # now no ports so state is torn down
del router[lib_constants.INTERFACE_KEY] del router[lib_constants.INTERFACE_KEY]
del router['gw_port'] del router['gw_port']
ri.process(agent) ri.process()
self.assertEqual(1, self.send_adv_notif.call_count) self.assertEqual(1, self.send_adv_notif.call_count)
distributed = ri.router.get('distributed', False) distributed = ri.router.get('distributed', False)
self.assertEqual(distributed, ri.process_floating_ip_addresses.called) self.assertEqual(distributed, ri.process_floating_ip_addresses.called)
@ -996,8 +986,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port
router['distributed'] = True router['distributed'] = True
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
ext_gw_port = ri.router.get('gw_port') ext_gw_port = ri.router.get('gw_port')
ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id']) ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id'])
ri.dist_fip_count = 0 ri.dist_fip_count = 0
@ -1062,8 +1052,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router[n_const.FLOATINGIP_AGENT_INTF_KEY] = [] router[n_const.FLOATINGIP_AGENT_INTF_KEY] = []
router['distributed'] = True router['distributed'] = True
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
ext_gw_port = ri.router.get('gw_port') ext_gw_port = ri.router.get('gw_port')
ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id']) ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id'])
@ -1107,8 +1097,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port
router['distributed'] = True router['distributed'] = True
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
ext_gw_port = ri.router.get('gw_port') ext_gw_port = ri.router.get('gw_port')
ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id']) ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id'])
@ -1158,8 +1148,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port
router['distributed'] = True router['distributed'] = True
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
ext_gw_port = ri.router.get('gw_port') ext_gw_port = ri.router.get('gw_port')
ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id']) ri.fip_ns = agent.get_fip_ns(ext_gw_port['network_id'])
ri.fip_ns.subscribe = mock.Mock(return_value=True) ri.fip_ns.subscribe = mock.Mock(return_value=True)
@ -1192,7 +1182,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router = l3_test_common.prepare_router_data(enable_snat=True) router = l3_test_common.prepare_router_data(enable_snat=True)
router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips']
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'],
router, **self.ri_kwargs)
ri.iptables_manager.ipv4['nat'] = mock.MagicMock() ri.iptables_manager.ipv4['nat'] = mock.MagicMock()
ri.get_external_device_name = mock.Mock(return_value='exgw') ri.get_external_device_name = mock.Mock(return_value='exgw')
self._test_process_floating_ip_addresses_add(ri, agent) self._test_process_floating_ip_addresses_add(ri, agent)
@ -1200,17 +1191,17 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_snat_disabled(self): def test_process_router_snat_disabled(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data(enable_snat=True) router = l3_test_common.prepare_router_data(enable_snat=True)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
ri.process(agent) ri.process()
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
orig_mangle_rules = ri.iptables_manager.ipv4['mangle'].rules[:] orig_mangle_rules = ri.iptables_manager.ipv4['mangle'].rules[:]
# Reprocess without NAT # Reprocess without NAT
router['enable_snat'] = False router['enable_snat'] = False
# Reassign the router object to RouterInfo # Reassign the router object to RouterInfo
ri.router = router ri.router = router
ri.process(agent) ri.process()
# For some reason set logic does not work well with # For some reason set logic does not work well with
# IpTablesRule instances # IpTablesRule instances
nat_rules_delta = [r for r in orig_nat_rules nat_rules_delta = [r for r in orig_nat_rules
@ -1227,17 +1218,17 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_snat_enabled(self): def test_process_router_snat_enabled(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data(enable_snat=False) router = l3_test_common.prepare_router_data(enable_snat=False)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# Process without NAT # Process without NAT
ri.process(agent) ri.process()
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
orig_mangle_rules = ri.iptables_manager.ipv4['mangle'].rules[:] orig_mangle_rules = ri.iptables_manager.ipv4['mangle'].rules[:]
# Reprocess with NAT # Reprocess with NAT
router['enable_snat'] = True router['enable_snat'] = True
# Reassign the router object to RouterInfo # Reassign the router object to RouterInfo
ri.router = router ri.router = router
ri.process(agent) ri.process()
# For some reason set logic does not work well with # For some reason set logic does not work well with
# IpTablesRule instances # IpTablesRule instances
nat_rules_delta = [r for r in ri.iptables_manager.ipv4['nat'].rules nat_rules_delta = [r for r in ri.iptables_manager.ipv4['nat'].rules
@ -1260,12 +1251,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'nexthop': '19.4.4.200'} 'nexthop': '19.4.4.200'}
calls = [mock.call('replace', fake_route1, q_netns)] calls = [mock.call('replace', fake_route1, q_netns)]
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, uuid, router)
agent, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
HOSTNAME,
uuid,
router,
**self.ri_kwargs)
ri._update_routing_table = mock.Mock() ri._update_routing_table = mock.Mock()
with mock.patch.object(ri, '_is_this_snat_host') as snat_host: with mock.patch.object(ri, '_is_this_snat_host') as snat_host:
@ -1285,15 +1272,15 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_interface_added(self): def test_process_router_interface_added(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
ri.process(agent) ri.process()
# Add an interface and reprocess # Add an interface and reprocess
l3_test_common.router_append_interface(router) l3_test_common.router_append_interface(router)
# Reassign the router object to RouterInfo # Reassign the router object to RouterInfo
ri.router = router ri.router = router
ri.process(agent) ri.process()
# send_ip_addr_adv_notif is called both times process is called # send_ip_addr_adv_notif is called both times process is called
self.assertEqual(2, self.send_adv_notif.call_count) self.assertEqual(2, self.send_adv_notif.call_count)
@ -1304,14 +1291,14 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Get NAT rules without the gw_port # Get NAT rules without the gw_port
gw_port = router['gw_port'] gw_port = router['gw_port']
router['gw_port'] = None router['gw_port'] = None
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
self._process_router_instance_for_agent(agent, ri, router) self._process_router_instance_for_agent(agent, ri, router)
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
# Get NAT rules with the gw_port # Get NAT rules with the gw_port
router['gw_port'] = gw_port router['gw_port'] = gw_port
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
p = ri.external_gateway_nat_fip_rules p = ri.external_gateway_nat_fip_rules
s = ri.external_gateway_nat_snat_rules s = ri.external_gateway_nat_snat_rules
attrs_to_mock = dict( attrs_to_mock = dict(
@ -1348,10 +1335,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def _process_router_ipv6_interface_added( def _process_router_ipv6_interface_added(
self, router, ra_mode=None, addr_mode=None): self, router, ra_mode=None, addr_mode=None):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
ri.process(agent) ri.process()
orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:] orig_nat_rules = ri.iptables_manager.ipv4['nat'].rules[:]
# Add an IPv6 interface and reprocess # Add an IPv6 interface and reprocess
l3_test_common.router_append_interface(router, count=1, l3_test_common.router_append_interface(router, count=1,
@ -1381,7 +1368,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def _process_router_ipv6_subnet_added(self, router, def _process_router_ipv6_subnet_added(self, router,
ipv6_subnet_modes=None, dns_nameservers=None, network_mtu=0): ipv6_subnet_modes=None, dns_nameservers=None, network_mtu=0):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
agent.external_gateway_added = mock.Mock() agent.external_gateway_added = mock.Mock()
self._process_router_instance_for_agent(agent, ri, router) self._process_router_instance_for_agent(agent, ri, router)
# Add an IPv6 interface with len(ipv6_subnet_modes) subnets # Add an IPv6 interface with len(ipv6_subnet_modes) subnets
@ -1455,7 +1442,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_ipv6_subnets_added_to_existing_port(self): def test_process_router_ipv6_subnets_added_to_existing_port(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
agent.external_gateway_added = mock.Mock() agent.external_gateway_added = mock.Mock()
self._process_router_instance_for_agent(agent, ri, router) self._process_router_instance_for_agent(agent, ri, router)
# Add the first subnet on a new interface # Add the first subnet on a new interface
@ -1497,10 +1484,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_ipv6v4_interface_added(self): def test_process_router_ipv6v4_interface_added(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
ri.process(agent) ri.process()
# Add an IPv4 and IPv6 interface and reprocess # Add an IPv4 and IPv6 interface and reprocess
l3_test_common.router_append_interface(router, count=1, ip_version=4) l3_test_common.router_append_interface(router, count=1, ip_version=4)
l3_test_common.router_append_interface(router, count=1, ip_version=6) l3_test_common.router_append_interface(router, count=1, ip_version=6)
@ -1511,22 +1498,22 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_interface_removed(self): def test_process_router_interface_removed(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# Process with NAT # Process with NAT
ri.process(agent) ri.process()
# Add an interface and reprocess # Add an interface and reprocess
del router[lib_constants.INTERFACE_KEY][1] del router[lib_constants.INTERFACE_KEY][1]
# Reassign the router object to RouterInfo # Reassign the router object to RouterInfo
ri.router = router ri.router = router
ri.process(agent) ri.process()
# send_ip_addr_adv_notif is called both times process is called # send_ip_addr_adv_notif is called both times process is called
self.assertEqual(2, self.send_adv_notif.call_count) self.assertEqual(2, self.send_adv_notif.call_count)
def test_process_router_ipv6_interface_removed(self): def test_process_router_ipv6_interface_removed(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
self._process_router_instance_for_agent(agent, ri, router) self._process_router_instance_for_agent(agent, ri, router)
# Add an IPv6 interface and reprocess # Add an IPv6 interface and reprocess
@ -1544,7 +1531,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_ipv6_subnet_removed(self): def test_process_router_ipv6_subnet_removed(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
agent.external_gateway_added = mock.Mock() agent.external_gateway_added = mock.Mock()
self._process_router_instance_for_agent(agent, ri, router) self._process_router_instance_for_agent(agent, ri, router)
# Add an IPv6 interface with two subnets and reprocess # Add an IPv6 interface with two subnets and reprocess
@ -1576,7 +1563,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_internal_network_added_unexpected_error(self): def test_process_router_internal_network_added_unexpected_error(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
with mock.patch.object( with mock.patch.object(
ri, ri,
@ -1584,7 +1571,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# raise RuntimeError to simulate that an unexpected exception # raise RuntimeError to simulate that an unexpected exception
# occurs # occurs
internal_network_added.side_effect = RuntimeError internal_network_added.side_effect = RuntimeError
self.assertRaises(RuntimeError, ri.process, agent) self.assertRaises(RuntimeError, ri.process)
self.assertNotIn( self.assertNotIn(
router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) router[lib_constants.INTERFACE_KEY][0], ri.internal_ports)
@ -1593,7 +1580,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# periodic_sync_routers_task finds out that _rpc_loop failed to # periodic_sync_routers_task finds out that _rpc_loop failed to
# process the router last time, it will retry in the next run. # process the router last time, it will retry in the next run.
ri.process(agent) ri.process()
# We were able to add the port to ri.internal_ports # We were able to add the port to ri.internal_ports
self.assertIn( self.assertIn(
router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) router[lib_constants.INTERFACE_KEY][0], ri.internal_ports)
@ -1601,10 +1588,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_process_router_internal_network_removed_unexpected_error(self): def test_process_router_internal_network_removed_unexpected_error(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
# add an internal port # add an internal port
ri.process(agent) ri.process()
with mock.patch.object( with mock.patch.object(
ri, ri,
@ -1614,7 +1601,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
internal_net_removed.side_effect = RuntimeError internal_net_removed.side_effect = RuntimeError
ri.internal_ports[0]['admin_state_up'] = False ri.internal_ports[0]['admin_state_up'] = False
# The above port is set to down state, remove it. # The above port is set to down state, remove it.
self.assertRaises(RuntimeError, ri.process, agent) self.assertRaises(RuntimeError, ri.process)
self.assertIn( self.assertIn(
router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) router[lib_constants.INTERFACE_KEY][0], ri.internal_ports)
@ -1623,7 +1610,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# periodic_sync_routers_task finds out that _rpc_loop failed to # periodic_sync_routers_task finds out that _rpc_loop failed to
# process the router last time, it will retry in the next run. # process the router last time, it will retry in the next run.
ri.process(agent) ri.process()
# We were able to remove the port from ri.internal_ports # We were able to remove the port from ri.internal_ports
self.assertNotIn( self.assertNotIn(
router[lib_constants.INTERFACE_KEY][0], ri.internal_ports) router[lib_constants.INTERFACE_KEY][0], ri.internal_ports)
@ -1639,7 +1626,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'floating_ip_address': '9.9.9.9'}) 'floating_ip_address': '9.9.9.9'})
router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2] router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2]
ri = legacy_router.LegacyRouter(router['id'], router, ri = legacy_router.LegacyRouter(agent, router['id'], router,
**self.ri_kwargs) **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
with mock.patch.object( with mock.patch.object(
@ -1648,7 +1635,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
mock.patch.object(ri, 'get_router_cidrs') as mock_get_cidrs: mock.patch.object(ri, 'get_router_cidrs') as mock_get_cidrs:
mock_get_cidrs.return_value = set( mock_get_cidrs.return_value = set(
[fip1['floating_ip_address'] + '/32']) [fip1['floating_ip_address'] + '/32'])
ri.process(agent) ri.process()
# make sure only the one that wasn't in existing cidrs was sent # make sure only the one that wasn't in existing cidrs was sent
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(
mock.ANY, ri.router_id, {fip2['id']: 'ACTIVE'}) mock.ANY, ri.router_id, {fip2['id']: 'ACTIVE'})
@ -1663,7 +1650,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
fip2.update({'id': _uuid(), 'status': 'DOWN', }) fip2.update({'id': _uuid(), 'status': 'DOWN', })
router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2] router[lib_constants.FLOATINGIP_KEY] = [fip1, fip2]
ri = legacy_router.LegacyRouter(router['id'], router, ri = legacy_router.LegacyRouter(agent, router['id'], router,
**self.ri_kwargs) **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
with mock.patch.object( with mock.patch.object(
@ -1671,7 +1658,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
) as mock_update_fip_status,\ ) as mock_update_fip_status,\
mock.patch.object(ri, 'get_router_cidrs') as mock_get_cidrs: mock.patch.object(ri, 'get_router_cidrs') as mock_get_cidrs:
mock_get_cidrs.return_value = set() mock_get_cidrs.return_value = set()
ri.process(agent) ri.process()
# make sure both was sent since not existed in existing cidrs # make sure both was sent since not existed in existing cidrs
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(
mock.ANY, ri.router_id, {fip1['id']: 'ACTIVE', mock.ANY, ri.router_id, {fip1['id']: 'ACTIVE',
@ -1691,11 +1678,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'status': 'DOWN', 'status': 'DOWN',
'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}] 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}]
ri = legacy_router.LegacyRouter(router['id'], ri = legacy_router.LegacyRouter(agent, router['id'],
router, router,
**self.ri_kwargs) **self.ri_kwargs)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
ri.process(agent) ri.process()
# Assess the call for putting the floating IP up was performed # Assess the call for putting the floating IP up was performed
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(
mock.ANY, ri.router_id, mock.ANY, ri.router_id,
@ -1704,7 +1691,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Process the router again, this time without floating IPs # Process the router again, this time without floating IPs
router[lib_constants.FLOATINGIP_KEY] = [] router[lib_constants.FLOATINGIP_KEY] = []
ri.router = router ri.router = router
ri.process(agent) ri.process()
# Assess the call for putting the floating IP up was performed # Assess the call for putting the floating IP up was performed
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(
mock.ANY, ri.router_id, mock.ANY, ri.router_id,
@ -1723,11 +1710,12 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'fixed_ip_address': '7.7.7.7', 'fixed_ip_address': '7.7.7.7',
'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}] 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}]
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'],
router, **self.ri_kwargs)
ri.process_floating_ip_addresses = mock.Mock( ri.process_floating_ip_addresses = mock.Mock(
side_effect=RuntimeError) side_effect=RuntimeError)
ri.external_gateway_added = mock.Mock() ri.external_gateway_added = mock.Mock()
ri.process(agent) ri.process()
# Assess the call for putting the floating IP into Error # Assess the call for putting the floating IP into Error
# was performed # was performed
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(
@ -1747,9 +1735,10 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
'fixed_ip_address': '7.7.7.7', 'fixed_ip_address': '7.7.7.7',
'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}] 'port_id': router[lib_constants.INTERFACE_KEY][0]['id']}]
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'],
router, **self.ri_kwargs)
ri.iptables_manager._apply = mock.Mock(side_effect=Exception) ri.iptables_manager._apply = mock.Mock(side_effect=Exception)
ri.process_external(agent) ri.process_external()
# Assess the call for putting the floating IP into Error # Assess the call for putting the floating IP into Error
# was performed # was performed
mock_update_fip_status.assert_called_once_with( mock_update_fip_status.assert_called_once_with(
@ -1760,12 +1749,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_handle_router_snat_rules_distributed_without_snat_manager(self): def test_handle_router_snat_rules_distributed_without_snat_manager(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, 'foo_router_id', {})
agent, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
HOSTNAME,
'foo_router_id',
{},
**self.ri_kwargs)
ri.iptables_manager = mock.MagicMock() ri.iptables_manager = mock.MagicMock()
ri._is_this_snat_host = mock.Mock(return_value=True) ri._is_this_snat_host = mock.Mock(return_value=True)
ri.get_ex_gw_port = mock.Mock(return_value=None) ri.get_ex_gw_port = mock.Mock(return_value=None)
@ -1775,7 +1760,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self.assertFalse(ri.iptables_manager.called) self.assertFalse(ri.iptables_manager.called)
def test_handle_router_snat_rules_add_back_jump(self): def test_handle_router_snat_rules_add_back_jump(self):
ri = l3router.RouterInfo(_uuid(), {}, **self.ri_kwargs) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(agent, _uuid(), {}, **self.ri_kwargs)
ri.iptables_manager = mock.MagicMock() ri.iptables_manager = mock.MagicMock()
port = {'fixed_ips': [{'ip_address': '192.168.1.4'}]} port = {'fixed_ips': [{'ip_address': '192.168.1.4'}]}
@ -1792,7 +1778,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
break break
def test_handle_router_snat_rules_add_rules(self): def test_handle_router_snat_rules_add_rules(self):
ri = l3router.RouterInfo(_uuid(), {}, **self.ri_kwargs) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(agent, _uuid(), {}, **self.ri_kwargs)
ex_gw_port = {'fixed_ips': [{'ip_address': '192.168.1.4'}]} ex_gw_port = {'fixed_ips': [{'ip_address': '192.168.1.4'}]}
ri.router = {'distributed': False} ri.router = {'distributed': False}
ri._handle_router_snat_rules(ex_gw_port, "iface") ri._handle_router_snat_rules(ex_gw_port, "iface")
@ -1835,7 +1822,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router = l3_test_common.prepare_router_data(enable_snat=True, router = l3_test_common.prepare_router_data(enable_snat=True,
num_internal_ports=1) num_internal_ports=1)
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
internal_ports = ri.router.get(lib_constants.INTERFACE_KEY, []) internal_ports = ri.router.get(lib_constants.INTERFACE_KEY, [])
self.assertEqual(1, len(internal_ports)) self.assertEqual(1, len(internal_ports))
@ -1850,7 +1837,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
mock.patch.object(ri, 'external_gateway_added' mock.patch.object(ri, 'external_gateway_added'
) as external_gateway_added: ) as external_gateway_added:
ri.process(agent) ri.process()
self.assertEqual(1, external_gateway_added.call_count) self.assertEqual(1, external_gateway_added.call_count)
self.assertFalse(external_gateway_removed.called) self.assertFalse(external_gateway_removed.called)
@ -1872,11 +1859,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router = l3_test_common.prepare_router_data(enable_snat=True, router = l3_test_common.prepare_router_data(enable_snat=True,
num_internal_ports=1) num_internal_ports=1)
del router['gw_port'] del router['gw_port']
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs) ri = l3router.RouterInfo(agent, router['id'], router, **self.ri_kwargs)
self.mock_ip.get_devices.return_value = stale_devlist self.mock_ip.get_devices.return_value = stale_devlist
ri.process(agent) ri.process()
self.mock_driver.unplug.assert_called_with( self.mock_driver.unplug.assert_called_with(
stale_devnames[0], stale_devnames[0],
@ -2072,7 +2059,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self.assertFalse(router_processor.fetched_and_processed.called) self.assertFalse(router_processor.fetched_and_processed.called)
agent._resync_router.assert_called_with(update) agent._resync_router.assert_called_with(update)
else: else:
router_info.delete.assert_called_once_with(agent) router_info.delete.assert_called_once_with()
self.assertFalse(agent.router_info) self.assertFalse(agent.router_info)
self.assertFalse(agent._resync_router.called) self.assertFalse(agent._resync_router.called)
router_processor.fetched_and_processed.assert_called_once_with( router_processor.fetched_and_processed.assert_called_once_with(
@ -2245,11 +2232,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_create_dvr_gateway(self): def test_create_dvr_gateway(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = dvr_router.DvrEdgeRouter(agent, self._set_ri_kwargs(agent, router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
port_id = _uuid() port_id = _uuid()
subnet_id = _uuid() subnet_id = _uuid()
@ -2281,11 +2265,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
router['gw_port_host'] = HOSTNAME router['gw_port_host'] = HOSTNAME
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrEdgeRouter(agent, self._set_ri_kwargs(agent, router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
ri.get_ex_gw_port = mock.Mock(return_value=None) ri.get_ex_gw_port = mock.Mock(return_value=None)
# Make sure the code doesn't crash if ri.snat_iptables_manager is None. # Make sure the code doesn't crash if ri.snat_iptables_manager is None.
@ -2332,8 +2313,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self.mock_driver.unplug.reset_mock() self.mock_driver.unplug.reset_mock()
external_net_id = router['gw_port']['network_id'] external_net_id = router['gw_port']['network_id']
ri = dvr_router.DvrEdgeRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
ri.remove_floating_ip = mock.Mock() ri.remove_floating_ip = mock.Mock()
agent._fetch_external_net_id = mock.Mock(return_value=external_net_id) agent._fetch_external_net_id = mock.Mock(return_value=external_net_id)
ri.ex_gw_port = ri.router['gw_port'] ri.ex_gw_port = ri.router['gw_port']
@ -2487,10 +2468,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def _pd_setup_agent_router(self): def _pd_setup_agent_router(self):
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
ri = l3router.RouterInfo(router['id'], router, **self.ri_kwargs)
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = l3router.RouterInfo(agent, router['id'],
router, **self.ri_kwargs)
agent.external_gateway_added = mock.Mock() agent.external_gateway_added = mock.Mock()
ri.process(agent) ri.process()
agent._router_added(router['id'], router) agent._router_added(router['id'], router)
# Make sure radvd monitor is created # Make sure radvd monitor is created
if not ri.radvd: if not ri.radvd:
@ -2561,7 +2543,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Process the router for removed interfaces # Process the router for removed interfaces
agent.pd.notifier = pd_notifier agent.pd.notifier = pd_notifier
ri.process(agent) ri.process()
# The number of external process calls takes radvd into account. # The number of external process calls takes radvd into account.
# This is because there is no ipv6 interface any more after removing # This is because there is no ipv6 interface any more after removing
@ -2677,7 +2659,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Create one pd-enabled subnet and add router interface # Create one pd-enabled subnet and add router interface
intfs = l3_test_common.router_append_pd_enabled_subnet(router) intfs = l3_test_common.router_append_pd_enabled_subnet(router)
ri.process(agent) ri.process()
# No client should be started since there is no gateway port # No client should be started since there is no gateway port
self.assertFalse(self.external_process.call_count) self.assertFalse(self.external_process.call_count)
@ -2690,7 +2672,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix) self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix)
# Update the router with the new prefix # Update the router with the new prefix
ri.process(agent) ri.process()
# Check that radvd is started and the router port is configured # Check that radvd is started and the router port is configured
# with the new prefix # with the new prefix
@ -2716,7 +2698,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Create one pd-enabled subnet and add router interface # Create one pd-enabled subnet and add router interface
intfs = l3_test_common.router_append_pd_enabled_subnet(router) intfs = l3_test_common.router_append_pd_enabled_subnet(router)
ri.process(agent) ri.process()
# Add the gateway interface # Add the gateway interface
self._pd_add_gw_interface(agent, router, ri) self._pd_add_gw_interface(agent, router, ri)
@ -2725,7 +2707,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix) self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix)
# Update the router with the new prefix # Update the router with the new prefix
ri.process(agent) ri.process()
# Check that radvd is started # Check that radvd is started
self._pd_assert_radvd_calls(ri) self._pd_assert_radvd_calls(ri)
@ -2734,7 +2716,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self._pd_remove_gw_interface(intfs, agent, router, ri) self._pd_remove_gw_interface(intfs, agent, router, ri)
# There will be a router update # There will be a router update
ri.process(agent) ri.process()
@mock.patch.object(dibbler.PDDibbler, 'get_prefix', autospec=True) @mock.patch.object(dibbler.PDDibbler, 'get_prefix', autospec=True)
@mock.patch.object(dibbler.os, 'getpid', return_value=1234) @mock.patch.object(dibbler.os, 'getpid', return_value=1234)
@ -2753,7 +2735,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Create 2 pd-enabled subnets and add router interfaces # Create 2 pd-enabled subnets and add router interfaces
intfs = l3_test_common.router_append_pd_enabled_subnet(router, count=2) intfs = l3_test_common.router_append_pd_enabled_subnet(router, count=2)
ri.process(agent) ri.process()
# No client should be started # No client should be started
self.assertFalse(self.external_process.call_count) self.assertFalse(self.external_process.call_count)
@ -2766,7 +2748,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix) self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix)
# Update the router with the new prefix # Update the router with the new prefix
ri.process(agent) ri.process()
# Check that radvd is started and the router port is configured # Check that radvd is started and the router port is configured
# with the new prefix # with the new prefix
@ -2795,13 +2777,13 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Create 1 pd-enabled subnet and add router interface # Create 1 pd-enabled subnet and add router interface
intfs = l3_test_common.router_append_pd_enabled_subnet(router, count=1) intfs = l3_test_common.router_append_pd_enabled_subnet(router, count=1)
ri.process(agent) ri.process()
# Get prefixes # Get prefixes
self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix) self._pd_get_prefixes(agent, router, ri, [], intfs, mock_get_prefix)
# Update the router with the new prefix # Update the router with the new prefix
ri.process(agent) ri.process()
# Check that radvd is started # Check that radvd is started
self._pd_assert_radvd_calls(ri) self._pd_assert_radvd_calls(ri)
@ -2810,14 +2792,14 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Create one pd-enabled subnet and add router interface # Create one pd-enabled subnet and add router interface
intfs1 = l3_test_common.router_append_pd_enabled_subnet(router, intfs1 = l3_test_common.router_append_pd_enabled_subnet(router,
count=1) count=1)
ri.process(agent) ri.process()
# Get prefixes # Get prefixes
self._pd_get_prefixes(agent, router, ri, intfs, self._pd_get_prefixes(agent, router, ri, intfs,
intfs1, mock_get_prefix) intfs1, mock_get_prefix)
# Update the router with the new prefix # Update the router with the new prefix
ri.process(agent) ri.process()
# Check that radvd is notified for the new prefix # Check that radvd is notified for the new prefix
self._pd_assert_radvd_calls(ri) self._pd_assert_radvd_calls(ri)
@ -2825,7 +2807,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
# Now remove the gw interface # Now remove the gw interface
self._pd_remove_gw_interface(intfs + intfs1, agent, router, ri) self._pd_remove_gw_interface(intfs + intfs1, agent, router, ri)
ri.process(agent) ri.process()
def _verify_address_scopes_iptables_rule(self, mock_iptables_manager): def _verify_address_scopes_iptables_rule(self, mock_iptables_manager):
filter_calls = [mock.call.add_chain('scope'), filter_calls = [mock.call.add_chain('scope'),
@ -2855,20 +2837,18 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
def test_initialize_address_scope_iptables_rules(self): def test_initialize_address_scope_iptables_rules(self):
id = _uuid() id = _uuid()
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
with mock.patch('neutron.agent.linux.iptables_manager.' with mock.patch('neutron.agent.linux.iptables_manager.'
'IptablesManager'): 'IptablesManager'):
ri = l3router.RouterInfo(id, {}, **self.ri_kwargs) ri = l3router.RouterInfo(agent, id, {}, **self.ri_kwargs)
self._verify_address_scopes_iptables_rule(ri.iptables_manager) self._verify_address_scopes_iptables_rule(ri.iptables_manager)
def test_initialize_address_scope_iptables_rules_dvr(self): def test_initialize_address_scope_iptables_rules_dvr(self):
router = l3_test_common.prepare_router_data() router = l3_test_common.prepare_router_data()
with mock.patch('neutron.agent.linux.iptables_manager.' with mock.patch('neutron.agent.linux.iptables_manager.'
'IptablesManager'): 'IptablesManager'):
ri = dvr_router.DvrEdgeRouter(mock.Mock(), self._set_ri_kwargs(mock.Mock(), router['id'], router)
HOSTNAME, ri = dvr_router.DvrEdgeRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
self._verify_address_scopes_iptables_rule(ri.iptables_manager) self._verify_address_scopes_iptables_rule(ri.iptables_manager)
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test( interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(
self, ri) self, ri)

View File

@ -152,13 +152,17 @@ class TestDvrRouterOperations(base.BaseTestCase):
self.router_id = _uuid() self.router_id = _uuid()
if not router: if not router:
router = mock.MagicMock() router = mock.MagicMock()
return dvr_router.DvrLocalRouter(agent, kwargs['agent'] = agent
HOSTNAME, kwargs['router_id'] = self.router_id
self.router_id, kwargs['router'] = router
router, kwargs['agent_conf'] = self.conf
self.conf, kwargs['interface_driver'] = mock.Mock()
mock.Mock(), return dvr_router.DvrLocalRouter(HOSTNAME, **kwargs)
**kwargs)
def _set_ri_kwargs(self, agent, router_id, router):
self.ri_kwargs['agent'] = agent
self.ri_kwargs['router_id'] = router_id
self.ri_kwargs['router'] = router
def test_create_dvr_fip_interfaces_update(self): def test_create_dvr_fip_interfaces_update(self):
ri = self._create_router() ri = self._create_router()
@ -374,8 +378,8 @@ class TestDvrRouterOperations(base.BaseTestCase):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
router['distributed'] = True router['distributed'] = True
ri = dvr_router.DvrLocalRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
ports = ri.router.get(lib_constants.INTERFACE_KEY, []) ports = ri.router.get(lib_constants.INTERFACE_KEY, [])
subnet_id = l3_test_common.get_subnet_id(ports[0]) subnet_id = l3_test_common.get_subnet_id(ports[0])
test_ports = [{'mac_address': '00:11:22:33:44:55', test_ports = [{'mac_address': '00:11:22:33:44:55',
@ -431,12 +435,10 @@ class TestDvrRouterOperations(base.BaseTestCase):
agent.add_arp_entry(None, payload) agent.add_arp_entry(None, payload)
def test__update_arp_entry_with_no_subnet(self): def test__update_arp_entry_with_no_subnet(self):
ri = dvr_router.DvrLocalRouter( self._set_ri_kwargs(mock.sentinel.agent,
mock.sentinel.agent, 'foo_router_id',
HOSTNAME, {'distributed': True, 'gw_port_host': HOSTNAME})
'foo_router_id', ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
{'distributed': True, 'gw_port_host': HOSTNAME},
**self.ri_kwargs)
with mock.patch.object(l3_agent.ip_lib, 'IPDevice') as f: with mock.patch.object(l3_agent.ip_lib, 'IPDevice') as f:
ri._update_arp_entry(mock.ANY, mock.ANY, 'foo_subnet_id', 'add') ri._update_arp_entry(mock.ANY, mock.ANY, 'foo_subnet_id', 'add')
self.assertFalse(f.call_count) self.assertFalse(f.call_count)
@ -445,8 +447,8 @@ class TestDvrRouterOperations(base.BaseTestCase):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
router['distributed'] = True router['distributed'] = True
ri = dvr_router.DvrLocalRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
subnet_id = l3_test_common.get_subnet_id( subnet_id = l3_test_common.get_subnet_id(
ri.router[lib_constants.INTERFACE_KEY][0]) ri.router[lib_constants.INTERFACE_KEY][0])
return ri, subnet_id return ri, subnet_id
@ -524,8 +526,8 @@ class TestDvrRouterOperations(base.BaseTestCase):
router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port router[n_const.FLOATINGIP_AGENT_INTF_KEY] = agent_gateway_port
router['distributed'] = True router['distributed'] = True
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrLocalRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
self.assertEqual( self.assertEqual(
agent_gateway_port[0], agent_gateway_port[0],
ri.get_floating_agent_gw_interface(fake_network_id)) ri.get_floating_agent_gw_interface(fake_network_id))
@ -549,11 +551,8 @@ class TestDvrRouterOperations(base.BaseTestCase):
router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips'] router[lib_constants.FLOATINGIP_KEY] = fake_floatingips['floatingips']
router['distributed'] = True router['distributed'] = True
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrLocalRouter(agent, self._set_ri_kwargs(agent, router['id'], router)
HOSTNAME, ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
ri.iptables_manager.ipv4['nat'] = mock.MagicMock() ri.iptables_manager.ipv4['nat'] = mock.MagicMock()
ri.dist_fip_count = 0 ri.dist_fip_count = 0
fip_ns = agent.get_fip_ns(mock.sentinel.ext_net_id) fip_ns = agent.get_fip_ns(mock.sentinel.ext_net_id)
@ -573,11 +572,8 @@ class TestDvrRouterOperations(base.BaseTestCase):
agent_mode, expected_call_count): agent_mode, expected_call_count):
router = l3_test_common.prepare_router_data(num_internal_ports=2) router = l3_test_common.prepare_router_data(num_internal_ports=2)
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ri = dvr_router.DvrLocalRouter(agent, self._set_ri_kwargs(agent, router['id'], router)
HOSTNAME, ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
router['id'],
router,
**self.ri_kwargs)
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(self, interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(self,
ri) ri)
@ -609,8 +605,8 @@ class TestDvrRouterOperations(base.BaseTestCase):
self.mock_driver.unplug.reset_mock() self.mock_driver.unplug.reset_mock()
external_net_id = router['gw_port']['network_id'] external_net_id = router['gw_port']['network_id']
ri = dvr_router.DvrLocalRouter( self._set_ri_kwargs(agent, router['id'], router)
agent, HOSTNAME, router['id'], router, **self.ri_kwargs) ri = dvr_router.DvrLocalRouter(HOSTNAME, **self.ri_kwargs)
ri.remove_floating_ip = mock.Mock() ri.remove_floating_ip = mock.Mock()
agent._fetch_external_net_id = mock.Mock(return_value=external_net_id) agent._fetch_external_net_id = mock.Mock(return_value=external_net_id)
ri.ex_gw_port = ri.router['gw_port'] ri.ex_gw_port = ri.router['gw_port']

View File

@ -34,6 +34,7 @@ class TestBasicRouterOperations(base.BaseTestCase):
self.agent_conf = mock.Mock() self.agent_conf = mock.Mock()
self.router_id = _uuid() self.router_id = _uuid()
return ha_router.HaRouter(mock.sentinel.enqueue_state, return ha_router.HaRouter(mock.sentinel.enqueue_state,
mock.sentinel.agent,
self.router_id, self.router_id,
router, router,
self.agent_conf, self.agent_conf,

View File

@ -34,7 +34,7 @@ class TestL3AgentExtensionApi(base.BaseTestCase):
'agent_conf': mock.ANY, 'agent_conf': mock.ANY,
'interface_driver': mock.ANY, 'interface_driver': mock.ANY,
'use_ipv6': mock.ANY} 'use_ipv6': mock.ANY}
ri = router_info.RouterInfo(self.router_id, **ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), self.router_id, **ri_kwargs)
ri.internal_ports = ports ri.internal_ports = ports
return {ri.router_id: ri}, ri return {ri.router_id: ri}, ri

View File

@ -30,7 +30,8 @@ class BasicRouterTestCaseFramework(base.BaseTestCase):
self.agent_conf = mock.Mock() self.agent_conf = mock.Mock()
self.driver = mock.Mock() self.driver = mock.Mock()
self.router_id = _uuid() self.router_id = _uuid()
return legacy_router.LegacyRouter(self.router_id, return legacy_router.LegacyRouter(mock.Mock(),
self.router_id,
router, router,
self.agent_conf, self.agent_conf,
self.driver, self.driver,

View File

@ -43,7 +43,7 @@ class TestRouterInfo(base.BaseTestCase):
any_order=True) any_order=True)
def test_routing_table_update(self): def test_routing_table_update(self):
ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs)
ri.router = {} ri.router = {}
fake_route1 = {'destination': '135.207.0.0/16', fake_route1 = {'destination': '135.207.0.0/16',
@ -78,7 +78,8 @@ class TestRouterInfo(base.BaseTestCase):
fake_route1 = {'destination': '135.207.0.0/16', fake_route1 = {'destination': '135.207.0.0/16',
'nexthop': '1.2.3.4'} 'nexthop': '1.2.3.4'}
ri = router_info.RouterInfo(uuid, {'id': uuid}, **self.ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), uuid,
{'id': uuid}, **self.ri_kwargs)
ri._update_routing_table = mock.Mock() ri._update_routing_table = mock.Mock()
ri.update_routing_table('replace', fake_route1) ri.update_routing_table('replace', fake_route1)
@ -87,7 +88,7 @@ class TestRouterInfo(base.BaseTestCase):
netns) netns)
def test_routes_updated(self): def test_routes_updated(self):
ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs)
ri.router = {} ri.router = {}
fake_old_routes = [] fake_old_routes = []
@ -123,7 +124,7 @@ class TestRouterInfo(base.BaseTestCase):
self._check_agent_method_called(expected) self._check_agent_method_called(expected)
def test_add_ports_address_scope_iptables(self): def test_add_ports_address_scope_iptables(self):
ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs)
port = { port = {
'id': _uuid(), 'id': _uuid(),
'fixed_ips': [{'ip_address': '172.9.9.9'}], 'fixed_ips': [{'ip_address': '172.9.9.9'}],
@ -146,7 +147,7 @@ class TestRouterInfo(base.BaseTestCase):
def test_address_scope_mark_ids_handling(self): def test_address_scope_mark_ids_handling(self):
mark_ids = set(range(router_info.ADDRESS_SCOPE_MARK_ID_MIN, mark_ids = set(range(router_info.ADDRESS_SCOPE_MARK_ID_MIN,
router_info.ADDRESS_SCOPE_MARK_ID_MAX)) router_info.ADDRESS_SCOPE_MARK_ID_MAX))
ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs)
# first mark id is used for the default address scope # first mark id is used for the default address scope
scope_to_mark_id = {router_info.DEFAULT_ADDRESS_SCOPE: mark_ids.pop()} scope_to_mark_id = {router_info.DEFAULT_ADDRESS_SCOPE: mark_ids.pop()}
self.assertEqual(scope_to_mark_id, ri._address_scope_to_mark_id) self.assertEqual(scope_to_mark_id, ri._address_scope_to_mark_id)
@ -161,27 +162,28 @@ class TestRouterInfo(base.BaseTestCase):
# new router should have it's own mark ids set # new router should have it's own mark ids set
new_mark_ids = set(range(router_info.ADDRESS_SCOPE_MARK_ID_MIN, new_mark_ids = set(range(router_info.ADDRESS_SCOPE_MARK_ID_MIN,
router_info.ADDRESS_SCOPE_MARK_ID_MAX)) router_info.ADDRESS_SCOPE_MARK_ID_MAX))
new_ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs) new_ri = router_info.RouterInfo(mock.Mock(), _uuid(),
{}, **self.ri_kwargs)
new_mark_ids.pop() new_mark_ids.pop()
self.assertEqual(new_mark_ids, new_ri.available_mark_ids) self.assertEqual(new_mark_ids, new_ri.available_mark_ids)
self.assertTrue(ri.available_mark_ids != new_ri.available_mark_ids) self.assertTrue(ri.available_mark_ids != new_ri.available_mark_ids)
def test_process_delete(self): def test_process_delete(self):
ri = router_info.RouterInfo(_uuid(), {}, **self.ri_kwargs) ri = router_info.RouterInfo(mock.Mock(), _uuid(), {}, **self.ri_kwargs)
ri.router = {'id': _uuid()} ri.router = {'id': _uuid()}
with mock.patch.object(ri, '_process_internal_ports') as p_i_p,\ with mock.patch.object(ri, '_process_internal_ports') as p_i_p,\
mock.patch.object(ri, '_process_external_on_delete') as p_e_o_d: mock.patch.object(ri, '_process_external_on_delete') as p_e_o_d:
self.mock_ip.netns.exists.return_value = False self.mock_ip.netns.exists.return_value = False
ri.process_delete(mock.Mock()) ri.process_delete()
self.assertFalse(p_i_p.called) self.assertFalse(p_i_p.called)
self.assertFalse(p_e_o_d.called) self.assertFalse(p_e_o_d.called)
p_i_p.reset_mock() p_i_p.reset_mock()
p_e_o_d.reset_mock() p_e_o_d.reset_mock()
self.mock_ip.netns.exists.return_value = True self.mock_ip.netns.exists.return_value = True
ri.process_delete(mock.Mock()) ri.process_delete()
p_i_p.assert_called_once_with(mock.ANY) p_i_p.assert_called_once_with()
p_e_o_d.assert_called_once_with(mock.ANY) p_e_o_d.assert_called_once_with()
class BasicRouterTestCaseFramework(base.BaseTestCase): class BasicRouterTestCaseFramework(base.BaseTestCase):
@ -190,7 +192,8 @@ class BasicRouterTestCaseFramework(base.BaseTestCase):
router = mock.MagicMock() router = mock.MagicMock()
self.agent_conf = mock.Mock() self.agent_conf = mock.Mock()
self.router_id = _uuid() self.router_id = _uuid()
return router_info.RouterInfo(self.router_id, return router_info.RouterInfo(mock.Mock(),
self.router_id,
router, router,
self.agent_conf, self.agent_conf,
mock.sentinel.interface_driver, mock.sentinel.interface_driver,

View File

@ -86,7 +86,7 @@ class TestMetadataDriverProcess(base.BaseTestCase):
agent = l3_agent.L3NATAgent('localhost') agent = l3_agent.L3NATAgent('localhost')
router_id = _uuid() router_id = _uuid()
router = {'id': router_id} router = {'id': router_id}
ri = router_info.RouterInfo(router_id, router, ri = router_info.RouterInfo(mock.Mock(), router_id, router,
agent.conf, mock.ANY) agent.conf, mock.ANY)
agent.router_info[router_id] = ri agent.router_info[router_id] = ri
agent._process_updated_router(router) agent._process_updated_router(router)