From ba1e05640e0be8d09cb0525e3c95dc61b3dfbdec Mon Sep 17 00:00:00 2001 From: qweqweasdasd <qweqweasdasd@infn.it> Date: Tue, 26 Jul 2022 11:57:33 +0200 Subject: [PATCH] Splitted the main in subfiles --- tasks/1-create-deployment.yml | 49 ++++++++++++++++ tasks/2-scan.yml | 41 +++++++++++++ tasks/3-clean.yml | 7 +++ tasks/main.yml | 107 ++-------------------------------- 4 files changed, 101 insertions(+), 103 deletions(-) create mode 100644 tasks/1-create-deployment.yml create mode 100644 tasks/2-scan.yml create mode 100644 tasks/3-clean.yml diff --git a/tasks/1-create-deployment.yml b/tasks/1-create-deployment.yml new file mode 100644 index 0000000..5bcee79 --- /dev/null +++ b/tasks/1-create-deployment.yml @@ -0,0 +1,49 @@ +- name: Get template + get_url: + url: "{{ paas_ci_test.template_url }}" + dest: "{{ paas_ci_workdir + '/template.yaml' }}" + +- name: Deployment command + set_fact: + depcreate_cmd: "orchent depcreate --ojson template.yaml -g admins/beta-testers {{ paas_ci_test.inputs }}" + +- name: Create the deployment + command: "{{ depcreate_cmd }}" + args: + chdir: "{{ paas_ci_workdir }}" + register: depcreate_output + failed_when: "'CREATE' not in depcreate_output.stdout" + +- set_fact: + deployment: "{{ depcreate_output.stdout|from_json }}" + +- debug: + var: deployment + +- name: Sleep for 60 seconds and timeout + wait_for: + delay: 60 + timeout: 0 + +- name: Check the deployment status (every 5 mins) + command: orchent depshow --ojson "{{ deployment.uuid }}" + register: depshow_output + until: "'PROGRESS' not in depshow_output.stdout" + retries: 10 + delay: 300 + failed_when: "'error' in depshow_output.stdout" + +- set_fact: + deployment: "{{ depshow_output.stdout|from_json }}" + +- name: Save result to file + copy: + dest: "{{ paas_ci_workdir }}/dep.json" + content: "{{ depshow_output.stdout }}" + +- name: Get deployment status and outputs (if successful) + assert: + that: + - deployment.status == 'CREATE_COMPLETE' + fail_msg: "TEST FAILED - deployment uuid: {{ deployment.uuid }}, status: {{ deployment.status }}" + success_msg: "TEST PASSED - deployment uuid: {{ deployment.uuid }}, status: {{ deployment.status }}, outputs: {{ deployment.outputs }}" \ No newline at end of file diff --git a/tasks/2-scan.yml b/tasks/2-scan.yml new file mode 100644 index 0000000..5d93f6f --- /dev/null +++ b/tasks/2-scan.yml @@ -0,0 +1,41 @@ +- name: Set SSH tunnel + command: ssh -f -N -L "{{ ansible_default_ipv4.address }}":9390:192.168.187.162:9390 jenkins@scans.cloud.infn.it + +- set_fact: + endpoints_to_scan: "{{ paas_ci_test.endpoints_to_scan }}" + +- debug: + var: endpoints_to_scan + +- name: Run scan + command: "{{ python3_script_path }} {{ endpoints_to_scan }} {{ paas_ci_workdir + '/dep.json'}} {{ paas_ci_workdir }}" + register: scan_output + +- name: Find report files + find: + paths: "{{paas_ci_workdir}}" + patterns: '*report.txt' + register: report_files + +- name: Show reports + debug: + msg: "{{lookup('file', item.path)}}" + with_items: "{{report_files.files}}" + +- name: get Severity file content + shell: cat "{{ paas_ci_workdir + '/severity.json'}}" + register: severity + +- name: import severity + set_fact: + severity_json: "{{ severity.stdout | from_json }}" + +- debug: + var: severity_json + +- name: Get scan outputs (if successful) + assert: + that: + - severity_json.global == 'OK' + fail_msg: "SCAN FAILED - global_severity: {{ severity_json.global_severity }}" + success_msg: "SCAN PASSED - global_severity: {{ severity_json.global_severity }}" \ No newline at end of file diff --git a/tasks/3-clean.yml b/tasks/3-clean.yml new file mode 100644 index 0000000..f716042 --- /dev/null +++ b/tasks/3-clean.yml @@ -0,0 +1,7 @@ +- set_fact: + deployment: "{{ lookup('file', paas_ci_workdir + '/dep.json') }}" + +- name: Delete deployment + command: orchent depdel "{{ deployment.uuid }}" + register: depdel_output + failed_when: "'error' in depdel_output.stdout" \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 190fc75..1e8fdd3 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -7,110 +7,11 @@ - debug: var: paas_ci_workdir -- block: - - name: Get template - get_url: - url: "{{ paas_ci_test.template_url }}" - dest: "{{ paas_ci_workdir + '/template.yaml' }}" - - - name: Deployment command - set_fact: - depcreate_cmd: "orchent depcreate --ojson template.yaml -g admins/beta-testers {{ paas_ci_test.inputs }}" - - - name: Create the deployment - command: "{{depcreate_cmd}}" - args: - chdir: "{{ paas_ci_workdir }}" - register: depcreate_output - failed_when: "'CREATE' not in depcreate_output.stdout" - - - set_fact: - deployment: "{{ depcreate_output.stdout|from_json }}" - - - debug: - var: deployment - - - name: Sleep for 60 seconds and timeout - wait_for: - delay: 60 - timeout: 0 - - - name: Check the deployment status (every 5 mins) - command: orchent depshow --ojson "{{ deployment.uuid }}" - register: depshow_output - until: "'PROGRESS' not in depshow_output.stdout" - retries: 10 - delay: 300 - failed_when: "'error' in depshow_output.stdout" - - - set_fact: - deployment: "{{ depshow_output.stdout|from_json }}" - - - name: Save result to file - copy: - dest: "{{ paas_ci_workdir }}/dep.json" - content: "{{ depshow_output.stdout }}" - - - name: Get deployment status and outputs (if successful) - assert: - that: - - deployment.status == 'CREATE_COMPLETE' - fail_msg: "TEST FAILED - deployment uuid: {{ deployment.uuid }}, status: {{ deployment.status }}" - success_msg: "TEST PASSED - deployment uuid: {{ deployment.uuid }}, status: {{ deployment.status }}, outputs: {{ deployment.outputs }}" - +- include: 1-create-deployment.yml when: paas_ci_test_step == 'create_deployment' -- block: - - name: Set ssh bind - command: ssh -f -N -L "{{ ansible_default_ipv4.address }}":9390:192.168.187.162:9390 jenkins@scans.cloud.infn.it - - - set_fact: - endpoints_to_scan: "{{ paas_ci_test.endpoints_to_scan }}" - - - debug: - var: endpoints_to_scan - - - name: Run scan - command: "{{ python3_script_path }} {{ endpoints_to_scan }} {{ paas_ci_workdir + '/dep.json'}} {{ paas_ci_workdir }}" - register: scan_output - - - name: Find report files - find: - paths: "{{paas_ci_workdir}}" - patterns: '*report.txt' - register: report_files - - - name: Show reports - debug: - msg: "{{lookup('file', item.path)}}" - with_items: "{{report_files.files}}" - - - name: get Severity file content - shell: cat "{{ paas_ci_workdir + '/severity.json'}}" - register: severity - - - name: import severity - set_fact: - severity_json: "{{ severity.stdout | from_json }}" - - - debug: - var: severity_json - - - name: Get scan outputs (if successful) - assert: - that: - - severity_json.global == 'OK' - fail_msg: "SCAN FAILED - global_severity: {{ severity_json.global_severity }}" - success_msg: "SCAN PASSED - global_severity: {{ severity_json.global_severity }}" - +- include: 2-scan.yml when: paas_ci_test_step == 'scan' -- block: - - set_fact: - deployment: "{{ lookup('file', paas_ci_workdir + '/dep.json') }}" - - - name: Delete deployment - command: orchent depdel "{{ deployment.uuid }}" - register: depdel_output - failed_when: "'error' in depdel_output.stdout" - when: paas_ci_test_step == 'clean' +- include: 3-clean.yml + when: paas_ci_test_step == 'clean' \ No newline at end of file -- GitLab