Skip to content

Commit

Permalink
(PA-3666) add tests to verify facts values from puppet
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Badescu committed Apr 20, 2021
1 parent fa43c49 commit 1dbdc9b
Show file tree
Hide file tree
Showing 15 changed files with 817 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ acceptance/tmp/*
acceptance/merged_options.rb
acceptance/.beaker/*
ext/smoke/*output.txt
*~
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
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
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 acceptance/tests/ensure_facter_values_for_dotted_custom_fact.rb
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 acceptance/tests/ensure_facter_values_for_dotted_external_fact.rb
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
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
Loading

0 comments on commit 1dbdc9b

Please sign in to comment.