Skip to content

Commit

Permalink
Merge branch 'master' into mgirgis-OSPRH-8378
Browse files Browse the repository at this point in the history
  • Loading branch information
mgirgisf committed Oct 21, 2024
2 parents 1ca2b51 + 9ecc35c commit 34d9d9c
Show file tree
Hide file tree
Showing 8 changed files with 250 additions and 25 deletions.
26 changes: 3 additions & 23 deletions callback_plugins/custom_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ def __init__(self):
super(CallbackModule, self).__init__()

# Custom environment variable handling
# self._output_dir = os.getcwd()
# Update this to parse these values from the config file, as well as the env.
self._output_dir = os.path.expanduser("~/.ansible.log")
# self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', '[TEST]')
self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', 'TEST')
#self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower()
self._fail_on_ignore = 'true' # this is needed because we use "ignore_errors" on the playbooks so that all the tests are run
self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'False').lower()
self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'True').lower()
Expand All @@ -37,7 +34,6 @@ def __init__(self):
def _finish_task(self, status, result):
""" record the results of a task for a single host """
task_uuid = result._task._uuid

if hasattr(result, '_host'):
host_uuid = result._host._uuid
host_name = result._host.name
Expand All @@ -62,7 +58,7 @@ def _finish_task(self, status, result):
if self._test_case_prefix in task_data.name:
task_data.add_host(HostData(host_uuid, host_name, status, result))

# This bit is new
# Debugging
if task_data.name.startswith(self._test_case_prefix):
print(f"This task ({task_data.name}) starts with the test_prefix({self._test_case_prefix})")
if self._test_case_prefix in task_data.name:
Expand All @@ -71,45 +67,30 @@ def _finish_task(self, status, result):
print(f"This task ({task_data.name}) failed, but may not be reported")

def mutate_task_name(self, task_name):
#print("enter mutate_task_name(task_name=%s)" % task_name)

# Debugging
if not self._test_case_prefix in task_name:
print("task_name (%s) does not contain prefix (%s)" % (task_name, self._test_case_prefix))

new_name = task_name
new_name = new_name.split("\n")[0] # only use the first line, so we can include IDs and additional description
#print("%s\t(take the first line of the task name)" % new_name)

# this covers when a task is included, but the including task is the one that is the test
new_name = new_name.split(":")[-1] # only provide the last part of the name when the role name is included
#print("%s\t(split at :, take last element)" % new_name)

if len(self._test_case_prefix) > 0:
# this one may not be needed...
new_name = new_name.split(self._test_case_prefix)[-1] # remove the test prefix and everything before it
#print("%s\t(remove test prefix)" % new_name)

new_name = new_name.lower()
#print("%s\t(lowercase)" % new_name)

new_name = re.sub(r'\W', ' ', new_name) # replace all non-alphanumeric characters (except _) with a space
#print("%s (Replace non-alphanumerics with a space)" % new_name)

new_name = re.sub(r'(^\W*|\W*$)', '', new_name) # trim any trailing or leading non-alphanumeric characters
#print("%s\t(trim leading or trailing characters" % new_name)

new_name = re.sub(r' +', '_', new_name) # replace any number of spaces with _
#print("%s\t(spaces -> _)" % new_name)

#print("exit mutate_task_name")
return new_name

def _build_test_case(self, task_data, host_data):
"""
This is used in generate_report. The task_data and host data will get passed.
"""
# Use the original task name to define the final name
#new_name = self.mutate_task_name(task_data.name)

print("%s\t(task_name, pre-_build_test_case)" % task_data.name)
tc = super()._build_test_case(task_data, host_data)
Expand All @@ -118,11 +99,10 @@ def _build_test_case(self, task_data, host_data):

print("%s\t(tc.name, post-mutate_task_name)" % tc.name)

# I don't want these properties for now; I may be able to omit them with a config option
# These can be able to omit with a config option
# These two control whether testcases contain the system_out and
# system_err elements that show STDOUT and STDERR
tc.system_out = None
tc.system_err = None

tc.classname = "openstack-observability"
return tc
1 change: 1 addition & 0 deletions ci/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ roles_path = ../roles:/usr/share/ansible/roles:/etc/ansible/roles:~/.ansible/rol

[custom_logger]
output_dir = /$HOME

5 changes: 5 additions & 0 deletions ci/logging_tests_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Run the compute node tests
ansible.builtin.import_playbook: logging_tests_computes.yml

- name: Run the controller tests
ansible.builtin.import_playbook: logging_tests_controller.yml
121 changes: 121 additions & 0 deletions ci/logging_tests_controller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
- name: "Verify logging projects, endpoints, credentials, nodes, pods, services, manifests and subscriptions"
hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOS0-12672"
common_pod_status_str: "Running"
common_pod_nspace: openstack-operators
common_pod_list:
- telemetry-operator-controller-manager
- dataplane-operator-controller-manager

- name: "Verify logging pods are running in openstack"
hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOSO-12752"
common_pod_status_str: "Running"
common_pod_nspace: openstack
common_pod_list:
- openstackclient
tasks:
- name: "Verify Running Pods"
ansible.builtin.import_role:
name: common


