@ -26,6 +26,7 @@ from neutron.agent import l3_agent
from neutron . agent . linux import interface
from neutron . common import config as base_config
from neutron . common import constants as l3_constants
from neutron . common import exceptions as n_exc
from neutron . openstack . common import uuidutils
from neutron . tests import base
@ -842,6 +843,76 @@ class TestBasicRouterOperations(base.BaseTestCase):
agent = l3_agent . L3NATAgent ( HOSTNAME , self . conf )
self . assertEqual ( [ ' 1234 ' ] , agent . _router_ids ( ) )
def test_process_routers_with_no_ext_net_in_conf ( self ) :
agent = l3_agent . L3NATAgent ( HOSTNAME , self . conf )
self . plugin_api . get_external_network_id . return_value = ' aaa '
routers = [
{ ' id ' : _uuid ( ) ,
' routes ' : [ ] ,
' admin_state_up ' : True ,
' external_gateway_info ' : { ' network_id ' : ' aaa ' } } ]
agent . _process_routers ( routers )
self . assertIn ( routers [ 0 ] [ ' id ' ] , agent . router_info )
def test_process_routers_with_no_ext_net_in_conf_and_two_net_plugin ( self ) :
agent = l3_agent . L3NATAgent ( HOSTNAME , self . conf )
routers = [
{ ' id ' : _uuid ( ) ,
' routes ' : [ ] ,
' admin_state_up ' : True ,
' external_gateway_info ' : { ' network_id ' : ' aaa ' } } ]
agent . router_info = { }
self . plugin_api . get_external_network_id . side_effect = (
n_exc . TooManyExternalNetworks ( ) )
self . assertRaises ( n_exc . TooManyExternalNetworks ,
agent . _process_routers ,
routers )
self . assertNotIn ( routers [ 0 ] [ ' id ' ] , agent . router_info )
def test_process_routers_with_ext_net_in_conf ( self ) :
agent = l3_agent . L3NATAgent ( HOSTNAME , self . conf )
self . plugin_api . get_external_network_id . return_value = ' aaa '
routers = [
{ ' id ' : _uuid ( ) ,
' routes ' : [ ] ,
' admin_state_up ' : True ,
' external_gateway_info ' : { ' network_id ' : ' aaa ' } } ,
{ ' id ' : _uuid ( ) ,
' routes ' : [ ] ,
' admin_state_up ' : True ,
' external_gateway_info ' : { ' network_id ' : ' bbb ' } } ]
agent . router_info = { }
self . conf . set_override ( ' gateway_external_network_id ' , ' aaa ' )
agent . _process_routers ( routers )
self . assertIn ( routers [ 0 ] [ ' id ' ] , agent . router_info )
self . assertNotIn ( routers [ 1 ] [ ' id ' ] , agent . router_info )
def test_process_routers_with_no_bridge_no_ext_net_in_conf ( self ) :
agent = l3_agent . L3NATAgent ( HOSTNAME , self . conf )
self . plugin_api . get_external_network_id . return_value = ' aaa '
routers = [
{ ' id ' : _uuid ( ) ,
' routes ' : [ ] ,
' admin_state_up ' : True ,
' external_gateway_info ' : { ' network_id ' : ' aaa ' } } ,
{ ' id ' : _uuid ( ) ,
' routes ' : [ ] ,
' admin_state_up ' : True ,
' external_gateway_info ' : { ' network_id ' : ' bbb ' } } ]
agent . router_info = { }
self . conf . set_override ( ' external_network_bridge ' , ' ' )
agent . _process_routers ( routers )
self . assertIn ( routers [ 0 ] [ ' id ' ] , agent . router_info )
self . assertIn ( routers [ 1 ] [ ' id ' ] , agent . router_info )
def test_nonexistent_interface_driver ( self ) :
self . conf . set_override ( ' interface_driver ' , None )
with mock . patch . object ( l3_agent , ' LOG ' ) as log :