#  Copyright 2020 Dell Inc. or its subsidiaries. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
---

# OMNIA_UKP_US_VFKP_TC_014
# Execute jupyterhub role in manager nodes with os installed centos 7.9
- name: OMNIA_UKP_US_VFKP_TC_014
  hosts: manager
  gather_facts: false
  vars_files:
    - test_vars/test_jupyterhub_vars.yml
  tasks:
    - block:
        - name: Call jupyterhub role
          include_role:
            name: ../platforms/roles/jupyterhub
      tags: TC_014

    - name: Waiting for the pods deployment
      pause:
        minutes: 5
      tags: TC_014

    - name: Checking all running pods under default namespace
      command: kubectl get pods --namespace default --field-selector=status.phase=Running
      register: namesapce_default_running_pods
      changed_when: false
      ignore_errors: True
      tags: TC_014, VERIFY_014

    - name: Checking K8s services
      command: kubectl get services
      register: k8s_services
      changed_when: false
      ignore_errors: True
      tags: TC_014, VERIFY_014

    - name: Validating JupyterHub pods
      assert:
        that:
          - "'hub' in namesapce_default_running_pods.stdout"
          - "'proxy' in namesapce_default_running_pods.stdout"
        fail_msg: "{{ jupyterhub_pods_fail_msg }}"
        success_msg: "{{ jupyterhub_pods_success_msg }}"
      tags: TC_014, VERIFY_014

    - name: Validating JupyterHub services
      assert:
        that:
          - "'hub' in k8s_services.stdout"
          - "'proxy-public' in k8s_services.stdout"
          - "'proxy-api' in k8s_services.stdout"
        fail_msg: "{{ jupyterhub_services_fail_msg }}"
        success_msg: "{{ jupyterhub_services_success_msg }}"
      tags: TC_014, VERIFY_014

# OMNIA_UKP_US_VFKP_TC_015
# Execute jupyterhub role in manager nodes with JupyterHub already deployed
- name: OMNIA_UKP_US_VFKP_TC_015
  hosts: manager
  gather_facts: false
  vars_files:
    - test_vars/test_jupyterhub_vars.yml
  tasks:
    - block:
        - name: Call jupyterhub role
          include_role:
            name: ../platforms/roles/jupyterhub
      tags: TC_015, VERIFY_015

    - name: Checking all running pods under default namespace
      command: kubectl get pods --namespace default --field-selector=status.phase=Running
      register: namesapce_default_running_pods
      changed_when: false
      ignore_errors: True
      tags: TC_015, VERIFY_015

    - name: Checking K8s services
      command: kubectl get services
      register: k8s_services
      changed_when: false
      ignore_errors: True
      tags: TC_015, VERIFY_015

    - name: Validating JupyterHub pods
      assert:
        that:
          - "'hub' in namesapce_default_running_pods.stdout"
          - "'proxy' in namesapce_default_running_pods.stdout"
        fail_msg: "{{ jupyterhub_pods_fail_msg }}"
        success_msg: "{{ jupyterhub_pods_success_msg }}"
      tags: TC_015, VERIFY_015

    - name: Validating JupyterHub services
      assert:
        that:
          - "'hub' in k8s_services.stdout"
          - "'proxy-public' in k8s_services.stdout"
          - "'proxy-api' in k8s_services.stdout"
        fail_msg: "{{ jupyterhub_services_fail_msg }}"
        success_msg: "{{ jupyterhub_services_success_msg }}"
      tags: TC_015, VERIFY_015