Skip to content

Commit 96828f9

Browse files
committed
(maint) Fix last server environment test
In bb1017f we changed the agent's behavior to fall back to making a node request if the lastrunfile does not contain a usable environment. Update the `use_last_server_specified_environment` test to reflect this change in behavior. Based on test ordering, this test could have passed if the `lastrunfile` was present when the first agent run started. To ensure the new behavior is triggered, always clean up the `lastrunfile` at the beginning of the test.
1 parent fd0a86e commit 96828f9

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

acceptance/tests/environment/use_last_server_specified_environment.rb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,25 @@
6363

6464
with_puppet_running_on(master, master_opts, testdir) do
6565
agents.each do |agent|
66-
run_agent_on(agent, '--no-daemonize --onetime --verbose') do |result|
67-
assert_match(/Info: Using environment 'production'/, result.stdout)
68-
assert_match(/Local environment: 'production' doesn't match server specified environment 'special', restarting agent run with environment 'special'/, result.stdout)
69-
assert_match(/Notice: special environment/, result.stdout)
66+
step 'ensure the lastrunfile is absent for the first run' do
67+
on(agent, puppet('config print lastrunfile')) do |command_result|
68+
agent.rm_rf(command_result.stdout)
69+
end
7070
end
7171

72-
run_agent_on(agent, '--no-daemonize --onetime --verbose') do |result|
73-
assert_match(/Info: Using environment 'special'/, result.stdout)
74-
assert_match(/Notice: special environment/, result.stdout)
72+
step 'first run: agent makes a node request to get the environment' do
73+
run_agent_on(agent, '--no-daemonize --onetime --debug') do |result|
74+
assert_match(/Local environment: 'production' doesn't match server specified node environment 'special', switching agent to 'special'/, result.stdout)
75+
assert_match(/Debug: HTTP GET .*\/puppet\/v3\/node/, result.stdout)
76+
assert_match(/Notice: special environment/, result.stdout)
77+
end
78+
end
79+
80+
step 'second run: agent uses the environment from lastrunfile' do
81+
run_agent_on(agent, '--no-daemonize --onetime --debug') do |result|
82+
assert_match(/Debug: Successfully loaded last environment from the lastrunfile/, result.stdout)
83+
assert_match(/Notice: special environment/, result.stdout)
84+
end
7585
end
7686
end
7787
end

0 commit comments

Comments
 (0)