---
- hosts: localhost
  connection: local
  gather_facts: False

  vars_files:
    - test_vars.yml

  tasks:
    - block:

        ## Generating the testname for deployment
        - include_tasks: /e2e-tests/hack/create_testname.yml

         ## RECORD START-OF-TEST IN e2e RESULT CR
        - include_tasks: "/e2e-tests/hack/update_e2e_result_resource.yml"
          vars:
            status: 'SOT'

        - block:
              ## Prerequisite tasks such as, namespace creation and replacing placeholder
              ## with test specific values, before deploying application 
            - include_tasks: /e2e-tests/utils/k8s/pre_create_app_deploy.yml
              vars:
                application: "{{ application_deployment }}"

              ## Deploying the application
            - include_tasks: /e2e-tests/utils/k8s/deploy_single_app.yml
              vars:
                application: "{{ application_deployment }}"

              ## Fetching the pod name
            - include_tasks: /e2e-tests/utils/k8s/fetch_app_pod.yml

                ## Checking the db is ready for connection
            - include_tasks: /e2e-tests/utils/applications/mysql/check_db_connection.yml

          when: "'deprovision' not in action"

        - name: Deprovisioning the Application
          include_tasks: /e2e-tests/utils/k8s/deprovision_deployment.yml
          vars:
            app_deployer: "{{ application_deployment }}"
          when: "'deprovision' is in action"

        - set_fact:
            flag: "Pass"
            
      rescue:
        - set_fact:
            flag: "Fail"     

      always:
            ## RECORD END-OF-TEST IN e2e RESULT CR
        - include_tasks: /e2e-tests/hack/update_e2e_result_resource.yml
          vars:
            status: 'EOT'
