From e42e0fb2f1b9a8ae2671d22bdb33e02a419983ce Mon Sep 17 00:00:00 2001 From: smiron Date: Wed, 5 Jun 2024 19:38:05 +0300 Subject: [PATCH] modify provision_vm_test to fit eco CI --- .gitignore | 4 + tests/integration/targets/.DS_Store | Bin 0 -> 8196 bytes tests/integration/targets/init.sh | 9 +- .../targets/provision_vm_test/run.yml | 13 -- .../targets/provision_vm_test/runme.sh | 3 - .../targets/provision_vm_test/tasks/main.yml | 22 --- .../mock.json | 0 .../run.yml | 2 +- .../runme.sh | 0 .../tasks/main.yml | 0 .../vars.yml | 0 .../vars/main.yml | 0 .../vmware_ops_provision_vm_test/run.yml | 27 +++ .../vmware_ops_provision_vm_test/runme.sh | 14 ++ .../tasks/cleanup_vms.yml | 23 +++ .../tasks/get_vm_info.yml | 14 ++ .../tasks/main.yml | 47 +++++ .../tasks/post_update_settings_validation.yml | 68 ++++++++ .../tasks/provision_vms_with_validation.yml | 46 +++++ .../tasks/update_name_with_validation.yml | 25 +++ .../tasks/update_state_with_validation.yml | 19 ++ .../tasks/update_vm.yml | 80 +++++++++ .../vmware_ops_provision_vm_test/vars.yml | 17 ++ .../vars/main.yml | 163 ++++++++++++++++++ 24 files changed, 555 insertions(+), 41 deletions(-) create mode 100644 tests/integration/targets/.DS_Store delete mode 100644 tests/integration/targets/provision_vm_test/run.yml delete mode 100755 tests/integration/targets/provision_vm_test/runme.sh delete mode 100644 tests/integration/targets/provision_vm_test/tasks/main.yml rename tests/integration/targets/{info_test => vmware_ops_info_test}/mock.json (100%) rename tests/integration/targets/{info_test => vmware_ops_info_test}/run.yml (95%) rename tests/integration/targets/{info_test => vmware_ops_info_test}/runme.sh (100%) rename tests/integration/targets/{info_test => vmware_ops_info_test}/tasks/main.yml (100%) rename tests/integration/targets/{info_test => vmware_ops_info_test}/vars.yml (100%) rename tests/integration/targets/{info_test => vmware_ops_info_test}/vars/main.yml (100%) create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/run.yml create mode 100755 tests/integration/targets/vmware_ops_provision_vm_test/runme.sh create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/cleanup_vms.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/get_vm_info.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/main.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/post_update_settings_validation.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/provision_vms_with_validation.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_name_with_validation.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_state_with_validation.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_vm.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/vars.yml create mode 100644 tests/integration/targets/vmware_ops_provision_vm_test/vars/main.yml diff --git a/.gitignore b/.gitignore index 75e3c055..8376e2be 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ context/ /tests/output/ /changelogs/.plugin-cache.yaml execution-environment/context/ +.DS_Store # Byte-compiled / optimized / DLL files __pycache__/ @@ -56,6 +57,9 @@ coverage.xml .hypothesis/ .pytest_cache/ +# Integration tests +tests/integration/integration_config.yml + # Translations *.mo *.pot diff --git a/tests/integration/targets/.DS_Store b/tests/integration/targets/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1260aaf11b11e79e611337dbe8db7e30fa46ee05 GIT binary patch literal 8196 zcmeHMO>Yx15FMw5wiM_Vnvw#Ch+dG8P?5MILMVa?p(2V<%h$3=+;m}MN4wikaR^s# z+_-Q>;?9j5C;kNDC%_*-@W$Rk(j}r?5U93f&#divwx4Ic8Hb2Ob+vJhs6<4=$Sl24 z6u(H^&N-I~S zk^w#+%E&A$ne13;jt&$i1b`ewwMozs2N;`jCM%ijSZPdwX`=^`nTjmL5Y`;+W$q4H z$z;b$Yfi$NlgLIES%f0Y=&&oB?j$N!y3#S=7|1igv3rr~6wxZ8_U`yS#ZyR%nyB|p z3)<%*U9UyD1}lEio*_T|W)ieNLJI3^ZHpw{*V<8-q%$+0JWmt`2KVhB8Xh??dhpQU zF>n0H(ea7#VzD@RtXP^Vo$$S*wV?i_8S7QmxU3@`SEE&VuNjApg?3O6RdX?w8|gy0 zC4KM6j;^<4nOUZlQ0dnTDqUC z==Hf&w&v8b#)xa7T%T`qQ*uYf31rS@@j(>SWHhg;I!$$JDTw1hHDz^^doo&GtDCW8 zq{R?AuVwn;7eg>jSFUd>r>)}Av{mp+Zem-@q!_uaw2~v!m9S&0hUpAlq8oIFp3oM( zpjY&U-q8p8NT2De7!p(BlsF^KiwokSxF+VrU2#u55`i@?WQQ-E%6W-0mHZ->$;Tu31i+@ieVr zZ3(glJ3gM6A@$?k?aNOO)`>n?A=aPbEC_HSWGrB$KJP!TtOvD(dGW5bnRCo9H9N<< z7~mX{*j+o*K6uRV!0WCRPXK2Vnb*_;7T+uG;#}f+_28V$vBa}uTp#Q)j|#|jJa4o5 zOBQ)Y2H$qg&jW6Y*0DO?c^}q_mVwu2eLSxoFD>n`XD`g}FR#4se0tUic$XXlyJTR% z_A7Dxf2IHZ|1Qy7H^+cu;D2O549+ghRx$JKpLaVK!LfE3`4KWF?$@!>n4mD>IHU>3 kA%FZ~2)&H1Y*Wc($4b;7{q>6g`wyl2{u}mPu~!-R4$C&iH~;_u literal 0 HcmV?d00001 diff --git a/tests/integration/targets/init.sh b/tests/integration/targets/init.sh index 2cefa174..492fce9b 100644 --- a/tests/integration/targets/init.sh +++ b/tests/integration/targets/init.sh @@ -1,8 +1,13 @@ #!/usr/bin/env bash # shellcheck disable=SC2155,SC2086 -# Export the collections path -export ANSIBLE_COLLECTIONS_PATH="$ANSIBLE_COLLECTIONS_PATH/ansible_collections" +export DEFAULT_COLLECTIONS_PATH="$ANSIBLE_COLLECTIONS_PATH/ansible_collections" + +# Check if the variable is already set (e.g., in CI) +if [ -z "$ANSIBLE_COLLECTIONS_PATH" ]; then + # If not, use base collections path + ANSIBLE_COLLECTIONS_PATH="$DEFAULT_COLLECTIONS_PATH" +fi echo "ANSIBLE_COLLECTIONS_PATH: $ANSIBLE_COLLECTIONS_PATH" BASE_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") diff --git a/tests/integration/targets/provision_vm_test/run.yml b/tests/integration/targets/provision_vm_test/run.yml deleted file mode 100644 index 69481b4a..00000000 --- a/tests/integration/targets/provision_vm_test/run.yml +++ /dev/null @@ -1,13 +0,0 @@ -- hosts: localhost - gather_facts: no - collections: - - community.general - - tasks: - - name: Vcsim - ansible.builtin.import_role: - name: prepare_soap - - - name: Import provision VM role - ansible.builtin.import_role: - name: provision_vm_test diff --git a/tests/integration/targets/provision_vm_test/runme.sh b/tests/integration/targets/provision_vm_test/runme.sh deleted file mode 100755 index a4c36631..00000000 --- a/tests/integration/targets/provision_vm_test/runme.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -source ../init.sh -exec ansible-playbook run.yml diff --git a/tests/integration/targets/provision_vm_test/tasks/main.yml b/tests/integration/targets/provision_vm_test/tasks/main.yml deleted file mode 100644 index 47be9ce2..00000000 --- a/tests/integration/targets/provision_vm_test/tasks/main.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: Provision VM - ansible.builtin.import_role: - name: cloud.vmware_ops.provision_vm - vars: - provision_vm_hostname: "127.0.0.1" - provision_vm_username: "test" - provision_vm_password: "test" - provision_vm_validate_certs: false - provision_vm_cluster: "DC0_C0" - provision_vm_folder: "/DC0/vm" - provision_vm_datacenter: "DC0" - provision_vm_name: "vm-test" - provision_vm_port: "8989" - provision_vm_disk: - - size_gb: 10 - type: thin - datastore: "LocalDS_0" - provision_vm_hardware: - memory_mb: 512 - num_cpus: 4 - provision_vm_guest_id: "centos64Guest" diff --git a/tests/integration/targets/info_test/mock.json b/tests/integration/targets/vmware_ops_info_test/mock.json similarity index 100% rename from tests/integration/targets/info_test/mock.json rename to tests/integration/targets/vmware_ops_info_test/mock.json diff --git a/tests/integration/targets/info_test/run.yml b/tests/integration/targets/vmware_ops_info_test/run.yml similarity index 95% rename from tests/integration/targets/info_test/run.yml rename to tests/integration/targets/vmware_ops_info_test/run.yml index a3e81541..52fbbeef 100644 --- a/tests/integration/targets/info_test/run.yml +++ b/tests/integration/targets/vmware_ops_info_test/run.yml @@ -28,7 +28,7 @@ - name: Import info role ansible.builtin.import_role: - name: info_test + name: vmware_ops_info_test tags: - eco-vcenter-ci - integration-ci diff --git a/tests/integration/targets/info_test/runme.sh b/tests/integration/targets/vmware_ops_info_test/runme.sh similarity index 100% rename from tests/integration/targets/info_test/runme.sh rename to tests/integration/targets/vmware_ops_info_test/runme.sh diff --git a/tests/integration/targets/info_test/tasks/main.yml b/tests/integration/targets/vmware_ops_info_test/tasks/main.yml similarity index 100% rename from tests/integration/targets/info_test/tasks/main.yml rename to tests/integration/targets/vmware_ops_info_test/tasks/main.yml diff --git a/tests/integration/targets/info_test/vars.yml b/tests/integration/targets/vmware_ops_info_test/vars.yml similarity index 100% rename from tests/integration/targets/info_test/vars.yml rename to tests/integration/targets/vmware_ops_info_test/vars.yml diff --git a/tests/integration/targets/info_test/vars/main.yml b/tests/integration/targets/vmware_ops_info_test/vars/main.yml similarity index 100% rename from tests/integration/targets/info_test/vars/main.yml rename to tests/integration/targets/vmware_ops_info_test/vars/main.yml diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/run.yml b/tests/integration/targets/vmware_ops_provision_vm_test/run.yml new file mode 100644 index 00000000..6164f3f0 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/run.yml @@ -0,0 +1,27 @@ +- hosts: localhost + gather_facts: no + collections: + - community.general + + tasks: + - name: Import eco-vcenter credentials + ansible.builtin.include_vars: + file: ../../integration_config.yml + tags: eco-vcenter-ci + + - name: Import simulator vars + ansible.builtin.include_vars: + file: vars.yml + tags: integration-ci + + - name: Vcsim + ansible.builtin.import_role: + name: prepare_soap + tags: integration-ci + + - name: Import provision VM role + ansible.builtin.include_role: + name: vmware_ops_provision_vm_test + tags: + - eco-vcenter-ci + - integration-ci diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/runme.sh b/tests/integration/targets/vmware_ops_provision_vm_test/runme.sh new file mode 100755 index 00000000..a3298746 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/runme.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +source ../init.sh + +# Extract the ansible_tags from integration_config.yml +ANSIBLE_TAGS=$(awk '/ansible_tags/ {print $2}' ../../integration_config.yml) + +# Check if the ANSIBLE_TAGS variable is set +if [[ -n "$ANSIBLE_TAGS" ]]; then + echo "ANSIBLE_TAGS is set to: $ANSIBLE_TAGS" + exec ansible-playbook run.yml --tags "$ANSIBLE_TAGS" +else + echo "ANSIBLE_TAGS is not set for Eco vCenter. Running on simulator." + exec ansible-playbook run.yml --tags integration-ci +fi diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/cleanup_vms.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/cleanup_vms.yml new file mode 100644 index 00000000..9424b9b6 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/cleanup_vms.yml @@ -0,0 +1,23 @@ +--- +- name: Deprovision VM {{ item.provision_vm_name }} + ansible.builtin.include_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ item.provision_vm_name }}" + provision_vm_state: "absent" + provision_vm_force: true + +- name: "Check that the following VM does not exist: {{ item.provision_vm_name }}" + community.vmware.vmware_vm_info: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + vm_name: "{{ item.provision_vm_name }}" + register: vm_info + ignore_errors: true + +- name: "Fail the task if the following VM exists: {{ item.provision_vm_name }}" + ansible.builtin.fail: + msg: "Provisioned VM {{ item.provision_vm_name }} still exists" + when: not vm_info.failed \ No newline at end of file diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/get_vm_info.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/get_vm_info.yml new file mode 100644 index 00000000..ae48d6c5 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/get_vm_info.yml @@ -0,0 +1,14 @@ +--- +- name: "Check VM existence: {{ vm_name }}" + community.vmware.vmware_vm_info: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + vm_name: "{{ vm_name }}" + register: vm_info + +- name: Fail the task if the VM doesn't exist + ansible.builtin.fail: + msg: "Provisioned VM does not exist" + when: vm_info is not defined or vm_info.failed diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/main.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/main.yml new file mode 100644 index 00000000..4f0638ae --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/main.yml @@ -0,0 +1,47 @@ +--- +- name: Provision VM for simulator + ansible.builtin.import_role: + name: cloud.vmware_ops.provision_vm + tags: integration-ci + +- name: Perform VM Lifecycle Operations in vCenter Environment + block: + - name: Provision multiple VMs + loop: "{{ provision_vms }}" + ansible.builtin.include_tasks: provision_vms_with_validation.yml + + - name: Turn one of the provisioned VMs into template + loop: "{{ provision_vms_template }}" + community.vmware.vmware_guest: + hostname: "{{ provision_vm_hostname }}" + username: "{{ provision_vm_username }}" + password: "{{ provision_vm_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + name: "{{ item.provision_vm_name }}" + is_template: true + folder: "{{ provision_vm_folder }}" + datacenter: "{{ provision_vm_datacenter }}" + + - name: Create a VM from the template + loop: "{{ provision_vms_from_template }}" + ansible.builtin.include_tasks: provision_vms_with_validation.yml + + - name: Update one the provisioned VMs + ansible.builtin.include_tasks: update_vm.yml + + always: + - name: Cleanup VMs and template from the vcenter env + loop: "{{ provision_vms + provision_vms_template + provision_vms_from_template }}" + ansible.builtin.include_tasks: cleanup_vms.yml + + - name: Cleanup Network + community.vmware.vmware_portgroup: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + cluster_name: "{{ provision_vm_cluster }}" + switch: "{{ vswitch_name }}" + portgroup: "{{ portgroup_name }}" + state: absent + tags: eco-vcenter-ci diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/post_update_settings_validation.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/post_update_settings_validation.yml new file mode 100644 index 00000000..50f90ce7 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/post_update_settings_validation.yml @@ -0,0 +1,68 @@ +--- +- name: Get info about the updated VM + ansible.builtin.include_tasks: + file: get_vm_info.yml + vars: + vm_name: "{{ vm_update_name }}" + +- name: "Get network info about '{{ vm_update_name }}' VM" + community.vmware.vmware_guest_network: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + uuid: "{{ vm_uuid }}" + gather_network_info: true + register: vm_network_info + +- name: "Print vm_network_info for '{{ vm_update_name }}'" + ansible.builtin.debug: + var: vm_network_info + +- name: "Validate updated network configuration of '{{ vm_update_name }}' VM" + ansible.builtin.assert: + that: + - vm_network_info.network_info[index].name == network.name + - vm_network_info.network_info[index].device_type == network.device_type + - vm_network_info.network_info[index].mac_address == network.mac + loop: "{{ vm_updated_networks }}" + loop_control: + loop_var: network + index_var: index + +- name: Retrieve the CPU information from the VM + vmware.vmware_rest.vcenter_vm_hardware_cpu_info: + vcenter_hostname: "{{ vcenter_hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_validate_certs: "{{ provision_vm_validate_certs }}" + vm: "{{ vm_moid }}" + register: cpu_info + +- name: Retrieve the memory information from the VM + vmware.vmware_rest.vcenter_vm_hardware_memory_info: + vcenter_hostname: "{{ vcenter_hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_validate_certs: "{{ provision_vm_validate_certs }}" + vm: "{{ vm_moid }}" + register: memory_info + +- name: Retrieve disk information using the disk label + vmware.vmware_rest.vcenter_vm_hardware_disk_info: + vcenter_hostname: "{{ vcenter_hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_validate_certs: "{{ provision_vm_validate_certs }}" + vm: "{{ vm_moid }}" + label: Hard disk 1 + register: disk_info + +- name: "Validate updated configuration of '{{ vm_update_name }}' VM" + ansible.builtin.assert: + that: + - vm_info.virtual_machines[0].guest_fullname == guest_fullnames[vm_updated_guest_id] + - cpu_info.value.count == vm_updated_hardware.num_cpus + - cpu_info.value.cores_per_socket == vm_updated_hardware.num_cpu_cores_per_socket + - memory_info.value.size_MiB == vm_updated_hardware.memory_mb + - disk_info.value.capacity == gib_to_bytes * ( vm_enlarge_disk[0].size_gb | int ) diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/provision_vms_with_validation.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/provision_vms_with_validation.yml new file mode 100644 index 00000000..0f653553 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/provision_vms_with_validation.yml @@ -0,0 +1,46 @@ +--- +- name: Run Provision VM Role + ansible.builtin.include_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ item.provision_vm_name }}" + provision_vm_state: "{{ item.provision_vm_state | default(omit) }}" + provision_vm_cdrom: "{{ item.provision_vm_cdrom | default(omit) }}" + provision_vm_networks: "{{ item.provision_vm_networks | default(omit) }}" + provision_vm_esxi_hostname: "{{ item.provision_vm_esxi_hostname | default(omit) }}" + provision_vm_resource_pool: "{{ item.provision_vm_resource_pool | default(omit) }}" + provision_vm_port: "{{ item.provision_vm_port | default(omit) }}" + provision_vm_disk: "{{ item.provision_vm_disk | default(omit) }}" + provision_vm_hardware: "{{ item.provision_vm_hardware | default(omit) }}" + provision_vm_guest_id: "{{ item.provision_vm_guest_id | default(omit) }}" + provision_vm_datastore: "{{ item.provision_vm_datastore | default(omit) }}" + provision_vm_template: "{{ item.provision_vm_template | default(omit) }}" + +- name: Run post validations for VMs creation + block: + - name: Get info about the VM + ansible.builtin.include_tasks: + file: get_vm_info.yml + vars: + vm_name: "{{ item.provision_vm_name }}" + + - name: "Validate the properties of the following VM: {{ item.provision_vm_name }}" + ansible.builtin.assert: + that: + - vm_info.virtual_machines[0].guest_name == item.provision_vm_name + - vm_info.virtual_machines[0].cluster == provision_vm_cluster + - vm_info.virtual_machines[0].datacenter == provision_vm_datacenter + - vm_info.virtual_machines[0].folder == provision_vm_folder + - vm_info.virtual_machines[0].power_state | lower == item.provision_vm_state + + - name: "Validate the following VM datastore when datastore was defined in provision_vm_datastore: {{ item.provision_vm_name }}" + ansible.builtin.assert: + that: + - vm_info.virtual_machines[0].datastore_url[0].name == item.provision_vm_datastore + when: "'provision_vm_datastore' in item" + + - name: "Validate the following VM datastore when datastore was defined in provision_vm_disk: {{ item.provision_vm_name }}" + ansible.builtin.assert: + that: + - vm_info.virtual_machines[0].datastore_url[0].name == item.provision_vm_disk[0].datastore + when: "'provision_vm_datastore' not in item" diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_name_with_validation.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_name_with_validation.yml new file mode 100644 index 00000000..d10584ec --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_name_with_validation.yml @@ -0,0 +1,25 @@ +--- +- name: Update the name of an existing VM with UUID {{ vm_uuid }} + ansible.builtin.include_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_uuid: "{{ vm_uuid }}" + provision_vm_name: "{{ item }}" + +- name: Collect information about VM with ID {{ vm_moid }} + vmware.vmware_rest.vcenter_vm_info: + vcenter_hostname: "{{ vcenter_hostname }}" + vcenter_username: "{{ vcenter_username }}" + vcenter_password: "{{ vcenter_password }}" + vcenter_validate_certs: "{{ provision_vm_validate_certs }}" + vm: '{{ vm_moid }}' + register: vm_info_updated_name + +- name: Print vm_info_updated_name for {{ vm_moid }} + ansible.builtin.debug: + var: vm_info_updated_name + +- name: Validate name of VM with ID {{ vm_moid }} + ansible.builtin.assert: + that: + - vm_info_updated_name.value.name == vm_name diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_state_with_validation.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_state_with_validation.yml new file mode 100644 index 00000000..01446c33 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_state_with_validation.yml @@ -0,0 +1,19 @@ +--- +- name: "Update the state of the VM to: {{ vm_update_name }}" + ansible.builtin.include_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ vm_update_name }}" + provision_vm_state: "{{ item }}" + provision_vm_force: true + +- name: Get info about the updated VM + ansible.builtin.include_tasks: + file: get_vm_info.yml + vars: + vm_name: "{{ vm_update_name }}" + +- name: "Validate that VM is in state {{ vm_state }}" + ansible.builtin.assert: + that: + - vm_info.virtual_machines[0].power_state | lower == vm_state diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_vm.yml b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_vm.yml new file mode 100644 index 00000000..b5b83ef3 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/tasks/update_vm.yml @@ -0,0 +1,80 @@ +- name: Get info about the VM to be updated + ansible.builtin.include_tasks: + file: get_vm_info.yml + vars: + vm_name: "{{ vm_update_name }}" + +- name: Set vm_uuid variable + ansible.builtin.set_fact: + vm_uuid: "{{ vm_info.virtual_machines[0].uuid }}" + +- name: Set vm_moid variable + ansible.builtin.set_fact: + vm_moid: "{{ vm_info.virtual_machines[0].moid }}" + +- name: Update existing VM's name and verify the name updated correctly + loop: "{{ vm_names_to_update }}" + ansible.builtin.include_tasks: + file: update_name_with_validation.yml + vars: + vm_name: "{{ item }}" + +- name: Update and verify the state of an existing VM + loop: "{{ vm_states }}" + ansible.builtin.include_tasks: + file: update_state_with_validation.yml + vars: + vm_state: "{{ item }}" + +- name: Add port group with network label {{ portgroup_name }} + community.vmware.vmware_portgroup: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: "{{ provision_vm_validate_certs }}" + cluster_name: "{{ provision_vm_cluster }}" + switch: "{{ vswitch_name }}" + portgroup: "{{ portgroup_name }}" + +- name: Update networks of existing VM {{ vm_update_name }} + ansible.builtin.import_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ vm_update_name }}" + provision_vm_networks: "{{ vm_updated_networks }}" + +- name: Update VM hardware properties + ansible.builtin.import_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ vm_update_name }}" + provision_vm_hardware: "{{ vm_updated_hardware }}" + +- name: Enlarge existing disk of existing VM {{ vm_update_name }} + ansible.builtin.import_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ vm_update_name }}" + provision_vm_disk: "{{ vm_enlarge_disk }}" + +- name: Update guest_id of existing VM {{ vm_update_name }} + ansible.builtin.import_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ vm_update_name }}" + provision_vm_guest_id: "{{ vm_updated_guest_id }}" + provision_vm_cdrom: "{{ vm_updated_cdrom }}" + +- name: Power on the updated VM {{ vm_update_name }} + loop: + - "poweredon" + ansible.builtin.include_role: + name: cloud.vmware_ops.provision_vm + vars: + provision_vm_name: "{{ vm_update_name }}" + provision_vm_state: "{{ item }}" + provision_vm_force: true + +- name: Verify updated VM settings + ansible.builtin.include_tasks: + file: post_update_settings_validation.yml \ No newline at end of file diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/vars.yml b/tests/integration/targets/vmware_ops_provision_vm_test/vars.yml new file mode 100644 index 00000000..afda0716 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/vars.yml @@ -0,0 +1,17 @@ +provision_vm_hostname: "127.0.0.1" +provision_vm_username: "test" +provision_vm_password: "test" +provision_vm_validate_certs: false +provision_vm_cluster: "DC0_C0" +provision_vm_folder: "/DC0/vm" +provision_vm_datacenter: "DC0" +provision_vm_name: "vm-test" +provision_vm_port: "8989" +provision_vm_disk: +- size_gb: 10 + type: thin + datastore: "LocalDS_0" +provision_vm_hardware: + memory_mb: 512 + num_cpus: 4 +provision_vm_guest_id: "centos64Guest" \ No newline at end of file diff --git a/tests/integration/targets/vmware_ops_provision_vm_test/vars/main.yml b/tests/integration/targets/vmware_ops_provision_vm_test/vars/main.yml new file mode 100644 index 00000000..87df7486 --- /dev/null +++ b/tests/integration/targets/vmware_ops_provision_vm_test/vars/main.yml @@ -0,0 +1,163 @@ +# vars.yaml +provision_vm_hostname: "{{ vcenter_hostname }}" +provision_vm_username: "{{ vcenter_username }}" +provision_vm_password: "{{ vcenter_password }}" +provision_vm_validate_certs: false + +provision_vm_cluster: "Eco-Cluster" +provision_vm_folder: "/Eco-Datacenter/vm/e2e-qe" +provision_vm_datacenter: "Eco-Datacenter" + +# Create VM template +provision_vms_template: + - provision_vm_name: "qe-provision-vm-rhel-9" + provision_vm_state: "poweredoff" + provision_vm_cdrom: + - controller_number: 0 + unit_number: 0 + state: present + type: iso + iso_path: "[datastore1] ISO/rhel-9.3-x86_64-dvd.iso" + provision_vm_networks: + - name: "VM Network" + device_type: "vmxnet3" + mac: "00:50:56:bd:d2:9e" + type: "dhcp" + provision_vm_resource_pool: null + provision_vm_disk: + - size_gb: 50 + type: thin + datastore: "datastore1" + provision_vm_hardware: + memory_mb: 2000 + num_cpus: 4 + boot_firmware: efi + secure_boot: true + provision_vm_guest_id: "rhel9_64Guest" + provision_vm_datastore: "datastore1" + +# Provision VMs from template +provision_vms_from_template: + - provision_vm_name: "qe-provision-vm-from-template" + provision_vm_state: "poweredon" + provision_vm_template: "{{ provision_vms_template[0].provision_vm_name }}" + provision_vm_datastore: "datastore1" + +provision_vms: +# RHEL9 VM + - provision_vm_name: "qe-provision-vm-rhel-9" + provision_vm_state: "poweredoff" + provision_vm_cdrom: + - controller_number: 0 + unit_number: 0 + state: present + type: iso + iso_path: "[datastore1] ISO/rhel-9.3-x86_64-dvd.iso" + provision_vm_networks: + - name: "VM Network" + device_type: "vmxnet3" + mac: "00:50:56:bd:d2:9e" + type: "dhcp" + provision_vm_resource_pool: null + provision_vm_disk: + - size_gb: 50 + type: thin + datastore: "datastore1" + provision_vm_hardware: + memory_mb: 2000 + num_cpus: 4 + boot_firmware: efi + secure_boot: true + provision_vm_guest_id: "rhel9_64Guest" + provision_vm_datastore: "datastore1" +# RHEL8 VM + - provision_vm_name: "qe-provision-vm-rhel-8" + provision_vm_state: "poweredon" + provision_vm_cdrom: + - controller_number: 0 + unit_number: 0 + state: present + type: iso + iso_path: "[datastore1] ISO/rhel-8.9-x86_64-boot.iso" + provision_vm_networks: + - name: "VM Network" + device_type: "vmxnet3" + mac: "00:50:56:bd:d2:9e" + type: "dhcp" + provision_vm_resource_pool: null + provision_vm_disk: + - size_gb: 50 + type: thin + datastore: "datastore1" + provision_vm_hardware: + memory_mb: 2000 + num_cpus: 4 + boot_firmware: efi + secure_boot: true + provision_vm_guest_id: "rhel8_64Guest" + provision_vm_datastore: "datastore1" + +vm_to_update: "{{ provision_vms[0] }}" +vm_update_name: "{{ vm_to_update.provision_vm_name }}" +vm_update_datastore: "{{ vm_to_update.provision_vm_datastore }}" + +vm_names_to_update: + - vm_updated_name + - "{{ vm_update_name }}" + +vm_states: +# - "rebootguest" # error msg: "VMware tools should be installed for guest shutdown/reboot" +# - "shutdownguest" # error msg: "VMware tools should be installed for guest shutdown/reboot" +# - "restarted" # test failing because after restart the status is poweredOn again + - "poweredon" + - "suspended" + - "poweredoff" + +vm_updated_hardware: + memory_mb: 2048 + num_cpus: 6 + num_cpu_cores_per_socket: 2 + boot_firmware: efi + secure_boot: true + +vswitch_name: vSwitch0 +portgroup_name: qe-network + +vm_network_to_add: + - name: "{{ portgroup_name }}" + device_type: "vmxnet3" + mac: "00:50:a6:b5:b2:3c" + type: "dhcp" + +vm_updated_networks: "{{ vm_to_update.provision_vm_networks + vm_network_to_add }}" + +vm_enlarge_disk: + - size_gb: "{{ vm_to_update.provision_vm_disk[0].size_gb + 10 }}" + type: "{{ vm_to_update.provision_vm_disk[0].type }}" + datastore: "{{ vm_to_update.provision_vm_disk[0].datastore }}" + +vm_disk_to_add: + - size_gb: 10 + type: thin + datastore: "datastore1" + +vm_add_disk: "{{ vm_to_update.provision_vm_disk + vm_disk_to_add }}" + +guest_fullnames: + rhel8_64Guest: "Red Hat Enterprise Linux 8 (64-bit)" + rhel9_64Guest: "Red Hat Enterprise Linux 9 (64-bit)" + +vm_updated_guest_id: "rhel8_64Guest" +vm_updated_cdrom: + - controller_number: 0 + unit_number: 0 + state: present + type: iso + iso_path: "[datastore1] ISO/rhel-8.9-x86_64-boot.iso" + +vm_update_os_customization: + existing_vm: true + hostname: my.customized.vm + timezone: Europe/Paris + +gib_to_bytes: 1073741824