From 5532ec742579ae901100c365ecc5ed79e923ec80 Mon Sep 17 00:00:00 2001
From: Marica Antonacci <marica.antonacci@ba.infn.it>
Date: Sat, 26 Mar 2022 19:51:07 +0100
Subject: [PATCH] Improve tasks

---
 defaults/main.yml |  3 +--
 tasks/main.yml    | 59 +++++++++++++++++++++++++++++++++++++++--------
 vars/main.yml     |  7 +++++-
 3 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/defaults/main.yml b/defaults/main.yml
index d8e2d88..692e2b7 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -1,6 +1,5 @@
 ---
 # defaults file for paas-ci
 paas_ci_orchestrator_url: https://paas.cloud.infn.it/orchestrator
-paas_ci_oidc_sock:
-        
+paas_ci_workdir: "{{ lookup('env','PWD') }}"        
         
diff --git a/tasks/main.yml b/tasks/main.yml
index 4c24ef2..641f4e6 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -4,18 +4,59 @@
   uri:
     url: "{{ paas_ci_orchestrator_url }}"
 
-- name: 
-  set_fact:
-    workdir: "{{ lookup('env','PWD') }}"
-
 - block:
   - name: Get template
     get_url:
-      url: https://baltig.infn.it/infn-cloud/tosca-templates/-/raw/master/single-vm/single_vm.yaml
-      dest: "{{ workdir }}"
-  - name: Run simple node
-    command: orchent depcreate single_vm.yaml '{}'
- 
+      url: "{{ paas_ci_test.template_url }}"
+      dest: "{{ paas_ci_workdir }}"
+
+  - name: Deployment command
+    set_fact:
+      depcreate_cmd: "orchent depcreate --ojson single_vm.yaml -g beta-testers {{ paas_ci_test.inputs }}"
+
+  - name:  Create the deployment
+    command: "{{depcreate_cmd}}"
+    register: depcreate_output
+    failed_when: "'CREATE' not in depcreate_output.stdout"
+
+  - set_fact:
+      deployment: "{{ depcreate_output.stdout|from_json }}"
+
+  - 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 }}"
+
+  when: paas_ci_test_step == 'create_deployment'
+
+- 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'
diff --git a/vars/main.yml b/vars/main.yml
index 0863a58..435f8b1 100644
--- a/vars/main.yml
+++ b/vars/main.yml
@@ -1,2 +1,7 @@
 ---
-# vars file for paas-ci
\ No newline at end of file
+# vars file for paas-ci
+paas_ci_test_step: ""
+paas_ci_test:
+  template_url: https://baltig.infn.it/infn-cloud/tosca-templates/-/raw/master/single-vm/single_vm.yaml
+  inputs: |
+    '{ "users": [{"os_user_add_to_sudoers": true, "os_user_name": "antonacci", "os_user_ssh_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDE887DQ8WcX5f8d9/MakzMhG/QovKzjrgDzJ0CwjxKm3kUYildhPcUtj7k73WdcP06st6cWpxQ+7HmFseuX+1GASorENAqMHbOvoT0K6pkNlgwgyDOYdR5JSnXIEfR7gTE391SuYN8lbLEvFCscNHYP6814tYochO+sSlpa3XJ2nHvvVp4Ikt/X2Q+zidkKzuMUwFeGf4MZz93Nlwcbg3UM+ENEjjksb7Rqxx2WtYAv8Gn6Jr1X3PmvMoaO9HBgZaosp7NXh20LRHJW+aiEKcr+vzFlgUjTcd/h2CrkgS6+AhjKqpMNS1sS/QuOvPVMUNr1dSOkmAR5EwfHcXpY9RL marica@MacBook-Air-di-marica.local"}]}'
-- 
GitLab