Skip to content

Commit aa763a4

Browse files
authored
Fix #397 move check_vm_settings.yml to be executed after revert base snapshot (#466)
Signed-off-by: ZouYuhua <[email protected]>
1 parent c4c5fc4 commit aa763a4

File tree

3 files changed

+63
-49
lines changed

3 files changed

+63
-49
lines changed

common/vm_cleanup_snapshot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
- include_tasks: vm_revert_snapshot.yml
5252
vars:
5353
snapshot_name: "{{ revert_to_snapshot_name }}"
54-
when:
55-
- revert_to_snapshot_name
56-
- current_snapshot_name != revert_to_snapshot_name
54+
when: revert_to_snapshot_name
55+
5756
- name: Delete all existing snapshots
5857
include_tasks: vm_remove_snapshot.yml
5958
vars:
6059
snapshot_remove_state: 'remove_all'
6160
snapshot_name: ''
61+
when: cleanup_old_snapshots | bool
6262
when: snapshots_num | int != 0

env_setup/env_setup.yml

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,24 @@
66
hosts: localhost
77
gather_facts: false
88
tasks:
9-
- include_tasks: get_ansible_info.yml
10-
- include_tasks: set_default_variables.yml
9+
- name: "Get ansible info"
10+
include_tasks: get_ansible_info.yml
1111

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

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

18-
# Set hostname of Ansible module connecting
19-
- include_tasks: ../common/set_vmware_module_hostname.yml
18+
- name: "Check and initialize variables for VM settings"
19+
include_tasks: check_testing_vars.yml
20+
21+
- name: "Set hostname of Ansible module connecting"
22+
include_tasks: ../common/set_vmware_module_hostname.yml
23+
24+
- name: "Check VM existence"
25+
include_tasks: ../common/vm_check_exist.yml
2026

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

37-
# Get VM related info if testing on existing VM
38-
- include_tasks: ../common/vm_get_vm_info.yml
39-
when: vm_exists is defined and vm_exists
40-
- name: Set fact of the VM datastore path
41-
ansible.builtin.set_fact:
42-
vm_datastore_path: "/vmfs/volumes/{{ datastore }}"
43-
- name: Display the datatore path of VM files
44-
ansible.builtin.debug: var=vm_datastore_path
45-
46-
# Get vCenter and ESXi version info
47-
- include_tasks: ../common/vcenter_get_version_build.yml
41+
- name: "Get vCenter Server version and build"
42+
include_tasks: ../common/vcenter_get_version_build.yml
4843
when: vcenter_is_defined is defined and vcenter_is_defined
49-
- include_tasks: ../common/esxi_get_version_build.yml
44+
45+
- name: "Get ESXi version and build"
46+
include_tasks: ../common/esxi_get_version_build.yml
5047

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

56-
# Get ESXi server model info
57-
- include_tasks: ../common/esxi_get_model.yml
53+
- name: "Get ESXi server model info"
54+
include_tasks: ../common/esxi_get_model.yml
5855

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

70-
# Add esxi host into memory inventory
71-
- include_tasks: ../common/add_host_in_memory_inventory.yml
67+
- name: "Cleanup snapshots and get VM related information"
68+
block:
69+
- name: "Not cleanup old snapshot by default"
70+
ansible.builtin.set_fact:
71+
cleanup_old_snapshots: false
72+
when: cleanup_old_snapshots is undefined
73+
74+
- name: "Revert and cleanup existing snapshots on existing VM if required"
75+
include_tasks: ../common/vm_cleanup_snapshot.yml
76+
77+
- name: "Get VM power state"
78+
include_tasks: ../common/vm_get_power_state.yml
79+
80+
- name: "Power on VM"
81+
include_tasks: ../common/vm_set_power_state.yml
82+
vars:
83+
vm_power_state_set: "powered-on"
84+
when: vm_power_state_get == "poweredOff"
85+
86+
- name: "Check VM settings"
87+
include_tasks: check_vm_settings.yml
88+
89+
- name: "Get existing VM info"
90+
include_tasks: ../common/vm_get_vm_info.yml
91+
when: vm_exists is defined and vm_exists
92+
93+
- name: Set fact of the VM datastore path
94+
ansible.builtin.set_fact:
95+
vm_datastore_path: "/vmfs/volumes/{{ datastore }}"
96+
97+
- name: Display the datatore path of VM files
98+
ansible.builtin.debug: var=vm_datastore_path
99+
100+
- name: "Add esxi host into memory inventory"
101+
include_tasks: ../common/add_host_in_memory_inventory.yml
72102
vars:
73103
add_host_in_memory_inventory_ip: "{{ esxi_hostname }}"
74104
add_host_in_memory_inventory_gp: "esxi"
@@ -79,21 +109,5 @@
79109
add_host_in_memory_inventory_remote_tmp: "{{ vm_datastore_path }}"
80110
add_host_in_memory_inventory_shell: "{{ esxi_shell }}"
81111

82-
# Enable guest IP hack on ESXi host to get VM IP address when
83-
# there is no VMware tools installed or VMware tools is not up
84-
- include_tasks: ../common/esxi_enable_guest_ip_hack.yml
85-
86-
# For existing VM
87-
- block:
88-
- name: "Not cleanup old snapshot by default"
89-
ansible.builtin.set_fact:
90-
cleanup_old_snapshots: false
91-
when: cleanup_old_snapshots is undefined
92-
93-
# Cleanup existing snapshots of existing VM if required
94-
- include_tasks: ../common/vm_cleanup_snapshot.yml
95-
when: cleanup_old_snapshots | bool
96-
97-
# Check VM settings
98-
- include_tasks: check_vm_settings.yml
99-
when: (new_vm is undefined) or (not new_vm | bool)
112+
- 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"
113+
include_tasks: ../common/esxi_enable_guest_ip_hack.yml

vars/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# Default value is false.
4141
#
4242
# cleanup_old_snapshots: false
43-
# revert_to_snapshot: ''
43+
revert_to_snapshot: 'BaseSnapshot'
4444

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

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

0 commit comments

Comments
 (0)