Skip to content

Commit

Permalink
[Windows] Fix incorrect user and sysprep error in GOSC test cases (#519)
Browse files Browse the repository at this point in the history
Signed-off-by: Diane Wang <dianew@vmware.com>
  • Loading branch information
Tomorrow9 committed Dec 18, 2023
1 parent 2fb0142 commit 7d59aa6
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 394 deletions.
62 changes: 34 additions & 28 deletions windows/guest_customization/check_autologon_count.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Get auto Admin logon value after gosc
- include_tasks: ../utils/win_execute_cmd.yml
# Check logon as Administrator automatically is set in guest OS
- name: "Initialize the registry value of logon as Administrator automatically"
ansible.builtin.set_fact:
auto_admin_logon: 0

- name: "Get logon as Administrator automatically registry value"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "(get-itemproperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoAdminLogon"
- name: Set fact of the Admin auto logon
win_powershell_cmd: >-
(Get-ItemProperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoAdminLogon
- name: "Set fact of logon as Administrator automatically registry value"
ansible.builtin.set_fact:
auto_admin_logon: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
- ansible.builtin.debug:
msg: "Get auto Admin logon enabled value: {{ auto_admin_logon }}"
when: enable_debug
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- name: Get auto admin logon count value after GOSC
ansible.windows.win_shell: "(get-itemproperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoLogonCount"
- name: "Check logon as Administrator automatically is enabled"
ansible.builtin.assert:
that:
- auto_admin_logon | int == 1
success_msg: "Logon as Administrator automatically is enabled in guest OS."
fail_msg: >-
Logon as Administrator automatically is not enabled in guest OS,
got registry value '{{ auto_admin_logon }}', not expected value 1.
- name: "Get number of times to logon as Administrator automatically"
ansible.windows.win_shell: >-
(Get-ItemProperty -path 'HKLM:\\software\\microsoft\\Windows NT\\CurrentVersion\\Winlogon').AutoLogonCount
register: get_auto_logon_count
delegate_to: "{{ vm_guest_ip }}"
until:
- get_auto_logon_count.stdout_lines is defined
- get_auto_logon_count.stdout_lines | length != 0
- get_auto_logon_count.stdout_lines[0] | int == customize_autologon_count | int - 1
- get_auto_logon_count.stdout_lines[0] | int == win_gosc_spec.gosc_autologon_count | int - 1
retries: 100
delay: 3
ignore_errors: true

- name: "Check auto admin logon count value after GOSC"
- name: "Check number of times to logon as Administrator automatically"
ansible.builtin.assert:
that:
- get_auto_logon_count is defined
- get_auto_logon_count.stdout_lines | length != 0
- get_auto_logon_count.stdout_lines[0] | int == customize_autologon_count | int - 1
- not get_auto_logon_count.failed
success_msg: "Number of times to logon as Administrator automatically is set correctly: {{ get_auto_logon_count.stdout_lines[0] }}."
fail_msg: >-
Auto admin logon count value after GOSC is still incorrect after 300 seconds.
Current auto admin logon count value is '{{ get_auto_logon_count.stdout_lines[0] | int | default("") }}',
not expected '{{ customize_autologon_count | int - 1 }}'.
- ansible.builtin.debug:
msg: "Get remain auto logon count: {{ get_auto_logon_count.stdout_lines[0] }}"
when: enable_debug

- name: Check auto admin logon enabled and count is accurate
ansible.builtin.assert:
that:
- "{{ auto_admin_logon | int == 1 }}"
success_msg: "Auto Admin logon is enabled and customized auto logon count is accurate."
fail_msg: "Auto Admin logon is not enabled."
The number of times to logon as Administrator automatically is incorrect after 300 seconds.
Got value '{{ get_auto_logon_count.stdout_lines[0] | default('') }}' in guest OS after GOSC,
expected value is '{{ win_gosc_spec.gosc_autologon_count | int - 1 }}'.
16 changes: 16 additions & 0 deletions windows/guest_customization/check_ip_hostname.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
- name: "Wait for VM IP address after GOSC"
include_tasks: ../../common/vm_wait_guest_ip.yml
vars:
wait_ipv4: "{{ win_gosc_spec.gosc_ip | default('') }}"

- name: "Update in-memory inventory after GOSC"
include_tasks: ../utils/win_update_inventory.yml
when: gosc_network_type == "dhcp"

- name: "Wait for guest OS hostname after GOSC"
include_tasks: ../../common/vm_wait_guest_hostname.yml
vars:
wait_guest_hostname: "{{ win_gosc_spec.gosc_hostname }}"
19 changes: 11 additions & 8 deletions windows/guest_customization/check_runonce_command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Check runonce command executed in guest OS
- name: Display the run once command
ansible.builtin.debug: var=customize_runonce
- name: "Display the GOSC run once command"
ansible.builtin.debug: var=win_gosc_spec.gosc_runonce

- include_tasks: ../utils/win_execute_cmd.yml
- name: "Get GOSC run once command output file"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "get-content -Path C:\\gosc_runonce.txt"
win_powershell_cmd: "Get-Content -Path {{ win_gosc_spec.gosc_echo_file }}"

- name: Check run once command executed
- name: "Check GOSC run once command executed in guest OS"
ansible.builtin.assert:
that:
- "{{ win_powershell_cmd_output.stdout_lines[0].strip() == customize_runonce_echo_string.strip() }}"
success_msg: "Run once command executed and test file created"
fail_msg: "Run once command not executed or test file not created"
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0
- win_powershell_cmd_output.stdout_lines[0].strip() == win_gosc_spec.gosc_echo_string.strip()
success_msg: "Run once command is executed in guest OS."
fail_msg: "Run once command is not executed successfully in guest OS."
37 changes: 23 additions & 14 deletions windows/guest_customization/check_timezone.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
# Check timezone name after gos customization
- ansible.builtin.debug:
msg: "Configured timezone: {{ customize_timezone_name }}"
when: enable_debug is defined and enable_debug
- name: Check timezone in guest OS
# Check timezone name after GOS customization
- name: "Initialize the timezone name in guest OS"
ansible.builtin.set_fact:
timezone_after_gosc: ""

- name: "Print timezone name in Windows GOSC spec"
ansible.builtin.debug:
msg: "Configured timezone in GOSC spec: {{ win_gosc_spec.gosc_timezone_name }}"

- name: "Get timezone info in guest OS"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "tzutil /g"
- name: Set fact of the timezone in guest OS

- name: "Set fact of the timezone in guest OS"
ansible.builtin.set_fact:
timezone_after_customize: "{{ win_powershell_cmd_output.stdout_lines[0] if not win_powershell_cmd_output.failed else 'NA'}}"
- ansible.builtin.debug:
msg: "Get timezone after customize: {{ timezone_after_customize }}"
- name: Check returned timezone name is the specified one
timezone_after_gosc: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
when:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0

- name: "Check customized timezone in guest OS"
ansible.builtin.assert:
that:
- "{{ not win_powershell_cmd_output.failed }}"
- "{{ win_powershell_cmd_output.stdout_lines[0] == customize_timezone_name }}"
success_msg: "Check customized timezone in guest OS succeed."
fail_msg: "Check customized timezone in guest OS failed."
- timezone_after_gosc == win_gosc_spec.gosc_timezone_name
success_msg: "Timezone '{{ timezone_after_gosc }}' is set by GOSC successfully in guest OS."
fail_msg: >-
Got timezone in guest OS '{{ timezone_after_gosc }}',
which is not the one set in GOSC sepc '{{ win_gosc_spec.gosc_timezone_name }}'.
25 changes: 13 additions & 12 deletions windows/guest_customization/get_gosc_logs_network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Fetch log files from Windows guest OS to local
- name: Initialize the absolute path of GOSC log folders
- name: "Initialize the absolute directory path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_folders_src: []
separator: '\'
win_gosc_log_dir: []

- name: Set fact of the GOSC log paths
- name: "Set fact of the relative directory path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_folders:
win_gosc_log_dir_rel:
- 'Temp\vmware-imc\'
- 'System32\Sysprep\Panther\'
- 'Panther\'
- 'Debug\'
- name: Set fact of the absolute path of GOSC log folders

- name: "Set fact of the absolute directory path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_folders_src: "{{ gosc_win_log_folders_src + [win_dir ~ separator ~ item] }}"
with_items: "{{ gosc_win_log_folders }}"
- name: Display the GOSC log paths
ansible.builtin.debug: var=gosc_win_log_folders_src
win_gosc_log_dir: "{{ [win_windows_dir] | ansible.builtin.product(win_gosc_log_dir_rel) | map('join', win_dir_separator) }}"

- name: "Display the directory path list of GOSC log"
ansible.builtin.debug: var=win_gosc_log_dir

- include_tasks: ../utils/win_get_folder.yml
- name: "Get GOSC log files from guest OS"
include_tasks: ../utils/win_get_folder.yml
vars:
win_get_folder_dst_path: "{{ current_test_log_folder }}"
with_items: "{{ gosc_win_log_folders_src }}"
with_items: "{{ win_gosc_log_dir }}"
loop_control:
loop_var: win_get_folder_src_path
41 changes: 22 additions & 19 deletions windows/guest_customization/get_gosc_logs_no_network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Fetch log files from Windows guest OS to local
- name: Initialize the dict of source log files and dest path
- name: "Initialize the GOSC log files source and dest paths"
ansible.builtin.set_fact:
separator: '\'
source_log_list: []
dest_log_list: []
gosc_win_log_src_dest: {}
win_gosc_log_files: []
win_gosc_log_files_dst: []
win_gosc_log_src_dest: {}

- name: Set fact of the GOSC log files' paths
- name: "Set fact of the relative file path list of GOSC log"
ansible.builtin.set_fact:
gosc_win_log_files:
win_gosc_log_files_rel:
- 'Temp\vmware-imc\guestcust.log'
- 'Temp\vmware-imc\toolsDeployPkg.log'
- 'System32\Sysprep\Panther\setupact.log'
Expand All @@ -23,23 +22,27 @@
- 'Debug\NetSetup.LOG'
- 'Debug\PASSWD.LOG'
- 'Debug\sammui.log'
- name: Set fact of the absolute file path list

- name: "Set fact of the absolute file path list of GOSC log"
ansible.builtin.set_fact:
source_log_list: "{{ source_log_list + [win_dir ~ separator ~ item] }}"
dest_log_list: "{{ dest_log_list + [current_test_log_folder ~ '/' ~ item.split(separator) | join('/')] }}"
with_items: "{{ gosc_win_log_files }}"
win_gosc_log_files: >-
{{ [win_windows_dir] | ansible.builtin.product(win_gosc_log_files_rel) |
map('join', win_dir_separator) }}
win_gosc_log_files_dst: >-
{{ [current_test_log_folder] | ansible.builtin.product(win_gosc_log_files_rel) |
map('join', win_dir_separator) | map('replace', win_dir_separator, '/') }}
- name: Set fact of the source file path and dest file path dict
- name: "Set fact of the source and dest log files path dict"
ansible.builtin.set_fact:
gosc_win_log_src_dest: "{{ dict(source_log_list | zip(dest_log_list)) }}"
- name: Display the GOSC log files to be fetched
ansible.builtin.debug: var=gosc_win_log_src_dest
win_gosc_log_src_dest: "{{ dict(win_gosc_log_files | zip(win_gosc_log_files_dst)) }}"

- name: "Display the GOSC log files to be fetched"
ansible.builtin.debug: var=win_gosc_log_src_dest

- include_tasks: ../../common/vm_guest_file_operation.yml
- name: "Fetch GOSC log files from guest OS"
include_tasks: ../../common/vm_guest_file_operation.yml
vars:
operation: "fetch_file"
src_path: "{{ item.key }}"
dest_path: "{{ item.value }}"
vm_username: 'Administrator'
vm_password: "{{ customize_logon_password }}"
loop: "{{ gosc_win_log_src_dest | dict2items }}"
loop: "{{ win_gosc_log_src_dest | dict2items }}"
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 checking guest OS customization (GOSC)
# with DHCP network configuration. If VMware Tools is not installed,
# the test result is 'Blocked'.
# Note: VM guest OS customization requires vCenter server.
#
- name: gosc_sanity_dhcp
hosts: localhost
gather_facts: false
vars:
gosc_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 configuration"
include_tasks: win_gosc_workflow.yml
Loading

0 comments on commit 7d59aa6

Please sign in to comment.