Skip to content

Commit

Permalink
Modified vcenter_vm_clone_on_library test (ansible-collections#554)
Browse files Browse the repository at this point in the history
Modified vcenter_vm_clone_on_library test to run on real vCenter env

Reviewed-by: mikemorency
Reviewed-by: Polina Rabinovich
  • Loading branch information
anna-savina authored Nov 27, 2024
1 parent 2c2acdf commit 80f3222
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 192 deletions.

This file was deleted.

4 changes: 0 additions & 4 deletions tests/integration/targets/vcenter_vm_clone_on_library/aliases

This file was deleted.

This file was deleted.

Empty file.
10 changes: 0 additions & 10 deletions tests/integration/targets/vcenter_vm_clone_on_library/playbook.yml

This file was deleted.

This file was deleted.

This file was deleted.

160 changes: 0 additions & 160 deletions tests/integration/targets/vcenter_vm_clone_on_library/tasks/main.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
resource_pool_name: "{{ tiny_prefix }}-clone-on-library-resource-pool"
vm_name: "{{ tiny_prefix }}-clone-on-library-vm"
vm_from_template_name: "{{ tiny_prefix }}-vm-from-template"
library_name: "{{ tiny_prefix }}-library-on-datastore"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- hosts: localhost
gather_facts: no

tasks:
- name: Import eco-vcenter credentials
ansible.builtin.include_vars:
file: ../group_vars.yml
tags: eco-vcenter-ci

- name: Import vmware_rest_lookup_plugin test
ansible.builtin.import_role:
name: vmware_rest_vcenter_vm_clone_on_library
tags:
- eco-vcenter-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
- name: Test VM clone on library
block:
- name: Create a content library based on a DataStore
vmware.vmware_rest.content_locallibrary:
name: "{{ library_name }}"
description: automated
publish_info:
published: true
authentication_method: 'NONE'
storage_backings:
- datastore_id: "{{ lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/' + eco_nfs_datastore_iso) }}"
type: 'DATASTORE'
state: present
register: nfs_lib

- name: Create a generic resource pool
vmware.vmware_rest.vcenter_resourcepool:
name: "{{ resource_pool_name }}"
parent: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + vcenter_resource_pool) }}"
register: resource_pool_info

- name: Create a VM
vmware.vmware_rest.vcenter_vm:
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name) }}"
datastore: "{{ lookup('vmware.vmware_rest.datastore_moid', '/' + vcenter_datacenter + '/' + shared_storage_01) }}"
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/' + vcenter_vm_folder) }}"
resource_pool: "{{ resource_pool_info.id }}"
name: "{{ vm_name }}"
guest_OS: RHEL_9_64
hardware_version: VMX_21
memory:
hot_add_enabled: true
size_MiB: 2000
nics:
- type: VMXNET3
backing:
type: DISTRIBUTED_PORTGROUP
network: "{{ lookup('vmware.vmware_rest.network_moid', '/' + vcenter_datacenter + '/' + vm_network_name) }}"
start_connected: true
cdroms:
- backing:
type: ISO_FILE
iso_file: "{{ rhel_9_3_iso_path }}"
start_connected: true
register: test_vm

- name: Create a VM template on the library
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: "{{ vm_name }}-template"
library: "{{ nfs_lib.id }}"
source_vm: "{{ test_vm.id }}"
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name) }}"
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/' + vcenter_vm_folder) }}"
resource_pool: "{{ resource_pool_info.id }}"
register: nfs_lib_item

- name: Verify VM template added to the library
ansible.builtin.assert:
that:
- nfs_lib_item is changed

- name: _Create the same template again
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: "{{ vm_name }}-template"
library: "{{ nfs_lib.id }}"
source_vm: "{{ test_vm.id }}"
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name) }}"
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/' + vcenter_vm_folder) }}"
resource_pool: "{{ resource_pool_info.id }}"
register: _result

- name: Verify no VM template added to the library
ansible.builtin.assert:
that:
- not (_result is changed)

- name: Get the list of items of the NFS library
vmware.vmware.content_library_item_info:
library_id: '{{ nfs_lib.id }}'
register: nfs_lib_items

- name: Verify VM template name
ansible.builtin.assert:
that:
- nfs_lib_items.library_item_info[0].name == "{{ vm_name }}-template"

- name: Deploy a new VM based on the template
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: "{{ vm_from_template_name }}"
library: "{{ nfs_lib.id }}"
template_library_item: "{{ nfs_lib_item.id }}"
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name) }}"
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/' + vcenter_datacenter + '/' + vcenter_vm_folder) }}"
resource_pool: "{{ resource_pool_info.id }}"
state: deploy
register: vm_from_template

- name: Retrieve all the details about the new VM
vmware.vmware_rest.vcenter_vm:
vm: "{{ vm_from_template.value }}"
register: vm_from_template_info

- name: Verify VM from template name
ansible.builtin.assert:
that:
- vm_from_template_info.value.name == vm_from_template_name

always:
- name: Delete test VM's
vmware.vmware_rest.vcenter_vm:
vm: "{{ lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + vm_name) }}"
state: absent

- name: Delete VM from template
vmware.vmware_rest.vcenter_vm:
vm: "{{ lookup('vmware.vmware_rest.vm_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + vm_from_template_name) }}"
state: absent

- name: Delete nfs library
vmware.vmware_rest.content_locallibrary:
library_id: "{{ nfs_lib.id }}"
state: absent
when: nfs_lib is defined

- name: Delete resource pool
vmware.vmware_rest.vcenter_resourcepool:
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/' + vcenter_datacenter + '/' + vcenter_cluster_name + '/' + resource_pool_name) }}"
state: absent

0 comments on commit 80f3222

Please sign in to comment.