#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_007
# Execute slurm_start_services role in manager node with os installed centos 7.9
- name: OMNIA_USP_US_VFSP_TC_007
  hosts: manager
  vars_files:
    - test_vars/test_slurm_start_services_vars.yml
  tasks:
    - block:
        - name: Call slurm start services role
          include_role:
            name: ../roles/slurm_start_services
      tags: TC_007

    - name: Checking slurmctld service status
      systemd:
        name: slurmctld
      register: slurmctld_service
      tags: TC_007, VERIFY_007

    - name: Checking slurmdbd service status
      systemd:
        name: slurmdbd
      register: slurmdbd_service
      tags: TC_007, VERIFY_007

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

    - name: Validating slurmctld service status
      assert:
        that:
          - slurmctld_service.status.ActiveState == 'active'
        fail_msg: "{{ slurmctld_service_fail_msg }}"
        success_msg: "{{ slurmctld_service_success_msg }}"
      tags: TC_007, VERIFY_007

    - name: Validating slurmdbd service status
      assert:
        that:
          - slurmdbd_service.status.ActiveState == 'active'
        fail_msg: "{{ slurmdbd_service_fail_msg }}"
        success_msg: "{{ slurmdbd_service_success_msg }}"
      tags: TC_007, VERIFY_007

    - 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_007, VERIFY_007

# Testcase OMNIA_USP_US_VFSP_TC_008
# Execute slurm_start_services role in manager node with services already running
- name: OMNIA_USP_US_VFSP_TC_008
  hosts: manager
  vars_files:
    - test_vars/test_slurm_start_services_vars.yml
  tasks:
    - block:
        - name: Call slurm start services role
          include_role:
            name: ../roles/slurm_start_services
      tags: TC_008

    - name: Checking slurmctld service status
      systemd:
        name: slurmctld
      register: slurmctld_service
      tags: TC_008, VERIFY_008

    - name: Checking slurmdbd service status
      systemd:
        name: slurmdbd
      register: slurmdbd_service
      tags: TC_008, VERIFY_008

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

    - name: Validating slurmctld service status
      assert:
        that:
          - slurmctld_service.status.ActiveState == 'active'
        fail_msg: "{{ slurmctld_service_fail_msg }}"
        success_msg: "{{ slurmctld_service_success_msg }}"
      tags: TC_008, VERIFY_008

    - name: Validating slurmdbd service status
      assert:
        that:
          - slurmdbd_service.status.ActiveState == 'active'
        fail_msg: "{{ slurmdbd_service_fail_msg }}"
        success_msg: "{{ slurmdbd_service_success_msg }}"
      tags: TC_008, VERIFY_008

    - 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_008, VERIFY_008