# Test code for the vmware_guest module.
# Copyright: (c) 2018, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: create new VMs with boot_firmware as 'bios'
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    hardware:
        num_cpus: 4
        boot_firmware: "bios"
        memory_mb: 512
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: "{{ f0 }}"
  register: clone_d1_c1_f0

- debug: var=clone_d1_c1_f0

- name: assert that changes were made
  assert:
    that:
        - clone_d1_c1_f0 is changed

# VCSIM does not recognizes existing VMs boot firmware
- when: vcsim is not defined
  block:
    - name: create new VMs again with boot_firmware as 'bios'
      vmware_guest:
        validate_certs: False
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        name: test_vm2
        guest_id: centos64Guest
        datacenter: "{{ dc1 }}"
        hardware:
          num_cpus: 4
          boot_firmware: "bios"
          memory_mb: 512
        disk:
          - size: 1gb
            type: thin
            autoselect_datastore: True
        state: poweredoff
        folder: "{{ f0 }}"
      register: clone_d1_c1_f0
    - debug: var=clone_d1_c1_f0
    - name: assert that changes were not made
      assert:
        that:
          - clone_d1_c1_f0 is changed

- name: create new VMs with boot_firmware as 'efi'
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm3
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    hardware:
        num_cpus: 4
        boot_firmware: "efi"
        memory_mb: 512
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: "{{ f0 }}"
  register: clone_d1_c1_f0

- debug: var=clone_d1_c1_f0

- name: assert that changes were made
  assert:
    that:
        - clone_d1_c1_f0 is changed

# VCSIM does not recognizes existing VMs boot firmware
- when: vcsim is not defined
  block:
    - name: create new VMs again with boot_firmware as 'efi'
      vmware_guest:
        validate_certs: False
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        name: test_vm3
        guest_id: centos64Guest
        datacenter: "{{ dc1 }}"
        hardware:
          num_cpus: 4
          boot_firmware: "efi"
          memory_mb: 512
        disk:
          - size: 1gb
            type: thin
            autoselect_datastore: True
        state: poweredoff
        folder: "{{ f0 }}"
      register: clone_d1_c1_f0
    - debug: var=clone_d1_c1_f0
    - name: assert that changes were not made
      assert:
        that:
          - not (clone_d1_c1_f0 is changed)
