From 3231255822a664ca159952562996cdef12424c83 Mon Sep 17 00:00:00 2001 From: ZouYuhua Date: Wed, 24 May 2023 14:33:02 +0800 Subject: [PATCH 1/6] fix issue 397: move check_vm_settings.yml to be executed after revert to base snasphot Signed-off-by: ZouYuhua --- common/vm_cleanup_snapshot.yml | 1 + env_setup/env_setup.yml | 14 +++++++++++--- vars/test.yml | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/common/vm_cleanup_snapshot.yml b/common/vm_cleanup_snapshot.yml index 54555008a..eaf9f0e6a 100644 --- a/common/vm_cleanup_snapshot.yml +++ b/common/vm_cleanup_snapshot.yml @@ -59,4 +59,5 @@ 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..24e3e9009 100644 --- a/env_setup/env_setup.yml +++ b/env_setup/env_setup.yml @@ -34,6 +34,9 @@ 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 + # Check VM settings + - include_tasks: check_vm_settings.yml + # 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 @@ -92,8 +95,13 @@ # 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 + - name: "Get VM power state" + include_tasks: ../../common/vm_get_power_state.yml + + - name: "Poweron VM" + include_tasks: ../../common/vm_set_power_state.yml + vars: + vm_power_state_set: "powered-on" + when: vm_power_state_get == "poweredOff" when: (new_vm is undefined) or (not new_vm | bool) 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/" From 9f13f6e5bbc446489c64ffc4516f646c4955e530 Mon Sep 17 00:00:00 2001 From: ZouYuhua Date: Wed, 24 May 2023 15:03:35 +0800 Subject: [PATCH 2/6] change code as codereview Signed-off-by: ZouYuhua --- env_setup/env_setup.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/env_setup/env_setup.yml b/env_setup/env_setup.yml index 24e3e9009..932a65c5d 100644 --- a/env_setup/env_setup.yml +++ b/env_setup/env_setup.yml @@ -34,12 +34,6 @@ 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 - # Check VM settings - - include_tasks: check_vm_settings.yml - - # 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 }}" @@ -104,4 +98,10 @@ vars: vm_power_state_set: "powered-on" when: vm_power_state_get == "poweredOff" + + # Check VM settings + - include_tasks: check_vm_settings.yml + + # Get VM related info if testing on existing VM + - include_tasks: ../common/vm_get_vm_info.yml when: (new_vm is undefined) or (not new_vm | bool) From b30c51c88c477c01dc2ab45e318a6f7ab9f26852 Mon Sep 17 00:00:00 2001 From: ZouYuhua Date: Wed, 24 May 2023 15:11:29 +0800 Subject: [PATCH 3/6] add name for tasks Signed-off-by: ZouYuhua --- env_setup/env_setup.yml | 60 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/env_setup/env_setup.yml b/env_setup/env_setup.yml index 932a65c5d..ac9541074 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: "Get 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: @@ -37,21 +41,24 @@ - 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 and ESXi version info" + 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: @@ -64,8 +71,8 @@ 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: "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" @@ -76,9 +83,8 @@ 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 + - 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 # For existing VM - block: @@ -87,8 +93,8 @@ 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 + - name: "Cleanup existing snapshots of existing VM if required" + include_tasks: ../common/vm_cleanup_snapshot.yml - name: "Get VM power state" include_tasks: ../../common/vm_get_power_state.yml @@ -98,10 +104,10 @@ vars: vm_power_state_set: "powered-on" when: vm_power_state_get == "poweredOff" - - # Check VM settings - - include_tasks: check_vm_settings.yml - # Get VM related info if testing on existing VM - - include_tasks: ../common/vm_get_vm_info.yml + - name: "Check VM settings" + include_tasks: check_vm_settings.yml + + - name: "Get VM related info if testing on existing VM" + include_tasks: ../common/vm_get_vm_info.yml when: (new_vm is undefined) or (not new_vm | bool) From af9beeaa1ef85daee2fa7af05c3981f72a9a3bb2 Mon Sep 17 00:00:00 2001 From: ZouYuhua Date: Wed, 24 May 2023 15:32:39 +0800 Subject: [PATCH 4/6] change code as codereview Signed-off-by: ZouYuhua --- env_setup/env_setup.yml | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/env_setup/env_setup.yml b/env_setup/env_setup.yml index ac9541074..fdce67b1c 100644 --- a/env_setup/env_setup.yml +++ b/env_setup/env_setup.yml @@ -38,13 +38,6 @@ 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 - - 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: "Get vCenter and ESXi version info" include_tasks: ../common/vcenter_get_version_build.yml when: vcenter_is_defined is defined and vcenter_is_defined @@ -71,23 +64,8 @@ esxi_shell: "/bin/supershell" when: esxi_version is version('8.0.0', '>=') - - 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" - add_host_in_memory_inventory_user: "{{ esxi_username }}" - add_host_in_memory_inventory_pwd: "{{ esxi_password }}" - add_host_in_memory_inventory_python: "/bin/python" - add_host_in_memory_inventory_ssh_pipeline: true - add_host_in_memory_inventory_remote_tmp: "{{ vm_datastore_path }}" - add_host_in_memory_inventory_shell: "{{ esxi_shell }}" - - - 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 - - # For existing VM - - block: + - name: "Cleanup snapshots and get VM related information" + block: - name: "Not cleanup old snapshot by default" ansible.builtin.set_fact: cleanup_old_snapshots: false @@ -109,5 +87,27 @@ include_tasks: check_vm_settings.yml - name: "Get VM related info if testing on existing VM" - include_tasks: ../common/vm_get_vm_info.yml - when: (new_vm is undefined) or (not new_vm | bool) + 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" + add_host_in_memory_inventory_user: "{{ esxi_username }}" + add_host_in_memory_inventory_pwd: "{{ esxi_password }}" + add_host_in_memory_inventory_python: "/bin/python" + add_host_in_memory_inventory_ssh_pipeline: true + add_host_in_memory_inventory_remote_tmp: "{{ vm_datastore_path }}" + add_host_in_memory_inventory_shell: "{{ esxi_shell }}" + + - 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 From 18cd2d5b3be6c20b3a2c3649feec95d63529fe35 Mon Sep 17 00:00:00 2001 From: ZouYuhua Date: Wed, 24 May 2023 17:56:52 +0800 Subject: [PATCH 5/6] change code as codereview Signed-off-by: ZouYuhua --- env_setup/env_setup.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/env_setup/env_setup.yml b/env_setup/env_setup.yml index fdce67b1c..51c007cbb 100644 --- a/env_setup/env_setup.yml +++ b/env_setup/env_setup.yml @@ -9,7 +9,7 @@ - name: "Get ansible info" include_tasks: get_ansible_info.yml - - name: "Get default variables" + - name: "Set default variables" include_tasks: set_default_variables.yml - name: "Create this test run log files path" @@ -38,7 +38,7 @@ 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 - - name: "Get vCenter and ESXi version info" + - 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 @@ -71,14 +71,14 @@ cleanup_old_snapshots: false when: cleanup_old_snapshots is undefined - - name: "Cleanup existing snapshots of existing VM if required" + - 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 + include_tasks: ../common/vm_get_power_state.yml - - name: "Poweron VM" - include_tasks: ../../common/vm_set_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" @@ -86,7 +86,7 @@ - name: "Check VM settings" include_tasks: check_vm_settings.yml - - name: "Get VM related info if testing on existing VM" + - name: "Get existing VM info" include_tasks: ../common/vm_get_vm_info.yml when: vm_exists is defined and vm_exists From e0d0b0f28de40ad750b1d591bb0c0b8a3fb52153 Mon Sep 17 00:00:00 2001 From: ZouYuhua Date: Thu, 25 May 2023 09:29:25 +0800 Subject: [PATCH 6/6] delete the condition current_snapshot_name != revert_to_snapshot_name for when sentence Signed-off-by: ZouYuhua --- common/vm_cleanup_snapshot.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/vm_cleanup_snapshot.yml b/common/vm_cleanup_snapshot.yml index eaf9f0e6a..e2c23bdce 100644 --- a/common/vm_cleanup_snapshot.yml +++ b/common/vm_cleanup_snapshot.yml @@ -51,9 +51,8 @@ - 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: