Skip to content

Commit

Permalink
Merge pull request puppetlabs#774 from smortex/facter-timeout
Browse files Browse the repository at this point in the history
Prefer timeout to time_limit for Facter::Core::Execution
  • Loading branch information
adrianiurca authored Sep 20, 2021
2 parents e124742 + f0fd930 commit 8440c89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/facter/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def interfaces
setcode do
if Facter::Core::Execution.which('docker')
value = Facter::Core::Execution.execute(
"#{docker_command} version --format '{{json .}}'", time_limit: 90
"#{docker_command} version --format '{{json .}}'", timeout: 90
)
val = JSON.parse(value)
end
Expand All @@ -81,7 +81,7 @@ def interfaces
setcode do
if Facter::Core::Execution.which('docker')
val = Facter::Core::Execution.execute(
"#{docker_command} swarm join-token worker -q", time_limit: 90
"#{docker_command} swarm join-token worker -q", timeout: 90
)
end
val
Expand All @@ -92,7 +92,7 @@ def interfaces
setcode do
if Facter::Core::Execution.which('docker')
val = Facter::Core::Execution.execute(
"#{docker_command} swarm join-token manager -q", time_limit: 90
"#{docker_command} swarm join-token manager -q", timeout: 90
)
end
val
Expand All @@ -105,20 +105,20 @@ def interfaces
if docker_version&.match?(%r{1[0-9][0-2]?[.]\w+})
if Facter::Core::Execution.which('docker')
docker_json_str = Facter::Core::Execution.execute(
"#{docker_command} info --format '{{json .}}'", time_limit: 90
"#{docker_command} info --format '{{json .}}'", timeout: 90
)
begin
docker = JSON.parse(docker_json_str)
docker['network'] = {}

docker['network']['managed_interfaces'] = {}
network_list = Facter::Core::Execution.execute("#{docker_command} network ls | tail -n +2", time_limit: 90)
network_list = Facter::Core::Execution.execute("#{docker_command} network ls | tail -n +2", timeout: 90)
docker_network_names = []
network_list.each_line { |line| docker_network_names.push line.split[1] }
docker_network_ids = []
network_list.each_line { |line| docker_network_ids.push line.split[0] }
docker_network_names.each do |network|
inspect = JSON.parse(Facter::Core::Execution.execute("#{docker_command} network inspect #{network}", time_limit: 90))
inspect = JSON.parse(Facter::Core::Execution.execute("#{docker_command} network inspect #{network}", timeout: 90))
docker['network'][network] = inspect[0]
network_id = docker['network'][network]['Id'][0..11]
interfaces.each do |iface|
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/lib/facter/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
allow(Facter::Core::Execution).to receive(:which).with('docker').and_return('/usr/bin/docker')
end
docker_info = File.read(fixtures('facts', 'docker_info'))
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", time_limit: 90).and_return(docker_info)
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} info --format '{{json .}}'", timeout: 90).and_return(docker_info)
processors = File.read(fixtures('facts', 'processors'))
allow(Facter.fact(:processors)).to receive(:value).and_return(JSON.parse(processors))
docker_version = File.read(fixtures('facts', 'docker_version'))
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} version --format '{{json .}}'", time_limit: 90).and_return(docker_version)
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} version --format '{{json .}}'", timeout: 90).and_return(docker_version)
docker_network_list = File.read(fixtures('facts', 'docker_network_list'))
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network ls | tail -n +2", time_limit: 90).and_return(docker_network_list)
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network ls | tail -n +2", timeout: 90).and_return(docker_network_list)
docker_network_names = []
docker_network_list.each_line { |line| docker_network_names.push line.split[1] }
docker_network_names.each do |network|
inspect = File.read(fixtures('facts', "docker_network_inspect_#{network}"))
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network inspect #{network}", time_limit: 90).and_return(inspect)
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} network inspect #{network}", timeout: 90).and_return(inspect)
end
docker_worker_token = File.read(fixtures('facts', 'docker_swarm_worker_token'))
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token worker -q", time_limit: 90).and_return(docker_worker_token.chomp)
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token worker -q", timeout: 90).and_return(docker_worker_token.chomp)
docker_manager_token = File.read(fixtures('facts', 'docker_swarm_manager_token'))
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token manager -q", time_limit: 90).and_return(docker_manager_token.chomp)
allow(Facter::Core::Execution).to receive(:execute).with("#{docker_command} swarm join-token manager -q", timeout: 90).and_return(docker_manager_token.chomp)
end
after(:each) { Facter.clear }

Expand Down

0 comments on commit 8440c89

Please sign in to comment.