Skip to content

Commit 8440c89

Browse files
authored
Merge pull request #774 from smortex/facter-timeout
Prefer timeout to time_limit for Facter::Core::Execution
2 parents e124742 + f0fd930 commit 8440c89

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

lib/facter/docker.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def interfaces
6969
setcode do
7070
if Facter::Core::Execution.which('docker')
7171
value = Facter::Core::Execution.execute(
72-
"#{docker_command} version --format '{{json .}}'", time_limit: 90
72+
"#{docker_command} version --format '{{json .}}'", timeout: 90
7373
)
7474
val = JSON.parse(value)
7575
end
@@ -81,7 +81,7 @@ def interfaces
8181
setcode do
8282
if Facter::Core::Execution.which('docker')
8383
val = Facter::Core::Execution.execute(
84-
"#{docker_command} swarm join-token worker -q", time_limit: 90
84+
"#{docker_command} swarm join-token worker -q", timeout: 90
8585
)
8686
end
8787
val
@@ -92,7 +92,7 @@ def interfaces
9292
setcode do
9393
if Facter::Core::Execution.which('docker')
9494
val = Facter::Core::Execution.execute(
95-
"#{docker_command} swarm join-token manager -q", time_limit: 90
95+
"#{docker_command} swarm join-token manager -q", timeout: 90
9696
)
9797
end
9898
val
@@ -105,20 +105,20 @@ def interfaces
105105
if docker_version&.match?(%r{1[0-9][0-2]?[.]\w+})
106106
if Facter::Core::Execution.which('docker')
107107
docker_json_str = Facter::Core::Execution.execute(
108-
"#{docker_command} info --format '{{json .}}'", time_limit: 90
108+
"#{docker_command} info --format '{{json .}}'", timeout: 90
109109
)
110110
begin
111111
docker = JSON.parse(docker_json_str)
112112
docker['network'] = {}
113113

114114
docker['network']['managed_interfaces'] = {}
115-
network_list = Facter::Core::Execution.execute("#{docker_command} network ls | tail -n +2", time_limit: 90)
115+
network_list = Facter::Core::Execution.execute("#{docker_command} network ls | tail -n +2", timeout: 90)
116116
docker_network_names = []
117117
network_list.each_line { |line| docker_network_names.push line.split[1] }
118118
docker_network_ids = []
119119
network_list.each_line { |line| docker_network_ids.push line.split[0] }
120120
docker_network_names.each do |network|
121-
inspect = JSON.parse(Facter::Core::Execution.execute("#{docker_command} network inspect #{network}", time_limit: 90))
121+
inspect = JSON.parse(Facter::Core::Execution.execute("#{docker_command} network inspect #{network}", timeout: 90))
122122
docker['network'][network] = inspect[0]
123123
network_id = docker['network'][network]['Id'][0..11]
124124
interfaces.each do |iface|

spec/unit/lib/facter/docker_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@
2121
allow(Facter::Core::Execution).to receive(:which).with('docker').and_return('/usr/bin/docker')
2222
end
2323
docker_info = File.read(fixtures('facts', 'docker_info'))
24-
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", time_limit: 90).and_return(docker_info)
24+
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info)
2525
processors = File.read(fixtures('facts', 'processors'))
2626
allow(Facter.fact(:processors)).to receive(:value).and_return(JSON.parse(processors))
2727
docker_version = File.read(fixtures('facts', 'docker_version'))
28-
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} version --format '{{json .}}'", time_limit: 90).and_return(docker_version)
28+
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} version --format '{{json .}}'", timeout: 90).and_return(docker_version)
2929
docker_network_list = File.read(fixtures('facts', 'docker_network_list'))
30-
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network ls | tail -n +2", time_limit: 90).and_return(docker_network_list)
30+
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network ls | tail -n +2", timeout: 90).and_return(docker_network_list)
3131
docker_network_names = []
3232
docker_network_list.each_line { |line| docker_network_names.push line.split[1] }
3333
docker_network_names.each do |network|
3434
inspect = File.read(fixtures('facts', "docker_network_inspect_#{network}"))
35-
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network inspect #{network}", time_limit: 90).and_return(inspect)
35+
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network inspect #{network}", timeout: 90).and_return(inspect)
3636
end
3737
docker_worker_token = File.read(fixtures('facts', 'docker_swarm_worker_token'))
38-
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token worker -q", time_limit: 90).and_return(docker_worker_token.chomp)
38+
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token worker -q", timeout: 90).and_return(docker_worker_token.chomp)
3939
docker_manager_token = File.read(fixtures('facts', 'docker_swarm_manager_token'))
40-
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token manager -q", time_limit: 90).and_return(docker_manager_token.chomp)
40+
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token manager -q", timeout: 90).and_return(docker_manager_token.chomp)
4141
end
4242
after(:each) { Facter.clear }
4343

0 commit comments

Comments
 (0)