Skip to content

Commit 9b93f3a

Browse files
committed
tests: Cleanup candlepin container
In always block, import a task to cleanup candlepin container in tests that import the task tests/tasks/setup_candlepin.yml, which starts candlepin container
1 parent 49e0d92 commit 9b93f3a

5 files changed

Lines changed: 547 additions & 515 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- name: Check if candlepin container is running
2+
command: podman ps -a --filter name=candlepin
3+
register: __rhc_candlepin_container
4+
change_when: false
5+
6+
- name: Stop Candlepin container
7+
command: podman stop candlepin
8+
changed_when: true
9+
when: '"candlepin" in __rhc_candlepin_container.stdout'
10+
11+
- name: Remove Candlepin container
12+
command: podman rm candlepin
13+
register: podman_stop_status
14+
changed_when: true
15+
when: '"candlepin" in __rhc_candlepin_container.stdout'

tests/tests_environments.yml

Lines changed: 93 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -7,101 +7,106 @@
77
tags:
88
- tests::slow
99
tasks:
10-
- name: Setup Candlepin
11-
import_tasks: tasks/setup_candlepin.yml
12-
vars:
13-
environments: true
14-
15-
- name: Skip if no test environments are set
16-
meta: end_play
17-
when:
18-
- >-
19-
lsr_rhc_test_data.envs_register is none
20-
or lsr_rhc_test_data.envs_register | d([]) | length == 0
21-
22-
- name: Ensure ansible_facts used by the test
23-
setup:
24-
gather_subset:
25-
- "!all"
26-
- "!min"
27-
- distribution
28-
- distribution_major_version
29-
- distribution_version
30-
31-
- name: Try to register (wrong environment)
32-
block:
33-
- name: Register (wrong environment)
34-
include_role:
35-
name: linux-system-roles.rhc
36-
vars:
37-
rhc_auth:
38-
login:
39-
username: "{{ lsr_rhc_test_data.reg_username }}"
40-
password: "{{ lsr_rhc_test_data.reg_password }}"
41-
rhc_insights:
42-
state: absent
43-
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
44-
rhc_server:
45-
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
46-
port: "{{ lsr_rhc_test_data.candlepin_port }}"
47-
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
48-
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
49-
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
50-
rhc_environments:
51-
- "{{ lsr_rhc_test_data.env_nonworking }}"
52-
53-
- name: Unreachable task
54-
fail:
55-
msg: The above task must fail
56-
rescue:
57-
- name: Assert registration failed
58-
assert:
59-
that: ansible_failed_result.msg != 'The above task must fail'
60-
61-
- name: Test environments on registration
10+
- name: Basic repository enablement/disablement test
6211
block:
63-
- name: Register (with existing environments)
64-
include_role:
65-
name: linux-system-roles.rhc
12+
- name: Setup Candlepin
13+
import_tasks: tasks/setup_candlepin.yml
6614
vars:
67-
rhc_auth:
68-
login:
69-
username: "{{ lsr_rhc_test_data.reg_username }}"
70-
password: "{{ lsr_rhc_test_data.reg_password }}"
71-
rhc_insights:
72-
state: absent
73-
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
74-
rhc_server:
75-
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
76-
port: "{{ lsr_rhc_test_data.candlepin_port }}"
77-
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
78-
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
79-
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
80-
rhc_environments: "{{ lsr_rhc_test_data.envs_register }}"
15+
environments: true
8116

82-
# 'subscription-manager environments' has a '--list' option only
83-
# in RHEL 8.6+ and greater (incl. RHEL 9+)
84-
- name: Check the enabled environments
17+
- name: Skip if no test environments are set
18+
meta: end_play
8519
when:
8620
- >-
87-
ansible_distribution not in ["CentOS", "RedHat"]
88-
or (ansible_distribution == "CentOS"
89-
and ansible_distribution_major_version | int >= 8)
90-
or (ansible_distribution_version is version("8.6", ">="))
21+
lsr_rhc_test_data.envs_register is none
22+
or lsr_rhc_test_data.envs_register | d([]) | length == 0
23+
24+
- name: Ensure ansible_facts used by the test
25+
setup:
26+
gather_subset:
27+
- "!all"
28+
- "!min"
29+
- distribution
30+
- distribution_major_version
31+
- distribution_version
32+
33+
- name: Try to register (wrong environment)
9134
block:
92-
- name: Get enabled environments
93-
include_tasks: tasks/list_environments.yml
35+
- name: Register (wrong environment)
36+
include_role:
37+
name: linux-system-roles.rhc
38+
vars:
39+
rhc_auth:
40+
login:
41+
username: "{{ lsr_rhc_test_data.reg_username }}"
42+
password: "{{ lsr_rhc_test_data.reg_password }}"
43+
rhc_insights:
44+
state: absent
45+
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
46+
rhc_server:
47+
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
48+
port: "{{ lsr_rhc_test_data.candlepin_port }}"
49+
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
50+
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
51+
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
52+
rhc_environments:
53+
- "{{ lsr_rhc_test_data.env_nonworking }}"
9454

95-
- name: Check environments to enable are enabled
55+
- name: Unreachable task
56+
fail:
57+
msg: The above task must fail
58+
rescue:
59+
- name: Assert registration failed
9660
assert:
97-
that:
98-
- >-
99-
(lsr_rhc_test_data.envs_register | sort) ==
100-
(test_environments.stdout_lines | sort)
61+
that: ansible_failed_result.msg != 'The above task must fail'
62+
63+
- name: Test environments on registration
64+
block:
65+
- name: Register (with existing environments)
66+
include_role:
67+
name: linux-system-roles.rhc
68+
vars:
69+
rhc_auth:
70+
login:
71+
username: "{{ lsr_rhc_test_data.reg_username }}"
72+
password: "{{ lsr_rhc_test_data.reg_password }}"
73+
rhc_insights:
74+
state: absent
75+
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
76+
rhc_server:
77+
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
78+
port: "{{ lsr_rhc_test_data.candlepin_port }}"
79+
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
80+
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
81+
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
82+
rhc_environments: "{{ lsr_rhc_test_data.envs_register }}"
10183

84+
# 'subscription-manager environments' has a '--list' option only
85+
# in RHEL 8.6+ and greater (incl. RHEL 9+)
86+
- name: Check the enabled environments
87+
when:
88+
- >-
89+
ansible_distribution not in ["CentOS", "RedHat"]
90+
or (ansible_distribution == "CentOS"
91+
and ansible_distribution_major_version | int >= 8)
92+
or (ansible_distribution_version is version("8.6", ">="))
93+
block:
94+
- name: Get enabled environments
95+
include_tasks: tasks/list_environments.yml
96+
97+
- name: Check environments to enable are enabled
98+
assert:
99+
that:
100+
- >-
101+
(lsr_rhc_test_data.envs_register | sort) ==
102+
(test_environments.stdout_lines | sort)
103+
104+
always:
105+
- name: Unregister
106+
include_role:
107+
name: linux-system-roles.rhc
108+
vars:
109+
rhc_state: absent
102110
always:
103-
- name: Unregister
104-
include_role:
105-
name: linux-system-roles.rhc
106-
vars:
107-
rhc_state: absent
111+
- name: Clean up Candlepin container
112+
include_tasks: tasks/cleanup_candlepin_container.yml

0 commit comments

Comments
 (0)