Update to healthcheck_deployment.yaml.j2

 * healthcheck_deployment.yaml.j2 updated to save robot report and log
 * Added healthcheck_pvc.yaml.j2 to create pvc to store robot output files
 * Added healthcheck reports job to collect robot test reports

Change-Id: Iaa9d9b604c4f0de9a087a180b32f2cf84fcdd771
diff --git a/playbooks/roles/prepare-testframework-online/tasks/prepare-xtesting-healthcheck.yaml b/playbooks/roles/prepare-testframework-online/tasks/prepare-xtesting-healthcheck.yaml
index 7d4dfe9..2744c50 100644
--- a/playbooks/roles/prepare-testframework-online/tasks/prepare-xtesting-healthcheck.yaml
+++ b/playbooks/roles/prepare-testframework-online/tasks/prepare-xtesting-healthcheck.yaml
@@ -99,15 +99,41 @@
 # eprasad: there is bug in ansible k8s module, removing a job doest not remove pods assisated with it hence using shell here.
 - name: Delete healthcheck job
   shell: |
-    "kubectl -n {{ onap_namespace }} delete job xtesting-onap-{{ healthcheck_test_tier }}"
+    kubectl -n {{ onap_namespace }} delete job xtesting-onap-{{ healthcheck_test_tier }}
   args:
     executable: "/bin/bash"
   changed_when: false
   ignore_errors: yes  # yamllint disable-line rule:truthy
 
+- name: Delete report job
+  shell: |
+    kubectl -n {{ onap_namespace }} delete job xtesting-onap-reports-{{ healthcheck_test_tier }}
+  args:
+    executable: "/bin/bash"
+  changed_when: false
+  ignore_errors: yes  # yamllint disable-line rule:truthy
+
+- name: Delete xtesting onap pvc
+  shell: |
+    kubectl -n {{ onap_namespace }} delete pvc xtesting-onap-pvc-{{ healthcheck_test_tier }}
+  args:
+    executable: "/bin/bash"
+  changed_when: false
+  ignore_errors: yes  # yamllint disable-line rule:truthy
+
+- name: Construct and save healthcheck pvc deployment to file
+  template:
+    src: "healthcheck_pvc.yaml.j2"
+    dest: "{{ testfw_configdir }}/healthcheck-pvc-{{ healthcheck_test_tier }}.yaml"
+
 - name: Construct and save healthcheck testsuite deployment to file
   template:
     src: "healthcheck_deployment.yaml.j2"
     dest: "{{ testfw_configdir }}/healthcheck-{{ healthcheck_test_tier }}.yaml"
 
+- name: Construct and save busybox job deployment to file
+  template:
+    src: "healthcheck_reports.yaml.j2"
+    dest: "{{ testfw_configdir }}/healthcheck-report-{{ healthcheck_test_tier }}.yaml"
+
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/prepare-testframework-online/templates/healthcheck_deployment.yaml.j2 b/playbooks/roles/prepare-testframework-online/templates/healthcheck_deployment.yaml.j2
index 1690256..7847054 100644
--- a/playbooks/roles/prepare-testframework-online/templates/healthcheck_deployment.yaml.j2
+++ b/playbooks/roles/prepare-testframework-online/templates/healthcheck_deployment.yaml.j2
@@ -31,6 +31,8 @@
                     name: robot-eteshare
                 -   mountPath: /var/lib/xtesting/results/
                     name: robot-save-results
+                -   mountPath: /var/lib/xtesting/results/{{ healthcheck_test_tier }}/
+                    name: robot-save-report
                 -   mountPath: /usr/lib/python3.7/site-packages/xtesting/ci/testcases.yaml
                     subPath: testcases.yaml
                     name: "{{ healthcheck_config_map }}"
@@ -51,3 +53,7 @@
                   path: "{{ testfw_resultdir }}"
                   type: DirectoryOrCreate
                 name: robot-save-results
