Skip to content

Commit

Permalink
address new comments
Browse files Browse the repository at this point in the history
Signed-off-by: Yanan Shen <yanans@vmware.com>
  • Loading branch information
123lzxm committed Jan 4, 2024
1 parent d6924c5 commit 70cf886
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 47 deletions.
29 changes: 17 additions & 12 deletions env_setup/env_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,37 @@

# Need to revert to base snapshot of target VM firstly, or removing portgroup would fail
- name: "Revert to base snapshot then cleanup network testbed configurations"
when:
- router_vm_deployed is defined
- router_vm_deployed | bool
block:
- include_tasks: ../common/vm_revert_snapshot.yml
- name: "Revert to snapshot {{ base_snapshot_name }}"
include_tasks: ../common/vm_revert_snapshot.yml
vars:
snapshot_name: "{{ base_snapshot_name }}"
skip_if_not_exist: true
when:
- base_snapshot_exists is defined
- base_snapshot_exists | bool
# Clean up router VM, vSwitch and portgroup
- include_tasks: ../common/network_testbed_cleanup.yml
when:
- router_vm_deployed is defined
- router_vm_deployed | bool
- name: "Cleanup router VM and vSwitch"
include_tasks: ../common/network_testbed_cleanup.yml

- name: Cleanup new deployed VM
- name: "Cleanup new deployed VM"
when:
- cleanup_vm | bool
- new_vm is defined and new_vm | bool
block:
- include_tasks: ../common/vm_set_power_state.yml
- name: "Power off VM"
include_tasks: ../common/vm_set_power_state.yml
vars:
vm_power_state_set: 'powered-off'
- include_tasks: ../common/vm_remove.yml
- name: "Set VM cleaned flag is True"
- name: "Remove VM"
include_tasks: ../common/vm_remove.yml
- name: "Set VM cleaned flag to true and VM exists to false"
ansible.builtin.set_fact:
vm_cleaned_up: true
when:
- cleanup_vm | bool
- new_vm is defined and new_vm | bool
vm_exists: false

- name: "Restore base snapshot for windows update installation"
when:
Expand Down
1 change: 1 addition & 0 deletions windows/gosv_testcase_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- import_playbook: deploy_vm/deploy_vm.yml
- import_playbook: check_inbox_driver/check_inbox_driver.yml
- import_playbook: wintools_complete_install_verify/wintools_complete_install_verify.yml
- import_playbook: windows_update_install/windows_update_install.yml
- import_playbook: guest_os_inplace_upgrade/guest_os_inplace_upgrade.yml
- import_playbook: secureboot_enable_disable/secureboot_enable_disable.yml
- import_playbook: check_efi_firmware/check_efi_firmware.yml
Expand Down
22 changes: 11 additions & 11 deletions windows/windows_update_install/install_msu_file.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2023 VMware, Inc.
# SPDX-License-Identifier: BSD-2-Clause
---
- name: "Set the msu file installation related parameters"
- 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: "{{ msu_file_dest_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' }}"

Expand All @@ -14,9 +14,9 @@
win_powershell_cmd: "net user Administrator /active:yes"
when: vm_username | lower != "administrator"

- name: "Install the msu file"
- name: "Install the .msu file"
ansible.windows.win_shell: >-
wusa.exe {{ msu_file_dest }} /quiet /norestart
wusa.exe {{ msu_file_dest_path }} /quiet /norestart
delegate_to: "{{ vm_guest_ip }}"
register: install_msu_result
become: true
Expand All @@ -27,7 +27,7 @@
environment:
ANSIBLE_WIN_ASYNC_STARTUP_TIMEOUT: 10

- name: "Check if the msu file is installed before restart"
- 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
ignore_errors: true
Expand All @@ -40,20 +40,20 @@
retries: "{{ msu_install_timeout // 300 }}"
delay: 300

- name: "The msu file installation failed"
- name: "The .msu file installation failed"
ansible.builtin.fail:
msg: "Failed to install the msu file in {{ msu_install_timeout }} seconds."
msg: "Failed to install the .msu file {{ msu_file_name }} in {{ msu_install_timeout }} seconds."
when:
- win_get_hotfix_result.failed is defined
- win_get_hotfix_result.failed

- name: "Restart guest OS after installing the msu file"
- name: "Restart guest OS after installing the .msu file"
include_tasks: ../utils/win_shutdown_restart.yml
vars:
set_win_power_state: "restart"
win_reboot_timeout: 1800

