From c8124ca39a76ec7264d7840d247e53cba9966bfb Mon Sep 17 00:00:00 2001 From: Paulo Matias Date: Wed, 16 Aug 2017 17:38:49 -0300 Subject: [PATCH] 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. --- lib/ansible/modules/cloud/openstack/os_router.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_router.py b/lib/ansible/modules/cloud/openstack/os_router.py index 46b2297ccf7..d27f40af77e 100644 --- a/lib/ansible/modules/cloud/openstack/os_router.py +++ b/lib/ansible/modules/cloud/openstack/os_router.py @@ -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'])