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

fix issue 397: move check_vm_settings.yml to be executed after revert… #466

Merged
merged 6 commits into from
May 25, 2023
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
6 changes: 3 additions & 3 deletions common/vm_cleanup_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@
- include_tasks: vm_revert_snapshot.yml
vars:
snapshot_name: "{{ revert_to_snapshot_name }}"
when:
- revert_to_snapshot_name
- current_snapshot_name != revert_to_snapshot_name
when: revert_to_snapshot_name

- name: Delete all existing snapshots
include_tasks: vm_remove_snapshot.yml
vars:
snapshot_remove_state: 'remove_all'
snapshot_name: ''
when: cleanup_old_snapshots | bool
when: snapshots_num | int != 0
102 changes: 58 additions & 44 deletions env_setup/env_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@
hosts: localhost
gather_facts: false
tasks:
- include_tasks: get_ansible_info.yml
- include_tasks: set_default_variables.yml
- name: "Get ansible info"
include_tasks: get_ansible_info.yml

# Create this test run log files path
- include_tasks: create_local_log_path.yml
- name: "Set default variables"
include_tasks: set_default_variables.yml

# Check and initialize variables for VM settings
- include_tasks: check_testing_vars.yml
- name: "Create this test run log files path"
include_tasks: create_local_log_path.yml

# Set hostname of Ansible module connecting
- include_tasks: ../common/set_vmware_module_hostname.yml
- name: "Check and initialize variables for VM settings"
include_tasks: check_testing_vars.yml

- name: "Set hostname of Ansible module connecting"
include_tasks: ../common/set_vmware_module_hostname.yml

- name: "Check VM existence"
include_tasks: ../common/vm_check_exist.yml

# Check VM existence
- include_tasks: ../common/vm_check_exist.yml
- name: "Check VM '{{ vm_name }}' does not exist"
ansible.builtin.assert:
that:
Expand All @@ -34,27 +38,20 @@
fail_msg: "VM '{{ vm_name }}' doesn't exist. Please set new_vm to True to deploy the VM or provide an existing VM name."
when: new_vm is undefined or not new_vm | bool

# Get VM related info if testing on existing VM
- include_tasks: ../common/vm_get_vm_info.yml
when: vm_exists is defined and vm_exists
- name: Set fact of the VM datastore path
ansible.builtin.set_fact:
vm_datastore_path: "/vmfs/volumes/{{ datastore }}"
- name: Display the datatore path of VM files
ansible.builtin.debug: var=vm_datastore_path

# Get vCenter and ESXi version info
- include_tasks: ../common/vcenter_get_version_build.yml
- name: "Get vCenter Server version and build"
include_tasks: ../common/vcenter_get_version_build.yml
when: vcenter_is_defined is defined and vcenter_is_defined
- include_tasks: ../common/esxi_get_version_build.yml

- name: "Get ESXi version and build"
include_tasks: ../common/esxi_get_version_build.yml

- name: "ESXi version {{ esxi_version }} is not supported"
ansible.builtin.fail:
msg: "This project only supports guest OS validation on ESXi 6.5 or later"
when: esxi_version == 'N/A' or esxi_version is version('6.5.0', '<')

# Get ESXi server model info
- include_tasks: ../common/esxi_get_model.yml
- name: "Get ESXi server model info"
include_tasks: ../common/esxi_get_model.yml

- name: "Set ESXi server default shell to /bin/sh on {{ esxi_version }}"
ansible.builtin.set_fact:
Expand All @@ -67,8 +64,41 @@
esxi_shell: "/bin/supershell"
when: esxi_version is version('8.0.0', '>=')

# Add esxi host into memory inventory
- include_tasks: ../common/add_host_in_memory_inventory.yml
- name: "Cleanup snapshots and get VM related information"
block:
- name: "Not cleanup old snapshot by default"
ansible.builtin.set_fact:
cleanup_old_snapshots: false
when: cleanup_old_snapshots is undefined

- name: "Revert and cleanup existing snapshots on existing VM if required"
include_tasks: ../common/vm_cleanup_snapshot.yml

- name: "Get VM power state"
include_tasks: ../common/vm_get_power_state.yml

- name: "Power on VM"
include_tasks: ../common/vm_set_power_state.yml
vars:
vm_power_state_set: "powered-on"
when: vm_power_state_get == "poweredOff"
keirazhang marked this conversation as resolved.
Show resolved Hide resolved

- name: "Check VM settings"
include_tasks: check_vm_settings.yml

- name: "Get existing VM info"
include_tasks: ../common/vm_get_vm_info.yml
when: vm_exists is defined and vm_exists

- name: Set fact of the VM datastore path
ansible.builtin.set_fact:
vm_datastore_path: "/vmfs/volumes/{{ datastore }}"

- name: Display the datatore path of VM files
ansible.builtin.debug: var=vm_datastore_path

- name: "Add esxi host into memory inventory"
include_tasks: ../common/add_host_in_memory_inventory.yml
vars:
add_host_in_memory_inventory_ip: "{{ esxi_hostname }}"
add_host_in_memory_inventory_gp: "esxi"
Expand All @@ -79,21 +109,5 @@
add_host_in_memory_inventory_remote_tmp: "{{ vm_datastore_path }}"
add_host_in_memory_inventory_shell: "{{ esxi_shell }}"

# Enable guest IP hack on ESXi host to get VM IP address when
# there is no VMware tools installed or VMware tools is not up
- include_tasks: ../common/esxi_enable_guest_ip_hack.yml

# For existing VM
- block:
- name: "Not cleanup old snapshot by default"
ansible.builtin.set_fact:
cleanup_old_snapshots: false
when: cleanup_old_snapshots is undefined

# Cleanup existing snapshots of existing VM if required
- include_tasks: ../common/vm_cleanup_snapshot.yml
when: cleanup_old_snapshots | bool

# Check VM settings
- include_tasks: check_vm_settings.yml
when: (new_vm is undefined) or (not new_vm | bool)
- name: "Enable guest IP hack on ESXi host to get VM IP address when there is no VMware tools installed or VMware tools is not up"
include_tasks: ../common/esxi_enable_guest_ip_hack.yml
4 changes: 2 additions & 2 deletions vars/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
# Default value is false.
#
# cleanup_old_snapshots: false
# revert_to_snapshot: ''
revert_to_snapshot: 'BaseSnapshot'

# If set to true, a snapshot will be taken when test case failed,
# if set to false, then will not take a test case failure state snapshot of VM.
Expand All @@ -52,7 +52,7 @@
# and will be reverted to at the setup stage of each test case.
# Default value is 'BaseSnapshot'.
#
# base_snapshot_name: "BaseSnapshot"
base_snapshot_name: "BaseSnapshot"

# The path to contain testing result file, log file and file collected in test case.
# If not set, the default path is "logs/vm_name/date_timestamp/"
Expand Down