- name: "Check if the msu file is installed after restart"
- name: "Check if the .msu file is installed after restart"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "Get-HotFix | Where-Object HotFixID -eq {{ msu_kb_number }}"
Expand All @@ -63,5 +63,5 @@
that:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0
fail_msg: "The msu file {{ msu_kb_number }} is not installed in guest OS."
success_msg: "The msu file {{ msu_kb_number }} is installed in guest OS."
fail_msg: "The .msu file {{ msu_file_name }} is not installed in guest OS."
success_msg: "The .msu file {{ msu_file_name }} is installed in guest OS."
28 changes: 14 additions & 14 deletions windows/windows_update_install/prepare_msu_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,45 @@
- name: "Get unused driver letter"
include_tasks: ../utils/win_get_unused_drive_letter.yml

- name: "Initialize the msu file path"
- name: "Initialize the .msu file path"
ansible.builtin.set_fact:
msu_file_src_path: "{{ drive_letter_new }}:\\{{ windows_update_msu_path }}\\*"
msu_file_dest_path: "C:\\msu"
msu_dir_path: "C:\\msu"
msu_file_name: ""

- name: "Check if folder {{ msu_file_dest_path }} exists on guest OS"
- name: "Check if folder {{ msu_dir_path }} exists on guest OS"
include_tasks: ../utils/win_is_folder.yml
vars:
win_is_folder_path: "{{ msu_file_dest_path }}"
win_is_folder_path: "{{ msu_dir_path }}"

- name: "Create folder {{ msu_file_dest_path }} on guest OS"
- name: "Create folder {{ msu_dir_path }} on guest OS"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: "mkdir {{ msu_file_dest_path }}"
win_powershell_cmd: "mkdir {{ msu_dir_path }}"
when: not win_is_folder_result

- name: "Copy the msu file to local disk of guest OS"
- 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 }};
Copy-Item -Path {{ msu_file_src_path }} -Include *.msu -Destination {{ msu_file_dest_path }} -ErrorAction Stop;
Copy-Item -Path {{ msu_file_src_path }} -Include *.msu -Destination {{ msu_dir_path }} -ErrorAction Stop;
net use {{ drive_letter_new }}: /delete
- name: "Get the msu file name"
- name: "Get the .msu file name"
include_tasks: ../utils/win_execute_cmd.yml
vars:
win_powershell_cmd: >-
Get-ChildItem -Path {{ msu_file_dest_path }} -Include *.msu -Name -ErrorAction Stop;
Get-ChildItem -Path {{ msu_dir_path }} -Include *.msu -Name -ErrorAction Stop;
- name: "Check if the msu file is copied to {{ msu_file_dest_path }}"
- name: "Check if the .msu file is copied to {{ msu_dir_path }}"
ansible.builtin.assert:
that:
- win_powershell_cmd_output.stdout_lines is defined
- win_powershell_cmd_output.stdout_lines | length != 0
fail_msg: "The msu file is not found in {{ msu_file_dest_path }} in guest OS."
success_msg: "The msu file is copied to {{ msu_file_dest_path }} in guest OS."
fail_msg: "The .msu file is not found in {{ msu_dir_path }} in guest OS."
success_msg: "The .msu file is copied to {{ msu_dir_path }} in guest OS."

- name: "Set the msu file name"
- name: "Set the .msu file name"
ansible.builtin.set_fact:
msu_file_name: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
20 changes: 10 additions & 10 deletions windows/windows_update_install/windows_update_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
vars:
create_current_test_folder: true

- name: "Prepare the msu file"
- name: "Prepare the .msu file"
include_tasks: prepare_msu_file.yml

- name: "Install the msu file"
- name: "Install the .msu file"
include_tasks: install_msu_file.yml

- name: "Reset base snapshot after installing the msu file"
- name: "Reset base snapshot after installing the .msu file"
include_tasks: ../../common/reset_base_snapshot.yml

- name: "Save the new name of the old base snapshot"
Expand All @@ -34,19 +34,19 @@
vars:
exit_testing_when_fail: true
always:
- name: "Delete the msu file from guest OS"
- name: "Delete the .msu file from guest OS"
when:
- msu_file_dest is defined
- msu_file_dest
- msu_file_dest_path is defined
- msu_file_dest_path
block:
- name: "Check if the msu file exists in guest OS"
- name: "Check if the .msu file exists in guest OS"
include_tasks: ../utils/win_check_file_exist.yml
vars:
win_check_file_exist_file: "{{ msu_file_dest }}"
win_check_file_exist_file: "{{ msu_file_dest_path }}"

- name: "Delete the msu file from guest OS"
- name: "Delete the .msu file from guest OS"
ansible.windows.win_file:
path: "{{ msu_file_dest }}"
path: "{{ msu_file_dest_path }}"
state: absent
delegate_to: "{{ vm_guest_ip }}"
register: delete_file_result
Expand Down

0 comments on commit 70cf886

Please sign in to comment.