Skip to content

Commit 9fbe5f9

Browse files
committed
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 ansible/ansible#85394 Signed-off-by: Rich Megginson <[email protected]>
1 parent 14f9044 commit 9fbe5f9

17 files changed

+215
-258
lines changed

tests/playbooks/down_profile+delete_interface.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/playbooks/remove_profile.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/playbooks/tests_bridge.yml

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,52 @@
44
hosts: all
55
vars:
66
interface: LSR-TST-br31
7-
87
tasks:
9-
- name: "Set interface={{ interface }}"
10-
set_fact:
11-
interface: "{{ interface }}"
128
- name: Include the task 'show_interfaces.yml'
139
include_tasks: tasks/show_interfaces.yml
10+
1411
- name: Include the task 'assert_device_absent.yml'
1512
include_tasks: tasks/assert_device_absent.yml
1613

17-
- name: Add test bridge
18-
hosts: all
19-
vars:
20-
network_connections:
21-
- name: "{{ interface }}"
22-
interface_name: "{{ interface }}"
23-
state: up
24-
type: bridge
25-
ip:
26-
dhcp4: false
27-
auto6: true
28-
roles:
29-
- linux-system-roles.network
30-
31-
- name: Import the playbook 'run_tasks.yml'
32-
import_playbook: run_tasks.yml
33-
vars:
34-
task: tasks/assert_device_present.yml
35-
36-
- name: Import the playbook 'run_tasks.yml'
37-
import_playbook: run_tasks.yml
38-
vars:
39-
profile: "{{ interface }}"
40-
task: tasks/assert_profile_present.yml
41-
42-
- name: Import the playbook 'down_profile+delete_interface.yml'
43-
import_playbook: down_profile+delete_interface.yml
44-
vars:
45-
profile: "{{ interface }}"
46-
# FIXME: assert profile/device down
47-
48-
- name: Import the playbook 'remove_profile.yml'
49-
import_playbook: remove_profile.yml
50-
vars:
51-
profile: "{{ interface }}"
52-
53-
- name: Import the playbook 'run_tasks.yml'
54-
import_playbook: run_tasks.yml
55-
vars:
56-
profile: "{{ interface }}"
57-
task: tasks/assert_profile_absent.yml
58-
59-
- name: Import the playbook 'run_tasks.yml'
60-
import_playbook: run_tasks.yml
61-
vars:
62-
task: tasks/assert_device_absent.yml
14+
- name: Add test bridge
15+
include_role:
16+
name: linux-system-roles.network
17+
vars:
18+
network_connections:
19+
- name: "{{ interface }}"
20+
interface_name: "{{ interface }}"
21+
state: up
22+
type: bridge
23+
ip:
24+
dhcp4: false
25+
auto6: true
26+
27+
- name: Assert device present
28+
include_tasks: tasks/assert_device_present.yml
29+
30+
- name: Assert profile present
31+
include_tasks: tasks/assert_profile_present.yml
32+
vars:
33+
profile: "{{ interface }}"
34+
35+
- name: Include the task 'down_profile+delete_interface.yml'
36+
include_tasks: tasks/down_profile+delete_interface.yml
37+
vars:
38+
profile: "{{ interface }}"
39+
# FIXME: assert profile/device down
40+
41+
- name: Include the task 'remove_profile.yml'
42+
include_tasks: tasks/remove_profile.yml
43+
vars:
44+
profile: "{{ interface }}"
45+
46+
- name: Assert profile absent
47+
include_tasks: tasks/assert_profile_absent.yml
48+
vars:
49+
profile: "{{ interface }}"
50+
51+
- name: Assert device absent
52+
include_tasks: tasks/assert_device_absent.yml
6353

