Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions tests/tasks/setup_candlepin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,8 @@
use: "{{ __rhc_is_ostree |
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"

- name: Stop and remove Candlepin container
command:
argv:
- podman
- stop
- candlepin
register: podman_stop_status
failed_when:
- podman_stop_status.rc != 0
- '"no such container" not in podman_stop_status.stderr'
changed_when: false
- name: Clean up Candlepin container
include_tasks: teardown_candlepin.yml

- name: Start Candlepin container
vars:
Expand Down
24 changes: 24 additions & 0 deletions tests/tasks/teardown_candlepin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
---
- name: Teardown Candlepin container
when: lsr_rhc_test_data_file | length == 0
block:
- name: Check if the candlepin container exists
command:
argv:
- podman
- ps
- -a
- --filter
- name=candlepin
register: __rhc_candlepin_cont_exists
changed_when: false

- name: Ensure that Candlepin container doesn't exist
command:
argv:
- podman
- stop
- candlepin
changed_when: true
when: '"candlepin" in __rhc_candlepin_cont_exists.stdout'
181 changes: 93 additions & 88 deletions tests/tests_environments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,101 +7,106 @@
tags:
- tests::slow
tasks:
- name: Setup Candlepin
import_tasks: tasks/setup_candlepin.yml
vars:
environments: true

- name: Skip if no test environments are set
meta: end_play
when:
- >-
lsr_rhc_test_data.envs_register is none
or lsr_rhc_test_data.envs_register | d([]) | length == 0

- name: Ensure ansible_facts used by the test
setup:
gather_subset:
- "!all"
- "!min"
- distribution
- distribution_major_version
- distribution_version

- name: Try to register (wrong environment)
block:
- name: Register (wrong environment)
include_role:
name: linux-system-roles.rhc
vars:
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
password: "{{ lsr_rhc_test_data.reg_password }}"
rhc_insights:
state: absent
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
rhc_server:
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
port: "{{ lsr_rhc_test_data.candlepin_port }}"
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
rhc_environments:
- "{{ lsr_rhc_test_data.env_nonworking }}"

- name: Unreachable task
fail:
msg: The above task must fail
rescue:
- name: Assert registration failed
assert:
that: ansible_failed_result.msg != 'The above task must fail'

- name: Test environments on registration
- name: Basic repository enablement/disablement test
block:
- name: Register (with existing environments)
include_role:
name: linux-system-roles.rhc
- name: Setup Candlepin
import_tasks: tasks/setup_candlepin.yml
vars:
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
password: "{{ lsr_rhc_test_data.reg_password }}"
rhc_insights:
state: absent
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
rhc_server:
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
port: "{{ lsr_rhc_test_data.candlepin_port }}"
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
rhc_environments: "{{ lsr_rhc_test_data.envs_register }}"
environments: true

# 'subscription-manager environments' has a '--list' option only
# in RHEL 8.6+ and greater (incl. RHEL 9+)
- name: Check the enabled environments
- name: Skip if no test environments are set
meta: end_play
when:
- >-
ansible_distribution not in ["CentOS", "RedHat"]
or (ansible_distribution == "CentOS"
and ansible_distribution_major_version | int >= 8)
or (ansible_distribution_version is version("8.6", ">="))
lsr_rhc_test_data.envs_register is none
or lsr_rhc_test_data.envs_register | d([]) | length == 0

- name: Ensure ansible_facts used by the test
setup:
gather_subset:
- "!all"
- "!min"
- distribution
- distribution_major_version
- distribution_version

- name: Try to register (wrong environment)
block:
- name: Get enabled environments
include_tasks: tasks/list_environments.yml
- name: Register (wrong environment)
include_role:
name: linux-system-roles.rhc
vars:
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
password: "{{ lsr_rhc_test_data.reg_password }}"
rhc_insights:
state: absent
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
rhc_server:
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
port: "{{ lsr_rhc_test_data.candlepin_port }}"
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
rhc_environments:
- "{{ lsr_rhc_test_data.env_nonworking }}"

- name: Check environments to enable are enabled
- name: Unreachable task
fail:
msg: The above task must fail
rescue:
- name: Assert registration failed
assert:
that:
- >-
(lsr_rhc_test_data.envs_register | sort) ==
(test_environments.stdout_lines | sort)
that: ansible_failed_result.msg != 'The above task must fail'

- name: Test environments on registration
block:
- name: Register (with existing environments)
include_role:
name: linux-system-roles.rhc
vars:
rhc_auth:
login:
username: "{{ lsr_rhc_test_data.reg_username }}"
password: "{{ lsr_rhc_test_data.reg_password }}"
rhc_insights:
state: absent
rhc_organization: "{{ lsr_rhc_test_data.reg_organization }}"
rhc_server:
hostname: "{{ lsr_rhc_test_data.candlepin_host }}"
port: "{{ lsr_rhc_test_data.candlepin_port }}"
prefix: "{{ lsr_rhc_test_data.candlepin_prefix }}"
insecure: "{{ lsr_rhc_test_data.candlepin_insecure }}"
rhc_baseurl: "{{ lsr_rhc_test_data.baseurl | d(omit) }}"
rhc_environments: "{{ lsr_rhc_test_data.envs_register }}"

# 'subscription-manager environments' has a '--list' option only
# in RHEL 8.6+ and greater (incl. RHEL 9+)
- name: Check the enabled environments
when:
- >-
ansible_distribution not in ["CentOS", "RedHat"]
or (ansible_distribution == "CentOS"
and ansible_distribution_major_version | int >= 8)
or (ansible_distribution_version is version("8.6", ">="))
block:
- name: Get enabled environments
include_tasks: tasks/list_environments.yml

- name: Check environments to enable are enabled
assert:
that:
- >-
(lsr_rhc_test_data.envs_register | sort) ==
(test_environments.stdout_lines | sort)

always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
vars:
rhc_state: absent
always:
- name: Unregister
include_role:
name: linux-system-roles.rhc
vars:
rhc_state: absent
- name: Clean up Candlepin container
include_tasks: tasks/teardown_candlepin.yml
Loading
Loading