forked from redhat-cop/cloud.vmware_ops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d35896
commit 6a05a40
Showing
10 changed files
with
708 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# cloud.vmware_ops Molecule E2E Testing | ||
|
||
This repository contains Molecule test scenarios for the `cloud.vmware_ops` Ansible collection. Each scenario represents a feature in the collection, allowing you to test individual features in isolation. | ||
Feel free to contribute, add new scenarios, or enhance existing ones to ensure comprehensive testing of the Ansible collection. | ||
|
||
## Prerequisites | ||
|
||
Before running Molecule scenarios, ensure that the following tools are installed on your system: | ||
|
||
- [Ansible](https://www.ansible.com/) | ||
- [Python 3](https://www.python.org/) | ||
- [Molecule](https://molecule.readthedocs.io/) | ||
- [ansible-junit](https://github.com/hspaans/ansible-junit) (for JUnit XML output) | ||
- [pyvmomi](https://github.com/vmware/pyvmomi) (required for vSphere testing) | ||
|
||
Additionally, create a password file for the vSphere credentials (vault password file). The password file should contain the vault password for the `vSphere creds` vault. The vault file should include the following variables: | ||
|
||
```yaml | ||
# vault.yml | ||
vault_vsphere_hostname: "your_vsphere_hostname" | ||
vault_vsphere_username: "your_vsphere_username" | ||
vault_vsphere_password: "your_vsphere_password" | ||
|
||
## Creating a New Molecule Scenario | ||
To create a new Molecule scenario, follow these steps: | ||
|
||
1. Create a new directory under tests/e2e/molecule/provision_vm/scenarios/ for your scenario. | ||
2. Define the scenario configuration in the molecule.yml file within the new scenario directory. | ||
3. Create the necessary playbook(s) and test files for your scenario. | ||
4. Run the scenario using molecule test -s <new_scenario_name>. | ||
|
||
## Running Molecule Scenarios | ||
To run a Molecule scenario, use the following command: | ||
molecule test -s <scenario_name> |
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,2 @@ | ||
[defaults] | ||
callback_whitelist = junit |
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,20 @@ | ||
- name: Run all playbooks in the scenarios directory | ||
hosts: localhost | ||
gather_facts: true | ||
|
||
tasks: | ||
- name: Include vSphere datacenter creds | ||
ansible.builtin.include_vars: | ||
file: vault_files/vsphere_creds.yml | ||
|
||
- name: Run provision_vm scenarios | ||
ansible.builtin.find: | ||
paths: "{{ lookup('env', 'MOLECULE_SCENARIO_NAME') }}/scenarios" | ||
recurse: true | ||
patterns: "*.yml" | ||
register: playbook_files | ||
|
||
- name: Include and run each playbook | ||
ansible.builtin.include_tasks: | ||
file: "{{ item.path }}" | ||
with_items: "{{ playbook_files.files }}" |
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,37 @@ | ||
--- | ||
dependency: | ||
name: galaxy | ||
|
||
# driver: | ||
# name: docker | ||
|
||
platforms: | ||
- name: instance | ||
image: geerlingguy/docker-ubuntu2004-ansible:latest | ||
command: /lib/systemd/systemd | ||
privileged: true | ||
volumes: | ||
- /sys/fs/cgroup:/sys/fs/cgroup:ro | ||
ansible_connection: ansible | ||
|
||
provisioner: | ||
name: ansible | ||
lint: | | ||
set -e | ||
echo "Run yamllint" | ||
yamllint . | ||
echo "Run ansible-lint" | ||
ansible-lint | ||
env: | ||
ANSIBLE_ROLES_PATH: "../../../../roles" | ||
config_options: | ||
defaults: | ||
vault_password_file: ${HOME}/vsphere_crds_vault_pass.txt | ||
callback_whitelist: junit | ||
playbooks: | ||
converge: ../converge.yml | ||
|
||
verifier: | ||
name: ansible | ||
options: | ||
junit-xml: ./test-results.xml |
29 changes: 29 additions & 0 deletions
29
tests/e2e/molecule/provision_vm/post_validations/verify_vm_post_provisioning.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,29 @@ | ||
--- | ||
- name: Verify Provisioned VM | ||
ansible.builtin.include_vars: | ||
file: ../vars/vars.yml | ||
|
||
- name: Check VM existence | ||
community.vmware.vmware_vm_info: | ||
hostname: "{{ provision_vm_hostname }}" | ||
username: "{{ provision_vm_username }}" | ||
password: "{{ provision_vm_password }}" | ||
validate_certs: "{{ provision_vm_validate_certs }}" | ||
vm_name: "{{ provision_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 | ||
|
||
- name: Validate VM properties | ||
ansible.builtin.assert: | ||
that: | ||
- vm_info.virtual_machines[0].guest_name == 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 == provision_vm_state | ||
- vm_info.virtual_machines[0].resource_pool == provision_vm_resource_pool | ||
- vm_info.virtual_machines[0].datastore_url[0].name == provision_vm_disk[0].datastore |
13 changes: 13 additions & 0 deletions
13
tests/e2e/molecule/provision_vm/scenarios/basic_provision_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,13 @@ | ||
- name: Basic Provision VM Scenario | ||
block: | ||
- name: Import vars | ||
ansible.builtin.include_vars: | ||
file: ../vars/vars.yml | ||
|
||
- name: Provision a VM | ||
ansible.builtin.import_role: | ||
name: provision_vm | ||
|
||
- name: Verify Provisioned VM | ||
ansible.builtin.include_tasks: | ||
file: ../post_validations/verify_vm_post_provisioning.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,19 @@ | ||
import testinfra | ||
import pytest | ||
|
||
@pytest.fixture | ||
def host(request): | ||
# Create the Testinfra host using the Ansible inventory | ||
print("the host :: ", testinfra.get_host(f'ansible://{request.config.getoption("--ansible-inventory")}')) | ||
return testinfra.get_host(f'ansible://{request.config.getoption("--ansible-inventory")}') | ||
|
||
def test_vm_os(host): | ||
# Use Testinfra to check the properties of the VM | ||
distribution = host.system_info.distribution | ||
release = host.system_info.release | ||
print("release :: ", release) | ||
version = host.system_info.release | ||
|
||
# Assert the expected OS type | ||
assert distribution.lower() == 'linux' | ||
assert version.startswith('7.') # Adjust this based on your expected OS version |
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,40 @@ | ||
# vars.yaml | ||
provision_vm_validate_certs: false | ||
provision_vm_cluster: "nestedcluster" | ||
provision_vm_folder: "/nesteddatacenter/vm" | ||
provision_vm_datacenter: "nesteddatacenter" | ||
provision_vm_name: "smiron-provision-vm-2" | ||
provision_vm_state: "poweredon" | ||
provision_vm_cdrom: | ||
- controller_number: 0 | ||
unit_number: 0 | ||
state: present | ||
type: iso | ||
iso_path: "[Datastore-host1] rhel-9.3-x86_64-dvd.iso" | ||
provision_vm_networks: | ||
- name: "Network1" | ||
device_type: "vmxnet3" | ||
mac: "00:50:56:bd:d2:9e" | ||
type: "dhcp" | ||
# ip: "192.168.168.10" | ||
# netmask: "255.255.255.0" | ||
# gateway: "10.185.246.1" | ||
# provision_vm_esxi_hostname: "10.185.246.5" | ||
# provision_vm_state: | ||
# poweredOff: "poweredoff" | ||
# poweredOn: "poweredon" | ||
# suspended: "suspended" | ||
provision_vm_resource_pool: null | ||
# provision_vm_port: "8989" | ||
provision_vm_disk: | ||
- size_gb: 50 | ||
type: thin | ||
datastore: "Datastore-host1" | ||
provision_vm_hardware: | ||
memory_mb: 2000 | ||
num_cpus: 4 | ||
boot_firmware: efi | ||
secure_boot: true | ||
# provision_vm_guest_id: "rhel9_64Guest" | ||
provision_vm_datastore: "Datastore-host1" | ||
provision_vm_template: "provision-vm-template" |
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 @@ | ||
$ANSIBLE_VAULT;1.1;AES256 | ||
62353361643765386533316139656438306166613765336366376563313666666538663838306336 | ||
3335623861613631303431623730366564663635643863640a396435306332373639326232643531 | ||
63356366366232623830383762653230626139343731366466623262626132623736663732366562 | ||
3237326363346263360a623535353534343365663431616537663634353563383639313334343463 | ||
35353637373237386133633234383939356537316632376139613366376132323436306464313439 | ||
34373939333930353931356432356361376437383338313732663866373663623865613166626632 | ||
36306564336464346164656431363865633465613864373231303538333935356434353966383164 | ||
65663566613333396435363866623066623530306662646162353665613034663434336261313865 | ||
36353738396334633263343766623736343362393765333030386563343563393138363035373135 | ||
31613839636538373339346266333863336139363534393339383361376232303939313036633263 | ||
66396438613030613433376334663637616566326566643162363430326239316334623534316437 | ||
31613962633362383132653166656561366535323236656363333736313536623663386434313234 | ||
30646130353664346530383264323433313666393162373261373465336266623032 |