Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add service tests to the logging job #153

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
119 changes: 119 additions & 0 deletions roles/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
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.

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

None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman is required


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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should only be adding the container tests

For container_tests.yml tasks:

container_test_id
container_list
- list of containers to validate

For cred_tests.yml tasks:

cred_test_id
cred_list
- list of credentials to validate

For endpoint_tests.yml tasks:

endpoint_test_id
endpoint_list
- list of endpoints to validate

For file_tests.yml tasks:

file_test_id
file_list
- list of files to verify

For node_tests.yml tasks:

node_test_id
node_list
- list of nodes to validate

For proj_test.yml tasks:

proj_test_id
proj_list
- list of projects to validate

For pod_tests.yml tasks:

pod_test_id
pod_list
- list of pods to validate
pod_status_str
- status of pods to check
pod_nspace
- list of projects where pods exist

For service_tests.yml tasks:

service_test_id
service_list
- list of services to validate
service_nspace
- project where services are running

For manifest_tests.yml tasks:

manifest_test_id
manifest_list
- list of package manifests to validate

For subscription_tests.yml tasks:

subscription_polar_id
subscription_list
- list of subscriptions to validate
subscription_nspace
- project where the subscription lives


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

None

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

Typically, for this role the tests should *not* use a "main.yml" and import or include all the tests in the role. On the contrary, a tests should explicitly include specific tests needed for a given job.


hosts: controller
gather_facts: no
vars:
proj_out_file: verify_logging_projects_exist_lresults.log
proj_list:
- openshift-openstack-infra
- openshift
- openstack-operators
- openshift-logging

tasks:
- name: Run projects tests
ansible.builtin.import_role:
name: common


License
-------

Apache 2

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

[email protected]
2 changes: 2 additions & 0 deletions roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for roles/common
13 changes: 13 additions & 0 deletions roles/common/tasks/container_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: "[TEST] verify container status"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TEST prefix isn't chosen yet, so this may change

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix will be "TEST"

ansible.builtin.shell:
cmd: |
podman ps -a --format "{{ '{{.Names}} {{.Status}}' }}" | grep "{{ container_name }}" | awk '{print $2}'
changed_when: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a failed_when, if you're going to mark it with a TEST prefix, otherwise, it'll pass as long as the shell cmd returns something.

Alternatively, don't mark this task as a test, but mark the following task as a test.

Currently, we rely on the custom_logger to produce a file that gathers the test-ids=passed|failed output, so there should be a test ID in the second line of the task name.
Hopefully, we can remove this at some point soon, and add a check to report_result that checks the junit output instead.

register: container_status

- name: Fail if container is not 'Up'
ansible.builtin.fail:
msg: "Container '{{ container_name }}' is not in 'Up' status. Current status: {{ container_status.stdout }}"
when:
- "'Up' not in container_status.stdout"
Comment on lines +9 to +13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this, it makes it clear why the test failed.

However, this task should be the one one with TEST in the name.

16 changes: 16 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
# All containers need to be up in order for this task to pass
- name: "[TEST] verify status of multiple containers"
ansible.builtin.include_tasks:
file: container_status.yml
loop: "{{ containers }}"
loop_control:
label: "{{ item }}"
vars:
container_name: "{{ item }}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is separate from adding the service checks.

It should NOT be run unconditionally

---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
---

- name: "[TEST] Verify service for logging"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a conditional here, so that the service_tests.yml will only be included when the right vars are defined

ansible.builtin.include_tasks:
file: service_tests.yml
tags: test
7 changes: 7 additions & 0 deletions roles/common/tasks/service_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
- name: Verify service is running
ansible.builtin.shell:
cmd: |
oc get service -n "{{ service_nspace }}" "{{ service_name }}"
mgirgisf marked this conversation as resolved.
Show resolved Hide resolved
changed_when: false
register: output
2 changes: 2 additions & 0 deletions roles/common/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for roles/common
Loading