diff --git a/roles/shiftstack/README.md b/roles/shiftstack/README.md index c01aa2b6f9..74617c20da 100644 --- a/roles/shiftstack/README.md +++ b/roles/shiftstack/README.md @@ -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`. @@ -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`. diff --git a/roles/shiftstack/defaults/main.yml b/roles/shiftstack/defaults/main.yml index 02f88809f0..3956c8a84d 100644 --- a/roles/shiftstack/defaults/main.yml +++ b/roles/shiftstack/defaults/main.yml @@ -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" @@ -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" diff --git a/roles/shiftstack/tasks/deploy_shiftstackclient_pod.yml b/roles/shiftstack/tasks/deploy_shiftstackclient_pod.yml index 51801d207e..7fe497f348 100644 --- a/roles/shiftstack/tasks/deploy_shiftstackclient_pod.yml +++ b/roles/shiftstack/tasks/deploy_shiftstackclient_pod.yml @@ -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 diff --git a/roles/shiftstack/tasks/exec_command_in_pod.yml b/roles/shiftstack/tasks/exec_command_in_pod.yml index 33650b99de..d71ac60cbd 100644 --- a/roles/shiftstack/tasks/exec_command_in_pod.yml +++ b/roles/shiftstack/tasks/exec_command_in_pod.yml @@ -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 }}" @@ -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" diff --git a/roles/shiftstack/tasks/pre_test_shiftstack.yml b/roles/shiftstack/tasks/pre_test_shiftstack.yml index 4c0a3cd9a4..a0d07e52a8 100644 --- a/roles/shiftstack/tasks/pre_test_shiftstack.yml +++ b/roles/shiftstack/tasks/pre_test_shiftstack.yml @@ -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 @@ -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 }}" diff --git a/roles/shiftstack/tasks/test_config.yml b/roles/shiftstack/tasks/test_config.yml new file mode 100644 index 0000000000..c9db2d56ca --- /dev/null +++ b/roles/shiftstack/tasks/test_config.yml @@ -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 }}/ diff --git a/roles/shiftstack/tasks/test_shiftstack.yml b/roles/shiftstack/tasks/test_shiftstack.yml index f69348921d..c0a1c3ec4f 100644 --- a/roles/shiftstack/tasks/test_shiftstack.yml +++ b/roles/shiftstack/tasks/test_shiftstack.yml @@ -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