From 98bb212ae4ae5202d615801c006bd82210e6d100 Mon Sep 17 00:00:00 2001 From: Andrew Bonney Date: Mon, 17 Mar 2025 13:46:55 +0000 Subject: [PATCH] Fix router module external IPs when only subnet specified The router module used to support adding external fixed IPs by specifying the subnet only, and the documentation still allows for this. Unfortunately the logic currently results in an error message stating that the ip_address cannot be null. This patch reinstates this functionality and adds tests to avoid a future regression. Change-Id: Ie29c7b2b763a58ea107cc50507e99f650ee9e53f --- ci/roles/router/tasks/main.yml | 40 ++++++++++++++++++++++++++++++++++ plugins/modules/router.py | 6 ++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/ci/roles/router/tasks/main.yml b/ci/roles/router/tasks/main.yml index 10f605b5..53694852 100644 --- a/ci/roles/router/tasks/main.yml +++ b/ci/roles/router/tasks/main.yml @@ -558,6 +558,46 @@ assert: that: router is not changed +- name: Create router without explicit IP address + openstack.cloud.router: + cloud: "{{ cloud }}" + state: present + name: "{{ router_name }}" + enable_snat: false + interfaces: + - shade_subnet1 + network: "{{ external_network_name }}" + external_fixed_ips: + - subnet_id: shade_subnet5 + register: router + +- name: Assert idempotent module + assert: + that: router is changed + +- name: Update router without explicit IP address + openstack.cloud.router: + cloud: "{{ cloud }}" + state: present + name: "{{ router_name }}" + enable_snat: false + interfaces: + - shade_subnet1 + network: "{{ external_network_name }}" + external_fixed_ips: + - subnet_id: shade_subnet5 + register: router + +- name: Assert idempotent module + assert: + that: router is not changed + +- name: Delete router + openstack.cloud.router: + cloud: "{{ cloud }}" + state: absent + name: "{{ router_name }}" + - name: Create router with simple interface openstack.cloud.router: cloud: "{{ cloud }}" diff --git a/plugins/modules/router.py b/plugins/modules/router.py index a90a1472..47df8c97 100644 --- a/plugins/modules/router.py +++ b/plugins/modules/router.py @@ -372,6 +372,10 @@ class RouterModule(OpenStackModule): for p in external_fixed_ips: if 'ip_address' in p: req_fip_map[p['subnet_id']].add(p['ip_address']) + elif p['subnet_id'] in cur_fip_map: + # handle idempotence of updating with no explicit ip + req_fip_map[p['subnet_id']].update( + cur_fip_map[p['subnet_id']]) # Check if external ip addresses need to be added for fip in external_fixed_ips: @@ -464,7 +468,7 @@ class RouterModule(OpenStackModule): subnet = self.conn.network.find_subnet( iface['subnet_id'], ignore_missing=False, **filters) fip = dict(subnet_id=subnet.id) - if 'ip_address' in iface: + if iface.get('ip_address', None) is not None: fip['ip_address'] = iface['ip_address'] external_fixed_ips.append(fip)