Bug fix: Do not fail on routers with no ext gw
Although I've not been able to reproduce it, some user have reported an exception from shade in the list_router_interfaces() call when trying to access the external_gateway_info of a router that does not have this key set. Let's just be safe and and a check to make sure that the key exists. Change-Id: I949b76b2b306e5161e7ee77d6c588a77ac4c7d87
This commit is contained in:
parent
cf43b98e33
commit
ff82154b90
4
releasenotes/notes/router_ext_gw-b86582317bca8b39.yaml
Normal file
4
releasenotes/notes/router_ext_gw-b86582317bca8b39.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- No longer fail in list_router_interfaces() if a router does
|
||||
not have the external_gateway_info key.
|
@ -1854,9 +1854,12 @@ class OpenStackCloud(object):
|
||||
|
||||
if interface_type:
|
||||
filtered_ports = []
|
||||
ext_fixed = (router['external_gateway_info']['external_fixed_ips']
|
||||
if router['external_gateway_info']
|
||||
else [])
|
||||
if ('external_gateway_info' in router and
|
||||
'external_fixed_ips' in router['external_gateway_info']):
|
||||
ext_fixed = \
|
||||
router['external_gateway_info']['external_fixed_ips']
|
||||
else:
|
||||
ext_fixed = []
|
||||
|
||||
# Compare the subnets (subnet_id, ip_address) on the ports with
|
||||
# the subnets making up the router external gateway. Those ports
|
||||
|
@ -250,6 +250,28 @@ class TestShade(base.TestCase):
|
||||
self.cloud.delete_router('123')
|
||||
self.assertTrue(mock_client.delete_router.called)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'search_ports')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_list_router_interfaces_no_gw(self, mock_client, mock_search):
|
||||
"""
|
||||
If a router does not have external_gateway_info, do not fail.
|
||||
"""
|
||||
external_port = {'id': 'external_port_id',
|
||||
'fixed_ips': [
|
||||
('external_subnet_id', 'ip_address'),
|
||||
]}
|
||||
port_list = [external_port]
|
||||
router = {
|
||||
'id': 'router_id',
|
||||
}
|
||||
mock_search.return_value = port_list
|
||||
ret = self.cloud.list_router_interfaces(router,
|
||||
interface_type='external')
|
||||
mock_search.assert_called_once_with(
|
||||
filters={'device_id': router['id']}
|
||||
)
|
||||
self.assertEqual([], ret)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'search_ports')
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_list_router_interfaces_all(self, mock_client, mock_search):
|
||||
|
Loading…
Reference in New Issue
Block a user