facter 4.0.26 → 4.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (206) hide show
  1. checksums.yaml +4 -4
  2. data/.github/actions/presuite.rb +1 -12
  3. data/.github/workflows/acceptance_tests.yml +4 -4
  4. data/.github/workflows/checks.yaml +9 -3
  5. data/.github/workflows/coverage.yaml +1 -1
  6. data/.github/workflows/unit_tests.yaml +2 -2
  7. data/.rubocop.yml +5 -0
  8. data/.rubocop_todo.yml +6 -4
  9. data/CHANGELOG.md +22 -0
  10. data/Rakefile +2 -1
  11. data/VERSION +1 -1
  12. data/acceptance/.beaker.yml +15 -0
  13. data/acceptance/.gitignore +12 -0
  14. data/acceptance/Gemfile +24 -0
  15. data/acceptance/Rakefile +2 -0
  16. data/acceptance/bin/ci-bootstrap-from-artifacts.sh +55 -0
  17. data/acceptance/config/aio/options.rb +6 -0
  18. data/acceptance/config/git/options.rb +3 -0
  19. data/acceptance/config/nodes/aix-53-power.yaml +7 -0
  20. data/acceptance/config/nodes/aix-61-power.yaml +7 -0
  21. data/acceptance/config/nodes/aix-71-power.yaml +7 -0
  22. data/acceptance/config/nodes/huaweios-6-powerpc.yaml +7 -0
  23. data/acceptance/config/nodes/solaris-10-sparc.yaml +9 -0
  24. data/acceptance/config/nodes/solaris-11-sparc.yaml +9 -0
  25. data/acceptance/lib/facter/acceptance/base_fact_utils.rb +565 -0
  26. data/acceptance/lib/facter/acceptance/user_fact_utils.rb +132 -0
  27. data/acceptance/lib/helper.rb +3 -0
  28. data/acceptance/lib/puppet/acceptance/common_utils.rb +10 -0
  29. data/acceptance/lib/puppet/acceptance/git_utils.rb +19 -0
  30. data/acceptance/lib/puppet/acceptance/install_utils.rb +58 -0
  31. data/acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb +75 -0
  32. data/acceptance/tests/custom_facts/cached_custom_fact.rb +82 -0
  33. data/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb +106 -0
  34. data/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb +30 -0
  35. data/acceptance/tests/custom_facts/expand_command.rb +30 -0
  36. data/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb +40 -0
  37. data/acceptance/tests/custom_facts/not_expand_command.rb +30 -0
  38. data/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb +33 -0
  39. data/acceptance/tests/custom_facts/weighted_cached_custom_facts.rb +94 -0
  40. data/acceptance/tests/custom_facts/windows_not_expand_command.rb +30 -0
  41. data/acceptance/tests/external_facts/env_var_overrides_external_fact.rb +46 -0
  42. data/acceptance/tests/external_facts/external_dir_overrides_default_external_fact.rb +34 -0
  43. data/acceptance/tests/external_facts/external_fact_overrides_custom_fact.rb +29 -0
  44. data/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_10000_weight_or_less.rb +30 -0
  45. data/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_confine.rb +35 -0
  46. data/acceptance/tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb +49 -0
  47. data/acceptance/tests/external_facts/external_facts_only_run_once.rb +43 -0
  48. data/acceptance/tests/external_facts/fact_directory_precedence.rb +109 -0
  49. data/acceptance/tests/external_facts/handle_same_filename_in_different_dirs.rb +59 -0
  50. data/acceptance/tests/external_facts/non_root_users_default_external_fact_directory.rb +142 -0
  51. data/acceptance/tests/external_facts/root_uses_default_external_fact_dir.rb +34 -0
  52. data/acceptance/tests/external_facts/structured_executable_facts.rb +139 -0
  53. data/acceptance/tests/facter_returns_success_on_non_existent_fact.rb +9 -0
  54. data/acceptance/tests/facts/dmi.rb +51 -0
  55. data/acceptance/tests/facts/facterversion.rb +11 -0
  56. data/acceptance/tests/facts/identity.rb +52 -0
  57. data/acceptance/tests/facts/mountpoints_fact.rb +12 -0
  58. data/acceptance/tests/facts/networking_facts.rb +93 -0
  59. data/acceptance/tests/facts/nim_type.rb +12 -0
  60. data/acceptance/tests/facts/non_root_users_without_errors.rb +32 -0
  61. data/acceptance/tests/facts/operatingsystem_detection_after_clear_on_ubuntu.rb +26 -0
  62. data/acceptance/tests/facts/os_processors_and_kernel.rb +20 -0
  63. data/acceptance/tests/facts/osx_numeric_hostname.rb +23 -0
  64. data/acceptance/tests/facts/partitions.rb +37 -0
  65. data/acceptance/tests/facts/productname.rb +15 -0
  66. data/acceptance/tests/facts/ruby.rb +59 -0
  67. data/acceptance/tests/facts/ssh_key.rb +59 -0
  68. data/acceptance/tests/facts/validate_file_system_size_bytes.rb +37 -0
  69. data/acceptance/tests/facts/verify_tmpfs_file_system.rb +54 -0
  70. data/acceptance/tests/facts/windows_os.rb +64 -0
  71. data/acceptance/tests/load_libfacter.rb +66 -0
  72. data/acceptance/tests/no_errors_on_stderr.rb +10 -0
  73. data/acceptance/tests/options/color.rb +16 -0
  74. data/acceptance/tests/options/config.rb +27 -0
  75. data/acceptance/tests/options/config_file/blocklist.rb +35 -0
  76. data/acceptance/tests/options/config_file/blocklist_from_puppet_facts.rb +40 -0
  77. data/acceptance/tests/options/config_file/custom_dir_overridden_by_cli_custom_dir.rb +56 -0
  78. data/acceptance/tests/options/config_file/custom_facts.rb +42 -0
  79. data/acceptance/tests/options/config_file/custom_facts_list.rb +56 -0
  80. data/acceptance/tests/options/config_file/debug.rb +34 -0
  81. data/acceptance/tests/options/config_file/debug_override_config_file.rb +34 -0
  82. data/acceptance/tests/options/config_file/default_file_location.rb +37 -0
  83. data/acceptance/tests/options/config_file/external_dir_conflicts_with_cli_no_external_facts.rb +37 -0
  84. data/acceptance/tests/options/config_file/external_dir_overridden_by_cli_external_dir.rb +40 -0
  85. data/acceptance/tests/options/config_file/external_facts.rb +37 -0
  86. data/acceptance/tests/options/config_file/external_facts_list.rb +43 -0
  87. data/acceptance/tests/options/config_file/load_from_ruby.rb +73 -0
  88. data/acceptance/tests/options/config_file/log_level.rb +35 -0
  89. data/acceptance/tests/options/config_file/no_custom_facts_and_custom_dir.rb +43 -0
  90. data/acceptance/tests/options/config_file/no_custom_facts_and_facterlib.rb +43 -0
  91. data/acceptance/tests/options/config_file/no_custom_facts_and_load_path.rb +49 -0
  92. data/acceptance/tests/options/config_file/no_external_facts.rb +38 -0
  93. data/acceptance/tests/options/config_file/no_external_facts_and_external_dir.rb +34 -0
  94. data/acceptance/tests/options/config_file/no_ruby_disables_custom_facts.rb +52 -0
  95. data/acceptance/tests/options/config_file/no_ruby_disables_ruby_facts.rb +34 -0
  96. data/acceptance/tests/options/config_file/trace.rb +48 -0
  97. data/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_json_output.rb +92 -0
  98. data/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_text_output.rb +74 -0
  99. data/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_yaml_output.rb +88 -0
  100. data/acceptance/tests/options/config_file/ttls_cached_external_json_resolver.rb +79 -0
  101. data/acceptance/tests/options/config_file/ttls_cached_external_text_resolver.rb +78 -0
  102. data/acceptance/tests/options/config_file/ttls_cached_external_yaml_resolver.rb +78 -0
  103. data/acceptance/tests/options/config_file/ttls_cached_facts_clear_by_empty_ttls_cache_list.rb +71 -0
  104. data/acceptance/tests/options/config_file/ttls_cached_facts_creates_json_cache_file.rb +48 -0
  105. data/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_do_not_read_the_old_cached_value.rb +58 -0
  106. data/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_refresh_the_cached_value.rb +61 -0
  107. data/acceptance/tests/options/config_file/ttls_cached_facts_read_from_the_cached_value.rb +57 -0
  108. data/acceptance/tests/options/config_file/ttls_cached_facts_that_are_corrupt_are_refreshed.rb +53 -0
  109. data/acceptance/tests/options/config_file/ttls_cached_facts_that_are_empty_return_an_empty_value.rb +53 -0
  110. data/acceptance/tests/options/config_file/ttls_puppet_facts_creates_json_for_cached_facts.rb +45 -0
  111. data/acceptance/tests/options/config_file/ttls_puppet_facts_honors_cached_facts.rb +54 -0
  112. data/acceptance/tests/options/config_file/verbose.rb +34 -0
  113. data/acceptance/tests/options/custom_facts.rb +34 -0
  114. data/acceptance/tests/options/custom_facts_facterlib.rb +33 -0
  115. data/acceptance/tests/options/custom_facts_list.rb +48 -0
  116. data/acceptance/tests/options/custom_facts_load_path.rb +42 -0
  117. data/acceptance/tests/options/debug.rb +12 -0
  118. data/acceptance/tests/options/external_facts.rb +28 -0
  119. data/acceptance/tests/options/external_facts_list.rb +35 -0
  120. data/acceptance/tests/options/help.rb +13 -0
  121. data/acceptance/tests/options/json.rb +43 -0
  122. data/acceptance/tests/options/list_block_groups.rb +15 -0
  123. data/acceptance/tests/options/list_block_groups_facter_4.rb +15 -0
  124. data/acceptance/tests/options/list_cache_groups.rb +65 -0
  125. data/acceptance/tests/options/log_level.rb +13 -0
  126. data/acceptance/tests/options/no_block.rb +34 -0
  127. data/acceptance/tests/options/no_cache_should_not_cache_facts.rb +43 -0
  128. data/acceptance/tests/options/no_cache_should_not_load_cached_facts.rb +58 -0
  129. data/acceptance/tests/options/no_cache_should_not_refresh_cached_facts.rb +63 -0
  130. data/acceptance/tests/options/no_color.rb +16 -0
  131. data/acceptance/tests/options/no_custom_facts.rb +34 -0
  132. data/acceptance/tests/options/no_custom_facts_and_custom_dir.rb +19 -0
  133. data/acceptance/tests/options/no_custom_facts_and_facterlib.rb +34 -0
  134. data/acceptance/tests/options/no_custom_facts_and_load_path.rb +43 -0
  135. data/acceptance/tests/options/no_external_facts.rb +28 -0
  136. data/acceptance/tests/options/no_external_facts_and_external_dir.rb +19 -0
  137. data/acceptance/tests/options/no_ruby.rb +44 -0
  138. data/acceptance/tests/options/puppet_facts.rb +37 -0
  139. data/acceptance/tests/options/show_legacy.rb +18 -0
  140. data/acceptance/tests/options/strict.rb +11 -0
  141. data/acceptance/tests/options/trace.rb +36 -0
  142. data/acceptance/tests/options/verbose.rb +12 -0
  143. data/acceptance/tests/options/version.rb +12 -0
  144. data/acceptance/tests/options/yaml.rb +43 -0
  145. data/acceptance/tests/ticket_1123_facter_with_invalid_locale.rb +23 -0
  146. data/acceptance/tests/ticket_1238_hostname_fqdn.rb +57 -0
  147. data/lib/custom_facts/core/execution/base.rb +18 -18
  148. data/lib/custom_facts/util/collection.rb +2 -7
  149. data/lib/custom_facts/util/config.rb +1 -1
  150. data/lib/custom_facts/util/directory_loader.rb +51 -24
  151. data/lib/custom_facts/util/fact.rb +10 -1
  152. data/lib/custom_facts/util/resolution.rb +1 -1
  153. data/lib/facts/aix/aio_agent_version.rb +14 -0
  154. data/lib/facts/bsd/processors/count.rb +17 -0
  155. data/lib/facts/bsd/processors/models.rb +23 -0
  156. data/lib/facts/bsd/processors/speed.rb +17 -0
  157. data/lib/facts/freebsd/disks.rb +15 -0
  158. data/lib/facts/freebsd/partitions.rb +15 -0
  159. data/lib/facts/freebsd/processors/count.rb +17 -0
  160. data/lib/facts/freebsd/processors/models.rb +23 -0
  161. data/lib/facts/freebsd/processors/speed.rb +17 -0
  162. data/lib/facts/linux/aio_agent_version.rb +14 -0
  163. data/lib/facts/linux/ec2_metadata.rb +47 -0
  164. data/lib/facts/linux/ec2_userdata.rb +47 -0
  165. data/lib/facts/linux/is_virtual.rb +2 -5
  166. data/lib/facts/linux/virtual.rb +1 -5
  167. data/lib/facts/macosx/aio_agent_version.rb +14 -0
  168. data/lib/facts/macosx/interfaces.rb +2 -2
  169. data/lib/facts/macosx/networking/dhcp.rb +17 -0
  170. data/lib/facts/macosx/networking/interfaces.rb +21 -0
  171. data/lib/facts/macosx/networking/ip.rb +4 -1
  172. data/lib/facts/macosx/networking/ip6.rb +21 -0
  173. data/lib/facts/macosx/networking/mac.rb +4 -1
  174. data/lib/facts/macosx/networking/mtu.rb +20 -0
  175. data/lib/facts/macosx/networking/netmask.rb +21 -0
  176. data/lib/facts/macosx/networking/netmask6.rb +21 -0
  177. data/lib/facts/macosx/networking/network.rb +21 -0
  178. data/lib/facts/macosx/networking/network6.rb +21 -0
  179. data/lib/facts/macosx/networking/primary.rb +17 -0
  180. data/lib/facts/macosx/networking/scope6.rb +20 -0
  181. data/lib/facts/solaris/aio_agent_version.rb +14 -0
  182. data/lib/facts/windows/aio_agent_version.rb +14 -0
  183. data/lib/facts/windows/ec2_metadata.rb +23 -0
  184. data/lib/facts/windows/ec2_userdata.rb +23 -0
  185. data/lib/facts_utils/hypervisors.rb +10 -0
  186. data/lib/framework/core/cache_manager.rb +42 -18
  187. data/lib/framework/core/fact/external/external_fact_manager.rb +3 -2
  188. data/lib/framework/core/fact_loaders/external_fact_loader.rb +3 -2
  189. data/lib/framework/formatters/legacy_fact_formatter.rb +6 -5
  190. data/lib/framework/parsers/query_parser.rb +14 -2
  191. data/lib/models/loaded_fact.rb +3 -1
  192. data/lib/models/resolved_fact.rb +1 -1
  193. data/lib/models/searched_fact.rb +1 -0
  194. data/lib/resolvers/{agent_resolver.rb → aio_agent_version.rb} +4 -3
  195. data/lib/resolvers/bsd/ffi/ffi_helper.rb +31 -0
  196. data/lib/resolvers/bsd/processors.rb +47 -0
  197. data/lib/resolvers/ec2.rb +77 -0
  198. data/lib/resolvers/freebsd/ffi/ffi_helper.rb +42 -0
  199. data/lib/resolvers/freebsd/geom_resolver.rb +109 -0
  200. data/lib/resolvers/freebsd/processors.rb +44 -0
  201. data/lib/resolvers/macosx/networking.rb +110 -0
  202. data/lib/resolvers/networking_linux_resolver.rb +8 -30
  203. data/lib/resolvers/utils/networking.rb +70 -0
  204. data/lib/resolvers/windows/aio_agent_version.rb +56 -0
  205. metadata +175 -5
  206. data/lib/resolvers/macosx/ipaddress_resolver.rb +0 -52
