Skip to content

Commit

Permalink
tests: minor improvement (ansible-collections#370)
Browse files Browse the repository at this point in the history
tests: minor improvement

better name for variables
drop a pause call
  • Loading branch information
goneri authored Nov 24, 2022
1 parent edf3d90 commit d44f958
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
name: test_vm1
guest_OS: DEBIAN_8_64
guest_OS: RHEL_7_64
hardware_version: VMX_11
memory:
hot_add_enabled: true
Expand Down Expand Up @@ -64,7 +64,7 @@
vmware.vmware_rest.content_locallibrary_info:
register: all_content_libraries

- name: Use the name to identify a content library
- name: Use the name to identify the right item
set_fact:
my_first_library: "{{ all_content_libraries.value | selectattr('name', 'equalto', 'my_library_on_nfs')|first }}"

Expand All @@ -83,7 +83,7 @@
target:
library_id: "{{ nfs_lib.id }}"
create_spec:
name: my_vm
name: golden_image
description: an OVF example
flags: []
state: present
Expand All @@ -102,7 +102,7 @@
target:
library_id: "{{ nfs_lib.id }}"
create_spec:
name: my_vm
name: golden_image
description: an OVF example
flags: []
state: present
Expand All @@ -120,7 +120,7 @@
- name: _Create a new VM from the OVF with a wrong folder
vmware.vmware_rest.vcenter_ovf_libraryitem:
session_timeout: 2900
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "my_vm")|first).id }}'
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
state: deploy
target:
resource_pool_id: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
Expand All @@ -134,8 +134,7 @@

- name: Create a new VM from the OVF
vmware.vmware_rest.vcenter_ovf_libraryitem:
session_timeout: 2900
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "my_vm")|first).id }}'
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
state: deploy
target:
resource_pool_id: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
Expand All @@ -150,8 +149,7 @@

- name: Create a new VM from the OVF and specify the host and folder
vmware.vmware_rest.vcenter_ovf_libraryitem:
session_timeout: 2900
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "my_vm")|first).id }}'
ovf_library_item_id: '{{ (lib_items.value|selectattr("name", "equalto", "golden_image")|first).id }}'
state: deploy
target:
resource_pool_id: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources') }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- datastore_id: "{{ lookup('vmware.vmware_rest.datastore_moid', '/my_dc/datastore/local') }}"
type: 'DATASTORE'
state: present
register: ds_lib
register: nfs_lib

- ansible.builtin.set_fact:
disk_name: rhel-8.5
Expand Down Expand Up @@ -93,8 +93,8 @@

- name: Create a VM template on the library
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: foobar2001
library: "{{ ds_lib.id }}"
name: golden-template
library: "{{ nfs_lib.id }}"
source_vm: "{{ my_vm.id }}"
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
Expand All @@ -109,8 +109,8 @@

- name: _Create the same template again
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: foobar2001
library: "{{ ds_lib.id }}"
name: golden-template
library: "{{ nfs_lib.id }}"
source_vm: "{{ my_vm.id }}"
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
Expand All @@ -122,12 +122,28 @@
that:
- not (_result is changed)

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

- debug:
var: all_content_libraries

- name: Use the name to identify the item
set_fact:
my_template_item: "{{ lib_items.value | selectattr('name', 'equalto', 'golden-template')|first }}"

- assert:
that:
- mylib_item.id == my_template_item.id


- name: Deploy a new VM based on the template
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
name: foobar2002
library: "{{ ds_lib.id }}"
template_library_item: "{{ mylib_item.id }}"
name: vm-from-template
library: "{{ nfs_lib.id }}"
template_library_item: "{{ my_template_item.id }}"
placement:
cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
folder: "{{ lookup('vmware.vmware_rest.folder_moid', '/my_dc/vm') }}"
Expand Down
12 changes: 10 additions & 2 deletions tests/integration/targets/vcenter_vm_cloning/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,16 @@
state: start
vm: '{{ my_vm.id }}'

- pause:
seconds: 30

- name: Wait until my VM is ready
vmware.vmware_rest.vcenter_vm_tools_info:
vm: '{{ my_vm.id }}'
register: vm_tools_info
until:
- vm_tools_info is not failed
- vm_tools_info.value.run_state == "RUNNING"
retries: 10
delay: 5

- name: Create an instant clone of a VM
vmware.vmware_rest.vcenter_vm:
Expand Down

0 comments on commit d44f958

Please sign in to comment.