#  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_016
# Execute kubeflow role in manager nodes with os installed centos 7.9
- name: OMNIA_UKP_US_VFKP_TC_016
  hosts: manager
  gather_facts: false
  vars_files:
    - test_vars/test_kubeflow_vars.yml
  tasks:
    - block:
        - name: Call kubeflow role
          include_role:
            name: ../platforms/roles/kubeflow
      tags: TC_016

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

    - name: Checking installed Kubeflow version
      command: kfctl version
      register: kfctl_version
      changed_when: false
      ignore_errors: True
      tags: TC_016, VERIFY_016

    - name: Checking pods under kubeflow namespace
      command: kubectl get pods --namespace kubeflow
      register: kubeflow_pods
      changed_when: false
      ignore_errors: True
      tags: TC_016, VERIFY_016

    - name: Checking pods under istio-system namespace
      command: kubectl get pods --namespace istio-system
      register: istio_system_pods
      changed_when: false
      ignore_errors: True
      tags: TC_016, VERIFY_016

    - name: Validating Kubeflow Installation
      assert:
        that:
          - "'command not found' not in kfctl_version.stdout"
        fail_msg: "{{ kubeflow_install_fail_msg }}"
        success_msg: "{{ kubeflow_install_success_msg }}"
      tags: TC_016, VERIFY_016

    - name: Validating Kubeflow pods deployment
      assert:
        that:
          - "'Running' in kubeflow_pods.stdout or 'ContainerCreating' in kubeflow_pods.stdout"
          - "'Running' in istio_system_pods.stdout or 'ContainerCreating' in istio_system_pods.stdout"
        fail_msg: "{{ kubeflow_pods_deployment_fail_msg }}"
        success_msg: "{{ kubeflow_pods_deployment_success_msg }}"
      tags: TC_016, VERIFY_016

# OMNIA_UKP_US_VFKP_TC_017
# Execute kubeflow role in manager nodes with kubeflow already deployed
- name: OMNIA_UKP_US_VFKP_TC_017
  hosts: manager
  gather_facts: false
  vars_files:
    - test_vars/test_kubeflow_vars.yml
  tasks:
    - block:
        - name: Call kubeflow role
          include_role:
            name: ../platforms/roles/kubeflow
      tags: TC_017, VERIFY_017

    - name: Checking installed Kubeflow version
      command: kfctl version
      register: kfctl_version
      changed_when: false
      ignore_errors: True
      tags: TC_017, VERIFY_017

    - name: Checking pods under kubeflow namespace
      command: kubectl get pods --namespace kubeflow
      register: kubeflow_pods
      changed_when: false
      ignore_errors: True
      tags: TC_017, VERIFY_017

    - name: Checking pods under istio-system namespace
      command: kubectl get pods --namespace istio-system
      register: istio_system_pods
      changed_when: false
      ignore_errors: True
      tags: TC_017, VERIFY_017

    - name: Validating Kubeflow Installation
      assert:
        that:
          - "'command not found' not in kfctl_version.stdout"
        fail_msg: "{{ kubeflow_install_fail_msg }}"
        success_msg: "{{ kubeflow_install_success_msg }}"
      tags: TC_017, VERIFY_017

    - name: Validating Kubeflow pods deployment
      assert:
        that:
          - "'Running' in kubeflow_pods.stdout or 'ContainerCreating' in kubeflow_pods.stdout"
          - "'Running' in istio_system_pods.stdout or 'ContainerCreating' in istio_system_pods.stdout"
        fail_msg: "{{ kubeflow_pods_deployment_fail_msg }}"
        success_msg: "{{ kubeflow_pods_deployment_success_msg }}"
      tags: TC_017, VERIFY_017