Skip to content

Commit

Permalink
(PA-6394) Add integration tests for windows service manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tvpartytonight committed Jun 6, 2024
1 parent 0c28d4f commit 4c9b385
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions acceptance/tests/windows/service_manager_integration.rb
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

0 comments on commit 4c9b385

Please sign in to comment.