os_router: fix checking if router needs update (#19780)

When verifying if a router needs update, the os_router module should
take into account only network ports which are owned by routers. Other
ports might have been added e.g. by the HA network tenant, which would
lead the router to always be detected as changed and cause the module to
try removing these network interfaces.
pull/19662/head
Paulo Matias 7 years ago committed by Ricardo Carrillo Cruz
parent ff7c0019c3
commit c8124ca39a

@ -180,6 +180,16 @@ except ImportError:
from distutils.version import StrictVersion
ROUTER_INTERFACE_OWNERS = set([
'network:router_interface',
'network:router_interface_distributed',
'network:ha_router_replicated_interface'
])
def _router_internal_interfaces(cloud, router):
for port in cloud.list_router_interfaces(router, 'internal'):
if port['device_owner'] in ROUTER_INTERFACE_OWNERS:
yield port
def _needs_update(cloud, module, router, network, internal_subnet_ids):
"""Decide if the given router needs an update.
@ -221,7 +231,7 @@ def _needs_update(cloud, module, router, network, internal_subnet_ids):
# check internal interfaces
if module.params['interfaces']:
existing_subnet_ids = []
for port in cloud.list_router_interfaces(router, 'internal'):
for port in _router_internal_interfaces(cloud, router):
if 'fixed_ips' in port:
for fixed_ip in port['fixed_ips']:
existing_subnet_ids.append(fixed_ip['subnet_id'])
@ -377,7 +387,7 @@ def main():
# just detach all existing internal interfaces and attach the new.
elif internal_ids:
router = updated_router
ports = cloud.list_router_interfaces(router, 'internal')
ports = _router_internal_interfaces(cloud, router)
for port in ports:
cloud.remove_router_interface(router, port_id=port['id'])
for internal_subnet_id in internal_ids:
@ -394,7 +404,7 @@ def main():
else:
# We need to detach all internal interfaces on a router before
# we will be allowed to delete it.
ports = cloud.list_router_interfaces(router, 'internal')
ports = _router_internal_interfaces(cloud, router)
router_id = router['id']
for port in ports:
cloud.remove_router_interface(router, port_id=port['id'])

Loading…
Cancel
Save