-
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 11, 2020
1 parent
fe98e99
commit 672ef77
Showing
5 changed files
with
110 additions
and
38 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
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 | ||
|
||
def create_custom_fact_file(file_name, file_content, fact_dir, agent) | ||
fact_file = File.join(fact_dir, file_name) | ||
create_remote_file(agent, fact_file, file_content) | ||
end | ||
|
||
agents.each do |agent| | ||
fact_dir = agent.tmpdir('facter') | ||
|
||
create_custom_fact_file('file1.rb', first_file_content, fact_dir, agent) | ||
create_custom_fact_file('file2.rb', second_file_content, fact_dir, agent) | ||
env = {'FACTERLIB' => fact_dir} | ||
|
||
teardown do | ||
agent.rm_rf(fact_dir) | ||
end | ||
|
||
step "Facter: Logs that command of the first custom fact had timeout after setted time limit" do | ||
on(agent, facter('foo --debug', environment: env), acceptable_exit_codes: [0]) do |facter_output| | ||
assert_match(/DEBUG Facter::Core::Execution::Posix - Timeout encounter after 2, 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_fact --debug', environment: env), acceptable_exit_codes: [0]) do |facter_output| | ||
assert_match(/DEBUG Facter::Core::Execution::Posix - Timeout encounter after 1.5, 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