From ba0e085df2ca2b7de1bc8d96b30210eac7db8462 Mon Sep 17 00:00:00 2001 From: Yanan Shen Date: Mon, 8 Jan 2024 14:18:53 +0800 Subject: [PATCH] fix review comments Signed-off-by: Yanan Shen --- env_setup/env_cleanup.yml | 2 +- vars/test.yml | 10 ++++++++++ windows/utils/add_windows_host.yml | 3 +++ windows/windows_update_install/install_msu_file.yml | 9 ++++++++- windows/windows_update_install/prepare_msu_file.yml | 12 +++++++++++- .../windows_update_install.yml | 9 +++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/env_setup/env_cleanup.yml b/env_setup/env_cleanup.yml index 813af5e03..5d419c31e 100644 --- a/env_setup/env_cleanup.yml +++ b/env_setup/env_cleanup.yml @@ -45,7 +45,7 @@ vm_cleaned_up: true vm_exists: false - - name: "Restore base snapshot for windows update installation" + - name: "Restore base snapshot for Windows Update installation" when: - win_update_snapshot_name is defined - win_update_snapshot_name diff --git a/vars/test.yml b/vars/test.yml index 78c99074f..28850cf02 100644 --- a/vars/test.yml +++ b/vars/test.yml @@ -71,6 +71,13 @@ base_snapshot_name: "BaseSnapshot" # # http_proxy_localhost: myproxy.company.com:8080 +# To keep sensitive values out of your logs, such as passwords and usernames, mark tasks that expose them +# with the "no_log: True" attribute. +# This var is the value for attribute no_log. +# Default value is false. +# +# hide_secrets: false + ##################################### # Testbed parameters ##################################### @@ -359,6 +366,9 @@ windows_product_key_upgrade: "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" windows_msu_share_point: '' # The path of the .msu file in windows_msu_share_point. E.g. WindowsClient\Windows11\23H2 windows_update_msu_path: '' +# The use name and password for accessing above Windows shared folder. +# windows_nfs_username: "CHANGEME" +# windows_nfs_pwd: "CHANGEME" ##################################### # GOS related parameters diff --git a/windows/utils/add_windows_host.yml b/windows/utils/add_windows_host.yml index 905f29f24..364b4cf3f 100644 --- a/windows/utils/add_windows_host.yml +++ b/windows/utils/add_windows_host.yml @@ -21,6 +21,7 @@ when: - win_ansible_connection is defined - win_ansible_connection | lower == 'winrm' + no_log: "{{ hide_secrets | default(false) }}" - name: "Add specified Windows IP to the hosts" add_host: @@ -47,6 +48,8 @@ when: > (win_ansible_connection is undefined) or (win_ansible_connection | lower == 'psrp') + no_log: "{{ hide_secrets | default(false) }}" - ansible.builtin.debug: var=add_host_result when: enable_debug is defined and enable_debug + no_log: "{{ hide_secrets | default(false) }}" diff --git a/windows/windows_update_install/install_msu_file.yml b/windows/windows_update_install/install_msu_file.yml index 1347e45de..eea974561 100644 --- a/windows/windows_update_install/install_msu_file.yml +++ b/windows/windows_update_install/install_msu_file.yml @@ -4,7 +4,7 @@ - name: "Set the .msu file installation related parameters" ansible.builtin.set_fact: msu_kb_number: "{{ msu_file_name | regex_search('(?i)KB\\d+') | upper }}" - msu_file_dest_path: "{{ msu_dir_path }}\\{{msu_file_name }}" + msu_file_dest_path: "{{ msu_dir_path }}\\{{ msu_file_name }}" msu_install_timeout: 7200 msu_become_user: "{{ 'SYSTEM' if guest_os_ansible_architecture == '32-bit' else 'Administrator' }}" @@ -27,6 +27,13 @@ environment: ANSIBLE_WIN_ASYNC_STARTUP_TIMEOUT: 10 +- name: "Check if the .msu file installation task started" + ansible.builtin.assert: + that: + - install_msu_result is defined + - install_msu_result.ansible_job_id is defined + fail_msg: "The result of above .msu file installation task executed in guest OS is not returned." + - name: "Check if the .msu file is installed before restart" ansible.windows.win_shell: "Get-HotFix | Where-Object HotFixID -eq {{ msu_kb_number }}" register: win_get_hotfix_result diff --git a/windows/windows_update_install/prepare_msu_file.yml b/windows/windows_update_install/prepare_msu_file.yml index f9668c72d..7ddeea95f 100644 --- a/windows/windows_update_install/prepare_msu_file.yml +++ b/windows/windows_update_install/prepare_msu_file.yml @@ -21,11 +21,21 @@ win_powershell_cmd: "mkdir {{ msu_dir_path }}" when: not win_is_folder_result +- name: "Set mount command for accessing the shared folder" + ansible.builtin.set_fact: + win_nfs_mount_cmd: |- + {%- if windows_nfs_username is defined and windows_nfs_username and + windows_nfs_pwd is defined and windows_nfs_pwd -%} + {{ 'net use ' ~ drive_letter_new ~ ': ' ~ windows_msu_share_point ~ ' ' ~ windows_nfs_pwd ~ ' /user:' ~ windows_nfs_username }} + {%- else -%} + {{ 'net use ' ~ drive_letter_new ~ ': ' ~ windows_msu_share_point }} + {%- endif -%} + - name: "Copy the .msu file to local disk of guest OS" include_tasks: ../utils/win_execute_cmd.yml vars: win_powershell_cmd: >- - net use {{ drive_letter_new }}: {{ windows_msu_share_point }} {{ windows_nfs_pwd }} /user:{{ windows_nfs_username }}; + {{ win_nfs_mount_cmd }}; Copy-Item -Path {{ msu_file_src_path }} -Include *.msu -Destination {{ msu_dir_path }} -ErrorAction Stop; net use {{ drive_letter_new }}: /delete diff --git a/windows/windows_update_install/windows_update_install.yml b/windows/windows_update_install/windows_update_install.yml index da000b85c..ab8322eb0 100644 --- a/windows/windows_update_install/windows_update_install.yml +++ b/windows/windows_update_install/windows_update_install.yml @@ -16,6 +16,15 @@ vars: create_current_test_folder: true + - name: "Skip test case" + include_tasks: ../../common/skip_test_case.yml + vars: + skip_msg: >- + Skip test case due to windows_update_msu_path is not provided + and no need to test the .msu file installation + skip_reason: "Skipped" + when: windows_update_msu_path is undefined or not windows_update_msu_path + - name: "Prepare the .msu file" include_tasks: prepare_msu_file.yml