Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change word powershell to PowerShell #530

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelogs/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ releases:
- Ignore the result check for getting process vmmemmdag.
- Fix issue of "guest_os_family" undefined.
- Fix deployment failure of ubuntu 20.04.6 desktop VM with bios firmware.
- Save the powershell result before using it in when condition.
- Save the PowerShell result before using it in when condition.
- Fix waiting IPv4 address failure when hw_eth0.ipaddresses is null.
- Fix the issue that PVRDMA client VM has same IP address with server VM.
- Fix variable 'boot_disk_label' undefined issue in test case "nvdimm_cold_add_remove".
Expand Down
2 changes: 1 addition & 1 deletion windows/eflow_deploy/deploy_eflow_vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@
- not win_powershell_cmd_output.failed
- win_powershell_cmd_output.stdout is defined
- "'failed' not in win_powershell_cmd_output.stdout"
fail_msg: "Deploy EFLOW virtual machine task failed or there is 'failed' keyword found in the output, please check the failure in above powershell command result."
fail_msg: "Deploy EFLOW virtual machine task failed or there is 'failed' keyword found in the output, please check the failure in above PowerShell command result."
10 changes: 5 additions & 5 deletions windows/utils/win_create_vswitch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
- win_vswitch_type in ['Private', 'Internal', 'External']
fail_msg: "Accepted values of parameter 'win_vswitch_type' are 'Private', 'Internal', 'External', while it's set to '{{ win_vswitch_type }}.'"

- name: "Set fact of 'External' virtual switch powershell commands"
- name: "Set fact of 'External' virtual switch PowerShell commands"
when: win_vswitch_type == 'External'
block:
- name: "Check required parameter for External virtual switch"
ansible.builtin.assert:
that:
- win_ethernet_name is defined
- win_ethernet_name
fail_msg: "Parameter 'win_ethernet_name' is required and set to a valid value when 'win_vswitch_type' is 'External'."
- name: "Set fact of virtual switch powershell commands"
- name: "Set fact of virtual switch PowerShell commands"
ansible.builtin.set_fact:
win_get_vswitch_cmd: "(Get-VMSwitch -SwitchType {{ win_vswitch_type }} | where-object {$_.Name -eq '{{ win_vswitch_name }}' -and $_.NetAdapterInterfaceDescription -eq '{{ win_ethernet_name }}'} | measure-object).Count"
win_create_vswitch_cmd: "New-VMSwitch -name '{{ win_vswitch_name }}' -NetAdapterName '{{ win_ethernet_name }}' -AllowManagementOS $true"
when: win_vswitch_type == 'External'

- name: "Set fact of 'Internal/Private' virtual switch powershell commands"
- name: "Set fact of 'Internal/Private' virtual switch PowerShell commands"
ansible.builtin.set_fact:
win_get_vswitch_cmd: "(Get-VMSwitch -SwitchType {{ win_vswitch_type }} | where-object {$_.Name -eq '{{ win_vswitch_name }}'} | measure-object).Count"
win_create_vswitch_cmd: "New-VMSwitch -name '{{ win_vswitch_name }}' -SwitchType {{ win_vswitch_type }}"
Expand All @@ -59,6 +59,7 @@
- win_powershell_cmd_output.stdout_lines | length == 1

- name: "vswitch with specified type and name not exist"
when: win_vswitch_exists | int == 0
block:
- name: "Create new vswitch"
include_tasks: win_execute_cmd.yml
Expand All @@ -75,7 +76,6 @@
- win_powershell_cmd_output.stdout_lines | length == 1
- win_powershell_cmd_output.stdout_lines[0] | int == 1
fail_msg: "Failed to get new vswitch with name '{{ win_vswitch_name }}' and type '{{ win_vswitch_type }}' after creation: '{{ win_powershell_cmd_output.stdout_lines | default('') }}'"
when: win_vswitch_exists | int == 0

- name: "vswitch with specified type and name exists"
debug:
Expand Down
2 changes: 1 addition & 1 deletion windows/utils/win_enable_client_hyperv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
# Enable Hyper-V feature in Windows Client guest OS.
#
- name: "Set fact of Hyper-V powershell commands"
- name: "Set fact of Hyper-V PowerShell commands"
ansible.builtin.set_fact:
win_enable_hyperv_cmd: "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart -WarningAction SilentlyContinue"
win_check_hyperv_cmd: "(Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V).State"
Expand Down
2 changes: 1 addition & 1 deletion windows/utils/win_enable_server_hyperv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
win_hyperv_state: ''
win_vmplatform_state: ''

- name: "Set fact of powershell commands"
- name: "Set fact of PowerShell commands"
ansible.builtin.set_fact:
win_enable_hyperv_cmd: "Install-WindowsFeature -Name Hyper-V -IncludeManagementTools"
win_enable_vmplatform_cmd: "Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -All -NoRestart -WarningAction SilentlyContinue"
Expand Down
2 changes: 1 addition & 1 deletion windows/utils/win_execute_cmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
- win_powershell_cmd_output.unreachable is defined
- win_powershell_cmd_output.unreachable

- name: "Display the PowerShell commmand result"
- name: "Display the PowerShell command result"
ansible.builtin.debug: var=win_powershell_cmd_output
when: enable_debug
no_log: "{{ win_execute_cmd_no_log | default(false) }}"
4 changes: 2 additions & 2 deletions windows/utils/win_get_disk_size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
ansible.builtin.set_fact:
win_get_disk_size_gb: 0

- name: "Set powershell command to get size of disk '{{ win_disk_num }}'"
- name: "Set PowerShell command to get size of disk '{{ win_disk_num }}'"
ansible.builtin.set_fact:
win_cmd_disk_size: "[math]::Round(((Get-Disk -Number {{ win_disk_num | int }}).Size)/1GB)"
when: win_disk_num is defined

- name: "Set powershell command to get size of disk '{{ win_disk_uid }}'"
- name: "Set PowerShell command to get size of disk '{{ win_disk_uid }}'"
ansible.builtin.set_fact:
win_cmd_disk_size: "[math]::Round(((Get-Disk -UniqueId '{{ win_disk_uid }}').Size)/1GB)"
when: win_disk_num is undefined and win_disk_uid is defined
Expand Down
9 changes: 5 additions & 4 deletions windows/utils/win_get_ethernet_name.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
# Parameters:
# win_get_ethernet_name_mac: the MAC address of network adapter to find
#
- name: Get Ethernet name of the network adapter with specified MAC address
- name: "Get Ethernet name of the network adapter with specified MAC address"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-NetAdapter | where-object {$_.MacAddress -eq '{{ win_get_ethernet_name_mac | replace(':','-') }}'}).Name"
win_execute_cmd_ignore_error: true

- name: Check powershell command result
- name: "Check PowerShell command result"
ansible.builtin.fail:
msg: "Not get Ethernet name with specified MAC address: {{ win_get_ethernet_name_mac }}"
when: win_powershell_cmd_output.rc != 0 or win_powershell_cmd_output.stdout_lines|length == 0

- name: Set fact of the Ethernet name
- name: "Set fact of the Ethernet name"
ansible.builtin.set_fact:
win_get_ethernet_name_result: "{{ win_powershell_cmd_output.stdout_lines[0] }}"
when: win_powershell_cmd_output.rc == 0 and win_powershell_cmd_output.stdout_lines|length != 0
- ansible.builtin.debug:
- name: "Display debug message"
ansible.builtin.debug:
msg: "Get Ethernet name of specified MAC address: {{ win_get_ethernet_name_mac }} in guest OS: {{ win_get_ethernet_name_result }}"
12 changes: 6 additions & 6 deletions windows/utils/win_get_set_disk_online.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@
ansible.builtin.set_fact:
win_is_disk_online: false

- name: "Set powershell commands to online disk '{{ win_online_disk_num }}'"
- name: "Set PowerShell commands to online disk '{{ win_online_disk_num }}'"
ansible.builtin.set_fact:
win_cmd_online_disk: "Set-Disk -Number {{ win_online_disk_num | int }} -IsOffline $False"
win_cmd_check_disk: "(Get-disk -Number {{ win_online_disk_num | int }}).OperationalStatus"
when: win_online_disk_num is defined

- name: "Set powershell commands to online disk '{{ win_online_disk_uid }}'"
- name: "Set PowerShell commands to online disk '{{ win_online_disk_uid }}'"
ansible.builtin.set_fact:
win_cmd_online_disk: "Set-Disk -UniqueId '{{ win_online_disk_uid }}' -IsOffline $False"
win_cmd_check_disk: "(Get-disk -UniqueId '{{ win_online_disk_uid }}').OperationalStatus"
when: win_online_disk_num is undefined and win_online_disk_uid is defined

# Set disk to online
- include_tasks: win_execute_cmd.yml
- name: "Set disk to online"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "{{ win_cmd_online_disk }}"
when:
- win_online_disk_ops is defined
- win_online_disk_ops | lower == 'set'

# Get disk online status
- include_tasks: win_execute_cmd.yml
- name: "Get disk online status"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "{{ win_cmd_check_disk }}"
- name: "Set fact of the disk online status"
Expand Down
15 changes: 8 additions & 7 deletions windows/utils/win_get_sub_files_folders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
# Return:
# win_get_files_folders_list
#
- ansible.builtin.debug:
- name: "Display debug message"
ansible.builtin.debug:
msg: "Specified folder path in guest OS: {{ win_get_files_folders_folder }}"

- name: Initialize the fact of sub folder and file list
- name: "Initialize the fact of sub folder and file list"
ansible.builtin.set_fact:
win_get_files_folders_list: []

# Get child items in specified folder
- include_tasks: win_execute_cmd.yml
- name: "Get child items in specified folder"
include_tasks: win_execute_cmd.yml
vars:
win_powershell_cmd: "(Get-ChildItem -Path '{{ win_get_files_folders_folder }}').Name"
win_execute_cmd_ignore_error: true

- name: Get files or folder from powershell output
- name: "Get files or folder from PowerShell output"
ansible.builtin.set_fact:
win_get_files_folders_list: "{% for item in win_powershell_cmd_output.stdout_lines %}{{ win_get_files_folders_folder }}\\{{ item }} {% endfor %}"
when: not win_powershell_cmd_output.failed

- name: Set fact of the files or folder list
- name: "Set fact of the files or folder list"
ansible.builtin.set_fact:
win_get_files_folders_list: "{{ win_get_files_folders_list.split() }}"
when: win_get_files_folders_list | length != 0

- name: Display the files or folders list
- name: "Display the files or folders list"
ansible.builtin.debug: var=win_get_files_folders_list
27 changes: 15 additions & 12 deletions windows/utils/win_pause_windows_update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
# SPDX-License-Identifier: BSD-2-Clause
---
# Windows Update will cause poweroff or restart taking a long time,
# or GOSC test cases failure, so here try to disable auto pdate
# or GOSC test cases failure, so here try to disable auto update
# and pause update 7 days.
#
# Transfer powershell script to guest OS
- name: Set fact of powershell script file path
# Transfer PowerShell script to guest OS
- name: "Set fact of PowerShell script file path"
ansible.builtin.set_fact:
local_ps_file: "scripts/pause_windows_update.ps1"
remote_ps_file: "C:\\pause_windows_update.ps1"
- include_tasks: win_copy_file_from_local.yml
- name: "Copy file from local to guest OS"
include_tasks: win_copy_file_from_local.yml
vars:
src_path_local: "{{ local_ps_file }}"
dest_path_remote: "C:\\"
- include_tasks: win_check_file_exist.yml
- name: "Check if file exists"
include_tasks: win_check_file_exist.yml
vars:
win_check_file_exist_file: "{{ remote_ps_file }}"

# Pause Windows update is not a demand task, so ignore errors
- block:
- name: Execute powershell script in guest OS
# Pause Windows Update is not a demand task, so ignore errors
- name: "Execute the PowerShell script to pause Windows Update"
when:
- win_check_file_exist_result is defined
- win_check_file_exist_result | bool
block:
- name: "Execute PowerShell script in guest OS"
ansible.windows.win_command: "powershell.exe -ExecutionPolicy bypass -File {{ remote_ps_file }}"
delegate_to: "{{ vm_guest_ip }}"
ignore_errors: true
register: pause_update_result
- name: Display the script execute result
- name: "Display the script execute result"
ansible.builtin.debug: var=pause_update_result
when: enable_debug
when:
- win_check_file_exist_result is defined
- win_check_file_exist_result | bool
4 changes: 2 additions & 2 deletions windows/utils/win_wait_service_status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Parameters:
# win_service_name: the service name
#
- name: Check required parameter
- name: "Check required parameter"
ansible.builtin.fail:
msg: "win_service_name must be defined before get service status"
when: win_service_name is undefined or not win_service_name
Expand Down Expand Up @@ -34,6 +34,6 @@
Windows service '{{ win_service_name }}' status is not running after 50 seconds.
Current service status is '{{ get_service_status.stdout_lines[0] | default("") }}'.

- name: Display the powershell command result
- name: "Display the PowerShell command result"
ansible.builtin.debug: var=get_service_status
when: enable_debug is defined and enable_debug