-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FACT-2793) Time limit for Facter::Core::Execute
- Loading branch information
Oana Tanasoiu
committed
Sep 22, 2020
1 parent
28677be
commit c5afaa8
Showing
21 changed files
with
195 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
acceptance/tests/custom_facts/time_limit_for_execute_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
test_name 'Facter::Core::Execution accepts and correctly sets a time limit option' do | ||
tag 'risk:high' | ||
|
||
first_file_content = <<-EOM | ||
Facter.add(:foo) do | ||
setcode do | ||
Facter::Core::Execution.execute("sleep 3", {:limit => 2}) | ||
end | ||
end | ||
EOM | ||
|
||
second_file_content = <<-EOM | ||
Facter.add(:custom_fact) do | ||
setcode do | ||
Facter::Core::Execution.execute("sleep 2") | ||
end | ||
end | ||
EOM | ||
|
||
|
||
agents.each do |agent| | ||
|
||
custom_dir = agent.tmpdir('arbitrary_dir') | ||
fact_file1 = File.join(custom_dir, 'file1.rb') | ||
fact_file2 = File.join(custom_dir, 'file2.rb') | ||
create_remote_file(agent, fact_file1, first_file_content) | ||
create_remote_file(agent, fact_file2, second_file_content) | ||
|
||
teardown do | ||
agent.rm_rf(custom_dir) | ||
end | ||
|
||
step "Facter: Logs that command of the first custom fact had timeout after setted time limit" do | ||
on agent, facter('--custom-dir', custom_dir, 'foo --debug') do |facter_output| | ||
assert_match(/DEBUG Facter::Core::Execution.* - Timeout encounter after 2s, killing process with pid:/, | ||
facter_output.stderr.chomp) | ||
end | ||
end | ||
|
||
step "Facter: Logs that command of the second custom fact had timeout after befault time limit" do | ||
on agent, facter('--custom-dir', custom_dir, 'custom_fact --debug') do |facter_output| | ||
assert_match(/DEBUG Facter::Core::Execution.* - Timeout encounter after 1.5s, killing process with pid:/, | ||
facter_output.stderr.chomp) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Resolvers | ||
module Aix | ||
class OsLevel < BaseResolver | ||
@fact_list ||= {} | ||
|
||
class << self | ||
private | ||
|
||
def post_resolve(fact_name) | ||
@fact_list.fetch(fact_name) { read_oslevel(fact_name) } | ||
end | ||
|
||
def read_oslevel(fact_name) | ||
output = Facter::Core::Execution.execute('/usr/bin/oslevel -s', { limit: 2, logger: log }) | ||
@fact_list[:build] = output unless output.empty? | ||
@fact_list[:kernel] = 'AIX' | ||
|
||
@fact_list[fact_name] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.