# Copyright 2022 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.
---

- name: Initialize variables
  set_fact:
    mngmnt_network_container_status: false

- name: Check mngmnt_network_container status on the machine
  command: kubectl get pods -n network-config
  register: mngmnt_network_container_result
  failed_when: false
  changed_when: false

- name: Validate if mngmnt_network is present if device_config is false
  set_fact:
    mngmnt_network_container_status: true
  when: "'mngmnt-network-container' in mngmnt_network_container_result.stdout"

- name: Validate if mngmnt_network is present if device_config is false
  assert:
    that: device_config_support != false
    success_msg: "{{ mgmnt_device_fail }}"
    fail_msg: "{{ mgmnt_device_fail }}"
  when: mngmnt_network_container_status

- name: Assert value of idrac_support if mngmnt_network container needed
  assert:
    that: idrac_support == true
    success_msg: "{{ idrac_support_valid }}"
    fail_msg: " {{ failed_idrac_support }}"
  when: device_config_support

- block:
    - name: Assert ethernet_switch_support
      assert:
        that: ethernet_switch_support == true or ethernet_switch_support == false
        success_msg: "{{ ethernet_switch_support_success_msg }}"
        fail_msg: "{{ ethernet_switch_support_fail_msg }}"

    - name: Assert ib_switch_support
      assert:
        that:  ib_switch_support == true or ib_switch_support == false
        success_msg: "{{ ib_switch_support_success_msg }}"
        fail_msg: "{{ ib_switch_support_fail_msg }}"

    - name: Assert powervault_support
      assert:
        that: powervault_support == true or powervault_support == false
        success_msg: "{{ powervault_support_success_msg }}"
        fail_msg: "{{ powervault_support_fail_msg }}"

  when: device_support_status

- block:
  - name: Check value of ethernet_switch_support when not device_config_support
    assert:
      that: ethernet_switch_support == true
      success_msg: "{{ ethernet_device_config }}"
    failed_when: false

  - name: Set ethernet_switch_support when not device_config_support
    set_fact:
      ethernet_switch_support: false

  - name: Check value of ib_switch_support when not device_config_support
    assert:
      that: ib_switch_support == true
      success_msg: "{{ ib_device_config }}"
    failed_when: false

  - name: Set ib_switch_support when not device_config_support
    set_fact:
      ib_switch_support: false

  - name: Check value of powervault_support when not device_config_support
    assert:
      that: powervault_support == true
      success_msg: "{{ pv_device_config }}"
    failed_when: false

  - name: Set powervault_support when not device_config_support
    set_fact:
      powervault_support: false
  when: not device_support_status