Skip to content

Commit

Permalink
[OSASINFRA] Add multi test configs support
Browse files Browse the repository at this point in the history
Support multiple test configs or job definitions from the calling
zuul job, i.e:

      cifmw_run_test_shiftstack_testconfig:
        - 4.16_ovnkubernetes_ipi_va1.yaml
        - 4.16_ovnkubernetes_upi_va1.yaml

The shiftstack role will run the shiftstack-qa automation for
each test config defined in `cifmw_run_test_shiftstack_testconfig`.

The artifacts directory includes now an additional directory for
each test config, as multiple test configs can run now from a
Zuul job.

This commit adds the `cifmw_shiftstack_manifests_dir` param as
well for the role generated manifest files and the
`cifmw_shiftstack_ansible_command_logs_dir` param for the
ansible command module output logs.
  • Loading branch information
eurijon committed Jun 28, 2024
1 parent e4a881d commit 0f97882
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 52 deletions.
2 changes: 2 additions & 0 deletions roles/shiftstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Role for triggering Openshift on Openstack QA automation (installation and tests).

## Parameters
* `cifmw_shiftstack_ansible_command_logs_dir`: (*string*) Directory name for the ansible command module output. Defaults to `"{{ cifmw_shiftstack_basedir }}/ansible_command_logs"`.
* `cifmw_shiftstack_artifacts_dir`: (*string*) Directory name for the role artifacts. Defaults to `"{{ cifmw_shiftstack_basedir }}/artifacts"`.
* `cifmw_shiftstack_basedir`: (*string*) Base directory for the role artifacts and logs. Defaults to `{{ cifmw_basedir }}/tests/shiftstack` (which defaults to `~/ci-framework-data/tests/shiftstack`.
* `cifmw_shiftstack_client_pod_name`: (*string*) Pod name for the pod running the Openshift installer and tests. Defaults to `shiftstackclient`.
Expand All @@ -11,6 +12,7 @@ Role for triggering Openshift on Openstack QA automation (installation and tests
* `cifmw_shiftstack_client_pvc_manifest`: (*string*) The file name for the shiftstackclient pvc manifest. Defaults to `"{{ cifmw_shiftstack_client_pod_name }}_pvc.yml"`.
* `cifmw_shiftstack_cluster_name`: (*string*) The Openshift cluster name. Defaults to `ostest`.
* `cifmw_shiftstack_installation_dir`: (*string*) Directory to place installation files. Defaults to `"{{ cifmw_shiftstack_shiftstackclient_artifacts_dir }}/installation"`.
* `cifmw_shiftstack_manifests_dir`: (*string*) Directory name for the role generated Openshift manisfests. Defaults to `"{{ cifmw_shiftstack_basedir }}/manifests"`.
* `cifmw_shiftstack_project_name`: (*string*) The Openstack project name. Defaults to `shiftstack`.
* `cifmw_shiftstack_qa_gerrithub_change`: (*string*) The gerrithub change to fetch from the `cifmw_shiftstack_qa_repo` repository (i.e. 'refs/changes/29/1188429/50)'. Defaults to ''.
* `cifmw_shiftstack_qa_repo`: (*string*) The repository containing the Openshift on Openstack QA automation. Defaults to `https://review.gerrithub.io/shiftstack/shiftstack-qa`.
Expand Down
2 changes: 2 additions & 0 deletions roles/shiftstack/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# All variables intended for modification should be placed in this file.
# All variables within this role should have a prefix of "cifmw_shiftstack"
cifmw_shiftstack_ansible_command_logs_dir: "{{ cifmw_shiftstack_basedir }}/ansible_command_logs"
cifmw_shiftstack_artifacts_dir: "{{ cifmw_shiftstack_basedir }}/artifacts"
cifmw_shiftstack_basedir: "{{ cifmw_basedir | default(ansible_user_dir ~ '/ci-framework-data') }}/tests/shiftstack"
cifmw_shiftstack_client_pod_image: "quay.io/shiftstack-qe/shiftstack-client:latest"
Expand All @@ -26,6 +27,7 @@ cifmw_shiftstack_client_pod_namespace: "openstack"
cifmw_shiftstack_client_pvc_manifest: "{{ cifmw_shiftstack_client_pod_name }}_pvc.yml"
cifmw_shiftstack_cluster_name: "ostest"
cifmw_shiftstack_installation_dir: "{{ cifmw_shiftstack_basedir }}/installation"
cifmw_shiftstack_manifests_dir: "{{ cifmw_shiftstack_basedir }}/manifests"
cifmw_shiftstack_project_name: "shiftstack"
cifmw_shiftstack_qa_gerrithub_change: ""
cifmw_shiftstack_qa_repo: "https://review.gerrithub.io/shiftstack/shiftstack-qa"
Expand Down
8 changes: 4 additions & 4 deletions roles/shiftstack/tasks/deploy_shiftstackclient_pod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@
- name: Render the pvc manifest
ansible.builtin.template:
src: templates/shiftstackclient_pvc.yml.j2
dest: "{{ (cifmw_shiftstack_basedir, cifmw_shiftstack_client_pvc_manifest) | path_join }}"
dest: "{{ (cifmw_shiftstack_manifests_dir, cifmw_shiftstack_client_pvc_manifest) | path_join }}"

- name: Apply the manifest for the PVC creation
kubernetes.core.k8s:
state: present
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
src: "{{ (cifmw_shiftstack_basedir, cifmw_shiftstack_client_pvc_manifest) | path_join }}"
src: "{{ (cifmw_shiftstack_manifests_dir, cifmw_shiftstack_client_pvc_manifest) | path_join }}"

- name: Render the pod manifest from a template
ansible.builtin.template:
src: "templates/shiftstackclient_pod.yml.j2"
dest: "{{ (cifmw_shiftstack_basedir, cifmw_shiftstack_client_pod_manifest) | path_join }}"
dest: "{{ (cifmw_shiftstack_manifests_dir, cifmw_shiftstack_client_pod_manifest) | path_join }}"
mode: "0644"

- name: Apply the manifest for the pod creation
kubernetes.core.k8s:
state: present
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
src: "{{ (cifmw_shiftstack_basedir, cifmw_shiftstack_client_pod_manifest) | path_join }}"
src: "{{ (cifmw_shiftstack_manifests_dir, cifmw_shiftstack_client_pod_manifest) | path_join }}"
wait: true
wait_condition:
type: Ready
Expand Down
4 changes: 2 additions & 2 deletions roles/shiftstack/tasks/exec_command_in_pod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
cmd: date +"%Y_%m_%d-%H_%M_%S"
register: current_date

- name: Save the command execution information in the log file in '{{ cifmw_shiftstack_basedir }}'
- name: Save the command execution information in the log file in '{{ cifmw_shiftstack_ansible_command_logs_dir }}'
vars:
command_info:
namespace: "{{ namespace }}"
Expand All @@ -47,5 +47,5 @@
command_result: "{{ command_result }}"
ansible.builtin.copy:
content: "{{ command_info | to_nice_yaml }}"
dest: "{{ cifmw_shiftstack_basedir }}/{{ current_date.stdout }}.{{ log_file_name }}"
dest: "{{ cifmw_shiftstack_ansible_command_logs_dir }}/{{ current_date.stdout }}.{{ log_file_name }}"
mode: "0644"
14 changes: 14 additions & 0 deletions roles/shiftstack/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
# License for the specific language governing permissions and limitations
# under the License.

- debug:
var: cifmw_run_test_shiftstack_testconfig

- name: Print testconfig from list
ansible.builtin.debug:
msg: "Current testconfig is: {{ testconfig }}"
loop: "{{ cifmw_run_test_shiftstack_testconfig }}"
loop_control:
loop_var: testconfig

- name: Include pre test shiftstack tasks
ansible.builtin.include_tasks: pre_test_shiftstack.yml

Expand All @@ -23,6 +33,10 @@
- name: Test Openshift on Openstack
ansible.builtin.include_tasks: test_shiftstack.yml

#- name: bye
# fail:
# msg: "bye bye"

# Cleanup not needed for now
# - name: Shiftstack role cleanup
# ansible.builtin.include_tasks: cleanup.yml
37 changes: 34 additions & 3 deletions roles/shiftstack/tasks/pre_test_shiftstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

- name: Remove the shiftstackclient pod if exists
kubernetes.core.k8s:
state: absent
Expand All @@ -21,12 +22,42 @@
namespace: "{{ cifmw_shiftstack_client_pod_namespace }}"
name: "{{ cifmw_shiftstack_client_pod_name }}"

- name: Remove the shiftstack role artifacts/logs directory (if exists)
- name: Remove the shiftstack role data directory (if exists)
ansible.builtin.file:
path: "{{ cifmw_shiftstack_basedir }}"
state: absent

- name: Create the directory for shiftstack role artifacts/logs ({{ cifmw_shiftstack_basedir }})
#- name: Create the directory for shiftstack role generated data ({{ cifmw_shiftstack_basedir }})
# ansible.builtin.file:
# path: "{{ cifmw_shiftstack_basedir }}"
# state: directory
# mode: "0755"
#
#- name: Create the directory for ansible command module output ({{ cifmw_shiftstack_ansible_command_logs_dir }})
# ansible.builtin.file:
# path: "{{ cifmw_shiftstack_ansible_command_logs_dir }}"
# state: directory
# mode: "0755"
#
#- name: Create the directory for shiftstack role manifests ({{ cifmw_shiftstack_manifests_dir }})
# ansible.builtin.file:
# path: "{{ cifmw_shiftstack_manifests_dir }}"
# state: directory
# mode: "0755"
#
#- name: Create the directory for the shiftstack role artifacts ({{ cifmw_shiftstack_artifacts_dir }})
# ansible.builtin.file:
# path: "{{ cifmw_shiftstack_artifacts_dir }}"
# state: directory
# mode: "0755"

- name: Create the directory ({{ item }})
ansible.builtin.file:
path: "{{ cifmw_shiftstack_basedir }}"
path: "{{ item }}"
state: directory
mode: "0755"
loop:
- "{{ cifmw_shiftstack_basedir }}"
- "{{ cifmw_shiftstack_ansible_command_logs_dir }}"
- "{{ cifmw_shiftstack_manifests_dir }}"
- "{{ cifmw_shiftstack_artifacts_dir }}"
51 changes: 51 additions & 0 deletions roles/shiftstack/tasks/test_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# These tasks are intended to be run inside a loop, where `testconfig`
# is the loop parameter and can take different values in each run.
- name: "{{ testconfig }} Check the test configuration file exists in the repository"
vars:
namespace: "{{ cifmw_shiftstack_client_pod_namespace }}"
pod: "{{ cifmw_shiftstack_client_pod_name }}"
command: >-
test -f shiftstack-qa/jobs_definitions/{{ testconfig }}
log_file_name: "{{ testconfig }}-find_test_config.log"
ansible.builtin.include_tasks: exec_command_in_pod.yml

- name: OCP install and test block
vars:
# Remove the file extension from the testconfig here
testconfig_dir_name: "{{ testconfig }}"
testconfig_artifacts_dir: "{{ (cifmw_shiftstack_artifacts_dir, testconfig_dir_name) | path_join }}"

block:
- name: "{{ testconfig }}: Create the directory for the test config artifacts ({{ testconfig_artifacts_dir }})"
ansible.builtin.file:
path: "{{ testconfig_artifacts_dir }}"
state: directory
mode: "0755"

- name: "{{ testconfig }}: Test Openshift on Openstack with the test configuration '{{ testconfig }}'"
vars:
namespace: "{{ cifmw_shiftstack_client_pod_namespace }}"
pod: "{{ cifmw_shiftstack_client_pod_name }}"
command: >-
cd shiftstack-qa &&
ansible-navigator run playbooks/{{ cifmw_shiftstack_run_playbook }} -e @jobs_definitions/{{ testconfig }} -e ocp_cluster_name={{ cifmw_shiftstack_cluster_name }} -e user_cloud={{ cifmw_shiftstack_project_name }}
ansible.builtin.include_tasks: exec_command_in_pod.yml

rescue:
- name: "{{ testconfig }}: Fail task when OCP installation/test fails"
ansible.builtin.fail:
msg: "OCP {{ testconfig }} install/test block failed, see logs for more information."

always:
- name: Retrieve the artifacts from the pod
block:
- name: "{{ testconfig }}: Copy the artifacts from the pod '{{ cifmw_shiftstack_client_pod_name }}'"
environment:
PATH: "{{ cifmw_path }}"
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
ansible.builtin.command:
cmd: >
oc rsync -n {{ cifmw_shiftstack_client_pod_namespace }}
{{ cifmw_shiftstack_client_pod_name }}:{{ cifmw_shiftstack_shiftstackclient_artifacts_dir }}/
{{ testconfig_artifacts_dir }}/
48 changes: 5 additions & 43 deletions roles/shiftstack/tasks/test_shiftstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,46 +55,8 @@
log_file_name: "find_playbook.log"
ansible.builtin.include_tasks: exec_command_in_pod.yml

- name: Check the test configuration file exists in the repository
vars:
namespace: "{{ cifmw_shiftstack_client_pod_namespace }}"
pod: "{{ cifmw_shiftstack_client_pod_name }}"
command: >-
test -f shiftstack-qa/jobs_definitions/{{ cifmw_run_test_shiftstack_testconfig }}
log_file_name: "find_test_config.log"
ansible.builtin.include_tasks: exec_command_in_pod.yml

- name: OCP install and test block
block:
- name: Test Openshift on Openstack with the test configuration '{{ cifmw_run_test_shiftstack_testconfig }}'
vars:
namespace: "{{ cifmw_shiftstack_client_pod_namespace }}"
pod: "{{ cifmw_shiftstack_client_pod_name }}"
command: >-
cd shiftstack-qa &&
ansible-navigator run playbooks/{{ cifmw_shiftstack_run_playbook }} -e @jobs_definitions/{{ cifmw_run_test_shiftstack_testconfig }} -e ocp_cluster_name={{ cifmw_shiftstack_cluster_name }} -e user_cloud={{ cifmw_shiftstack_project_name }}
ansible.builtin.include_tasks: exec_command_in_pod.yml

rescue:
- name: Fail task when OCP installation/test fails
ansible.builtin.fail:
msg: "OCP install/test block failed, see logs for more information."

always:
- name: Retrieve artifacts from the pod
block:
- name: Create the directory for the artifacts
ansible.builtin.file:
path: "{{ cifmw_shiftstack_artifacts_dir }}"
state: directory
mode: "0755"

- name: Copy the artifacts from the pod '{{ cifmw_shiftstack_client_pod_name }}'
environment:
PATH: "{{ cifmw_path }}"
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
ansible.builtin.command:
cmd: >
oc rsync -n {{ cifmw_shiftstack_client_pod_namespace }}
{{ cifmw_shiftstack_client_pod_name }}:{{ cifmw_shiftstack_shiftstackclient_artifacts_dir }}/
{{ cifmw_shiftstack_artifacts_dir }}/
- name: Include test config tasks and loop over '{{ cifmw_run_test_shiftstack_testconfig }}'
ansible.builtin.include_tasks: test_config.yml
loop: "{{ cifmw_run_test_shiftstack_testconfig }}"
loop_control:
loop_var: testconfig

0 comments on commit 0f97882

Please sign in to comment.