Skip to content

Commit

Permalink
restructure test case
Browse files Browse the repository at this point in the history
Signed-off-by: Diane Wang <[email protected]>
  • Loading branch information
Tomorrow9 committed Nov 29, 2023
1 parent 6a58281 commit 2b720f9
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 223 deletions.
108 changes: 8 additions & 100 deletions windows/guest_customization/gosc_sanity_dhcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
105 changes: 8 additions & 97 deletions windows/guest_customization/gosc_sanity_staticip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions windows/guest_customization/win_gosc_execution.yml
Original file line number Diff line number Diff line change
@@ -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) }}"
Expand Down Expand Up @@ -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"
48 changes: 24 additions & 24 deletions windows/guest_customization/win_gosc_prepare.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"
Loading

0 comments on commit 2b720f9

Please sign in to comment.