Skip to content

Commit 121f1a8

Browse files
committed
tests: Assert ethernet profile and device state
Implement the tests_ethernet FIXMEs for actually validating the `nmcli` state and generated on-disk profiles. Do the latter separately in anticipation of future support for offline (bootc build) mode. This needs some conditionals, as NetworkManager before RHEL 9 uses the initscripts config backend. Signed-off-by: Martin Pitt <mpitt@redhat.com>
1 parent 1a9fd07 commit 121f1a8

1 file changed

Lines changed: 48 additions & 2 deletions

File tree

tests/playbooks/tests_ethernet.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,54 @@
4747
- name: Include the task 'assert_output_in_stderr_without_warnings.yml'
4848
include_tasks: tasks/assert_output_in_stderr_without_warnings.yml
4949

50-
# FIXME: assert profile present
51-
# FIXME: assert profile/device up + IP address
50+
- name: Get NM connection file
51+
slurp:
52+
src: "/etc/NetworkManager/system-connections/{{ interface }}.nmconnection"
53+
register: nm_connection_file
54+
when:
55+
- network_provider == 'nm'
56+
# RHEL up to 8 uses initscripts backend
57+
- ansible_distribution_major_version | int >= 9
58+
59+
- name: Assert settings in NM connection file
60+
assert:
61+
that:
62+
- "('interface-name=' + interface) in nm_connection_file.content | b64decode"
63+
- "'type=ethernet' in nm_connection_file.content | b64decode"
64+
- "'address1=192.0.2.1/24' in nm_connection_file.content | b64decode"
65+
- "'method=manual' in nm_connection_file.content | b64decode"
66+
when:
67+
- network_provider == 'nm'
68+
# RHEL up to 8 uses initscripts backend
69+
- ansible_distribution_major_version | int >= 9
70+
71+
- name: Get NM connection status
72+
command: "nmcli connection show {{ interface }}"
73+
changed_when: false
74+
register: nm_connection_status
75+
when: network_provider == 'nm'
76+
77+
- name: Assert NM connection status
78+
assert:
79+
that:
80+
- nm_connection_status.stdout | regex_search("ipv4.addresses:\s+192.0.2.1/24")
81+
when: network_provider == 'nm'
82+
83+
- name: Get initscripts connection file
84+
slurp:
85+
src: "/etc/sysconfig/network-scripts/ifcfg-{{ interface }}"
86+
register: initscripts_connection_file
87+
when: network_provider == 'initscripts' or ansible_distribution_major_version | int < 9
88+
89+
- name: Assert settings in initscripts connection file
90+
assert:
91+
that:
92+
- "'TYPE=Ethernet' in initscripts_connection_file.content | b64decode"
93+
- "'DEVICE={{ interface }}' in initscripts_connection_file.content | b64decode"
94+
- "'IPADDR=192.0.2.1' in initscripts_connection_file.content | b64decode"
95+
- "'PREFIX=24' in initscripts_connection_file.content | b64decode"
96+
when: network_provider == 'initscripts' or ansible_distribution_major_version | int < 9
97+
5298
- name: Import the playbook 'down_profile+delete_interface.yml'
5399
import_playbook: down_profile+delete_interface.yml
54100
vars:

0 commit comments

Comments
 (0)