-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
1ab4370
commit d5a0dd6
Showing
8 changed files
with
210 additions
and
36 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
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
57 changes: 57 additions & 0 deletions
57
acceptance/tests/options/config_file/ttls_cached_fact_in_multiple_groups.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,57 @@ | ||
# This test verifies that individual facts can be cached | ||
test_name "ttls config with fact in multiple groups should not cache fact twice" do | ||
tag 'risk:high' | ||
|
||
require 'facter/acceptance/user_fact_utils' | ||
extend Facter::Acceptance::UserFactUtils | ||
|
||
# This fact must be resolvable on ALL platforms | ||
# Do NOT use the 'kernel' fact as it is used to configure the tests | ||
cached_fact_name = 'os.name' | ||
first_fact_group = 'first' | ||
second_fact_group = 'second' | ||
|
||
config = <<EOM | ||
facts : { | ||
ttls : [ | ||
{ "#{first_fact_group}" : 30 days }, | ||
{ "#{second_fact_group}" : 1 days }, | ||
] | ||
} | ||
fact-groups : { | ||
#{first_fact_group}: [#{cached_fact_name}], | ||
#{second_fact_group}: ["os"], | ||
} | ||
EOM | ||
|
||
agents.each do |agent| | ||
step "Agent #{agent}: create cache file with individual fact" do | ||
config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) | ||
config_file = File.join(config_dir, "facter.conf") | ||
cached_facts_dir = get_cached_facts_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) | ||
|
||
first_cached_fact_file = File.join(cached_facts_dir, first_fact_group) | ||
second_cached_fact_file = File.join(cached_facts_dir, second_fact_group) | ||
|
||
# Setup facter conf | ||
agent.mkdir_p(config_dir) | ||
create_remote_file(agent, config_file, config) | ||
|
||
teardown do | ||
agent.rm_rf(config_dir) | ||
agent.rm_rf(cached_facts_dir) | ||
end | ||
|
||
step "should create a JSON file for a fact that is to be cached" do | ||
agent.rm_rf(cached_facts_dir) | ||
on(agent, facter("--debug")) do |facter_output| | ||
assert_match(/caching values for .+ facts/, facter_output.stderr, "Expected debug message to state that values will be cached") | ||
end | ||
first_cat_output = agent.cat(first_cached_fact_file) | ||
assert_match(/#{cached_fact_name}/, first_cat_output.strip, "Expected cached fact file to contain fact information") | ||
second_cat_output = agent.cat(second_cached_fact_file) | ||
assert_not_match(/#{cached_fact_name}/, second_cat_output.strip, "Expected cached fact file to not contain fact information") | ||
end | ||
end | ||
end | ||
end |
63 changes: 63 additions & 0 deletions
63
acceptance/tests/options/config_file/ttls_cached_individual_fact_name.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,63 @@ | ||
# This test verifies that individual facts can be cached | ||
test_name "ttls config that contains fact name caches individual facts" do | ||
tag 'risk:high' | ||
|
||
require 'facter/acceptance/user_fact_utils' | ||
extend Facter::Acceptance::UserFactUtils | ||
|
||
# This fact must be resolvable on ALL platforms | ||
# Do NOT use the 'kernel' fact as it is used to configure the tests | ||
cached_fact_name = 'system_uptime.days' | ||
cached_fact_value = "CACHED_FACT_VALUE" | ||
cached_fact_content = <<EOM | ||
{ | ||
"#{cached_fact_name}": "#{cached_fact_value}" | ||
} | ||
EOM | ||
|
||
config = <<EOM | ||
facts : { | ||
ttls : [ | ||
{ "#{cached_fact_name}" : 30 days } | ||
] | ||
} | ||
EOM | ||
|
||
agents.each do |agent| | ||
step "Agent #{agent}: create cache file with individual fact" do | ||
config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) | ||
config_file = File.join(config_dir, "facter.conf") | ||
cached_facts_dir = get_cached_facts_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) | ||
|
||
cached_fact_file = File.join(cached_facts_dir, cached_fact_name) | ||
|
||
# Setup facter conf | ||
agent.mkdir_p(config_dir) | ||
create_remote_file(agent, config_file, config) | ||
|
||
teardown do | ||
agent.rm_rf(config_dir) | ||
agent.rm_rf(cached_facts_dir) | ||
end | ||
|
||
step "should create a JSON file for a fact that is to be cached" do | ||
agent.rm_rf(cached_facts_dir) | ||
on(agent, facter("--debug")) do |facter_output| | ||
assert_match(/caching values for .+ facts/, facter_output.stderr, "Expected debug message to state that values will be cached") | ||
end | ||
cat_output = agent.cat(cached_fact_file) | ||
assert_match(/#{cached_fact_name}/, cat_output.strip, "Expected cached fact file to contain fact information") | ||
end | ||
|
||
step "should read from a cached JSON file for a fact that has been cached" do | ||
agent.mkdir_p(cached_facts_dir) | ||
create_remote_file(agent, cached_fact_file, cached_fact_content) | ||
|
||
on(agent, facter("#{cached_fact_name} --debug")) do | ||
assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") | ||
assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") | ||
end | ||
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
Oops, something went wrong.