Skip to content

Commit 8babd71

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 <[email protected]>
1 parent f3dcba4 commit 8babd71

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

tests/playbooks/tests_ethernet.yml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,54 @@
4545
debug:
4646
var: network_provider
4747

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

0 commit comments

Comments
 (0)