+            -   persistentVolumeClaim:
+                  claimName: "xtesting-onap-pvc-{{ healthcheck_test_tier }}"
+                  readOnly: false
+                name: robot-save-report
diff --git a/playbooks/roles/prepare-testframework-online/templates/healthcheck_pvc.yaml.j2 b/playbooks/roles/prepare-testframework-online/templates/healthcheck_pvc.yaml.j2
new file mode 100644
index 0000000..6dc3334
--- /dev/null
+++ b/playbooks/roles/prepare-testframework-online/templates/healthcheck_pvc.yaml.j2
@@ -0,0 +1,12 @@
+kind: PersistentVolumeClaim
+apiVersion: v1
+metadata:
+  name: "xtesting-onap-pvc-{{ healthcheck_test_tier }}"
+  namespace: "{{ onap_namespace }}"
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 1Gi
+  storageClassName: block-storage
\ No newline at end of file
diff --git a/playbooks/roles/prepare-testframework-online/templates/healthcheck_reports.yaml.j2 b/playbooks/roles/prepare-testframework-online/templates/healthcheck_reports.yaml.j2
new file mode 100644
index 0000000..4f6d1c8
--- /dev/null
+++ b/playbooks/roles/prepare-testframework-online/templates/healthcheck_reports.yaml.j2
@@ -0,0 +1,25 @@
+apiVersion: batch/v1
+kind: Job
+metadata:
+    name: "xtesting-onap-reports-{{ healthcheck_test_tier }}"
+    namespace: "{{ onap_namespace }}"
+spec:
+    template:
+        spec:
+            containers:
+            -   image: "{{ busybox_image }}:{{ busybox_image_tag }}"
+                imagePullPolicy: IfNotPresent
+                name: xtesting-onap-busybox
+                args:
+                - /bin/sh
+                - "-c"
+                - "sleep 5m"
+                volumeMounts:
+                -   mountPath: /var/lib/xtesting/results/{{ healthcheck_test_tier }}/
+                    name: robot-save-report
+            restartPolicy: OnFailure
+            volumes:
+            -   persistentVolumeClaim:
+                  claimName: "xtesting-onap-pvc-{{ healthcheck_test_tier }}"
+                  readOnly: false
+                name: robot-save-report
\ No newline at end of file
diff --git a/playbooks/roles/run-tests/tasks/healthcheck.yaml b/playbooks/roles/run-tests/tasks/healthcheck.yaml
index 6a0234f..c7b9baf 100644
--- a/playbooks/roles/run-tests/tasks/healthcheck.yaml
+++ b/playbooks/roles/run-tests/tasks/healthcheck.yaml
@@ -17,6 +17,11 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
+- name: create pvc for healthcheck job
+  k8s:
+    state: present
+    src: "{{ config_path }}/xtesting/healthcheck-pvc-{{ healthcheck_test_tier }}.yaml"
+
 - name: start healthcheck job
   k8s:
     state: present
@@ -60,6 +65,41 @@
     content: "{{ healthcheck_log.stdout }}"
     dest: "{{ test_cache }}/xtesting/{{ healthcheck_test_tier }}/results/xtesting.log"
 
+- name: start report job
+  k8s:
+    state: present
+    src: "{{ config_path }}/xtesting/healthcheck-report-{{ healthcheck_test_tier }}.yaml"
+
+- name: Get the name of pod created by repot job
+  shell: |
+    set -o pipefail
+    kubectl -n {{ onap_namespace }} get pods -l job-name=xtesting-onap-reports-{{ healthcheck_test_tier }} -o name \
+    --no-headers=true | sed 's/\<pod\>//g'  | sed 's/\///'
+  args:
+    executable: "/bin/bash"
+  changed_when: false
+  register: xtesting_reports_pod
+
+- name: Wait for healthcheck reports job to complete
+  shell: |
+    kubectl -n {{ onap_namespace }} get pods {{ xtesting_reports_pod.stdout }}
+  args:
+    executable: "/bin/bash"
+  changed_when: false
+  register: healthcheck_report_pod
+  until: '" Running "  in healthcheck_report_pod.stdout'
+  retries: 100
+  delay: 4
+
+- name: Copy robot files to jumphost
+  shell: |
+    kubectl cp {{ onap_namespace }}/{{ xtesting_reports_pod.stdout }}:/var/lib/xtesting/results/{{ healthcheck_test_tier }} \
+    /opt/test/.cache/xtesting/{{ healthcheck_test_tier }}
+  args:
+    executable: "/bin/bash"
+  changed_when: false
+  ignore_errors: yes  # yamllint disable-line rule:truthy
+
 - name: Determine the test verdict
   fail:
     msg: "Tests failed!"
diff --git a/vars/onap.yaml b/vars/onap.yaml
index 3af4690..6e43c71 100644
--- a/vars/onap.yaml
+++ b/vars/onap.yaml
@@ -52,6 +52,9 @@
 # xtesting container image registry
 xtesting_image_repo: nexus3.onap.org:10001/onap
 
+busybox_image: nexus3.onap.org:10001/library/busybox
+busybox_image_tag: latest
+
 # versions of docker as of 13.07.2020 needed for packaging
 docker_ce_version: "5:19.03.12~3-0~ubuntu-bionic"
 docker_ce_cli_version: "{{ docker_ce_version }}"