From 7add5f4df99644ade07d2728086adcb03b5b6ff1 Mon Sep 17 00:00:00 2001 From: Gris Ge Date: Thu, 1 Jul 2021 20:04:47 +0800 Subject: [PATCH] nm: Fix the incorrect change indication for dns option When applying with `dhcp4: "no"` or `auto6: "no"`, we get incorrect change indication even when network connection was not changed. The root cause is the `NM.SettingIPConfig.clear_dns_options(True)` will create an empty list which will be discard by ifcfg plugin. The follow up `NM.Connection.compare()` will show configuration changed as dns option entry missing. Fixed by remove dns option completely before appending. Signed-off-by: Gris Ge --- library/network_connections.py | 12 ++++- .../tests_change_indication_on_repeat_run.yml | 49 +++++++++++++------ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/library/network_connections.py b/library/network_connections.py index 9e489da9b..69a06e9b3 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -1044,7 +1044,11 @@ def connection_create(self, connections, idx, connection_current=None): s_ip4.add_dns(nameserver["address"]) for search_domain in ip["dns_search"]: s_ip4.add_dns_search(search_domain) - s_ip4.clear_dns_options(True) + # NetworkManager ifcfg plguin will discard empty dns option which + # cause follow up NM.Connection.compare() raise false alarm + # Use False here to ask NetworkManager remove dns option completely instead + # of keeping an empty list + s_ip4.clear_dns_options(False) for option in ip["dns_options"]: s_ip4.add_dns_option(option) @@ -1086,7 +1090,11 @@ def connection_create(self, connections, idx, connection_current=None): s_ip6.add_dns(nameserver["address"]) for search_domain in ip["dns_search"]: s_ip6.add_dns_search(search_domain) - s_ip6.clear_dns_options(True) + # NetworkManager ifcfg plguin will discard empty dns option which + # cause follow up NM.Connection.compare() raise false alarm + # Use False here to ask NetworkManager remove dns option completely instead + # of keeping an empty list + s_ip6.clear_dns_options(False) for option in ip["dns_options"]: s_ip6.add_dns_option(option) diff --git a/tests/tests_change_indication_on_repeat_run.yml b/tests/tests_change_indication_on_repeat_run.yml index fddcace94..e060274ba 100644 --- a/tests/tests_change_indication_on_repeat_run.yml +++ b/tests/tests_change_indication_on_repeat_run.yml @@ -12,20 +12,7 @@ state: present - include_tasks: tasks/assert_device_present.yml - block: - - block: - - include_role: - name: linux-system-roles.network - register: __network_connections_result - - name: Assert change:true - assert: - that: __network_connections_result is changed - - include_role: - name: linux-system-roles.network - register: __network_connections_result - - name: Assert change:false - assert: - that: not __network_connections_result is changed - vars: + - vars: network_connections: - name: "{{ interface }}" state: up @@ -33,6 +20,40 @@ ip: address: - 192.0.2.2/24 + block: + - include_role: + name: linux-system-roles.network + register: __network_connections_result + - name: Assert change:true + assert: + that: __network_connections_result is changed + - include_role: + name: linux-system-roles.network + register: __network_connections_result + - name: Assert change:false + assert: + that: not __network_connections_result is changed + - vars: + network_connections: + - name: "{{ interface }}" + state: up + type: ethernet + ip: + dhcp4: "no" + auto6: "no" + block: + - include_role: + name: linux-system-roles.network + register: __network_connections_result + - name: Assert change:true + assert: + that: __network_connections_result is changed + - include_role: + name: linux-system-roles.network + register: __network_connections_result + - name: Assert change:false + assert: + that: not __network_connections_result is changed always: - block: - include_role: