network/tests/playbooks/tests_vlan_mtu.yml
Rich Megginson 65e74567d4 refactor: support Ansible 2.19
The big problem was trying to use `vars` with `import_playbook`.

We do not need to use `import_playbook` when `include_tasks` will
work.  Perhaps the original author of these tests thought that
the play `roles` keyword was the only way to invoke roles, so
that had to be "called" using an `import_playbook`?

Use `include_tasks` instead of `import_playbook`, and move some
of those "tasks" playbooks to be tasks files in tests/tasks.

Use `include_role` instead of `import_role`.

Do not set variables using `set_fact` if they have already been
set at the appropriate scope using `vars`.

"Modernize" the code somewhat.

Improve formatting.

Work around an Ansible bug https://github.com/ansible/ansible/issues/85394

Fix ansible-lint and ansible-test issues related newer versions of
those tools.

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2025-07-02 14:42:43 -06:00

78 lines
2.5 KiB
YAML

# SPDX-License-Identifier: BSD-3-Clause
---
- name: Play for testing vlan mtu setting
hosts: all
vars:
type: veth
interface: lsr101
vlan_interface: lsr101.90
tasks:
- name: Include the task 'show_interfaces.yml'
include_tasks: tasks/show_interfaces.yml
- name: Include the task 'manage_test_interface.yml'
include_tasks: tasks/manage_test_interface.yml
vars:
state: present
- name: Include the task 'assert_device_present.yml'
include_tasks: tasks/assert_device_present.yml
- name: >-
TEST: I can configure the MTU for a vlan interface without autoconnect.
debug:
msg: "##################################################"
- name: Import network role
import_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
type: ethernet
state: up
mtu: 1492
autoconnect: false
ip:
dhcp4: false
auto6: false
- name: "{{ vlan_interface }}"
parent: "{{ interface }}"
type: vlan
vlan_id: 90
mtu: 1280
state: up
autoconnect: false
ip:
dhcp4: false
auto6: false
- name: Include the task 'assert_device_present.yml' after running role
include_tasks: tasks/assert_device_present.yml
vars:
interface: "{{ vlan_interface }}"
- name: Include the task 'assert_profile_present.yml'
include_tasks: tasks/assert_profile_present.yml
vars:
profile: "{{ item }}"
loop:
- "{{ interface }}"
- "{{ vlan_interface }}"
- name: "TEARDOWN: remove profiles."
debug:
msg: "##################################################"
- name: Import network role to remove interfaces
import_role:
name: linux-system-roles.network
vars:
network_connections:
- name: "{{ interface }}"
persistent_state: absent
state: down
- name: "{{ vlan_interface }}"
persistent_state: absent
state: down
ignore_errors: true # noqa ignore-errors
- name: Include the task 'manage_test_interface.yml' to remove interfaces
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml