Skip to content

Commit f35b6d5

Browse files
committed
(PUP-12061) Handle changing splay in puppet.conf
Previously, enabling or disabling splay in puppet.conf did not work if the agent was already running periodically. If the agent was started with splay disabled, then enabling it would cause a NoMethodError, when trying to call Puppet::Scheduler::Job#splay_limit If the agent was started with splay enabled, then disabling it would have no effect, since we never recalculated the splay limit. To handle these cases, always create a SplayJob for the agent_run job and set its splay_limit to either the limit or 0, depending on whether splay is enabled or not. Setting a splay_limit to 0 causes the splay to also be set to 0 because rand(1) always returns 0.
1 parent ccfcec2 commit f35b6d5

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/puppet/daemon.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def remove_pidfile
157157

158158
# Loop forever running events - or, at least, until we exit.
159159
def run_event_loop
160-
agent_run = Puppet::Scheduler.create_job(Puppet[:runinterval], Puppet[:splay], Puppet[:splaylimit]) do |job|
160+
splaylimit = Puppet[:splay] ? Puppet[:splaylimit] : 0
161+
162+
agent_run = Puppet::Scheduler.create_job(Puppet[:runinterval], true, splaylimit) do |job|
161163
if job.splay != 0
162164
Puppet.info "Running agent every #{job.run_interval} seconds with splay #{job.splay} of #{job.splay_limit} seconds"
163165
else
@@ -171,7 +173,7 @@ def run_event_loop
171173
reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do
172174
Puppet.settings.reparse_config_files
173175
agent_run.run_interval = Puppet[:runinterval]
174-
agent_run.splay_limit = Puppet[:splaylimit] if Puppet[:splay]
176+
agent_run.splay_limit = Puppet[:splay] ? Puppet[:splaylimit] : 0
175177
if Puppet[:filetimeout] == 0
176178
reparse_run.disable
177179
else

spec/unit/daemon_spec.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run_loop(jobs)
8585

8686
it "does not splay the agent run by default" do
8787
daemon.start
88-
expect(agent_run).to be_an_instance_of(Puppet::Scheduler::Job)
88+
expect(agent_run.splay).to eq(0)
8989
end
9090

9191
describe "and calculating splay" do
@@ -115,6 +115,26 @@ def run_loop(jobs)
115115

116116
expect(agent_run.splay).to eq(init_splay)
117117
end
118+
119+
it "recalculates when splay is enabled later" do
120+
Puppet[:splay] = false
121+
daemon.start
122+
123+
Puppet[:splay] = true
124+
allow(agent_run).to receive(:rand).and_return(999)
125+
reparse_run.run(Time.now)
126+
127+
expect(agent_run.splay).to eq(999)
128+
end
129+
130+
it "sets splay to 0 when splay is disabled" do
131+
daemon.start
132+
133+
Puppet[:splay] = false
134+
reparse_run.run(Time.now)
135+
136+
expect(agent_run.splay).to eq(0)
137+
end
118138
end
119139
end
120140

0 commit comments

Comments
 (0)