# 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_001
# Execute slurm_common role in manager & compute nodes with os installed centos 7.9
- name: OMNIA_USP_US_VFSP_TC_001
  hosts: manager, compute
  vars_files:
    - test_vars/test_slurm_common_vars.yml
  tasks:
    - block:
        - name: Call slurm common role
          include_role:
            name: ../roles/slurm_common
      tags: TC_001

    - name: Fetch common packages installed
      package_facts:
        manager: auto
      tags: TC_001,VERIFY_001

    - name: Checking munge service status
      systemd:
        name: munge
      register: munge_service
      tags: TC_001, VERIFY_001

    - name: Verify all required packages are installed
      assert:
        that: "'{{ item }}' in ansible_facts.packages"
        success_msg: "{{ packages_status_success_msg }}"
        fail_msg: "{{ packages_status_fail_msg }}"
      with_items: "{{ common_packages }}"
      tags: TC_001,VERIFY_001

    - name: Validating munge service status
      assert:
        that:
          - munge_service.status.ActiveState == 'active'
        fail_msg: "{{ munge_service_fail_msg }}"
        success_msg: "{{ munge_service_success_msg }}"
      tags: TC_001, VERIFY_001

# Testcase OMNIA_USP_US_VFSP_TC_002
# Execute slurm_common role in manager & compute nodes with common packages already installed
- name: OMNIA_USP_US_VFSP_TC_002
  hosts: manager, compute
  vars_files:
    - test_vars/test_slurm_common_vars.yml
  tasks:
    - block:
        - name: Call slurm common role
          include_role:
            name: ../roles/slurm_common
      tags: TC_002, VERIFY_002

    - name: Fetch common packages installed
      package_facts:
        manager: auto
      tags: TC_002,VERIFY_002

    - name: Checking munge service status
      systemd:
        name: munge
      register: munge_service
      tags: TC_002, VERIFY_002

    - name: Verify all required packages are installed
      assert:
        that: "'{{ item }}' in ansible_facts.packages"
        success_msg: "{{ packages_status_success_msg }}"
        fail_msg: "{{ packages_status_fail_msg }}"
      with_items: "{{ common_packages }}"
      tags: TC_002,VERIFY_002

    - name: Validating munge service status
      assert:
        that:
          - munge_service.status.ActiveState == 'active'
        fail_msg: "{{ munge_service_fail_msg }}"
        success_msg: "{{ munge_service_success_msg }}"
      tags: TC_002, VERIFY_002