#  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_003
# Execute slurm_manager role in manager node with os installed centos 7.9
- name: OMNIA_USP_US_VFSP_TC_003
  hosts: manager
  vars_files:
    - test_vars/test_slurm_manager_vars.yml
    - ../appliance/roles/common/vars/main.yml
  tasks:
    - block:
        - name: Call cluster_validation role
          include_role:
            name: ../roles/cluster_validation
            tasks_from: fetch_password
          tags: TC_003

        - name: Call slurm manager role
          include_role:
            name: ../roles/slurm_manager
          tags: TC_003

    - name: Fetch slurm packages installed
      package_facts:
        manager: auto
      tags: TC_003,VERIFY_003

    - name: Start and enable firewalld
      service:
        name: firewalld
        state: started
        enabled: yes
      tags: TC_003, VERIFY_003

    - name: Checking firewalld tcp/udp ports on manager node
      command: firewall-cmd --list-ports
      register: manager_firewalld_ports
      when: "'manager' in group_names"
      tags: TC_003, VERIFY_003

    - name: Checking mariadb service status
      systemd:
        name: mariadb
      register: mariadb_service
      tags: TC_003, VERIFY_003

    - name: Validating tcp/udp ports on manager node
      assert:
        that:
          - "'6817/tcp' in manager_firewalld_ports.stdout"
          - "'6817/udp' in manager_firewalld_ports.stdout"
          - "'6818/tcp' in manager_firewalld_ports.stdout"
          - "'6818/udp' in manager_firewalld_ports.stdout"
          - "'6819/tcp' in manager_firewalld_ports.stdout"
          - "'6819/udp' in manager_firewalld_ports.stdout"
        fail_msg: "{{ manager_ports_status_fail_msg }}"
        success_msg: "{{ manager_ports_status_success_msg }}"
      when: "'manager' in group_names"
      tags: TC_003, VERIFY_003

    - 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_003, VERIFY_003

    - name: Validating mariadb service status
      assert:
        that:
          - mariadb_service.status.ActiveState == 'active'
        fail_msg: "{{ mariadb_service_fail_msg }}"
        success_msg: "{{ mariadb_service_success_msg }}"
      tags: TC_003, VERIFY_003

# Testcase OMNIA_USP_US_VFSP_TC_004
# Execute slurm_manager role in manager node with slurm packages already installed
- name: OMNIA_USP_US_VFSP_TC_004
  hosts: manager
  vars_files:
    - test_vars/test_slurm_manager_vars.yml
    - ../appliance/roles/common/vars/main.yml
  tasks:
    - block:
        - name: Call cluster_validation role
          include_role:
            name: ../roles/cluster_validation
            tasks_from: fetch_password
          tags: TC_004

        - name: Call slurm manager role
          include_role:
            name: ../roles/slurm_manager
          tags: TC_004

    - name: Fetch slurm packages installed
      package_facts:
        manager: auto
      tags: TC_004,VERIFY_004

    - name: Start and enable firewalld
      service:
        name: firewalld
        state: started
        enabled: yes
      tags: TC_004, VERIFY_004

    - name: Checking firewalld tcp/udp ports on manager node
      command: firewall-cmd --list-ports
      register: manager_firewalld_ports
      when: "'manager' in group_names"
      tags: TC_004, VERIFY_004

    - name: Checking mariadb service status
      systemd:
        name: mariadb
      register: mariadb_service
      tags: TC_004, VERIFY_004

    - name: Validating tcp/udp ports on manager node
      assert:
        that:
          - "'6817/tcp' in manager_firewalld_ports.stdout"
          - "'6817/udp' in manager_firewalld_ports.stdout"
          - "'6818/tcp' in manager_firewalld_ports.stdout"
          - "'6818/udp' in manager_firewalld_ports.stdout"
          - "'6819/tcp' in manager_firewalld_ports.stdout"
          - "'6819/udp' in manager_firewalld_ports.stdout"
        fail_msg: "{{ manager_ports_status_fail_msg }}"
        success_msg: "{{ manager_ports_status_success_msg }}"
      when: "'manager' in group_names"
      tags: TC_004, VERIFY_004

    - 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_004, VERIFY_004

    - name: Validating mariadb service status
      assert:
        that:
          - mariadb_service.status.ActiveState == 'active'
        fail_msg: "{{ mariadb_service_fail_msg }}"
        success_msg: "{{ mariadb_service_success_msg }}"
      tags: TC_004, VERIFY_004