Skip to content

Commit

Permalink
Merge pull request #66 from anna-savina/modify_vcenter_host_connectio…
Browse files Browse the repository at this point in the history
…n_test

Modify vcenter_host_connection_test to fit eco vcenter CI
  • Loading branch information
shellymiron authored Jun 27, 2024
2 parents 8f40766 + 1ad5ae8 commit ea57e7a
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 33 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/66_vcenter-host-connection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- vcenter_host_connection_test - modified vcenter_host_connection_test to run on a real vcenter environment
17 changes: 0 additions & 17 deletions tests/integration/targets/vcenter_host_connection_test/run.yml

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- 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: ESXi
ansible.builtin.import_role:
name: prepare_esx
tags: integration-ci

- name: Import vcenter_host_connection_test
ansible.builtin.include_role:
name: vmware_ops_vcenter_host_connection_test
tags:
- eco-vcenter-ci
- integration-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
- name: Test vCenter host connection role on vCenter env
tags: eco-vcenter-ci
block:
- name: Add Resource Pool
ansible.builtin.include_tasks: manage_resource_pool.yml
vars:
required_state: present

- name: Provision ESXI VM and set ESXI hostname
ansible.builtin.include_tasks: provision_esxi.yml

- name: Add ESXI Host to vCenter Cluster
ansible.builtin.import_role:
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: present

- name: Gather ESXI Host facts
community.vmware.vmware_host_facts:
hostname: "{{ vcenter_host_connection_hostname }}"
username: "{{ vcenter_host_connection_username }}"
password: "{{ vcenter_host_connection_password }}"
validate_certs: false
esxi_hostname: "{{ vcenter_host_connection_esxi_hostname }}"
register: _host_facts

- name: Verify ESXI Host connected to vCenter Cluster
ansible.builtin.assert:
that:
- _host_facts.ansible_facts.cluster == cluster_name
- _host_facts.ansible_facts.ansible_host_connection_state == 'connected'

- name: Remove ESXI Host from vCenter Cluster
ansible.builtin.import_role:
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: absent

- name: Ensure ESXI Host removed from vCenter Cluster
block:
- name: Gather ESXI Host facts
community.vmware.vmware_host_facts:
hostname: "{{ vcenter_host_connection_hostname }}"
username: "{{ vcenter_host_connection_username }}"
password: "{{ vcenter_host_connection_password }}"
validate_certs: false
esxi_hostname: "{{ vcenter_host_connection_esxi_hostname }}"
register: _no_host_facts

- name: Force failure if ESXI Host was found
ansible.builtin.fail:
msg: "'{{ vcenter_host_connection_esxi_hostname }}' host exists, collected info is '{{ _no_host_facts }}'"

rescue:
- name: ESXI Host doesn't exist as expected
when: _no_host_facts.msg is contains 'not found'
ansible.builtin.debug:
msg: ESXI Host doesn't exist as expected

always:
- name: Remove ESXI Host from vCenter Cluster to cleanup env
community.vmware.vmware_host:
hostname: "{{ vcenter_host_connection_hostname }}"
username: "{{ vcenter_host_connection_username }}"
password: "{{ vcenter_host_connection_password }}"
datacenter: "{{ vcenter_host_connection_datacenter }}"
cluster: "{{ vcenter_host_connection_cluster }}"
validate_certs: false
esxi_hostname: "{{ vcenter_host_connection_esxi_hostname }}"
esxi_username: "{{ vcenter_host_connection_esxi_username }}"
esxi_password: "{{ vcenter_host_connection_esxi_password }}"
state: absent

- name: Remove ESXI VM to cleanup env
ansible.builtin.include_role:
name: cloud.vmware_ops.provision_vm
vars:
provision_vm_state: absent
provision_vm_force: true

- name: Remove Resource Pool to cleanup env
ansible.builtin.include_tasks: manage_resource_pool.yml
vars:
required_state: absent

- name: Test vCenter host connection role on simulator
tags: integration-ci
block:
- name: Add ESXI Host to vCenter Cluster
ansible.builtin.import_role:
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: present

- name: Remove ESXI Host from vCenter Cluster
ansible.builtin.import_role:
name: cloud.vmware_ops.vcenter_host_connection
vars:
vcenter_host_connection_state: absent
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: Manage resource pool
community.vmware.vmware_resource_pool:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
validate_certs: false
cluster: "{{ provision_virtual_esxi_cluster }}"
resource_pool: "{{ provision_virtual_esxi_resource_pool }}"
state: "{{ required_state }}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
- name: Provision Virtual ESXI
ansible.builtin.import_role:
name: cloud.vmware_ops.provision_virtual_esxi

