tests: Fix tests_network_state_nm.yml CI failure

Since the merge of nmstate commit 'nm dns: Support appending static DNS
before dynamic DNS' (https://github.com/nmstate/nmstate/pull/2438),
nmstate treats interface with `auto-dns: true` as valid to store DNS
and tries to use NetworkManager global DNS as much as possible. However,
in NM, `dns=systemd-resolved` does not support global DNS configuration,
because systemd-resolved only supports per-interface DNS servers (via
the D-Bus API). Therefore, write and validate the DNS configuration in
/run/NetworkManager/no-stub-resolv.conf, which contains the original
DNS settings pushed to the DNS plugin.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2023-11-27 11:39:02 -05:00 committed by Richard Megginson
parent 0c590cdf5a
commit 7c4f11f1d9

View file

@ -130,31 +130,6 @@
- route.stdout is search("table-id:(\s+)254")
msg: the route configuration does not contain the specified route
- name: Set the DNS processing mode and the resolv.conf management mode
lineinfile:
path: /etc/NetworkManager/NetworkManager.conf
line: "rc-manager=unmanaged\ndns=systemd-resolved"
insertafter: \[main\]
- name: Restart the NetworkManager
service:
name: NetworkManager
state: restarted
- name: Install the systemd-resolved
package:
name: systemd-resolved
state: present
use: "{{ (__network_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
when:
- ansible_distribution_major_version | int > 8
- name: Enable the systemd-resolved service
service:
name: systemd-resolved
enabled: true
- name: Configure the DNS
import_role:
name: linux-system-roles.network
@ -174,16 +149,10 @@
ignore_errors: true # noqa ignore-errors
changed_when: false
- name: Get the DNS configuration from the file `/etc/resolv.conf`
command: cat /etc/resolv.conf
register: resolvconf
ignore_errors: true # noqa ignore-errors
changed_when: false
- name: Check if `/etc/resolv.conf` is generated by NM
command: grep "Generated by NetworkManager" /etc/resolv.conf
register: generate_by_nm
ignore_errors: true # noqa ignore-errors
- name: Get the DNS configuration from the file
`/run/NetworkManager/no-stub-resolv.conf`
command: cat /run/NetworkManager/no-stub-resolv.conf
register: no_stub_resolvconf
changed_when: false
- name: Assert that the nmstatectl contains the specified DNS configuration
@ -194,24 +163,15 @@
- nmstatectl.stdout is search("2001:4860:4860::8888")
msg: the nmstatectl does not contain the specified DNS configuration
- name: Assert that the file `/etc/resolv.conf` does not contain the
specified DNS configuration
- name: Assert that the file `/run/NetworkManager/no-stub-resolv.conf`
contains the specified DNS configuration
assert:
that:
- resolvconf.stdout is not search("example.com") and
resolvconf.stdout is not search("example.org") and
resolvconf.stdout is not search("2001:4860:4860::8888") or
generate_by_nm.stdout | length == 0
msg: the file `/etc/resolv.conf` contains the specified DNS
configuration
- name: "** TEST check resolvectl"
command: resolvectl
register: result
until: "'example.com' in result.stdout"
retries: 20
delay: 2
changed_when: false
- no_stub_resolvconf.stdout is search("example.com")
- no_stub_resolvconf.stdout is search("example.org")
- no_stub_resolvconf.stdout is search("2001:4860:4860::8888")
msg: the file `/run/NetworkManager/no-stub-resolv.conf` does not
contain the specified DNS configuration
- name: Include the task 'delete_interface.yml'
include_tasks: tasks/delete_interface.yml