@@ -0,0 +1,58 @@
1
+ # This test is intended to verify that the `--no-cache` command line flag will
2
+ # cause facter to not load already cached facts
3
+ test_name "C100123: --no-cache command-line option does not load facts from the cache" do
4
+ tag 'risk:high'
5
+
6
+ require 'facter/acceptance/user_fact_utils'
7
+ extend Facter::Acceptance::UserFactUtils
8
+
9
+ # the uptime fact should be resolvable on ALL systems
10
+ # Note: do NOT use the kernel fact, as it is used to configure the tests
11
+ cached_fact_name = "uptime"
12
+ bad_cached_fact_value = "CACHED_FACT_VALUE"
13
+ bad_cached_content = <<EOM
14
+ {
15
+ "#{cached_fact_name}": "fake #{bad_cached_fact_value}"
16
+ }
17
+ EOM
18
+
19
+
20
+ config = <<-FILE
21
+ cli : { debug : true }
22
+ facts : { ttls : [ { "#{cached_fact_name}" : 30 minutes } ] }
23
+ FILE
24
+
25
+ agents.each do |agent|
26
+ kernel_version = on(agent, facter('kernelmajversion')).stdout.chomp.to_f
27
+ config_dir = get_default_fact_dir(agent['platform'], kernel_version)
28
+ config_file = File.join(config_dir, "facter.conf")
29
+
30
+ cached_facts_dir = get_cached_facts_dir(agent['platform'], kernel_version)
31
+ cached_fact_file = File.join(cached_facts_dir, cached_fact_name)
32
+
33
+ teardown do
34
+ on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1])
35
+ on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1])
36
+ end
37
+
38
+ step "Agent #{agent}: create config file in default location" do
39
+ on(agent, "mkdir -p '#{config_dir}'")
40
+ create_remote_file(agent, config_file, config)
41
+ end
42
+
43
+ step "facter should not load facts from the cache when --no-cache is specified" do
44
+ # clear the fact cache
45
+ on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1])
46
+
47
+ # run once to cache the uptime fact
48
+ on(agent, facter(""))
49
+ # override cached content
50
+ create_remote_file(agent, cached_fact_file, bad_cached_content)
51
+
52
+ on(agent, facter("--no-cache #{cached_fact_name}")) do |facter_output|
53
+ assert_no_match(/loading cached values for .+ fact/, facter_output.stderr, "facter should not have tried to load any cached facts")
54
+ assert_no_match(/#{bad_cached_fact_value}/, facter_output.stdout, "facter should not have loaded the cached value")
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,63 @@
1
+ # This test is intended to verify that the `--no-cache` command line flag will
2
+ # cause facter to not refresh a cached fact that is expired
3
+ test_name "C100124: --no-cache does not refresh expired cached facts" do
4
+ tag 'risk:high'
5
+
6
+ require 'facter/acceptance/user_fact_utils'
7
+ extend Facter::Acceptance::UserFactUtils
8
+
9
+ # the uptime fact should be resolvable on ALL systems
10
+ # Note: do NOT use the kernel fact, as it is used to configure the tests
11
+ cached_fact_name = "uptime"
12
+ bad_cached_fact_value = "CACHED_FACT_VALUE"
13
+ bad_cached_content = <<EOM
14
+ {
15
+ "#{cached_fact_name}": "fake #{bad_cached_fact_value}"
16
+ }
17
+ EOM
18
+
19
+ config = <<-FILE
20
+ cli : { debug : true }
21
+ facts : { ttls : [ { "#{cached_fact_name}" : 30 minutes } ] }
22
+ FILE
23
+
24
+ agents.each do |agent|
25
+ kernel_version = on(agent, facter('kernelmajversion')).stdout.chomp.to_f
26
+ config_dir = get_default_fact_dir(agent['platform'], kernel_version)
27
+ config_file = File.join(config_dir, "facter.conf")
28
+
29
+ cached_facts_dir = get_cached_facts_dir(agent['platform'], kernel_version)
30
+ cached_fact_file = File.join(cached_facts_dir, cached_fact_name)
31
+
32
+ teardown do
33
+ on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1])
34
+ on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1])
35
+ end
36
+
37
+ step "Agent #{agent}: create config file in default location" do
38
+ on(agent, "mkdir -p '#{config_dir}'")
39
+ create_remote_file(agent, config_file, config)
40
+ end
41
+
42
+ step "facter should not refresh an expired cache when --no-cache is specified" do
43
+ # clear the fact cache
44
+ on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1])
45
+
46
+ # run once to cache the uptime fact
47
+ on(agent, facter(""))
48
+
49
+ # override cached content
50
+ create_remote_file(agent, cached_fact_file, bad_cached_content)
51
+ # update the modify time on the new cached fact to prompt a refresh
52
+ on(agent, "touch -mt 0301010000 '#{cached_fact_file}'")
53
+
54
+ on(agent, facter("--no-cache")) do |facter_output|
55
+ assert_no_match(/caching/, facter_output.stderr, "facter should not have tried to refresh the cache")
56
+ end
57
+
58
+ on(agent, "cat '#{cached_fact_file}'", :acceptable_exit_codes => [0]) do |cat_output|
59
+ assert_match(/#{bad_cached_content}/, cat_output.stdout, "facter should not have updated the cached value")
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,16 @@
1
+ # This test is intended to ensure with --debug and --no-color, facter does not send any escape sequences
2
+ # to colorize the output
3
+ test_name "C99975: --debug and --no-color command-line options should print DEBUG messages without color escape sequences" do
4
+ tag 'risk:low'
5
+
6
+ confine :except, :platform => 'windows' # On windows we don't get an escape sequence so we can't detect a color change
7
+
8
+ agents.each do |agent|
9
+ step "Agent #{agent}: retrieve debug info from stderr using --debug anod --no-color options" do
10
+ on(agent, facter('--debug --no-color')) do |facter_output|
11
+ assert_match(/DEBUG/, facter_output.stderr, "Expected DEBUG information in stderr")
12
+ refute_match(/\e\[0;/, facter_output.stderr, "Expected to output to not contain an escape sequence")
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ # This test verifies that --no-custom-facts does not load custom facts
2
+ test_name "C64171: custom fact command line option --no-custom-facts does not load custom facts" do
3
+ tag 'risk:med'
4
+
5
+ require 'facter/acceptance/user_fact_utils'
6
+ extend Facter::Acceptance::UserFactUtils
7
+
8
+ content = <<EOM
9
+ Facter.add('custom_fact') do
10
+ setcode do
11
+ "testvalue"
12
+ end
13
+ end
14
+ EOM
15
+
16
+ agents.each do |agent|
17
+ step "Agent #{agent}: create custom fact directory and custom fact" do
18
+ custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f)
19
+ on(agent, "mkdir -p '#{custom_dir}'")
20
+ custom_fact = File.join(custom_dir, 'custom_fact.rb')
21
+ create_remote_file(agent, custom_fact, content)
22
+
23
+ teardown do
24
+ on(agent, "rm -f '#{custom_fact}'")
25
+ end
26
+
27
+ step "Agent #{agent}: --no-custom-facts option should not load custom facts" do
28
+ on(agent, facter("--no-custom-facts custom_fact")) do |facter_output|
29
+ assert_equal("", facter_output.stdout.chomp, "Custom fact should not have resolved")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # This test verifies that calling facter with both --no-custom-facts and --custom-dir results
2
+ # in an options conflict error
3
+ test_name "C100001: custom fact commandline options --no-custom-facts together with --custom-dir should produce an error" do
4
+ tag 'risk:low'
5
+
6
+ agents.each do |agent|
7
+ custom_dir = agent.tmpdir('custom_dir')
8
+
9
+ teardown do
10
+ on(agent, "rm -rf '#{custom_dir}'")
11
+ end
12
+
13
+ step "Agent #{agent}: --no-custom-facts and --custom-dir options should result in a error" do
14
+ on(agent, facter("--no-custom-facts --custom-dir '#{custom_dir}'"), :acceptable_exit_codes => 1) do |facter_output|
15
+ assert_match(/options conflict/, facter_output.stderr.chomp, "Output does not contain error string")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # This test verifies that --no-custom-facts keeps facter from loading facts from the environment
2
+ # variable FACTERLIB
3
+ test_name "C100000: custom fact commandline options --no-custom-facts does not load from FACTERLIB" do
4
+ tag 'risk:low'
5
+
6
+ require 'facter/acceptance/user_fact_utils'
7
+ extend Facter::Acceptance::UserFactUtils
8
+
9
+ content = <<EOM
10
+ Facter.add('custom_fact') do
11
+ setcode do
12
+ "testvalue"
13
+ end
14
+ end
15
+ EOM
16
+
17
+ agents.each do |agent|
18
+ step "Agent #{agent}: create a custom fact directory and fact" do
19
+ facterlib_dir = agent.tmpdir('facterlib')
20
+ custom_fact = File.join(facterlib_dir, 'custom_fact.rb')
21
+ create_remote_file(agent, custom_fact, content)
22
+
23
+ teardown do
24
+ on(agent, "rm -rf '#{facterlib_dir}'")
25
+ end
26
+
27
+ step "Agent #{agent}: --no-custom-facts should ignore the FACTERLIB environment variable" do
28
+ on(agent, facter('--no-custom-facts custom_fact', :environment => { 'FACTERLIB' => facterlib_dir })) do |facter_output|
29
+ assert_equal("", facter_output.stdout.chomp, "Custom fact in FACTERLIB should not have resolved")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ # This tests verifies that when --no-custom-facts is used we do not look for
2
+ # 'facter' subdirectories in the $LOAD_PATH
3
+ #
4
+ # Facter searches all directories in the Ruby $LOAD_PATH variable for subdirectories
5
+ # named ‘facter’, and loads all Ruby files in those directories.
6
+ test_name "C100003: custom fact commandline options --no-custom-facts does not load $LOAD_PATH facter directories" do
7
+ confine :except, :platform => 'cisco_nexus' # see BKR-749
8
+ tag 'risk:low'
9
+
10
+ require 'puppet/acceptance/common_utils'
11
+ extend Puppet::Acceptance::CommandUtils
12
+
13
+ require 'facter/acceptance/user_fact_utils'
14
+ extend Facter::Acceptance::UserFactUtils
15
+
16
+ content = <<EOM
17
+ Facter.add('custom_fact') do
18
+ setcode do
19
+ "testvalue"
20
+ end
21
+ end
22
+ EOM
23
+
24
+ agents.each do |agent|
25
+ step("Agent #{agent}: determine the load path and create a custom facter directory on it") do
26
+ on(agent, "#{ruby_command(agent)} -e 'puts $LOAD_PATH[0]'")
27
+ load_path_facter_dir = File.join(stdout.chomp, 'facter')
28
+ on(agent, "mkdir -p \"#{load_path_facter_dir}\"")
29
+ custom_fact = File.join(load_path_facter_dir, 'custom_fact.rb')
30
+ create_remote_file(agent, custom_fact, content)
31
+
32
+ teardown do
33
+ on(agent, "rm -rf '#{load_path_facter_dir}'")
34
+ end
35
+
36
+ step("Agent #{agent}: using --no-custom-facts should not resolve facts on the $LOAD_PATH") do
37
+ on(agent, facter("--no-custom-facts custom_fact")) do |facter_output|
38
+ assert_equal("", facter_output.stdout.chomp, "Custom fact in $LOAD_PATH/facter should not have resolved")
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ # This test verifies that --no-external-facts does not load external facts
2
+
3
+ test_name "C99961: external fact command line option --no-external-facts does not load external facts" do
4
+ tag 'risk:medium'
5
+
6
+ require 'facter/acceptance/user_fact_utils'
7
+ extend Facter::Acceptance::UserFactUtils
8
+
9
+ agents.each do |agent|
10
+ step "Agent #{agent}: create external fact directory and external fact" do
11
+ external_dir = agent.tmpdir('external_dir')
12
+ ext = get_external_fact_script_extension(agent['platform'])
13
+ external_fact = File.join(external_dir, "external_fact#{ext}")
14
+ create_remote_file(agent, external_fact, external_fact_content(agent['platform'], 'external_fact', 'external_value'))
15
+ on(agent, "chmod +x '#{external_fact}'")
16
+
17
+ teardown do
18
+ on(agent, "rm -rf '#{external_dir}'")
19
+ end
20
+
21
+ step "Agent #{agent}: --no-external-facts option should not load external facts" do
22
+ on(agent, facter("--no-external-facts external_fact")) do |facter_output|
23
+ assert_equal("", facter_output.stdout.chomp, "External fact should not have resolved")
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # This test verifies that calling facter with both --no-external-facts and --external-dir results
2
+ # in an options conflict error
3
+ test_name "C100002: external fact commandline options --no-external-facts together with --external-dir should produce an error" do
4
+ tag 'risk:low'
5
+
6
+ agents.each do |agent|
7
+ external_dir = agent.tmpdir('external_dir')
8
+
9
+ teardown do
10
+ on(agent, "rm -rf '#{external_dir}'")
11
+ end
12
+
13
+ step "Agent #{agent}: --no-external-facts and --external-dir options should result in a error" do
14
+ on(agent, facter("--no-external-facts --external-dir '#{external_dir}'"), :acceptable_exit_codes => 1) do |facter_output|
15
+ assert_match(/options conflict/, facter_output.stderr.chomp, "Output does not contain error string")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ # These tests are intended to ensure that the --no-ruby command-line option
2
+ # works properly. The first ensures that the built in Ruby fact does not resolve
3
+ # when using the --no-ruby fact, and also checks that the 'No Ruby' warning does
4
+ # not appear in stderr. The second test ensures that custom facts are not resolved
5
+ # when the --no-ruby option is present.
6
+ test_name "C99987: --no-ruby commandline option" do
7
+
8
+ require 'facter/acceptance/user_fact_utils'
9
+ extend Facter::Acceptance::UserFactUtils
10
+
11
+ content = <<EOM
12
+ Facter.add('custom_fact') do
13
+ setcode do
14
+ "testvalue"
15
+ end
16
+ end
17
+ EOM
18
+
19
+ agents.each do |agent|
20
+ step "--no-ruby option should disable Ruby and facts requiring ruby from being loaded" do
21
+ on(agent, facter("--no-ruby ruby")) do
22
+ assert_equal("", stdout.chomp, "Expected Ruby and Ruby fact to be disabled, but got output: #{stdout.chomp}")
23
+ assert_equal("", stderr.chomp, "Expected no warnings about Ruby on stderr, but got output: #{stderr.chomp}")
24
+ end
25
+ end
26
+
27
+ step "--no-ruby option should disable custom facts" do
28
+ step "Agent #{agent}: create custom fact directory and custom fact" do
29
+ custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f)
30
+ on(agent, "mkdir -p '#{custom_dir}'")
31
+ custom_fact = File.join(custom_dir, 'custom_fact.rb')
32
+ create_remote_file(agent, custom_fact, content)
33
+
34
+ teardown do
35
+ on(agent, "rm -f '#{custom_fact}'")
36
+ end
37
+
38
+ on(agent, facter('--no-ruby custom_fact', :environment => { 'FACTERLIB' => custom_dir })) do
39
+ assert_equal("", stdout.chomp, "Expected custom fact to be disabled while using --no-ruby option, but it resolved as #{stdout.chomp}")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ # Verify that -p loads external and custom facts from puppet locations
2
+ test_name "C14783: facter -p loads facts from puppet" do
3
+ tag 'risk:high'
4
+
5
+ confine :to, :platform => /Skipped/
6
+
7
+ agents.each do |agent|
8
+ external_dir = agent.puppet['pluginfactdest']
9
+ external_file = File.join(external_dir, "external.txt")
10
+ custom_dir = File.join(agent.puppet['plugindest'], "facter")
11
+ custom_file = "#{custom_dir}/custom.rb"
12
+
13
+ teardown do
14
+ on agent, "rm -f '#{external_file}' '#{custom_file}'"
15
+ end
16
+
17
+ step "Agent #{agent}: create external fact" do
18
+ on agent, "mkdir -p '#{external_dir}'"
19
+ create_remote_file(agent, external_file, "external=external")
20
+ end
21
+
22
+ step "Agent #{agent}: create custom fact" do
23
+ on agent, "mkdir -p '#{custom_dir}'"
24
+ create_remote_file(agent, custom_file, "Facter.add(:custom) { setcode { 'custom' } }")
25
+ end
26
+
27
+ step "Agent #{agent}: verify facts" do
28
+ on(agent, facter("-p external")) do |facter_output|
29
+ assert_equal("external", facter_output.stdout.chomp)
30
+ end
31
+
32
+ on(agent, facter("-p custom")) do |facter_output|
33
+ assert_equal("custom", facter_output.stdout.chomp)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ # This test is intended to demonstrate that the `--show-legacy` command line option
2
+ # causes hidden old facts to appear in the fact list.
3
+ test_name "C87580: --show-legacy command-line option results in output with legacy (hidden) facts" do
4
+
5
+ agents.each do |agent|
6
+ step "Agent #{agent}: retrieve legacy output using a hash" do
7
+ on(agent, facter("--show-legacy")) do
8
+ assert_match(/^rubyversion => [0-9]+\.[0-9]+\.[0-9]+$/, stdout.chomp, 'hash legacy output does not contain legacy fact rubyversion')
9
+ end
10
+ end
11
+
12
+ step "Agent #{agent}: retrieve legacy output using the --json option" do
13
+ on(agent, facter("--show-legacy --json")) do
14
+ assert_match(/^ "rubyversion": "[0-9]+\.[0-9]+\.[0-9]+",$/, stdout.chomp, 'json legacy output does not contain legacy fact rubyversion')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ test_name 'C98098: --strict flag returns errors on non-existent facts' do
2
+ tag 'risk:high'
3
+
4
+ agents.each do |agent|
5
+ step 'facter should return exit code 1 for querying non-existing-fact with --strict flag' do
6
+ on(agent, facter('non-existing-fact --strict'), :acceptable_exit_codes => 1) do |facter_output|
7
+ assert_match(/ERROR\s+.* - .*fact "non-existing-fact" does not exist/, facter_output.stderr, 'Unexpected error was detected!')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ # This test is intended to ensure that the --trace command-line option works
2
+ # properly. This option provides backtraces for erroring custom Ruby facts.
3
+ # To test, we try to resolve an erroneous custom fact and catch the backtrace.
4
+ test_name "C99982: --trace command-line option enables backtraces for custom facts" do
5
+
6
+ require 'facter/acceptance/user_fact_utils'
7
+ extend Facter::Acceptance::UserFactUtils
8
+
9
+ content = <<EOM
10
+ Facter.add('custom_fact') do
11
+ setcode do
12
+ non_existent_value
13
+ end
14
+ end
15
+ EOM
16
+
17
+ agents.each do |agent|
18
+ step "Agent #{agent}: create custom fact directory and executable custom fact" do
19
+ custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f)
20
+ on(agent, "mkdir -p '#{custom_dir}'")
21
+ custom_fact = File.join(custom_dir, 'custom_fact.rb')
22
+ create_remote_file(agent, custom_fact, content)
23
+ on(agent, "chmod +x '#{custom_fact}'")
24
+
25
+ teardown do
26
+ on(agent, "rm -f '#{custom_fact}'")
27
+ end
28
+
29
+ step "--trace option should provide a backtrace for a custom fact with errors" do
30
+ on(agent, facter("--custom-dir '#{custom_dir}' --trace custom_fact"), :acceptable_exit_codes => [1]) do
31
+ assert_match(/backtrace:\s+#{custom_fact}/, stderr, "Expected a backtrace for erroneous custom fact")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end