# Copyright (c) 2023 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
---

# Hardware Validation Tests

- name: Gather power supplies status
  arista.eos.eos_command:
    commands: "show system environment power | json"
  register: system_environment_power
  tags:
    - hardware

- name: Validate power supplies status
  delegate_to: localhost
  ansible.builtin.assert:
    that:
      - "powerSupply.value.state in {{ accepted_pwr_supply_states }}"
    fail_msg: "Power supply state is {{ powerSupply.value.state | replace('\"', '') }}"
    quiet: true
  loop: "{{ system_environment_power.stdout_lines.0.powerSupplies | dict2items }}"
  loop_control:
    loop_var: powerSupply
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: power_supplies_results
  tags:
    - hardware

- name: Gather system environment fan status
  arista.eos.eos_command:
    commands: "show system environment cooling | json"
  register: system_environment_cooling
  tags:
    - hardware

- name: Validate fan status (power supplies)
  delegate_to: localhost
  ansible.builtin.assert:
    that:
      - "powerSupplySlot.status in {{ accepted_fan_states }}"
    fail_msg: "Power supply fan status is {{ powerSupplySlot.status | replace('\"', '') }}"
    quiet: true
  loop: "{{ system_environment_cooling.stdout_lines.0.powerSupplySlots }}"
  loop_control:
    loop_var: powerSupplySlot
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: fan_power_supplies_results
  tags:
    - hardware

- name: Validate fan status (fan tray)
  delegate_to: localhost
  ansible.builtin.assert:
    that:
      - "fanTraySlot.status in {{ accepted_fan_states }}"
    fail_msg: "Fan status is {{ fanTraySlot.status | replace('\"', '') }}"
    quiet: true
  loop: "{{ system_environment_cooling.stdout_lines.0.fanTraySlots }}"
  loop_control:
    loop_var: fanTraySlot
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: fan_tray_status_results
  tags:
    - hardware

- name: Gather system environment temperature
  arista.eos.eos_command:
    commands: "show system environment temperature | json"
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: environment_temperature
  tags:
    - hardware

- name: Validate system temperature
  delegate_to: localhost
  ansible.builtin.assert:
    that:
      - environment_temperature.stdout[0].systemStatus == 'temperatureOk'
    fail_msg: "System temperature is {{ environment_temperature.stdout[0].systemStatus | replace('\"', '') }}"
    quiet: true
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: environment_temperature_results
  tags:
    - hardware

- name: Gather transceivers inventory
  arista.eos.eos_command:
    commands: "show inventory | json"
  register: inventory
  tags:
    - hardware

- name: Validate transceivers manufacturers
  delegate_to: localhost
  ansible.builtin.assert:
    that:
      - "xcvrSlot.value.mfgName in {{ accepted_xcvr_manufacturers }}"
    fail_msg: "Transceivers manufacturers is {{ xcvrSlot.value.mfgName | replace('\"', '') }}"
    quiet: true
  loop: "{{ inventory.stdout_lines.0.xcvrSlots | dict2items }}"
  loop_control:
    loop_var: xcvrSlot
  ignore_errors: "{{ eos_validate_state_validation_mode_loose }}"
  register: transceiver_inventory_results
  when: "xcvrSlot.value.mfgName != 'Not Present'"
  tags:
    - hardware
