diff --git a/common/vm_cleanup_snapshot.yml b/common/vm_cleanup_snapshot.yml index 54555008a..e2c23bdce 100644 --- a/common/vm_cleanup_snapshot.yml +++ b/common/vm_cleanup_snapshot.yml @@ -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 diff --git a/env_setup/env_setup.yml b/env_setup/env_setup.yml index 7d30b2a54..51c007cbb 100644 --- a/env_setup/env_setup.yml +++ b/env_setup/env_setup.yml @@ -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: @@ -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: @@ -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" + + - 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" @@ -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 diff --git a/vars/test.yml b/vars/test.yml index b2db81c26..beea814c9 100644 --- a/vars/test.yml +++ b/vars/test.yml @@ -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. @@ -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/"