diff --git a/tests/integration/test_ethernet.py b/tests/integration/test_ethernet.py index c0e2c0c..a0e4080 100644 --- a/tests/integration/test_ethernet.py +++ b/tests/integration/test_ethernet.py @@ -122,4 +122,7 @@ def test_static_ip_with_ethernet(testnic1, provider, network_lsr_nm_mock): ] _configure_network(connections, provider) assert ip_address in _get_ip_addresses(testnic1) - assert os.path.exists("/etc/sysconfig/network-scripts/ifcfg-" + testnic1) + if provider == "initscripts": + assert os.path.exists("/etc/sysconfig/network-scripts/ifcfg-" + testnic1) + else: + subprocess.check_call(["nmcli", "connection", "show", testnic1]) diff --git a/tests/tasks/assert_profile_absent.yml b/tests/tasks/assert_profile_absent.yml index 05dc3fc..13f6eb1 100644 --- a/tests/tasks/assert_profile_absent.yml +++ b/tests/tasks/assert_profile_absent.yml @@ -3,5 +3,5 @@ - include: get_profile_stat.yml - name: "assert that profile '{{ profile }}' is absent" assert: - that: not profile_stat.stat.exists - msg: "profile {{ profile_path }} does exist" + that: not lsr_net_profile_exists + msg: "profile {{ profile }} does exist" diff --git a/tests/tasks/assert_profile_present.yml b/tests/tasks/assert_profile_present.yml index 2691c9e..8e3bb0b 100644 --- a/tests/tasks/assert_profile_present.yml +++ b/tests/tasks/assert_profile_present.yml @@ -3,5 +3,5 @@ - include: get_profile_stat.yml - name: "assert that profile '{{ profile }}' is present" assert: - that: profile_stat.stat.exists - msg: "profile {{ profile_path }} does not exist" + that: lsr_net_profile_exists + msg: "profile {{ profile }} does not exist" diff --git a/tests/tasks/get_profile_stat.yml b/tests/tasks/get_profile_stat.yml index bd33a32..efe3a9e 100644 --- a/tests/tasks/get_profile_stat.yml +++ b/tests/tasks/get_profile_stat.yml @@ -1,26 +1,24 @@ # SPDX-License-Identifier: BSD-3-Clause --- -- name: "Get stat for network-scripts" - stat: - get_attributes: false - get_checksum: false - get_mime: false - path: "/etc/sysconfig/network-scripts" - register: network_scripts_stat -- name: Set profile path (network-scripts) - set_fact: - profile_path: /etc/sysconfig/network-scripts/ifcfg-{{ profile }} - when: - - network_scripts_stat.stat.exists -- name: Set profile path (NetworkManager system-connections) - set_fact: - profile_path: /etc/NetworkManager/system-connections/{{ profile }} - when: - - not network_scripts_stat.stat.exists +- set_fact: lsr_net_profile_exists=false + - name: stat profile file stat: get_attributes: false get_checksum: false get_mime: false - path: "{{ profile_path }}" + path: /etc/sysconfig/network-scripts/ifcfg-{{ profile }} register: profile_stat + +- set_fact: lsr_net_profile_exists=true + when: profile_stat.stat.exists + +# When certain profile is marked as absent but still up, the `nmcli connection` +# still show it with FILENAME starting with /run. Only consider profile exists +# when its FILENAME is in /etc folder +- shell: nmcli -f NAME,FILENAME connection show |grep {{ profile }} | grep /etc + register: nm_profile_exists + ignore_errors: yes + +- set_fact: lsr_net_profile_exists=true + when: nm_profile_exists.rc == 0