facter 4.0.26 → 4.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,9 @@
1
+ test_name 'C100160: facter exits with success when asked for a non-existent fact' do
2
+ tag 'risk:high'
3
+
4
+ agents.each do |agent|
5
+ step 'facter should return exit code 0 for querying non-existing-fact without --strict flag' do
6
+ on(agent, facter('non-existing-fact'), :acceptable_exit_codes => 0)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ test_name "C96148: verify dmi facts" do
2
+ tag 'risk:med'
3
+
4
+ confine :except, :platform => 'aix' # no dmi support
5
+ confine :except, :platform => 'huawei' # no dmi support
6
+ confine :except, :platform => 'osx' # no dmi support
7
+ confine :except, :platform => 'sparc' # no dmi support
8
+ confine :except, :platform => 'ppc64' # no dmi support on linux on powerpc
9
+
10
+ require 'json'
11
+ require 'facter/acceptance/base_fact_utils'
12
+ extend Facter::Acceptance::BaseFactUtils
13
+
14
+ agents.each do |agent|
15
+ expected_facts = {
16
+ 'dmi.manufacturer' => /\w+/,
17
+ 'dmi.product.name' => /\w+/,
18
+ 'dmi.product.uuid' => /[-0-9A-Fa-f]+/,
19
+ }
20
+ unless agent['platform'] =~ /windows/
21
+ expected_facts.merge!({'dmi.bios.release_date' => /\d+\/\d+\/\d+/,
22
+ 'dmi.bios.vendor' => /\w+/,
23
+ 'dmi.bios.version' => /\d+/,
24
+ 'dmi.chassis.type' => /\w+/,
25
+ })
26
+ end
27
+ unless agent['platform'] =~ /windows|cisco|aarch64|el-/
28
+ expected_facts.merge!({'dmi.chassis.asset_tag' => /\w+/})
29
+ end
30
+ unless agent['platform'] =~ /cisco|aarch64|el-/
31
+ expected_facts.merge!({'dmi.product.serial_number' => /\w+/})
32
+ end
33
+ unless agent['platform'] =~ /windows|cisco|solaris|aarch64|el-/
34
+ expected_facts.merge!({'dmi.board.asset_tag' => /\w+|/,
35
+ 'dmi.board.manufacturer' => /\w+/,
36
+ 'dmi.board.product' => /\w+/,
37
+ 'dmi.board.serial_number' => /None|\w+/
38
+ })
39
+ end
40
+
41
+ step("verify that dmi structured fact contains facts") do
42
+ on(agent, facter("--json dmi")) do |facter_results|
43
+ json_facts = JSON.parse(facter_results.stdout)
44
+ expected_facts.each do |fact, value|
45
+ actual_fact = json_result_fact_by_key_path(json_facts, fact)
46
+ assert_match(value, actual_fact.to_s, "Incorrect fact pattern for '#{fact}'")
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,11 @@
1
+ test_name "C15286: verify facterversion fact" do
2
+ tag 'risk:low'
3
+
4
+ agents.each do |agent|
5
+ step("verify that fact facterversion is a version string") do
6
+ on(agent, facter("facterversion")) do |facter_result|
7
+ assert_match(/\d+\.\d+\.\d+/, facter_result.stdout.chomp, "Expected 'facterversion' fact to be a version string")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ test_name 'C100202: Facter identity facts resolve on all platforms' do
2
+ tag 'risk:high'
3
+
4
+ require 'json'
5
+
6
+ agents.each do |agent|
7
+ step 'Ensure the identity fact resolves as expected' do
8
+ if agent['platform'] =~ /windows/
9
+ # Regular expression to validate the username from facter in the form of '<domain>\<username>'
10
+ # Reference - https://msdn.microsoft.com/en-us/library/bb726984.aspx
11
+ # - The domain name can be any character or empty
12
+ # - Must contain a backslash between the domain and username
13
+ # - Username must be at least one character and not contain the following charaters; " / \ [ ] : ; | = , + * ? < >
14
+ expected_identity = {
15
+ 'user' => /.*\\[^\\\/\"\[\]:|<>+=;,?*@]+$/,
16
+ 'privileged' => 'true'
17
+ }
18
+ elsif agent['platform'] =~ /aix-/
19
+ expected_identity = {
20
+ 'gid' => '0',
21
+ 'group' => 'system',
22
+ 'uid' => '0',
23
+ 'user' => 'root',
24
+ 'privileged' => 'true'
25
+ }
26
+ elsif agent['platform'] =~ /osx-/
27
+ expected_identity = {
28
+ 'gid' => '0',
29
+ 'group' => 'wheel',
30
+ 'uid' => '0',
31
+ 'user' => 'root',
32
+ 'privileged' => 'true'
33
+ }
34
+ else
35
+ expected_identity = {
36
+ 'gid' => '0',
37
+ 'group' => 'root',
38
+ 'uid' => '0',
39
+ 'user' => 'root',
40
+ 'privileged' => 'true'
41
+ }
42
+ end
43
+
44
+ on(agent, facter('--json')) do |facter_result|
45
+ results = JSON.parse(facter_result.stdout)
46
+ expected_identity.each do |fact, value|
47
+ assert_match(value, results['identity'][fact].to_s, "Incorrect fact value for identity.#{fact}")
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ test_name '(FACT-1964) Facter mountpoints does not show rootfs as type for root directory' do
2
+
3
+ confine :to, :platform => /el/
4
+
5
+ agents.each do |agent|
6
+ step 'Ensure that mountpoints does not contain rootfs as type for root directory' do
7
+ on(agent, facter("mountpoints")) do |facter_result|
8
+ assert_no_match(/rootfs/, facter_result.stdout.chomp, "Expected mountpoint with rootfs type to not be present")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,93 @@
1
+ test_name 'C59029: networking facts should be fully populated' do
2
+ tag 'risk:high'
3
+
4
+ #
5
+ # This test is intended to ensure that networking facts resolves
6
+ # as expected across supported platforms.
7
+ #
8
+
9
+ @ip_regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
10
+ @netmask_regex = /^(((128|192|224|240|248|252|254)\.0\.0\.0)|(255\.(0|128|192|224|240|248|252|254)\.0\.0)|(255\.255\.(0|128|192|224|240|248|252|254)\.0)|(255\.255\.255\.(0|128|192|224|240|248|252|254)))$/
11
+
12
+ expected_networking = {
13
+ "networking.dhcp" => @ip_regex,
14
+ "networking.ip" => @ip_regex,
15
+ "networking.ip6" => /[a-f0-9]+:+/,
16
+ "networking.mac" => /[a-f0-9]{2}:/,
17
+ "networking.mtu" => /\d+/,
18
+ "networking.netmask" => @netmask_regex,
19
+ "networking.netmask6" => /[a-f0-9]+:/,
20
+ "networking.network" => @ip_regex,
21
+ "networking.network6" => /([a-f0-9]+)?:([a-f0-9]+)?/
22
+ }
23
+
24
+ agents.each do |agent|
25
+ primary_interface = fact_on(agent, 'networking.primary')
26
+ refute_empty(primary_interface)
27
+
28
+ expected_bindings = {
29
+ "networking.interfaces.#{primary_interface}.bindings.0.address" => @ip_regex,
30
+ "networking.interfaces.#{primary_interface}.bindings.0.netmask" => @netmask_regex,
31
+ "networking.interfaces.#{primary_interface}.bindings.0.network" => @ip_regex,
32
+ "networking.interfaces.#{primary_interface}.bindings6.0.address" => /[a-f0-9:]+/,
33
+ "networking.interfaces.#{primary_interface}.bindings6.0.netmask" => /[a-f0-9:]+/,
34
+ "networking.interfaces.#{primary_interface}.bindings6.0.network" => /[a-f0-9:]+/
35
+ }
36
+
37
+ if agent['platform'] =~ /eos|solaris|aix|cisco/
38
+ #remove the invalid networking facts on eccentric platforms
39
+ expected_networking.delete("networking.ip6")
40
+ expected_networking.delete("networking.netmask6")
41
+ expected_networking.delete("networking.network6")
42
+
43
+ #remove invalid bindings for the primary networking interface eccentric platforms
44
+ expected_bindings.delete("networking.interfaces.#{primary_interface}.bindings6.0.address")
45
+ expected_bindings.delete("networking.interfaces.#{primary_interface}.bindings6.0.netmask")
46
+ expected_bindings.delete("networking.interfaces.#{primary_interface}.bindings6.0.network")
47
+ end
48
+
49
+ if agent['platform'] =~ /aix|sparc|cisco|huawei|sles|s390x/
50
+ # some of our testing platforms do not use DHCP
51
+ expected_networking.delete("networking.dhcp")
52
+ end
53
+
54
+ if agent['platform'] =~ /cisco/
55
+ # Cisco main interface does not define netmask or network
56
+ expected_networking.delete("networking.network")
57
+ expected_networking.delete("networking.netmask")
58
+
59
+ #remove invalid bindings for Cisco's primary networking interface
60
+ expected_bindings.delete("networking.interfaces.#{primary_interface}.bindings.0.netmask")
61
+ expected_bindings.delete("networking.interfaces.#{primary_interface}.bindings.0.network")
62
+ end
63
+
64
+ step "Ensure the Networking fact resolves with reasonable values for at least one interface" do
65
+ expected_networking.each do |fact, value|
66
+ assert_match(value, fact_on(agent, fact).to_s)
67
+ end
68
+ end
69
+
70
+ step "Ensure bindings for the primary networking interface are present" do
71
+ expected_bindings.each do |fact, value|
72
+ assert_match(value, fact_on(agent, fact).to_s)
73
+ end
74
+ end
75
+ end
76
+
77
+ # Verify that IP Address v6 and network v6 is retrieved correctly and does not contain the interface identifier
78
+ agents.each do |agent|
79
+ if agent['platform'] =~ /windows/
80
+ step("verify that ipaddress6 is retrieved correctly") do
81
+ on(agent, facter("ipaddress6")) do |facter_result|
82
+ assert_match(/^[a-fA-F0-9:]+$/, facter_result.stdout.chomp)
83
+ end
84
+ end
85
+
86
+ step("verify that network6 is retrieved correctly") do
87
+ on(agent, facter("network6")) do |facter_result|
88
+ assert_match(/([a-fA-F0-9:]+)?:([a-fA-F0-9:]+)?$/, facter_result.stdout.chomp)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,12 @@
1
+ test_name "Test nim_type fact" do
2
+
3
+ confine :to, :platform => /aix/
4
+
5
+ agents.each do |agent|
6
+ step("verify that nim_type is retrieved correctly") do
7
+ on(agent, facter("nim_type")) do |facter_result|
8
+ assert_equal("standalone", facter_result.stdout.chomp)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ test_name "C59196: running facter as a non-root user should not produce permission errors" do
2
+ tag 'risk:high'
3
+
4
+ confine :except, :platform => 'windows' # this test currently only supported on unix systems FACT-1647
5
+ confine :except, :platform => 'aix' # system su(1) command prints errors cannot access parent directories and ticket FACT-1586
6
+ confine :except, :platform => 'cisco' # system su(1) command prints errors cannot access parent directories
7
+ confine :except, :platform => 'osx' # system su(1) command prints errors cannot access parent directories
8
+ confine :except, :platform => 'solaris' # system su(1) command prints errors cannot access parent directories
9
+ confine :except, :platform => 'eos-' # does not support user creation ARISTA-37
10
+
11
+ require 'facter/acceptance/user_fact_utils'
12
+ extend Facter::Acceptance::UserFactUtils
13
+
14
+ agents.each do |agent|
15
+ non_root_user = "nonroot"
16
+ facter_path = on(agent, "which facter").stdout.chomp
17
+
18
+ step "Agent #{agent}: create a #{non_root_user} user to run facter with" do
19
+ on(agent, "puppet resource user #{non_root_user} ensure=present shell='#{user_shell(agent)}'")
20
+ end
21
+
22
+ teardown do
23
+ on(agent, puppet("resource user #{non_root_user} ensure=absent"))
24
+ end
25
+
26
+ step "Agent #{agent}: run facter as #{non_root_user} and get no errors" do
27
+ on(agent, %Q[su #{non_root_user} -c "'#{facter_path}'"]) do |facter_results|
28
+ assert_empty(facter_results.stderr.chomp, "Expected no errors from facter when run as user #{non_root_user}")
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ test_name 'C14891: Facter should properly detect operatingsystem on Ubuntu after a Facter.clear' do
2
+ tag 'risk:high'
3
+
4
+ confine :to, :platform => /ubuntu/
5
+
6
+ require "puppet/acceptance/common_utils"
7
+
8
+ script_contents = <<-OS_DETECT
9
+ require 'facter'
10
+ Facter['operatingsystem'].value
11
+ Facter.clear
12
+ exit Facter['operatingsystem'].value == 'Ubuntu'
13
+ OS_DETECT
14
+
15
+ agents.each do |agent|
16
+ script_dir = agent.tmpdir('ubuntu')
17
+ script_name = File.join(script_dir, "facter_os_detection_test")
18
+ create_remote_file(agent, script_name, script_contents)
19
+
20
+ teardown do
21
+ on(agent, "rm -rf '#{script_dir}'")
22
+ end
23
+
24
+ on(agent, "#{Puppet::Acceptance::CommandUtils.ruby_command(agent)} #{script_name}", :acceptable_exit_codes => 0)
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ test_name 'C100193: Facter os, processors, and kernel facts resolve on all platforms' do
2
+ tag 'risk:high'
3
+
4
+ require 'json'
5
+ require 'facter/acceptance/base_fact_utils'
6
+ extend Facter::Acceptance::BaseFactUtils
7
+
8
+ agents.each do |agent|
9
+ step 'Ensure the os, processors, and kernel fact resolves as expected' do
10
+ expected_facts = os_processors_and_kernel_expected_facts(agent)
11
+ on(agent, facter('--json')) do |facter_result|
12
+ results = JSON.parse(facter_result.stdout)
13
+ expected_facts.each do |fact, value|
14
+ actual_fact = json_result_fact_by_key_path(results, fact)
15
+ assert_match(value, actual_fact.to_s, "Incorrect fact value for #{fact}")
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ test_name 'Querying the fqdn with a numeric hostname should not fail' do
2
+
3
+ # calling getaddrinfo with a numeric value on OS X does not fill the
4
+ # ai_canonname field of the addrinfo structure
5
+ confine :to, :platform => /^osx-/
6
+
7
+ agents.each do |agent|
8
+ original_hostname = agent.hostname.split('.').first
9
+ numeric_hostname = 42
10
+
11
+ teardown do
12
+ on(agent, "scutil --set HostName #{original_hostname}")
13
+ end
14
+
15
+ step "Change hostname from '#{original_hostname}' to '#{numeric_hostname}'" do
16
+ on(agent, "scutil --set HostName #{numeric_hostname}")
17
+ end
18
+
19
+ step 'Verify fqdn fact does not fail' do
20
+ on(agent, facter('fqdn'))
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,37 @@
1
+ test_name "C96148: verify partitions facts" do
2
+ tag 'risk:high'
3
+
4
+ confine :except, :platform => 'osx' # no partitions on osx
5
+ confine :except, :platform => 'windows' # no partitions on windows
6
+ confine :except, :platform => 'solaris' # no partitions on solaris
7
+
8
+ require 'json'
9
+
10
+ possible_facts = [
11
+ ['backing_file', /^\/.*/],
12
+ ['filesystem', /\w/],
13
+ ['uuid', /^[-a-zA-Z0-9]+$/],
14
+ ['partuuid', /^[-a-f0-9]+$/],
15
+ ['mount', /^\/.*/],
16
+ ['label', /.*/],
17
+ ['partlabel', /\w+/],
18
+ ]
19
+
20
+ agents.each do |agent|
21
+ step("verify that partitions contain facts") do
22
+ on(agent, facter("--json partitions")) do |facter_output|
23
+ facter_results = JSON.parse(facter_output.stdout)
24
+ facter_results['partitions'].each_key do |partition_name|
25
+ partition_facts = facter_results['partitions'][partition_name]
26
+ assert_match(/\d+\.\d+ [TGMK]iB/, partition_facts['size'], "Expected partition '#{partition_name}' fact 'size' to match expression")
27
+ assert(partition_facts['size_bytes'] >= 0, "Expected partition '#{partition_name}' fact 'size_bytes' to be positive")
28
+ possible_facts.each do |fact, expression|
29
+ unless partition_facts[fact].nil?
30
+ assert_match(expression, partition_facts[fact], "Expected partition '#{partition_name}' fact '#{fact}' to match expression")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ test_name "C89604: verify productname fact" do
2
+ tag 'risk:low'
3
+
4
+ confine :except, :platform => 'aix' # not supported on
5
+ confine :except, :platform => 'huawei' # not supported on
6
+ confine :except, :platform => 'ppc64' # not supported on linux on powerpc
7
+
8
+ agents.each do |agent|
9
+ step("verify the fact productname") do
10
+ on(agent, facter("productname")) do |facter_result|
11
+ assert_match(/\w+/, facter_result.stdout.chomp, "Expected fact 'productname' to be set")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,59 @@
1
+ test_name "C100305: The Ruby fact should resolve as expected in AIO" do
2
+ tag 'risk:high'
3
+
4
+ #
5
+ # This test is intended to ensure that the the ruby fact resolves
6
+ # as expected in AIO across supported platforms.
7
+ #
8
+ skip_test "Ruby fact test is confined to AIO" if @options[:type] != 'aio'
9
+
10
+ require 'json'
11
+ require 'facter/acceptance/base_fact_utils'
12
+ extend Facter::Acceptance::BaseFactUtils
13
+
14
+ agents.each do |agent|
15
+ step "Ensure the Ruby fact resolves as expected" do
16
+ case agent['platform']
17
+ when /windows/
18
+ ruby_platform = agent['ruby_arch'] == 'x64' ? 'x64-mingw32' : 'i386-mingw32'
19
+ when /osx/
20
+ ruby_platform = /x86_64-darwin[\d.]+/
21
+ when /aix/
22
+ ruby_platform = /powerpc-aix[\d.]+/
23
+ when /solaris/
24
+ if agent['platform'] =~ /sparc/
25
+ ruby_platform = /sparc-solaris[\d.]+/
26
+ else
27
+ ruby_platform = /i386-solaris[\d.]+/
28
+ end
29
+ when /cisco_ios_xr/
30
+ ruby_platform = /x86_64-linux/
31
+ when /huaweios/
32
+ ruby_platform = /powerpc-linux/
33
+ else
34
+ if agent['ruby_arch']
35
+ ruby_platform = agent['ruby_arch'] == 'x64' ? /(x86_64|powerpc64le|aarch64)-linux/ : /(i486|i686|s390x)-linux/
36
+ else
37
+ ruby_platform = agent['platform'] =~ /64/ ? /(x86_64|powerpc64le|aarch64)-linux/ : /(i486|i686|s390x)-linux/
38
+ end
39
+ end
40
+
41
+ ruby_version = /2\.\d+\.\d+/
42
+ expected_facts = {
43
+ 'ruby.platform' => ruby_platform,
44
+ 'ruby.sitedir' => /\/site_ruby/,
45
+ 'ruby.version' => ruby_version
46
+ }
47
+
48
+ step("verify that ruby structured fact contains facts") do
49
+ on(agent, facter("--json ruby")) do |facter_results|
50
+ json_facts = JSON.parse(facter_results.stdout)
51
+ expected_facts.each do |fact, value|
52
+ actual_fact = json_result_fact_by_key_path(json_facts, fact)
53
+ assert_match(value, actual_fact.to_s, "Incorrect fact pattern for '#{fact}'")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end