Skip to content

Commit

Permalink
nm: Fix the incorrect change indication for dns option
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cathay4t committed Jul 1, 2021
1 parent 5ee63fe commit 1cb331e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/network_connections.py
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
21 changes: 21 additions & 0 deletions tests/tests_change_indication_on_repeat_run.yml
Expand Up @@ -33,6 +33,27 @@
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"
always:
- block:
- include_role:
Expand Down

0 comments on commit 1cb331e

Please sign in to comment.