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 <fge@redhat.com>
This commit is contained in:
Gris Ge 2021-07-01 20:04:47 +08:00
parent f538865c68
commit 245ff58e25
2 changed files with 45 additions and 16 deletions

View file

@ -1044,7 +1044,11 @@ class NMUtil:
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 @@ class NMUtil:
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)

View file

@ -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: