Skip to content

Commit fb7e026

Browse files
committed
[telemetry_chargeback] Add CloudKitty Scope API verification tests (OSPRH-23754)
Verify that the CloudKitty Scope API POST /v2/scope works correctly after the fix in CL 970605. Tests that creating a scope with last_processed_timestamp succeeds, the scope persists via GET, and that omitting last_processed_timestamp returns HTTP 400.
1 parent d36d732 commit fb7e026

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
---
22
openstack_cmd: "openstack"
3+
4+
# Scope API test variables (OSPRH-23754)
5+
ck_test_scope_id: "fvt_scope_api_test"
6+
ck_test_scope_timestamp: "2025-01-01T00:00:00+00:00"

roles/telemetry_chargeback/tasks/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
- name: "Validate Chargeback Feature"
33
ansible.builtin.include_tasks: "chargeback_tests.yml"
44

5+
- name: "Validate CloudKitty Scope API (OSPRH-23754)"
6+
ansible.builtin.include_tasks: "scope_api_tests.yml"
7+
58
- name: "Generate Synthetic Data"
69
ansible.builtin.include_tasks: "gen_synth_loki_data.yml"
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
# Verification test for OSPRH-23754: CloudKitty Scope API POST fix
3+
# The Scope API POST /v2/scope was broken because last_processed_timestamp
4+
# was not accepted as input, and the active field defaulted to None.
5+
# CL 970605 fixed this by making last_processed_timestamp a required input
6+
# parameter and defaulting active to True.
7+
8+
- name: Get OpenStack auth token
9+
ansible.builtin.command:
10+
cmd: "{{ openstack_cmd }} token issue -f value -c id"
11+
register: os_token
12+
changed_when: false
13+
failed_when: os_token.rc != 0
14+
15+
- name: Get CloudKitty rating endpoint
16+
ansible.builtin.shell:
17+
cmd: "{{ openstack_cmd }} endpoint list --service rating --interface internal -f value -c URL | head -1"
18+
register: ck_endpoint
19+
changed_when: false
20+
failed_when: ck_endpoint.rc != 0 or ck_endpoint.stdout == ""
21+
22+
- name: Display CloudKitty endpoint
23+
ansible.builtin.debug:
24+
msg: "CloudKitty endpoint: {{ ck_endpoint.stdout | trim }}"
25+
26+
- name: Create a scope via the Scope API POST
27+
ansible.builtin.uri:
28+
url: "{{ ck_endpoint.stdout | trim }}/v2/scope"
29+
method: POST
30+
headers:
31+
X-Auth-Token: "{{ os_token.stdout | trim }}"
32+
Content-Type: "application/json"
33+
body_format: json
34+
body:
35+
scope_id: "{{ ck_test_scope_id }}"
36+
scope_key: "project_id"
37+
fetcher: "keystone"
38+
collector: "prometheus"
39+
last_processed_timestamp: "{{ ck_test_scope_timestamp }}"
40+
status_code: [200, 409]
41+
return_content: true
42+
register: scope_create_response
43+
44+
- name: TEST RHOSO Verify CloudKitty Scope API POST creates a scope (OSPRH-23754)
45+
ansible.builtin.assert:
46+
that:
47+
- scope_create_response.status in [200, 409]
48+
- (scope_create_response.status == 409) or
49+
(scope_create_response.json.scope_id == ck_test_scope_id and
50+
scope_create_response.json.scope_key == "project_id" and
51+
scope_create_response.json.fetcher == "keystone" and
52+
scope_create_response.json.collector == "prometheus" and
53+
scope_create_response.json.active == true and
54+
scope_create_response.json.last_processed_timestamp is defined and
55+
scope_create_response.json.last_processed_timestamp | length > 0)
56+
fail_msg: "FAILED: CloudKitty Scope API POST did not return expected scope data. Response: {{ scope_create_response.json }}"
57+
success_msg: >-
58+
{{ 'SUCCESS: CloudKitty Scope API POST correctly creates a scope with all fields populated.'
59+
if scope_create_response.status == 200 else
60+
'SUCCESS: Scope already exists from a previous run (HTTP 409), creation was previously verified.' }}
61+
62+
- name: Retrieve scope via Scope API GET to confirm persistence
63+
ansible.builtin.uri:
64+
url: "{{ ck_endpoint.stdout | trim }}/v2/scope"
65+
method: GET
66+
headers:
67+
X-Auth-Token: "{{ os_token.stdout | trim }}"
68+
return_content: true
69+
register: scope_get_response
70+
71+
- name: TEST RHOSO Verify CloudKitty Scope API GET returns the created scope (OSPRH-23754)
72+
ansible.builtin.assert:
73+
that:
74+
- scope_get_response.json is defined
75+
- scope_get_response.json | selectattr('scope_id', 'equalto', ck_test_scope_id) | list | length > 0
76+
fail_msg: "FAILED: Created scope '{{ ck_test_scope_id }}' not found in Scope API GET response."
77+
success_msg: "SUCCESS: Created scope '{{ ck_test_scope_id }}' confirmed via Scope API GET."
78+
79+
- name: POST to Scope API without last_processed_timestamp
80+
ansible.builtin.uri:
81+
url: "{{ ck_endpoint.stdout | trim }}/v2/scope"
82+
method: POST
83+
headers:
84+
X-Auth-Token: "{{ os_token.stdout | trim }}"
85+
Content-Type: "application/json"
86+
body_format: json
87+
body:
88+
scope_id: "fvt_scope_no_timestamp"
89+
status_code: 400
90+
return_content: true
91+
register: scope_create_no_ts
92+
93+
- name: TEST RHOSO Verify CloudKitty Scope API POST rejects request without last_processed_timestamp (OSPRH-23754)
94+
ansible.builtin.assert:
95+
that:
96+
- scope_create_no_ts.status == 400
97+
fail_msg: "FAILED: CloudKitty Scope API POST should return 400 when last_processed_timestamp is missing."
98+
success_msg: "SUCCESS: CloudKitty Scope API POST correctly rejects request without last_processed_timestamp (HTTP 400)."

0 commit comments

Comments
 (0)