64-
- name: Verify that cleanup restored state to default
65-
hosts: all
66-
tasks:
6754
- name: Verify network state restored to default
6855
include_tasks: tasks/check_network_dns.yml
Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
---
33
- name: Test configuring bridges
4-
hosts: all
5-
tasks:
6-
- name: Define vars
7-
set_fact:
8-
interface: "LSR-TST-br31"
9-
cloned_mac: "12:23:34:45:56:70"
10-
11-
- name: Add test bridge
124
hosts: all
135
vars:
14-
network_connections:
15-
- name: "{{ interface }}"
16-
interface_name: "{{ interface }}"
17-
state: up
18-
type: bridge
19-
ip:
20-
dhcp4: false
21-
auto6: true
22-
cloned_mac: "{{ cloned_mac }}"
23-
roles:
24-
- linux-system-roles.network
6+
interface: "LSR-TST-br31"
7+
cloned_mac: "12:23:34:45:56:70"
258
tasks:
9+
- name: Add test bridge
10+
include_role:
11+
name: linux-system-roles.network
12+
vars:
13+
network_connections:
14+
- name: "{{ interface }}"
15+
interface_name: "{{ interface }}"
16+
state: up
17+
type: bridge
18+
ip:
19+
dhcp4: false
20+
auto6: true
21+
cloned_mac: "{{ cloned_mac }}"
22+
2623
- name: Verify ifcfg MACADDR entry
2724
command: >-
2825
grep ^MACADDR= /etc/sysconfig/network-scripts/ifcfg-{{ interface }}
@@ -51,18 +48,15 @@
5148
cloned_mac_address_nm.stdout.find(cloned_mac) != -1
5249
msg: "cloned-mac-address is configured incorrectly"
5350

54-
- name: Import the playbook 'down_profile+delete_interface.yml'
55-
import_playbook: down_profile+delete_interface.yml
56-
vars:
57-
profile: "{{ interface }}"
51+
- name: Include the tasks 'down_profile+delete_interface.yml'
52+
include_tasks: tasks/down_profile+delete_interface.yml
53+
vars:
54+
profile: "{{ interface }}"
5855

59-
- name: Import the playbook 'remove_profile.yml'
60-
import_playbook: remove_profile.yml
61-
vars:
62-
profile: "{{ interface }}"
56+
- name: Include the task 'remove_profile.yml'
57+
include_tasks: tasks/remove_profile.yml
58+
vars:
59+
profile: "{{ interface }}"
6360

64-
- name: Verify that cleanup restored state to default
65-
hosts: all
66-
tasks:
6761
- name: Verify network state restored to default
6862
include_tasks: tasks/check_network_dns.yml

tests/playbooks/tests_eth_dns_support.yml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,20 @@
55
vars:
66
type: veth
77
interface: ethtest0
8-
9-
108
tasks:
11-
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
12-
set_fact:
13-
type: "{{ type }}"
14-
interface: "{{ interface }}"
159
- name: Include the task 'show_interfaces.yml'
1610
include_tasks: tasks/show_interfaces.yml
11+
1712
- name: Include the task 'manage_test_interface.yml'
1813
include_tasks: tasks/manage_test_interface.yml
1914
vars:
2015
state: present
16+
2117
- name: Include the task 'assert_device_present.yml'
2218
include_tasks: tasks/assert_device_present.yml
2319

24-
- name: Import network role
25-
import_role:
20+
- name: Include network role
21+
include_role:
2622
name: linux-system-roles.network
2723
vars:
2824
network_connections:
@@ -120,24 +116,24 @@
120116
- "'9999' in ipv6_dns.stdout"
121117
msg: "DNS priority is configured incorrectly"
122118

123-
- name: Import the playbook 'down_profile+delete_interface.yml'
124-
import_playbook: down_profile+delete_interface.yml
125-
vars:
126-
profile: "{{ interface }}"
127-
# FIXME: assert profile/device down
128-
- name: Import the playbook 'remove_profile.yml'
129-
import_playbook: remove_profile.yml
130-
vars:
131-
profile: "{{ interface }}"
132-
- name: Assert profile and device are absent
133-
hosts: all
134-
tasks:
119+
- name: Include the tasks 'down_profile+delete_interface.yml'
120+
include_tasks: tasks/down_profile+delete_interface.yml
121+
vars:
122+
profile: "{{ interface }}"
123+
124+
# FIXME: assert profile/device down
125+
- name: Include the task 'remove_profile.yml'
126+
include_tasks: tasks/remove_profile.yml
127+
vars:
128+
profile: "{{ interface }}"
129+
135130
- name: Include the task 'assert_profile_absent.yml'
136131
include_tasks: tasks/assert_profile_absent.yml
137132
vars:
138133
profile: "{{ interface }}"
134+
139135
- name: Include the task 'assert_device_absent.yml'
140136
include_tasks: tasks/assert_device_absent.yml
137+
141138
- name: Verify network state restored to default
142139
include_tasks: tasks/check_network_dns.yml
143-
...

