Skip to content

Commit 100dfb9

Browse files
elfiesmelfieayefimov-1
authored andcommitted
[ci] Add chargeback role to FVT jobs. Assisted by
Gemini
1 parent ac5c3d5 commit 100dfb9

File tree

8 files changed

+292
-1
lines changed

8 files changed

+292
-1
lines changed

ci/chargeback_tests.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
- name: Run pre-test steps
3+
ansible.builtin.import_playbook: pre-test-steps.yml
4+
5+
- name: "Verify all the applicable projects, endpoints, pods & services for cloudkitty"
6+
hosts: controller
7+
gather_facts: no
8+
ignore_errors: true
9+
environment:
10+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
11+
PATH: "{{ cifmw_path }}"
12+
vars_files:
13+
- vars/osp18_env.yml
14+
vars:
15+
common_pod_status_str: "Running"
16+
common_pod_nspace: openstack
17+
common_pod_list:
18+
- cloudkitty-api
19+
- cloudkitty-lokistack-compactor
20+
- cloudkitty-lokistack-distributor
21+
- cloudkitty-lokistack-gateway
22+
- cloudkitty-lokistack-index-gateway
23+
- cloudkitty-lokistack-ingester
24+
- cloudkitty-lokistack-querier
25+
- cloudkitty-lokistack-query-frontend
26+
- cloudkitty-proc
27+
28+
common_project_list:
29+
- openstack
30+
- openstack-operators
31+
32+
common_endpoint_list:
33+
- [cloudkitty,rating,public]
34+
- [cloudkitty,rating,internal]
35+
36+
common_service_nspace: openstack
37+
common_service_list:
38+
- cloudkitty-internal
39+
- cloudkitty-lokistack-compactor-grpc
40+
- cloudkitty-lokistack-compactor-http
41+
- cloudkitty-lokistack-distributor-grpc
42+
- cloudkitty-lokistack-distributor-http
43+
- cloudkitty-lokistack-gateway-http
44+
- cloudkitty-lokistack-gossip-ring
45+
- cloudkitty-lokistack-index-gateway-grpc
46+
- cloudkitty-lokistack-index-gateway-http
47+
- cloudkitty-lokistack-ingester-grpc
48+
- cloudkitty-lokistack-ingester-http
49+
- cloudkitty-lokistack-querier-grpc
50+
- cloudkitty-lokistack-querier-http
51+
- cloudkitty-lokistack-query-frontend-grpc
52+
- cloudkitty-lokistack-query-frontend-http
53+
- cloudkitty-public
54+
55+
tasks:
56+
- name: "Verify cloudkitty infrastructure components"
57+
ansible.builtin.import_role:
58+
name: common
59+
60+
- name: "Verify cloudkitty deployment"
61+
ansible.builtin.import_role:
62+
name: observe_chargeback

