Skip to content

Commit

Permalink
Merge branch 'alexy_logging2' into alexy_logging
Browse files Browse the repository at this point in the history
  • Loading branch information
elfiesmelfie authored Aug 7, 2024
2 parents 474a140 + 5db5aba commit 76955cc
Show file tree
Hide file tree
Showing 13 changed files with 306 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ exclude_paths:
- ci/
- roles/telemetry_autoscaling
- roles/telemetry_logging
- roles/qe_common
- roles/commmon
skip_list:
- command-instead-of-module # Using command rather than module
- galaxy
- meta-no-info # meta/main.yml should contain relevant info
- risky-shell-pipe # Shells that use pipes should set the pipefail option
- unnamed-task # All tasks should be named
- var-naming[no-role-prefix] # Variables names from within roles should use role_name_ as a prefix
- yaml # Violations reported by yamllint
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

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

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]
9 changes: 9 additions & 0 deletions roles/common/tasks/container_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Get container status
ansible.builtin.shell:
cmd: |
podman ps -a --format "{{ '{{.Names}} {{.Status}}' }}" | grep "{{ item }}" | awk '{print $2;}'
change_when: false
register: container_status
failed_when: container_status.stdout != "Up"
8 changes: 8 additions & 0 deletions roles/common/tasks/cred_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

- name: Verify logging credentials "{{ item }}"
ansible.builtin.shell:
cmd: |
oc get crd "{{ item }}"
changed_when: false
register: output
9 changes: 9 additions & 0 deletions roles/common/tasks/endpoint_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Get Endpoint
ansible.builtin.shell:
cmd: |
oc project openstack
kubectl exec openstackclient -- openstack endpoint list --service="{{ item[0] }}" --service="{{ item[1] }}" --interface="{{ item[2] }}"
changed_when: false
register: output
12 changes: 12 additions & 0 deletions roles/common/tasks/file_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---

- name: Get stats for file
ansible.builtin.stat:
path: "{{ item }}"
register: fstats
failed_when:
- fstats.stat.pw_name != "root"
- fstats.stat.size | int < 300
- not fstats.stat.exists
- not fstats.stat.isreg

65 changes: 65 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- name: "Verify container - {{ container_test_id }}"
when: container_list is defined
ansible.builtin.include_tasks: "container_tests.yml"
loop: "{{ container_list }}"


- name: "Verify credential - {{ cred_test_id }}"
when: cred_list is defined
ansible.builtin.include_tasks: "cred_tests.yml"
loop: "{{ cred_list }}"


- name: "Verify endpoint in OSP - {{ endpoint_test_id }}"
when: endpoint_list is defined
ansible.builtin.include_tasks: "endpoint_tests.yml"
loop: "{{ endpoint_list }}"


- name: "Verify file - {{ file_test_id }}"
when: file_list is defined
ansible.builtin.include_tasks: "file_tests.yml"
loop: "{{ file_list }}"


- name: "Verify manifest - {{ manifest_test_id }}"
when: manifest_list is defined
ansible.builtin.include_tasks: "manifest_tests.yml"
loop: "{{ manifest_list }}"


- name: "Verify OSP node - {{ node_test_id }}"
when: node_list is defined
ansible.builtin.include_tasks: node_tests.yml
loop: "{{ node_list }}"


- name: "Verify pod - {{ pod_test_id }}"
when:
- pod_list is defined
- nspace is defined
- pod_status_str is defined
ansible.builtin.include_tasks: "pod_tests.yml"
loop: "{{ pod_list }}"



- name: "Verify project - {{ proj_test_id }}"
when: proj_list is defined
ansible.builtin.include_tasks: "proj_tests.yml"
loop: "{{ proj_list }}"


- name: "Verify service - {{ service_test_id }}"
when:
- service_list is defined
- nspace is defined
ansible.builtin.include_tasks: "service_tests.yml"
loop: "{{ service_list }}"


- name: "Verify subscription - {{ subscription_test_id }}"
when: subscription_list is defined
ansible.builtin.include_tasks: "subscription_tests.yml"
loop: "{{ subscription_list }}"
23 changes: 23 additions & 0 deletions roles/common/tasks/manifest_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

- name: Get number of packages
ansible.builtin.shell:
cmd: |
echo "{{ item }}" | awk '{print $2;}'
register: num_expected
changed_when: false

- name: Get package name
ansible.builtin.shell:
cmd: |
echo "{{ item }}" | awk '{print $1;}'
register: pack_name
changed_when: false

- name: Get packagemanifest
ansible.builtin.shell:
cmd: |
oc get packagemanifests | grep "{{ pack_name.stdout }}" | wc -l
register: num_found
changed_when: false
failed_when: num_expected.stdout != num_found.stdout
18 changes: 18 additions & 0 deletions roles/common/tasks/node_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

- name: Get running node
become: true
ansible.builtin.shell:
cmd: |
virsh list --state-running | grep "{{ item }}" | awk '{print $2;}'
register: nodefound
changed_when: false

- name: Get node status
become: true
ansible.builtin.shell:
cmd: |
virsh list --state-running | grep "{{ item }}" | awk '{print $3;}'
register: output
changed_when: false
failed_when: output.stdout != "running"
20 changes: 20 additions & 0 deletions roles/common/tasks/pod_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

- name: Get Pod Instance "{{ pod_status_str }}"
ansible.builtin.shell:
cmd: |
oc get pods -n "{{ pod_nspace }}" | grep "{{ item }}" | grep "{{ pod_status_str }}" | awk '{print $1;}'
register: podinstance
changed_when: false

- name: Check terminated pod
ansible.builtin.shell:
cmd: |
oc get pod -n "{{ pod_nspace }} {{ podinstance.stdout }}"
register: output
changed_when: false
failed_when:
- output.rc != 0
- podinstance.stdout == ""


8 changes: 8 additions & 0 deletions roles/common/tasks/proj_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

- name: Verify Project exists - "{{ item }}"
ansible.builtin.shell:
cmd: |
oc project "{{ item }}"
register: output
changed_when: false
6 changes: 6 additions & 0 deletions roles/common/tasks/service_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: Verify Service Running - "{{ item }}"
ansible.builtin.shell:
cmd: |
oc get service -n "{{ service_nspace }}" "{{ item }}"
register: output
changed_when: false
8 changes: 8 additions & 0 deletions roles/common/tasks/subscription_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---

- name: Verify subscription
ansible.builtin.shell:
cmd: |
oc get subscriptions -n "{{ subscription_nspace }}" "{{ item }}"
register: output
changed_when: false

0 comments on commit 76955cc

Please sign in to comment.