forked from puppetlabs/puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PA-6394) Add integration tests for windows service manager
- Loading branch information
1 parent
0c28d4f
commit 4c9b385
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
test_name 'Test agent state via service control manager' do | ||
|
||
tag 'audit:integration' | ||
|
||
confine :to, platform: 'windows' | ||
|
||
teardown do | ||
agents.each do |agent| | ||
state = query_agent_state(agent) | ||
if state != "STOPPED" | ||
stop_puppet_windows_daemon(agent) | ||
ensure_agent_state(agent, "STOPPED") | ||
end | ||
end | ||
end | ||
|
||
def query_agent_state(host) | ||
on(host, 'sc query puppet').stdout.match(/STATE.+\s{1}(\w+)/)[1] | ||
end | ||
|
||
def start_puppet_windows_daemon(host) | ||
on(host, 'sc start puppet') | ||
end | ||
|
||
def stop_puppet_windows_daemon(host) | ||
on(host, 'sc stop puppet') | ||
end | ||
|
||
def ensure_agent_state(host, state) | ||
retry_attempts = 0 | ||
while retry_attempts < 5 | ||
return if state == query_agent_state(host) | ||
retry_attempts += 1 | ||
sleep 1 | ||
end | ||
fail_test "State not #{state} after 5 tries" | ||
end | ||
|
||
step 'store initial state' do | ||
|
||
agents.each do |agent| | ||
initial_state = query_agent_state(agent) | ||
assert_match("STOPPED", initial_state, "agent daemon should initially be stopped") | ||
|
||
start_puppet_windows_daemon(agent) | ||
ensure_agent_state(agent, "RUNNING") | ||
stop_puppet_windows_daemon(agent) | ||
ensure_agent_state(agent, "STOPPED") | ||
end | ||
end | ||
end |