Skip to content

Commit 5e53f75

Browse files
committed
(PUP-12061) Handle changing splay in puppet.conf
Previously, splay could not be enabled or disabled in puppet.conf if the daemonized agent was already running. If the daemon was started with splay disabled, then enabling it would cause a NoMethodError, when trying to call `splay_limit` on a regular Job. If the daemon was started with splay enabled, then disabling it would have no effect, since we never recalculated the splay limit. To handle situations where `splay` may be enabled or disabled in puppet.conf, always create a SplayJob for the agent_run job and set its `splay_limit` to either the limit or 0, respectively. Note setting a `splay_limit` to 0 causes the splay offset to also be set to 0 because `rand(1)` always returns 0.
1 parent 45c4547 commit 5e53f75

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

lib/puppet/daemon.rb

+4-2
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
Puppet.info "Running agent #{job}"
162164

163165
# Splay for the daemon is handled in the scheduler
@@ -167,7 +169,7 @@ def run_event_loop
167169
reparse_run = Puppet::Scheduler.create_job(Puppet[:filetimeout]) do
168170
Puppet.settings.reparse_config_files
169171
agent_run.run_interval = Puppet[:runinterval]
170-
agent_run.splay_limit = Puppet[:splaylimit] if Puppet[:splay]
172+
agent_run.splay_limit = Puppet[:splay] ? Puppet[:splaylimit] : 0
171173
if Puppet[:filetimeout] == 0
172174
reparse_run.disable
173175
else

spec/unit/daemon_spec.rb

+37-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run_loop(jobs)
8484
it "does not splay the agent run by default" do
8585
daemon.start
8686
agent_run = scheduler.jobs[1]
87-
expect(agent_run).to be_an_instance_of(Puppet::Scheduler::Job)
87+
expect(agent_run.splay).to eq(0)
8888
end
8989

9090
it "recalculates splay if splaylimit changes" do
@@ -124,6 +124,42 @@ def run_loop(jobs)
124124

125125
expect(agent_run.splay).to eq(init_splay)
126126
end
127+
128+
it "recalculates splay if splay is enabled later" do
129+
# Set file timeout so the daemon reparses
130+
Puppet[:filetimeout] = 1
131+
Puppet[:splay] = false
132+
daemon.start
133+
134+
# enable splay
135+
Puppet[:splay] = true
136+
137+
agent_run = scheduler.jobs[1]
138+
allow(agent_run).to receive(:rand).and_return(999)
139+
140+
# run the reparse job
141+
reparse_run = scheduler.jobs[0]
142+
reparse_run.run(Time.now)
143+
144+
expect(agent_run.splay).to eq(999)
145+
end
146+
147+
it "sets splay to 0 if splay is disabled" do
148+
# Set file timeout so the daemon reparses
149+
Puppet[:filetimeout] = 1
150+
Puppet[:splay] = true
151+
daemon.start
152+
153+
# disable splay
154+
Puppet[:splay] = false
155+
156+
# run the reparse job
157+
reparse_run = scheduler.jobs[0]
158+
reparse_run.run(Time.now)
159+
160+
agent_run = scheduler.jobs[1]
161+
expect(agent_run.splay).to eq(0)
162+
end
127163
end
128164

129165
describe "when stopping" do

0 commit comments

Comments
 (0)