Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify provision_vm_test to fit eco vcenter CI #53

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ context/
/tests/output/
/changelogs/.plugin-cache.yaml
execution-environment/context/
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -56,6 +57,9 @@ coverage.xml
.hypothesis/
.pytest_cache/

# Integration tests
tests/integration/integration_config.yml

# Translations
*.mo
*.pot
Expand Down
Binary file added tests/integration/targets/.DS_Store
Binary file not shown.
9 changes: 7 additions & 2 deletions tests/integration/targets/init.sh
Original file line number Diff line number Diff line change
@@ -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]}")")
Expand Down
13 changes: 0 additions & 13 deletions tests/integration/targets/provision_vm_test/run.yml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/integration/targets/provision_vm_test/runme.sh

This file was deleted.

22 changes: 0 additions & 22 deletions tests/integration/targets/provision_vm_test/tasks/main.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions tests/integration/targets/vmware_ops_provision_vm_test/run.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/integration/targets/vmware_ops_provision_vm_test/runme.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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:
shellymiron marked this conversation as resolved.
Show resolved Hide resolved
- 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
Original file line number Diff line number Diff line change
@@ -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 )
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading