Skip to content

Commit aaa3c3a

Browse files
committed
test task
Signed-off-by: dw035535 <diane.wang@broadcom.com>
1 parent 2a9ec5f commit aaa3c3a

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
11
# Copyright 2022-2024 VMware, Inc.
22
# SPDX-License-Identifier: BSD-2-Clause
33
---
4-
# Retry to get serivce status in Windows guest OS until it's running
4+
# Retry to get serivce status in Windows guest OS until it reaches the expected state.
55
# Parameters:
6-
# win_service_name: the service name
6+
# win_service_name: the service name to getting status.
7+
# win_wait_service_state (optional): the state of the service, e.g., 'Stopped', 'Running'.
8+
# Default value is 'Running'.
9+
# win_wait_service_timeout (optional): the timeout in seconds to wait for service state.
10+
# Default value is 60s.
711
#
812
- name: "Check required parameter"
9-
ansible.builtin.fail:
10-
msg: "win_service_name must be defined before get service status"
11-
when: win_service_name is undefined or not win_service_name
13+
ansible.builtin.assert:
14+
that:
15+
- win_service_name is defined
16+
- win_service_name | length > 0
17+
msg: "Parameter 'win_service_name' must be defined before get service status."
1218

1319
- name: "Check specified service '{{ win_service_name }}' status in Windows"
14-
ansible.windows.win_shell: 'get-service -Name {{ win_service_name }} | foreach {$_.Status}'
15-
delay: 5
16-
retries: 10
20+
ansible.windows.win_shell: 'Get-Service -Name {{ win_service_name }} | foreach {$_.Status}'
1721
delegate_to: "{{ vm_guest_ip }}"
1822
register: get_service_status
23+
delay: 5
24+
retries: "{{ (win_wait_service_timeout | default(60) / 5) | round | int }}"
1925
until:
2026
- get_service_status is defined
2127
- get_service_status.stdout_lines is defined
22-
- get_service_status.stdout_lines | length != 0
23-
- get_service_status.stdout_lines[0] == 'Running'
28+
- get_service_status.stdout_lines | length == 1
29+
- get_service_status.stdout_lines[0] == win_wait_service_state | default('Running')
2430
ignore_errors: true
31+
ignore_unreachable: true
2532

2633
- name: "Check service '{{ win_service_name }}' status in Windows"
2734
ansible.builtin.assert:
2835
that:
29-
- get_service_status is defined
30-
- get_service_status.stdout_lines is defined
31-
- get_service_status.stdout_lines | length != 0
32-
- get_service_status.stdout_lines[0] == 'Running'
36+
- get_service_status.failed is defined
37+
- not get_service_status.failed
3338
fail_msg: >-
34-
Windows service '{{ win_service_name }}' status is not running after 50 seconds.
35-
Current service status is '{{ get_service_status.stdout_lines[0] | default("") }}'.
36-
37-
- name: "Display the PowerShell command result"
38-
ansible.builtin.debug: var=get_service_status
39-
when: enable_debug is defined and enable_debug
39+
Windows service '{{ win_service_name }}' status is not {{ win_wait_service_state | default('Running') }}
40+
after {{ win_wait_service_timeout | default(60) }} seconds.
41+
Get service status in guest OS '{{ get_service_status.stdout_lines | default("") }}'.

0 commit comments

Comments
 (0)