Skip to content

Commit 4c9b385

Browse files
(PA-6394) Add integration tests for windows service manager
1 parent 0c28d4f commit 4c9b385

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
test_name 'Test agent state via service control manager' do
2+
3+
tag 'audit:integration'
4+
5+
confine :to, platform: 'windows'
6+
7+
teardown do
8+
agents.each do |agent|
9+
state = query_agent_state(agent)
10+
if state != "STOPPED"
11+
stop_puppet_windows_daemon(agent)
12+
ensure_agent_state(agent, "STOPPED")
13+
end
14+
end
15+
end
16+
17+
def query_agent_state(host)
18+
on(host, 'sc query puppet').stdout.match(/STATE.+\s{1}(\w+)/)[1]
19+
end
20+
21+
def start_puppet_windows_daemon(host)
22+
on(host, 'sc start puppet')
23+
end
24+
25+
def stop_puppet_windows_daemon(host)
26+
on(host, 'sc stop puppet')
27+
end
28+
29+
def ensure_agent_state(host, state)
30+
retry_attempts = 0
31+
while retry_attempts < 5
32+
return if state == query_agent_state(host)
33+
retry_attempts += 1
34+
sleep 1
35+
end
36+
fail_test "State not #{state} after 5 tries"
37+
end
38+
39+
step 'store initial state' do
40+
41+
agents.each do |agent|
42+
initial_state = query_agent_state(agent)
43+
assert_match("STOPPED", initial_state, "agent daemon should initially be stopped")
44+
45+
start_puppet_windows_daemon(agent)
46+
ensure_agent_state(agent, "RUNNING")
47+
stop_puppet_windows_daemon(agent)
48+
ensure_agent_state(agent, "STOPPED")
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)