tests/playbooks/tests_ethernet.yml

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,69 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
---
3-
- name: Play for showing the network provider
3+
- name: Test configuring ethernet devices
44
hosts: all
5+
vars:
6+
type: veth
7+
interface: lsr27
58
tasks:
69
- name: Show inside ethernet tests
710
debug:
811
msg: Inside ethernet tests
12+
913
- name: Show network_provider
1014
debug:
1115
var: network_provider
1216

13-
- name: Test configuring ethernet devices
14-
hosts: all
15-
vars:
16-
type: veth
17-
interface: lsr27
18-
19-
tasks:
20-
- name: "Set type={{ type }} and interface={{ interface }}" # noqa name
21-
set_fact:
22-
type: "{{ type }}"
23-
interface: "{{ interface }}"
2417
- name: Include the task 'show_interfaces.yml'
2518
include_tasks: tasks/show_interfaces.yml
19+
2620
- name: Include the task 'manage_test_interface.yml'
2721
include_tasks: tasks/manage_test_interface.yml
2822
vars:
2923
state: present
24+
3025
- name: Include the task 'assert_device_present.yml'
3126
include_tasks: tasks/assert_device_present.yml
3227

33-
- name: Test static interface up
34-
hosts: all
35-
vars:
36-
network_connections:
37-
- name: "{{ interface }}"
38-
interface_name: "{{ interface }}"
39-
state: up
40-
type: ethernet
41-
autoconnect: true
42-
ip:
43-
address: 192.0.2.1/24
44-
roles:
45-
- linux-system-roles.network
46-
tasks:
28+
- name: Test static interface up
29+
include_role:
30+
name: linux-system-roles.network
31+
vars:
32+
network_connections:
33+
- name: "{{ interface }}"
34+
interface_name: "{{ interface }}"
35+
state: up
36+
type: ethernet
37+
autoconnect: true
38+
ip:
39+
address: 192.0.2.1/24
40+
4741
- name: Include the task 'assert_output_in_stderr_without_warnings.yml'
4842
include_tasks: tasks/assert_output_in_stderr_without_warnings.yml
4943

50-
- name: Play for cleaning up the test device and the connection profile
51-
hosts: all
52-
tasks:
5344
- name: Show network_provider
5445
debug:
5546
var: network_provider
5647

57-
# FIXME: assert profile present
58-
# FIXME: assert profile/device up + IP address
59-
- name: Import the playbook 'down_profile+delete_interface.yml'
60-
import_playbook: down_profile+delete_interface.yml
61-
vars:
62-
profile: "{{ interface }}"
63-
# FIXME: assert profile/device down
64-
- name: Import the playbook 'remove_profile.yml'
65-
import_playbook: remove_profile.yml
66-
vars:
67-
profile: "{{ interface }}"
68-
- name: Assert device and profile are absent
69-
hosts: all
70-
tasks:
48+
# FIXME: assert profile present
49+
# FIXME: assert profile/device up + IP address
50+
- name: Include the tasks 'down_profile+delete_interface.yml'
51+
include_tasks: tasks/down_profile+delete_interface.yml
52+
vars:
53+
profile: "{{ interface }}"
54+
55+
# FIXME: assert profile/device down
56+
- name: Include the task 'remove_profile.yml'
57+
include_tasks: tasks/remove_profile.yml
58+
vars:
59+
profile: "{{ interface }}"
60+
7161
- name: Include the task 'assert_profile_absent.yml'
7262
include_tasks: tasks/assert_profile_absent.yml
7363
vars:
7464
profile: "{{ interface }}"
7565
- name: Include the task 'assert_device_absent.yml'
7666
include_tasks: tasks/assert_device_absent.yml
77-
- name: Verify that cleanup restored state to default
78-
hosts: all
79-
tasks:
67+
8068
- name: Verify network state restored to default
8169
include_tasks: tasks/check_network_dns.yml

0 commit comments

Comments
 (0)