- name: Wait until ESXI VM is powered off after OS installation
community.vmware.vmware_guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
validate_certs: false
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: _esxi_power_status
until: _esxi_power_status.instance.hw_power_status == 'poweredOff'
retries: 30
delay: 20

- name: Power on ESXI VM after provisioning
ansible.builtin.include_role:
name: cloud.vmware_ops.provision_vm
vars:
provision_vm_state: poweredon

- name: Wait until ESXI VM has an IP address
community.vmware.vmware_guest_info:
hostname: "{{ provision_virtual_esxi_hostname }}"
username: "{{ provision_virtual_esxi_username }}"
password: "{{ provision_virtual_esxi_password }}"
datacenter: "{{ provision_virtual_esxi_datacenter }}"
validate_certs: false
name: "{{ provision_virtual_esxi_vms[0].name }}"
register: esxi_host_info
until: esxi_host_info.instance.ipv4 is defined and esxi_host_info.instance.ipv4 is not none
retries: 30
delay: 10

- name: Check if ESXI is up
wait_for:
host: "{{ esxi_host_info.instance.ipv4 }}"
port: 22
delay: 10
timeout: 300
state: started

- name: Set ESXI hostname
ansible.builtin.set_fact:
vcenter_host_connection_esxi_hostname: "{{ esxi_host_info.instance.ipv4 }}"
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ vcenter_host_connection_datacenter: "DC0"

vcenter_host_connection_esxi_hostname: "127.0.0.1"
vcenter_host_connection_esxi_username: test
vcenter_host_connection_esxi_password: test
vcenter_host_connection_esxi_password: test
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
# General
cluster_name: "Eco-Cluster"
vcenter_datacenter: "Eco-Datacenter"
resource_pool_name: "host-connection-test-pool"
esxi_username: "root"
esxi_password: "!#%135qEt"
network_name: "TestNetwork"

# Vars for cloud.vmware_ops.provision_virtual_esxi role
provision_virtual_esxi_hostname: "{{ vcenter_hostname }}"
provision_virtual_esxi_username: "{{ vcenter_username }}"
provision_virtual_esxi_password: "{{ vcenter_password }}"
provision_virtual_esxi_validate_certs: false
provision_virtual_esxi_port: 443
provision_virtual_esxi_cluster: "{{ cluster_name }}"
provision_virtual_esxi_datacenter: "{{ vcenter_datacenter }}"
provision_virtual_esxi_folder: ""
provision_virtual_esxi_resource_pool: "{{ resource_pool_name }}"
provision_virtual_esxi_datastore_iso_path: "[eco-nfs-datastore-iso] custom_esxi_8.iso"
provision_virtual_esxi_vms:
- name: "vm-host-connection-test"
provision_virtual_esxi_networks:
- name: "{{ network_name }}"
device_type: "vmxnet3"
type: "dhcp"
mac: "00:50:56:8b:ea:f0"
provision_virtual_esxi_disks:
- size_gb: 100
type: thin
datastore: datastore1

# Vars for cloud.vmware_ops.vcenter_host_connection role
vcenter_host_connection_hostname: "{{ vcenter_hostname }}"
vcenter_host_connection_username: "{{ vcenter_username }}"
vcenter_host_connection_password: "{{ vcenter_password }}"
vcenter_host_connection_validate_certs: false
vcenter_host_connection_port: 443
vcenter_host_connection_cluster: "{{ cluster_name }}"
vcenter_host_connection_datacenter: "{{ vcenter_datacenter }}"
vcenter_host_connection_esxi_hostname: ""
vcenter_host_connection_esxi_username: "{{ esxi_username }}"
vcenter_host_connection_esxi_password: "{{ esxi_password }}"

# Var for cloud.vmware_ops.provision_vm role
provision_vm_hostname: "{{ provision_virtual_esxi_hostname }}"
provision_vm_username: "{{ provision_virtual_esxi_username }}"
provision_vm_password: "{{ provision_virtual_esxi_password }}"
provision_vm_validate_certs: false
provision_vm_port: "{{ provision_virtual_esxi_port }}"
provision_vm_cluster: "{{ provision_virtual_esxi_cluster }}"
provision_vm_datacenter: "{{ provision_virtual_esxi_datacenter }}"
provision_vm_name: "{{ provision_virtual_esxi_vms[0].name }}"

0 comments on commit ea57e7a

Please sign in to comment.