-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modify provision_vm_test to fit eco CI
- Loading branch information
1 parent
9bf53a7
commit 699d8bd
Showing
10 changed files
with
379 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
#!/usr/bin/env bash | ||
source ../init.sh | ||
exec ansible-playbook run.yml | ||
|
||
# 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 |
23 changes: 23 additions & 0 deletions
23
tests/integration/targets/provision_vm_test/tasks/cleanup_vms.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
14 changes: 14 additions & 0 deletions
14
tests/integration/targets/provision_vm_test/tasks/get_vm_info.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
52 changes: 33 additions & 19 deletions
52
tests/integration/targets/provision_vm_test/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
--- | ||
- name: Provision VM | ||
- name: Provision VM for simulator | ||
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" | ||
when: "'integration-ci' in ansible_run_tags" | ||
|
||
- name: Perform VM Lifecycle Operations in vCenter Environment | ||
block: | ||
- name: Provision multiple VMs | ||
loop: "{{ provision_vms }}" | ||
ansible.builtin.include_tasks: provision_multiple_vms.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_multiple_vms.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 | ||
when: "'eco-vcenter-ci' in ansible_run_tags" |
17 changes: 17 additions & 0 deletions
17
tests/integration/targets/provision_vm_test/tasks/provision_multiple_vms.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
- 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) }}" |
79 changes: 79 additions & 0 deletions
79
tests/integration/targets/provision_vm_test/tasks/update_vm.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
- 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 the name of an existing VM with UUID {{ vm_uuid }} | ||
loop: "{{ vm_names_to_update }}" | ||
ansible.builtin.include_role: | ||
name: cloud.vmware_ops.provision_vm | ||
vars: | ||
provision_vm_uuid: "{{ vm_uuid }}" | ||
provision_vm_name: "{{ item }}" | ||
|
||
- name: "Update the state of an existing VM to: {{ vm_update_name }}" | ||
loop: "{{ vm_states }}" | ||
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: 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Oops, something went wrong.