ci/pre-test-steps.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
- name: Run telemetry tests to verify metrics on osp18
3+
hosts: "{{ cifmw_target_hook_host | default('localhost') }}"
4+
gather_facts: true
5+
environment:
6+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
7+
PATH: "{{ cifmw_path }}:/var/lib/ansible/bin"
8+
vars_files:
9+
- vars/common.yml
10+
- vars/osp18_env.yml
11+
vars:
12+
cifmw_ci_setup_oc_install_path: "{{ ansible_user_dir ~ '/bin' }}"
13+
# openshift client
14+
cifmw_ci_setup_openshift_client_download_uri: "https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp"
15+
cifmw_ci_setup_openshift_minimum_version: 4
16+
cifmw_ci_setup_openshift_client_version: 'stable-4.16'
17+
tasks:
18+
#TODO: Add this as a common playbook so it can be added to the other tests as well.
19+
#- name: Install oc
20+
# ansible.builtin.include_role:
21+
# name: cifmw.general.ci_setup
22+
# tasks_from: packages
23+
# vars:
24+
# cifmw_ci_setup_packages: []
25+
#TODO: use ci_setup one deps installation is sorted
26+
- name: Ensure openshift client install path is present
27+
ansible.builtin.file:
28+
path: "{{ cifmw_ci_setup_oc_install_path }}"
29+
state: directory
30+
mode: "0755"
31+
32+
- name: Install openshift client
33+
ansible.builtin.unarchive:
34+
src: "{{ cifmw_ci_setup_openshift_client_download_uri }}/{{ cifmw_ci_setup_openshift_client_version }}/openshift-client-linux.tar.gz"
35+
dest: "{{ cifmw_ci_setup_oc_install_path }}"
36+
remote_src: true
37+
mode: "0755"
38+
creates: "{{ cifmw_ci_setup_oc_install_path }}/oc"
39+
40+
- name: Add the OC path to cifmw_path if needed
41+
vars:
42+
_cifmw_paths_list: >-
43+
{{
44+
cifmw_path | split(':')
45+
if cifmw_path is defined else []
46+
}}
47+
when: cifmw_ci_setup_oc_install_path not in _cifmw_paths_list
48+
ansible.builtin.set_fact:
49+
cifmw_path: "{{ cifmw_ci_setup_oc_install_path }}:{{ ansible_env.PATH }}"
50+
cacheable: true
51+
52+
- name: Inject oc completion in local profile
53+
block:
54+
- name: Create completion file
55+
ansible.builtin.shell: # noqa: risky-shell-pipe
56+
cmd: >-
57+
{{ cifmw_ci_setup_oc_install_path }}/oc completion bash |
58+
tee -a ~/.oc_completion
59+
creates: "{{ ansible_user_dir }}/.oc_completion"
60+
no_log: true
61+
62+
- name: Source completion from within .bashrc
63+
ansible.builtin.blockinfile:
64+
create: true
65+
mode: "0644"
66+
path: "{{ ansible_user_dir }}/.bashrc"
67+
block: |-
68+
if [ -f ~/.oc_completion ]; then
69+
source ~/.oc_completion
70+
fi
71+
72+
- name: Log into openshift
73+
ansible.builtin.shell:
74+
cmd: |
75+
oc login -u {{ cifmw_openshift_user }} -p {{ cifmw_openshift_password }} --insecure-skip-tls-verify {{ cifmw_openshift_api }}
76+
register: cmd
77+
retries: 10
78+
delay: 10
79+
until: cmd.rc == 0
80+
81+
82+
- name: Patch openstackclient to include cloudkitty client
83+
hosts: "{{ cifmw_target_hook_host | default('localhost') }}"
84+
gather_facts: true
85+
environment:
86+
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
87+
PATH: "{{ cifmw_path }}"
88+
vars_files:
89+
- vars/common.yml
90+
- vars/osp18_env.yml
91+
tasks:
92+
- name: Patch cloudkittyclient into openstackclient
93+
ansible.builtin.shell:
94+
cmd: |
95+
oc exec -n openstack openstackclient -- python3 -m ensurepip --upgrade
96+
oc exec -n openstack openstackclient -- python3 -m pip install --upgrade git+https://github.com/openstack/python-cloudkittyclient@stable/2025.1
97+
98+

ci/vars-use-master-containers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
post_ctlplane_deploy_99_modify_openstackversions:
2+
pre_tests_99_modify_openstackversions:
33
source: "{{ ansible_user_dir }}/{{ zuul.projects['github.com/infrawatch/feature-verification-tests'].src_dir }}/ci/use-master-containers.yml"
44
type: playbook

roles/observe_chargeback/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Role Name
2+
=========
3+
The **`observe_chargeback`** role is designed to test the **RHOSO Cloudkitty** feature. These tests are specific to the Cloudkitty feature. Tests that are not specific to this feature (e.g., standard OpenStack deployment validation, basic networking) should be added to a common role.
4+
5+
Requirements
6+
------------
7+
The following resources are required in the OpenStack cloud
8+
* network called public
9+
* network called private
10+
* security group called basic with ssh and tcp enabled to the VMs
11+
12+
13+
It relies on the following being available on the target or control host:
14+
15+
* This role requires **Ansible 2.9** or newer.
16+
* The **OpenStack CLI client** must be installed and configured with administrative credentials (e.g., source the `openrc` file).
17+
* Required Python libraries for the `openstack` CLI (e.g., `python3-openstackclient`).
18+
* Connectivity to the OpenStack API endpoint.
19+
20+
It is expected to be run **after** a successful deployment and configuration of the following components:
21+
22+
* **OpenStack:** A functional OpenStack cloud (RHOSO) environment.
23+
* **Cloudkitty:** The Cloudkitty service must be installed, configured, and running.
24+
25+
Role Variables
26+
--------------
27+
The role uses a few primary variables to control the testing environment and execution.
28+
29+
| Variable | Default Value | Description |
30+
|----------|---------------|-------------|
31+
| `openstack_cmd` | `openstack` | The command used to execute OpenStack CLI calls. This can be customized if the binary is not in the standard PATH. |
32+
33+
Dependencies
34+
------------
35+
This role has no direct hard dependencies on other Ansible roles.
36+
37+
Example Playbook
38+
----------------
39+
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too.
40+
41+
Each tasks/playbook.yml should be called independently via "ansible.builtin.import_role" with appropriate vars passed:
42+
43+
- name: "name of ansible playbook"
44+
hosts: controllers
45+
gather_facts: no
46+
vars:
47+
48+
tasks:
49+
- name: "Run chargeback specific tests"
50+
ansible.builtin.import_role:
51+
name: observe_chargeback
52+
53+
Author Information
54+
------------------
55+
56+
Alex Yefimov, Red Hat
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
openstack_cmd: "openstack"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
galaxy_info:
3+
author: Alex Yefimov
4+
description: Tests the chargeback feature is set up in OpenStack running running on OpenShift
5+
company: Red Hat
6+
7+
license: Apache-2.0
8+
9+
min_ansible_version: "2.1"
10+
11+
galaxy_tags: []
12+
13+
dependencies: []
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
- name: Enable Cloudkitty Module (hashmap)
3+
ansible.builtin.command:
4+
cmd: "{{ openstack_cmd }} rating module enable hashmap"
5+
register: enable_hashmap
6+
# The task is only 'changed' if the output confirms the module was enabled/changed
7+
# This is the critical line to resolve the 'no-changed-when' error
8+
changed_when: "'Enabled' in enable_hashmap.stdout or 'change' in enable_hashmap.stdout"
9+
failed_when: enable_hashmap.rc != 0
10+
11+
- name: Enable Cloudkitty Module (noop)
12+
ansible.builtin.command:
13+
cmd: "{{ openstack_cmd }} rating module enable noop"
14+
register: enable_noop
15+
changed_when: "'Enabled' in enable_noop.stdout or 'change' in enable_noop.stdout"
16+
failed_when: enable_noop.rc != 0
17+
18+
- name: Disable Cloudkitty Module (pyscripts)
19+
ansible.builtin.command:
20+
cmd: "{{ openstack_cmd }} rating module disable pyscripts"
21+
register: disable_pyscripts
22+
changed_when: "'Disabled' in disable_pyscripts.stdout or 'change' in disable_pyscripts.stdout"
23+
failed_when: disable_pyscripts.rc != 0
24+
25+
- name: Find the current value of hashmap
26+
ansible.builtin.shell:
27+
cmd: "{{ openstack_cmd }} rating module get hashmap -c Priority -f csv | tail -n +2"
28+
register: get_hashmap_priority
29+
changed_when: false
30+
31+
- name: Change priority for CloudKitty hashmap module
32+
ansible.builtin.command:
33+
cmd: "{{ openstack_cmd }} rating module set priority hashmap 100"
34+
register: set_hashmap_priority
35+
when: get_hashmap_priority.stdout | trim != '100'
36+
failed_when: set_hashmap_priority.rc >= 1 or get_hashmap_priority.stdout == ""
37+
changed_when: set_hashmap_priority.rc == 0
38+
39+
- name: Get status of all CloudKitty rating modules
40+
ansible.builtin.command:
41+
cmd: "{{ openstack_cmd }} rating module list"
42+
changed_when: false
43+
register: module_list
44+
45+
- name: TEST Validate CloudKitty module states
46+
ansible.builtin.assert:
47+
that:
48+
- "'noop' in module_list.stdout and 'True' in (module_list.stdout_lines | select('search', 'noop') | first)"
49+
- "'hashmap' in module_list.stdout and 'True' in (module_list.stdout_lines | select('search', 'hashmap') | first)"
50+
- "'pyscripts' in module_list.stdout and 'False' in (module_list.stdout_lines | select('search', 'pyscripts') | first)"
51+
fail_msg: "CloudKitty module validation FAILED. Module states are not as expected."
52+
success_msg: "SUCCESS: CloudKitty modules (noop=True, hashmap=True, pyscripts=False) are configured correctly."
53+
54+
- name: TEST Set priority for CloudKitty hashmap module
55+
ansible.builtin.debug:
56+
msg: "The hashmap priority is set to 100"
57+
when: (get_hashmap_priority.stdout | trim == '100') or (set_hashmap_priority.rc is defined and set_hashmap_priority.rc == 0)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- name: "Validate ChargeBack Feature"
3+
ansible.builtin.include_tasks: "chargeback_tests.yml"

0 commit comments

Comments
 (0)