diff --git a/windows/guest_customization/gosc_sanity_dhcp.yml b/windows/guest_customization/gosc_sanity_dhcp.yml index e5faffdef..c66691e02 100644 --- a/windows/guest_customization/gosc_sanity_dhcp.yml +++ b/windows/guest_customization/gosc_sanity_dhcp.yml @@ -2,108 +2,16 @@ # SPDX-License-Identifier: BSD-2-Clause --- # Description: -# This test case is used for check guest customization with DHCP -# network configuration. If VMware tools is not installed, the test -# result is 'No Run'. -# Note: VM guest customization requires vCenter server. +# This test case is used for check guest OS customization (GOSC) +# with DHCP network configuration. If VMware Tools is not installed, +# the test result is 'No Run'. +# Note: VM guest OS customization requires vCenter server. # - name: gosc_sanity_dhcp hosts: localhost gather_facts: false + vars: + customize_network_type: "dhcp" tasks: - - block: - - include_tasks: ../setup/test_setup.yml - vars: - skip_test_no_vmtools: true - - - include_tasks: ../../common/skip_test_case.yml - vars: - skip_msg: "Test case '{{ ansible_play_name }}' is blocked because vCenter server is not configured" - skip_reason: "Blocked" - when: vcenter_is_defined is undefined or not vcenter_is_defined | bool - - - include_tasks: win_gosc_prepare.yml - - name: Set fact of the network customize type to dhcp - ansible.builtin.set_fact: - customize_network_type: 'dhcp' - vm_dhcp_gosc_start: true - - include_tasks: win_gosc_execution.yml - vars: - customize_network: "{{ gosc_dhcp_network | default('VM Network') }}" - timeout: 2400 - - # Check guest customization state is completed - - include_tasks: ../../common/vm_wait_log_msg.yml - vars: - vm_wait_log_name: "vmware.log" - vm_wait_log_msg: "Chipset: The guest has requested that the virtual machine be hard reset.*|GuestRpc: Reinitializing Channel 0.*" - vm_wait_log_retries: 60 - vm_wait_log_delay: 30 - vm_wait_log_msg_times: 2 - when: - - esxi_version is defined and esxi_version - - esxi_version is version('6.5.0', '=') - - include_tasks: ../../common/vm_wait_gosc_completed.yml - when: > - (esxi_version is undefined) or - (not esxi_version) or - (esxi_version is version('6.5.0', '>')) - - # Wait guest get IP address - - include_tasks: ../../common/vm_wait_guest_ip.yml - - # Get guest IP after customization from guestinfo - - include_tasks: ../../common/vm_get_ip_from_vmtools.yml - - name: Set fact of the guest IP after GOSC - ansible.builtin.set_fact: - guest_ip_after_gosc: "{{ vm_guest_ip }}" - - include_tasks: ../utils/win_check_winrm.yml - - # Get guest hostname after customization from guestinfo - - include_tasks: ../../common/vm_wait_guest_hostname.yml - vars: - wait_guest_hostname: "{{ customize_gos_hostname }}" - - - include_tasks: ../../common/vm_get_config.yml - vars: - property_list: ['guest.hostName'] - - name: Set fact of the hostname after GOSC - ansible.builtin.set_fact: - hostname_after_gosc: "{{ vm_config.guest.hostName }}" - - ansible.builtin.debug: - msg: "Get guest OS hostname/IP after customization: {{ hostname_after_gosc }}/{{ guest_ip_after_gosc }}" - - - name: Check if IP address and hostname changed after customization - ansible.builtin.assert: - that: - - "{{ hostname_before_gosc != hostname_after_gosc }}" - - "{{ hostname_after_gosc == customize_gos_hostname }}" - success_msg: "Check hostname after GOSC succeed." - fail_msg: "Check hostname after GOSC failed." - - # After customize Administrator user password changed - # Add customizated IP address to Ansible hosts - - include_tasks: ../utils/add_windows_host.yml - vars: - vm_password: "{{ customize_logon_password }}" - when: vm_username | lower == "administrator" - - - name: "Add customizated IP address to Ansible hosts using user '{{ vm_username }}'" - include_tasks: ../utils/add_windows_host.yml - when: vm_username | lower != "administrator" - - # Check auto admin logon and count - - include_tasks: check_autologon_count.yml - # Check run once command executed - - include_tasks: check_runonce_command.yml - # Check timezone configured - - include_tasks: check_timezone.yml - rescue: - - include_tasks: ../../common/test_rescue.yml - always: - - block: - - include_tasks: ../../common/vm_get_power_state.yml - # Get all gosc logs from guest to local - - include_tasks: get_gosc_logs_network.yml - when: vm_power_state_get == "poweredOn" - when: vm_dhcp_gosc_start is defined and vm_dhcp_gosc_start + - name: "GOSC test with DHCP network configure" + include_tasks: win_gosc_workflow.yml diff --git a/windows/guest_customization/gosc_sanity_staticip.yml b/windows/guest_customization/gosc_sanity_staticip.yml index 47e355b9e..37f0a1258 100644 --- a/windows/guest_customization/gosc_sanity_staticip.yml +++ b/windows/guest_customization/gosc_sanity_staticip.yml @@ -2,105 +2,16 @@ # SPDX-License-Identifier: BSD-2-Clause --- # Description: -# This test case is used for check guest customization with static -# network configuration. If VMware tools is not installed, the test -# result is 'No Run'. -# Note: VM guest customization requires vCenter server. +# This test case is used for check guest OS customization (GOSC) +# with static network configuration. If VMware Tools is not installed, +# the test result is 'No Run'. +# Note: VM guest OS customization requires vCenter server. # - name: gosc_sanity_staticip hosts: localhost gather_facts: false + vars: + customize_network_type: "static" tasks: - - block: - - include_tasks: ../setup/test_setup.yml - vars: - skip_test_no_vmtools: true - - - include_tasks: ../../common/skip_test_case.yml - vars: - skip_msg: "Test case '{{ ansible_play_name }}' is blocked because vCenter server is not configured" - skip_reason: "Blocked" - when: vcenter_is_defined is undefined or not vcenter_is_defined | bool - - # Prepare router VM, vSwitch and portgroup - - include_tasks: ../../common/network_testbed_setup.yml - when: router_vm_deployed is undefined or not router_vm_deployed | bool - - - include_tasks: win_gosc_prepare.yml - - # Use router VM as the default gateway hardcoded to 192.168.192.1, - # use configured static IP address in this subnet - - name: Set fact of customize static network and gosc start - ansible.builtin.set_fact: - customize_network_type: 'static' - vm_static_gosc_start: true - - - include_tasks: win_gosc_execution.yml - vars: - customize_ip: '192.168.192.10' - customize_gateway: "{{ vlan_gateway }}" - customize_netmask: '255.255.255.0' - customize_network: "{{ portgroup_name }}" - timeout: 2400 - - # Wait guest customization state is completed - - include_tasks: ../../common/vm_wait_log_msg.yml - vars: - vm_wait_log_name: "vmware.log" - vm_wait_log_msg: "Chipset: The guest has requested that the virtual machine be hard reset.*|GuestRpc: Reinitializing Channel 0.*" - vm_wait_log_retries: 60 - vm_wait_log_delay: 30 - vm_wait_log_msg_times: 2 - when: - - esxi_version is defined and esxi_version - - esxi_version is version('6.5.0', '=') - - include_tasks: ../../common/vm_wait_gosc_completed.yml - when: > - (esxi_version is undefined) or - (not esxi_version) or - (esxi_version is version('6.5.0', '>')) - - # Wait guest get the customized static IP - - include_tasks: ../../common/vm_wait_guest_ip.yml - vars: - wait_ipv4: "192.168.192.10" - - # Get guest IP after customization from guestinfo - - include_tasks: ../../common/vm_get_ip_from_vmtools.yml - - name: Set fact of the VM guest IP after GOSC - ansible.builtin.set_fact: - guest_ip_after_gosc: "{{ vm_guest_ip }}" - - # Get guest hostname after customization from guestinfo - - include_tasks: ../../common/vm_wait_guest_hostname.yml - vars: - wait_guest_hostname: "{{ customize_gos_hostname }}" - - - include_tasks: ../../common/vm_get_config.yml - vars: - property_list: ['guest.hostName'] - - name: Set fact of the hostname after GOSC - ansible.builtin.set_fact: - hostname_after_gosc: "{{ vm_config.guest.hostName }}" - - ansible.builtin.debug: - msg: "Get guest OS hostname/IP after customization: {{ hostname_after_gosc }}/{{ guest_ip_after_gosc }}" - - - name: Check IP and hostname changed after customization - ansible.builtin.assert: - that: - - "{{ guest_ip_before_gosc != guest_ip_after_gosc }}" - - "{{ hostname_before_gosc != hostname_after_gosc }}" - - "{{ hostname_after_gosc == customize_gos_hostname }}" - - "{{ guest_ip_after_gosc == '192.168.192.10' }}" - success_msg: "Check guest IP address, hostname after GOSC succeed." - fail_msg: "Check guest IP address, hostname after GOSC failed." - - rescue: - - include_tasks: ../../common/test_rescue.yml - always: - - block: - - include_tasks: ../../common/vm_get_power_state.yml - # Get GOSC log files - - include_tasks: get_gosc_logs_no_network.yml - when: vm_power_state_get == "poweredOn" - when: vm_static_gosc_start is defined and vm_static_gosc_start + - name: "GOSC test with static network configure" + include_tasks: win_gosc_workflow.yml diff --git a/windows/guest_customization/win_gosc_execution.yml b/windows/guest_customization/win_gosc_execution.yml index 38c540657..5f04e2054 100644 --- a/windows/guest_customization/win_gosc_execution.yml +++ b/windows/guest_customization/win_gosc_execution.yml @@ -1,6 +1,10 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- +- name: "Set fact of GOSC starts" + ansible.builtin.set_fact: + win_customize_start: true + - name: "Customize Windows guest OS" community.vmware.vmware_guest: validate_certs: "{{ validate_certs | default(false) }}" @@ -29,9 +33,14 @@ runonce: - "{{ customize_runonce }}" wait_for_customization: true - wait_for_customization_timeout: "{{ timeout | default(omit) }}" + wait_for_customization_timeout: 2400 register: customize_windows_result -- name: Display the Windows customization result +- name: "Display the Windows GOSC result" ansible.builtin.debug: var=customize_windows_result when: enable_debug + +- name: "Set fact of the password for user 'Administrator'" + ansible.builtin.set_fact: + vm_password: "{{ customize_logon_password }}" + when: vm_username | lower == "administrator" diff --git a/windows/guest_customization/win_gosc_prepare.yml b/windows/guest_customization/win_gosc_prepare.yml index d7612717e..62dd5713e 100644 --- a/windows/guest_customization/win_gosc_prepare.yml +++ b/windows/guest_customization/win_gosc_prepare.yml @@ -1,12 +1,17 @@ # Copyright 2021-2023 VMware, Inc. # SPDX-License-Identifier: BSD-2-Clause --- -# Set the common parameters in static and dhcp -# GOSC specification +# Set the parameters in static and DHCP GOSC specifications # Note: refer to this page to set time zone id and name: # https://msdn.microsoft.com/en-us/library/ms912391.aspx # -- name: "Set fact of the common parameters in static and dhcp GOSC spec" +- name: "Prepare router VM, vSwitch and portgroup" + include_tasks: ../../common/network_testbed_setup.yml + when: + - (router_vm_deployed is undefined) or (not router_vm_deployed | bool) + - customize_network_type == "static" + +- name: "Set fact of the common parameters in static and DHCP GOSC spec" ansible.builtin.set_fact: customize_gos_hostname: 'gosc-test-win' customize_domain: "autotest.com" @@ -22,39 +27,35 @@ ansible.builtin.set_fact: customize_runonce: "cmd.exe /c echo {{ customize_runonce_echo_string }} > C:\\gosc_runonce.txt" -- name: "Set fact of the VM guest IP before GOSC" +- name: "Set fact of the static network config parameters" ansible.builtin.set_fact: - guest_ip_before_gosc: "{{ vm_guest_ip }}" - -- name: "Get guest OS hostname from VM guestinfo" - include_tasks: ../../common/vm_get_config.yml - vars: - property_list: ['guest.hostName'] + customize_ip: '192.168.192.10' + customize_gateway: "{{ vlan_gateway }}" + customize_netmask: '255.255.255.0' + customize_network: "{{ portgroup_name }}" + when: customize_network_type == "static" -- name: "Set fact of the hostname before GOSC" +- name: "Set fact of the DHCP network config parameter" ansible.builtin.set_fact: - hostname_before_gosc: "{{ vm_config.guest.hostName }}" - -- ansible.builtin.debug: - msg: "Get guest OS hostname/IP before customization: {{ hostname_before_gosc }}/{{ guest_ip_before_gosc }}" + customize_network: "{{ gosc_dhcp_network | default('VM Network') }}" + when: customize_network_type == "dhcp" - name: "Set fact of default Windows dir" ansible.builtin.set_fact: win_dir: '$env:windir' - -- name: "Get OS directory" +- name: "Get directory path in Windows guest OS" include_tasks: ../utils/win_get_path.yml vars: win_get_path_specified: "{{ win_dir }}" - - name: "Set fact of the absolute path of Windows dir" ansible.builtin.set_fact: win_dir: "{{ win_get_path_absolute }}" -- ansible.builtin.debug: +- name: "Print Windows dir" + ansible.builtin.debug: msg: "Windows GOSC log files in Windows dir: {{ win_dir }}" # Uninstall OneDrive in Windows 11 for the known 3rd-party issue -# Paramter 'uninstall_onedrive' is used for internal testing only +# Parameter 'uninstall_onedrive' is used for internal testing only - name: "Uninstall OneDrive" include_tasks: uninstall_onedrive.yml when: @@ -63,8 +64,8 @@ - guest_os_ansible_distribution_ver is version('10.0.22000.0', '>=') - guest_os_product_type | lower == 'client' -# Disable BitLocker which will cause sysprep failure. -# BitLocker is not installed by default on Windows Server. +# Disable BitLocker which will cause sysprep failure +# BitLocker is not installed by default on Windows Server - name: "Disable BitLocker" when: guest_os_product_type | lower == 'client' block: @@ -82,8 +83,7 @@ - name: "Decrypt Bitlocker volumes" include_tasks: ../utils/win_decrypt_bitlocker_volume.yml -# Shutdown guest OS before execute guest customization -- name: "Shutdown OS" +- name: "Shutdown guest OS before execute GOSC" include_tasks: ../utils/win_shutdown_restart.yml vars: set_win_power_state: "shutdown" diff --git a/windows/guest_customization/win_gosc_verify.yml b/windows/guest_customization/win_gosc_verify.yml new file mode 100644 index 000000000..49135362d --- /dev/null +++ b/windows/guest_customization/win_gosc_verify.yml @@ -0,0 +1,66 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +- name: "Check GOSC state in vmware.log on ESXi 6.5" + include_tasks: ../../common/vm_wait_log_msg.yml + vars: + vm_wait_log_name: "vmware.log" + vm_wait_log_msg: "Chipset: The guest has requested that the virtual machine be hard reset.*|GuestRpc: Reinitializing Channel 0.*" + vm_wait_log_retries: 60 + vm_wait_log_delay: 30 + vm_wait_log_msg_times: 2 + when: esxi_version is version('6.5.0', '=') + +- name: "Check GOSC state in vmware.log on ESXi {{ esxi_version }}" + include_tasks: ../../common/vm_wait_gosc_completed.yml + when: esxi_version is version('6.5.0', '>') + +- name: "Wait for VM IP address after GOSC" + include_tasks: ../../common/vm_wait_guest_ip.yml + vars: + wait_ipv4: "{{ customize_ip if (customize_network_type == 'static') else '' }}" + +- name: "Get VM IP address after GOSC" + include_tasks: ../../common/vm_get_ip_from_vmtools.yml + +- name: "Wait for guest OS hostname after GOSC" + include_tasks: ../../common/vm_wait_guest_hostname.yml + vars: + wait_guest_hostname: "{{ customize_gos_hostname }}" +- name: "Set fact of the guest OS hostname" + ansible.builtin.set_fact: + hostname_after_gosc: "{{ vm_guest_facts.instance.guest.hostName }}" + +- name: "Print guest OS info" + ansible.builtin.debug: + msg: "Guest OS hostname/IP address after GOSC: {{ hostname_after_gosc }}/{{ vm_guest_ip }}" + +- name: "Check customized guest OS hostname" + ansible.builtin.assert: + that: + - "{{ hostname_after_gosc == customize_gos_hostname }}" + success_msg: "Guest OS hostname is customized successfully: {{ hostname_after_gosc }}." + fail_msg: "Guest OS hostname is '{{ hostname_after_gosc }} after GOSC, expected '{{ customize_gos_hostname }}'." + +- name: "Check customized IP address" + ansible.builtin.assert: + that: + - "{{ vm_guest_ip == '192.168.192.10' }}" + success_msg: "Guest OS IP address is customized successfully: {{ vm_guest_ip }}." + fail_msg: "Guest OS IP address is '{{ vm_guest_ip }}' after GOSC, expected '192.168.192.10'." + when: customize_network_type == "static" + +- name: "Verify customization results" + when: customize_network_type == "dhcp" + block: + - name: "Check Windows winrm is connectable" + include_tasks: ../utils/win_check_winrm.yml + - name: "Add VM IP address to Ansible hosts" + include_tasks: ../utils/add_windows_host.yml + + - name: "Check auto admin logon and count" + include_tasks: check_autologon_count.yml + - name: "Check run once command executed" + include_tasks: check_runonce_command.yml + - name: "Check timezone configured" + include_tasks: check_timezone.yml diff --git a/windows/guest_customization/win_gosc_workflow.yml b/windows/guest_customization/win_gosc_workflow.yml new file mode 100644 index 000000000..2743aa043 --- /dev/null +++ b/windows/guest_customization/win_gosc_workflow.yml @@ -0,0 +1,49 @@ +# Copyright 2023 VMware, Inc. +# SPDX-License-Identifier: BSD-2-Clause +--- +- name: "Test case block" + block: + - name: "Initialize GOSC state" + ansible.builtin.set_fact: + win_customize_start: false + + - name: "Test setup" + include_tasks: ../setup/test_setup.yml + vars: + skip_test_no_vmtools: true + + - name: "Skip test case" + include_tasks: ../../common/skip_test_case.yml + vars: + skip_msg: "Test case '{{ ansible_play_name }}' is blocked because vCenter server is not configured" + skip_reason: "Blocked" + when: > + (vcenter_is_defined is undefined) or + (not vcenter_is_defined | bool) + + - name: "Prepare Windows GOSC" + include_tasks: win_gosc_prepare.yml + + - name: "Execute Windows GOSC" + include_tasks: win_gosc_execution.yml + + - name: "Verify Windows GOSC" + include_tasks: win_gosc_verify.yml + rescue: + - name: "Test case failure" + include_tasks: ../../common/test_rescue.yml + always: + - name: "Collect GOSC log files" + when: win_customize_start + block: + - name: "Get VM power state" + include_tasks: ../../common/vm_get_power_state.yml + - name: "Get GOSC log files when VM is power on" + when: vm_power_state_get == "poweredOn" + block: + - name: "Get GOSC log files in VM with DHCP IP" + include_tasks: get_gosc_logs_network.yml + when: customize_network_type == "dhcp" + - name: "Get GOSC log files in VM with static IP" + include_tasks: get_gosc_logs_no_network.yml + when: customize_network_type == "static"