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

# Testcase OMNIA_USP_US_VFSP_TC_005
# Execute slurm_worker role in compute node with os installed centos 7.9
- name: OMNIA_USP_US_VFSP_TC_005
  hosts: compute
  vars_files:
    - test_vars/test_slurm_workers_vars.yml
  tasks:
    - block:
        - name: Call slurm worker role
          include_role:
            name: ../roles/slurm_workers
      tags: TC_005

    - name: Fetch slurm packages installed
      package_facts:
        manager: auto
      tags: TC_005,VERIFY_005

    - name: Check if slurm is installed
      command: sinfo -V
      register: slurm_version
      changed_when: false
      ignore_errors: True
      tags: TC_005,VERIFY_005

    - name: Checking slurmd service status
      service:
        name: slurmd.service
      register: slurmd_service
      tags: TC_005, VERIFY_005

    - name: Verify all slurm packages are installed
      assert:
        that: "'{{ item }}' in ansible_facts.packages"
        success_msg: "{{ slurm_packages_status_success_msg }}"
        fail_msg: "{{ slurm_packages_status_fail_msg }}"
      with_items:
          - "{{ slurm_packages }}"
          - "{{ dev_tools }}"
      tags: TC_005, VERIFY_005

    - name: Validate slurm installation
      assert:
        that: "'command not found' not in slurm_version.stdout"
        fail_msg: "{{ slurm_status_fail_msg }}"
        success_msg: "{{ slurm_status_success_msg }}"
      tags: TC_005, VERIFY_005

    - name: Validating slurmd service status
      assert:
        that:
          - slurmd_service.status.ActiveState == 'active'
        fail_msg: "{{ slurmd_service_fail_msg }}"
        success_msg: "{{ slurmd_service_success_msg }}"
      tags: TC_005, VERIFY_005

# Testcase OMNIA_USP_US_VFSP_TC_006
# Execute slurm_workers role in compute node with slurm packages already installed
- name: OMNIA_USP_US_VFSP_TC_006
  hosts: compute
  vars_files:
    - test_vars/test_slurm_workers_vars.yml
  tasks:
    - block:
        - name: Call slurm worker role
          include_role:
            name: ../roles/slurm_workers
      tags: TC_006

    - name: Fetch slurm packages installed
      package_facts:
        manager: auto
      tags: TC_006,VERIFY_006

    - name: Checking slurmd service status
      service:
        name: slurmd.service
      register: slurmd_service
      tags: TC_006, VERIFY_006

    - name: Check if slurm is installed
      command: sinfo -V
      register: slurm_version
      changed_when: false
      ignore_errors: True
      tags: TC_006,VERIFY_006

    - name: Verify all slurm packages are installed
      assert:
        that: "'{{ item }}' in ansible_facts.packages"
        success_msg: "{{ slurm_packages_status_success_msg }}"
        fail_msg: "{{ slurm_packages_status_fail_msg }}"
      with_items:
          - "{{ slurm_packages }}"
          - "{{ dev_tools }}"
      tags: TC_006, VERIFY_006

    - name: Validate slurm installation
      assert:
        that: "'command not found' not in slurm_version.stdout"
        fail_msg: "{{ slurm_status_fail_msg }}"
        success_msg: "{{ slurm_status_success_msg }}"
      tags: TC_006, VERIFY_006

    - name: Validating slurmd service status
      assert:
        that:
          - slurmd_service.status.ActiveState == 'active'
        fail_msg: "{{ slurmd_service_fail_msg }}"
        success_msg: "{{ slurmd_service_success_msg }}"
      tags: TC_006, VERIFY_006