- name: "Verify logging pods are running in openshift-operators-redhat"
hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOSO-12673"
common_pod_status_str: "Running"
common_pod_nspace: openshift-operators-redhat
common_pod_list:
- loki-operator-controller-manager

tasks:
- name: "Verify Pods running"
ansible.builtin.import_role:
name: common

- name: "Verify logging pods are running in openshift-logging"
hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOSO-12676"
common_pod_status_str: "Running"
common_pod_nspace: openshift-logging
common_pod_list:
- cluster-logging-operator
- collector
- logging-loki-compactor
- logging-loki-distributor
#- logging-loki-gateway
- logging-loki-index-gateway
- logging-loki-ingester
- logging-loki-querier
- logging-loki-query-frontend
- logging-view-plugin

### see JIRA LOG-5431 if pods not running
tasks:
- name: "Verify Pods running"
ansible.builtin.import_role:
name: common

- name: "Verify logging pods are running in minio-dev"
hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOSO-12674"
common_pod_status_str: "Running"
common_pod_nspace: minio-dev
common_pod_list:
- minio

tasks:
- name: "Run pod running tests"
ansible.builtin.import_role:
name: common


- name: "Verify logging pods have complete status in openstack"
hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOSO-12679"
common_pod_nspace: openstack
common_pod_status_str: "Completed"
common_pod_list:
- logging-edpm-deployment-openstack-edpm-ipam
tasks:
- name: "Run pods completed tests"
ansible.builtin.import_role:
name: common

5 changes: 3 additions & 2 deletions ci/vars-logging-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
post_deploy_00_fvt_logging_computes:
source: "{{ ansible_user_dir }}/{{ zuul.projects['github.com/infrawatch/feature-verification-tests'].src_dir }}/ci/logging_tests_computes.yml"
# pre_tests or post_tests are also options for when the FVT roles are run
post_deploy_00_fvt_logging:
source: "{{ ansible_user_dir }}/{{ zuul.projects['github.com/infrawatch/feature-verification-tests'].src_dir }}/ci/logging_tests_all.yml"
config_file: "{{ ansible_user_dir }}/{{ zuul.projects['github.com/infrawatch/feature-verification-tests'].src_dir }}/ci/ansible.cfg"
type: playbook
post_deploy_99_collect_results:
Expand Down
78 changes: 78 additions & 0 deletions roles/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
common
======

The tests in this role are not specific to any one functional area but are an
aggregate of common tests that can be used in all OSP 18.0/OCP jobs.

The available tasks tests are:

* pod tests

Requirements
------------

The requirements vary according to the tests run.

For the pod tests, access to a kubernetes cluster and the oc command is needed,
this is done by passing the KUBECONFIG env var and PATH into the play.

The following tools are also needed:
* grep
* awk

Role Variables
--------------
Variable required for all tasks to run

For pod_tests.yml tasks:

common_pod_test_id
- polarion ID number for each test.
common_pod_list
- list of pods to validate
common_pod_status_str
- status of pods to check
common_pod_nspace
- list of projects where pods exist


Dependencies
------------

None

Example Playbook
----------------

The tasks run in this role are dependant on the vars that are configured
As such, the role can be called multiple times within the same play, with the
tests being configured at the task level (e.g. with import_role) or the vars
can be set at the play level.

- hosts: controller
gather_facts: no
ignore_errors: true
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
vars:
common_pod_test_id: "RHOSO-12752"
common_pod_status_str: "Running"
common_pod_nspace: openstack
common_pod_list:
- openstackclient
tasks:
- name: "Verify Running Pods"
ansible.builtin.import_role:
name: common


License
-------

Apache 2

Author Information
------------------

alexy@redhat.com
8 changes: 8 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: "Run pod tests"
when:
- common_pod_list is defined
- common_pod_nspace is defined
- common_pod_status_str is defined
ansible.builtin.include_tasks: "pod_tests.yml"
loop: "{{ common_pod_list }}"
31 changes: 31 additions & 0 deletions roles/common/tasks/pod_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
- block:
# expects that one line will be returned
# todo: define what hapens when there are multiple pods returned
- name: Get Pod Instance name "{{ common_pod_status_str }}"
ansible.builtin.shell:
cmd: |
oc get pods -n "{{ common_pod_nspace }}" | grep "{{ item }}" | grep "{{ common_pod_status_str }}" | awk '{print $1;}'
register: podinstance
failed_when:
- podinstance.stdout_lines | length != 1
changed_when: false

- name: Check pod {{ common_pod_test_id }}
ansible.builtin.command:
cmd: |
oc get pod -n "{{ common_pod_nspace }}" "{{ podinstance.stdout }}"
register: output
changed_when: false
failed_when:
- output.rc != 0
- podinstance.stdout == ""
rescue:
- name: Get Pod Instance "{{ item }}"
ansible.builtin.shell:
cmd: |
oc get pods -n "{{ common_pod_nspace }}" | grep "{{ item }}"
register: podinstance
failed_when:
- podinstance.stdout_lines | length == 0
changed_when: false

0 comments on commit 34d9d9c

Please sign in to comment.