network/tests/playbooks/tests_checkpoint_cleanup.yml
Rich Megginson 0c590cdf5a refactor: improve support for ostree systems
The dependency on `ansible.utils.update_fact` is causing issue with
some users who now must install that collection in order to run
the role, even if they do not care about ostree.

The fix is to stop trying to set `ansible_facts.pkg_mgr`, and instead
force the use of the ostree package manager with the `package:` module
`use:` option.  The strategy is - on ostree systems, set the flag
`__$ROLENAME_is_ostree` if the system is an ostree system.  The flag
will either be undefined or `false` on non-ostree systems.
Then, change every invocation of the `package:` module like this:

```yaml
- name: Ensure required packages are present
  package:
    name: "{{ __$ROLENAME_packages }}"
    state: present
    use: "{{ (__$ROLENAME_is_ostree | d(false)) |
      ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
```

This should ensure that the `use:` parameter is not used if the system
is non-ostree.  The goal is to make the ostree support as unobtrusive
as possible for non-ostree systems.
The user can also set `__$ROLENAME_is_ostree: true` in the inventory or play
if the user knows that ostree is being used and wants to skip the check.
Or, the user is concerned about the performance hit for ostree detection
on non-ostree systems, and sets `__$ROLENAME_is_ostree: false` to skip
the check.
The flag `__$ROLENAME_is_ostree` can also be used in the role or tests to
include or exclude tasks from being run on ostree systems.

This fix also improves error reporting in the `get_ostree_data.sh` script
when included roles cannot be found.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2023-11-29 07:05:00 -07:00

103 lines
3.9 KiB
YAML

# SPDX-License-Identifier: BSD-3-Clause
# This test is supposed to check that checkpoints are properly cleaned-up after
# failures in the module. This test currently uses the initscripts provider to
# mark a device as unmanaged for NM and then tries to activiate it using NM.
# This failed without removing the checkpoint.
---
- name: Play for testing checkpoint cleanup
hosts: all
vars:
interface: cptstbr
profile: "{{ interface }}"
network_provider: nm
pre_tasks:
- name: Show test banner
debug:
msg: Inside states tests
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
roles:
- linux-system-roles.network
tasks:
- name: Test checkpoint cleanup
block:
# Workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1832897
- name: Install dbus-tools
package:
name: dbus-tools
state: present
use: "{{ (__network_is_ostree | d(false)) |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
# create test profile
- name: Include network role
include_role:
name: linux-system-roles.network
vars:
network_provider: initscripts
network_connections:
- name: "{{ interface }}"
state: up
type: bridge
ip:
dhcp4: false
auto6: false
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: Include the task 'assert_profile_present.yml'
include_tasks: tasks/assert_profile_present.yml
# Use internal module directly for speedup
- name: Use network_connections
network_connections:
provider: nm
connections:
- name: "{{ interface }}"
state: up
type: bridge
ip:
dhcp4: false
auto6: false
ignore_errors: true
register: error_trigger
- name: Assert that the module call did not fail
assert:
fail_msg: The module call did not fail. Therefore the test
condition was not triggered. This test needs to be adjusted or
dropped.
that: error_trigger.failed
# yamllint disable-line rule:line-length
- name: Get NM dbus objects
command: busctl --system tree --list org.freedesktop.NetworkManager
register: nm_dbus_objects
changed_when: false
- name: Show nm_dbus_objects
debug:
var: nm_dbus_objects
- name: Assert that no checkpoints are left
assert:
fail_msg: Checkpoints not cleaned up
that: >
'/org/freedesktop/NetworkManager/Checkpoint/' not in
nm_dbus_objects.stdout_lines
always:
- name: Clean up the test device and the connection profile
tags:
- "tests::cleanup"
ignore_errors: true # noqa ignore-errors
block:
# Use internal module directly for speedup
- name: Deactivate the connection and remove the connection profile
network_connections:
provider: nm
connections:
- name: "{{ interface }}"
persistent_state: absent
state: down
- name: Remove the connection profile
file:
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ interface }}"
state: absent
- name: Delete the device '{{ interface }}'
command: ip link del "{{ interface }}"
changed_when: false