forked from puppetlabs/puppet-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PA-3666) add tests to verify facts values from puppet
- Loading branch information
Ciprian Badescu
committed
Apr 20, 2021
1 parent
fa43c49
commit 1dbdc9b
Showing
15 changed files
with
817 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ acceptance/tmp/* | |
acceptance/merged_options.rb | ||
acceptance/.beaker/* | ||
ext/smoke/*output.txt | ||
*~ |
79 changes: 79 additions & 0 deletions
79
acceptance/tests/ensure_facter_values_for_custom_overrides_core_dotted_fact.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,79 @@ | ||
test_name 'Ensure Facter values usage for custom fact overriding core dotted fact' do | ||
agents.each do |agent| | ||
|
||
output = on agent, puppet('config print modulepath') | ||
|
||
module_path = output.stdout.split(':')[0] | ||
foo_module_dir = File.join(module_path, 'foo') | ||
foo_custom_facts_dir = File.join(foo_module_dir, 'lib', 'facter') | ||
|
||
initial_ruby_version = on(agent, facter("ruby.version")).stdout.chomp | ||
|
||
step 'create module directories' do | ||
agent.mkdir_p(foo_custom_facts_dir) | ||
end | ||
|
||
teardown do | ||
agent.rm_rf(foo_module_dir) | ||
end | ||
|
||
step 'custom fact' do | ||
create_remote_file(agent, File.join(foo_custom_facts_dir, "my_fizz_fact.rb"), <<-FILE) | ||
Facter.add('ruby.version') do | ||
has_weight 10001 | ||
setcode do | ||
'1.1.1' | ||
end | ||
end | ||
FILE | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"ruby.version\"])'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that previous value is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"ruby\"][\"version\"])'") do |output| | ||
assert_match(/Notice: .*: #{initial_ruby_version}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"ruby.version\"))'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that previous value is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"ruby\", \"version\"))'") do |output| | ||
assert_match(/Notice: .*: #{initial_ruby_version}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"\\\"ruby.version\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that previous value is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"ruby.version\"))'") do |output| | ||
assert_match(/Notice: .*: #{initial_ruby_version}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.\\\"ruby.version\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that previous value is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.ruby.version\"))'") do |output| | ||
assert_match(/Notice: .*: #{initial_ruby_version}/, output.stdout) | ||
end | ||
end | ||
end | ||
end |
61 changes: 61 additions & 0 deletions
61
acceptance/tests/ensure_facter_values_for_custom_overrides_core_top_fact.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,61 @@ | ||
test_name 'Ensure Facter values usage for custom fact overriding core top fact' do | ||
agents.each do |agent| | ||
|
||
output = on agent, puppet('config print modulepath') | ||
|
||
module_path = output.stdout.split(':')[0] | ||
foo_module_dir = File.join(module_path, 'foo') | ||
foo_custom_facts_dir = File.join(foo_module_dir, 'lib', 'facter') | ||
|
||
custom_ruby_value = '{"version": "1.1.1"}' | ||
|
||
step 'create module directories' do | ||
agent.mkdir_p(foo_custom_facts_dir) | ||
end | ||
|
||
teardown do | ||
agent.rm_rf(foo_module_dir) | ||
end | ||
|
||
step 'create external and custom fact' do | ||
create_remote_file(agent, File.join(foo_custom_facts_dir, "ruby.rb"), <<-FILE) | ||
Facter.add('ruby') do | ||
has_weight(999) | ||
setcode do | ||
'#{custom_ruby_value}' | ||
end | ||
end | ||
FILE | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"ruby\"])'") do |output| | ||
assert_match(/Notice: .*: #{custom_ruby_value}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"ruby\"))'") do |output| | ||
assert_match(/Notice: .*: #{custom_ruby_value}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"ruby\"))'") do |output| | ||
assert_match(/Notice: .*: #{custom_ruby_value}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.ruby\"))'") do |output| | ||
assert_match(/Notice: .*: #{custom_ruby_value}/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that json custom fact is interpreted as text' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"ruby\"][\"version\"])'") , acceptable_exit_codes: [1] do |output| | ||
assert_not_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
end | ||
end |
56 changes: 56 additions & 0 deletions
56
acceptance/tests/ensure_facter_values_for_custom_overrides_external.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,56 @@ | ||
test_name 'Ensure Facter values usage custom fact overriding external fact' do | ||
agents.each do |agent| | ||
|
||
output = on agent, puppet('config print modulepath') | ||
|
||
module_path = output.stdout.split(':')[0] | ||
foo_module_dir = File.join(module_path, 'foo') | ||
foo_custom_facts_dir = File.join(foo_module_dir, 'lib', 'facter') | ||
foo_external_facts_dir = File.join(foo_module_dir, 'facts.d') | ||
|
||
step 'create module directories' do | ||
agent.mkdir_p(foo_custom_facts_dir) | ||
agent.mkdir_p(foo_external_facts_dir) | ||
end | ||
|
||
teardown do | ||
agent.rm_rf(foo_module_dir) | ||
end | ||
|
||
step 'create external and custom fact' do | ||
create_remote_file(agent, File.join(foo_custom_facts_dir, "my_fizz_fact.rb"), <<-FILE) | ||
Facter.add(:fizz) do | ||
has_weight 10001 | ||
setcode do | ||
'custom_fact_buzz' | ||
end | ||
end | ||
FILE | ||
create_remote_file(agent, File.join(foo_external_facts_dir, "my_fizz_fact.txt"),'fizz=external_fact_buzz') | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"fizz\"])'") do |output| | ||
assert_match(/Notice: .*: custom_fact_buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"fizz\"))'") do |output| | ||
assert_match(/Notice: .*: custom_fact_buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"fizz\"))'") do |output| | ||
assert_match(/Notice: .*: custom_fact_buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.fizz\"))'") do |output| | ||
assert_match(/Notice: .*: custom_fact_buzz/, output.stdout) | ||
end | ||
end | ||
end | ||
end |
52 changes: 52 additions & 0 deletions
52
acceptance/tests/ensure_facter_values_for_dotted_custom_fact.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,52 @@ | ||
test_name 'Ensure Facter values usage for dotted custom fact' do | ||
agents.each do |agent| | ||
|
||
output = on agent, puppet('config print modulepath') | ||
|
||
module_path = output.stdout.split(':')[0] | ||
foo_module_dir = File.join(module_path, 'foo') | ||
foo_facts_dir = File.join(foo_module_dir, 'lib', 'facter') | ||
|
||
step 'create module directories' do | ||
agent.mkdir_p(foo_facts_dir) | ||
end | ||
|
||
teardown do | ||
agent.rm_rf(foo_module_dir) | ||
end | ||
|
||
step 'create simple custom fact' do | ||
create_remote_file(agent, File.join(foo_facts_dir, "my_fizz_fact.rb"), <<-FILE) | ||
Facter.add('f.i.z.z') do | ||
setcode do | ||
'buzz' | ||
end | ||
end | ||
FILE | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"f.i.z.z\"])'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"f.i.z.z\"))'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"\\\"f.i.z.z\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that custom fact is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.\\\"f.i.z.z\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
end | ||
end |
46 changes: 46 additions & 0 deletions
46
acceptance/tests/ensure_facter_values_for_dotted_external_fact.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,46 @@ | ||
test_name 'Ensure Facter values usage for dotted external fact' do | ||
agents.each do |agent| | ||
|
||
output = on agent, puppet('config print modulepath') | ||
|
||
module_path = output.stdout.split(':')[0] | ||
foo_module_dir = File.join(module_path, 'foo') | ||
foo_facts_dir = File.join(foo_module_dir, 'facts.d') | ||
|
||
step 'create module directories' do | ||
agent.mkdir_p(foo_facts_dir) | ||
end | ||
|
||
teardown do | ||
agent.rm_rf(foo_module_dir) | ||
end | ||
|
||
step 'create simple external fact' do | ||
create_remote_file(agent, File.join(foo_facts_dir, "my_fizz_fact.txt"),'f.i.z.z=buzz') | ||
end | ||
|
||
step 'check that external fact is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"f.i.z.z\"])'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that external fact is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"f.i.z.z\"))'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that external fact is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"\\\"f.i.z.z\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that external fact is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.\\\"f.i.z.z\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: buzz/, output.stdout) | ||
end | ||
end | ||
end | ||
end |
46 changes: 46 additions & 0 deletions
46
acceptance/tests/ensure_facter_values_for_external_overrides_core_dotted_fact.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,46 @@ | ||
test_name 'Ensure Facter values usage for external fact overriding core dotted fact' do | ||
agents.each do |agent| | ||
|
||
output = on agent, puppet('config print modulepath') | ||
|
||
module_path = output.stdout.split(':')[0] | ||
foo_module_dir = File.join(module_path, 'foo') | ||
foo_external_facts_dir = File.join(foo_module_dir, 'facts.d') | ||
|
||
step 'create module directories' do | ||
agent.mkdir_p(foo_external_facts_dir) | ||
end | ||
|
||
teardown do | ||
agent.rm_rf(foo_module_dir) | ||
end | ||
|
||
step 'create external and custom fact' do | ||
create_remote_file(agent, File.join(foo_external_facts_dir, "my_fizz_fact.txt"),'ruby.version=1.1.1') | ||
end | ||
|
||
step 'check that external fact is visible to puppet in $facts' do | ||
on agent, puppet("apply -e 'notice(\$facts[\"ruby.version\"])'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that external fact is visible to puppet in $facts.dig' do | ||
on agent, puppet("apply -e 'notice(\$facts.dig(\"ruby.version\"))'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that external fact is visible to puppet in $facts.get' do | ||
on agent, puppet("apply -e 'notice(\$facts.get(\"\\\"ruby.version\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
|
||
step 'check that external fact is visible to puppet in getvar' do | ||
on agent, puppet("apply -e 'notice(getvar(\"facts.\\\"ruby.version\\\"\"))'") do |output| | ||
assert_match(/Notice: .*: 1.1.1/, output.stdout) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.