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.
- checksums.yaml +4 -4
- data/.github/actions/presuite.rb +1 -12
- data/.github/workflows/acceptance_tests.yml +4 -4
- data/.github/workflows/checks.yaml +9 -3
- data/.github/workflows/coverage.yaml +1 -1
- data/.github/workflows/unit_tests.yaml +2 -2
- data/.rubocop.yml +5 -0
- data/.rubocop_todo.yml +6 -4
- data/CHANGELOG.md +22 -0
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/acceptance/.beaker.yml +15 -0
- data/acceptance/.gitignore +12 -0
- data/acceptance/Gemfile +24 -0
- data/acceptance/Rakefile +2 -0
- data/acceptance/bin/ci-bootstrap-from-artifacts.sh +55 -0
- data/acceptance/config/aio/options.rb +6 -0
- data/acceptance/config/git/options.rb +3 -0
- data/acceptance/config/nodes/aix-53-power.yaml +7 -0
- data/acceptance/config/nodes/aix-61-power.yaml +7 -0
- data/acceptance/config/nodes/aix-71-power.yaml +7 -0
- data/acceptance/config/nodes/huaweios-6-powerpc.yaml +7 -0
- data/acceptance/config/nodes/solaris-10-sparc.yaml +9 -0
- data/acceptance/config/nodes/solaris-11-sparc.yaml +9 -0
- data/acceptance/lib/facter/acceptance/base_fact_utils.rb +565 -0
- data/acceptance/lib/facter/acceptance/user_fact_utils.rb +132 -0
- data/acceptance/lib/helper.rb +3 -0
- data/acceptance/lib/puppet/acceptance/common_utils.rb +10 -0
- data/acceptance/lib/puppet/acceptance/git_utils.rb +19 -0
- data/acceptance/lib/puppet/acceptance/install_utils.rb +58 -0
- data/acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb +75 -0
- data/acceptance/tests/custom_facts/cached_custom_fact.rb +82 -0
- data/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb +106 -0
- data/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb +30 -0
- data/acceptance/tests/custom_facts/expand_command.rb +30 -0
- data/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb +40 -0
- data/acceptance/tests/custom_facts/not_expand_command.rb +30 -0
- data/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb +33 -0
- data/acceptance/tests/custom_facts/weighted_cached_custom_facts.rb +94 -0
- data/acceptance/tests/custom_facts/windows_not_expand_command.rb +30 -0
- data/acceptance/tests/external_facts/env_var_overrides_external_fact.rb +46 -0
- data/acceptance/tests/external_facts/external_dir_overrides_default_external_fact.rb +34 -0
- data/acceptance/tests/external_facts/external_fact_overrides_custom_fact.rb +29 -0
- data/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_10000_weight_or_less.rb +30 -0
- data/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_confine.rb +35 -0
- data/acceptance/tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb +49 -0
- data/acceptance/tests/external_facts/external_facts_only_run_once.rb +43 -0
- data/acceptance/tests/external_facts/fact_directory_precedence.rb +109 -0
- data/acceptance/tests/external_facts/handle_same_filename_in_different_dirs.rb +59 -0
- data/acceptance/tests/external_facts/non_root_users_default_external_fact_directory.rb +142 -0
- data/acceptance/tests/external_facts/root_uses_default_external_fact_dir.rb +34 -0
- data/acceptance/tests/external_facts/structured_executable_facts.rb +139 -0
- data/acceptance/tests/facter_returns_success_on_non_existent_fact.rb +9 -0
- data/acceptance/tests/facts/dmi.rb +51 -0
- data/acceptance/tests/facts/facterversion.rb +11 -0
- data/acceptance/tests/facts/identity.rb +52 -0
- data/acceptance/tests/facts/mountpoints_fact.rb +12 -0
- data/acceptance/tests/facts/networking_facts.rb +93 -0
- data/acceptance/tests/facts/nim_type.rb +12 -0
- data/acceptance/tests/facts/non_root_users_without_errors.rb +32 -0
- data/acceptance/tests/facts/operatingsystem_detection_after_clear_on_ubuntu.rb +26 -0
- data/acceptance/tests/facts/os_processors_and_kernel.rb +20 -0
- data/acceptance/tests/facts/osx_numeric_hostname.rb +23 -0
- data/acceptance/tests/facts/partitions.rb +37 -0
- data/acceptance/tests/facts/productname.rb +15 -0
- data/acceptance/tests/facts/ruby.rb +59 -0
- data/acceptance/tests/facts/ssh_key.rb +59 -0
- data/acceptance/tests/facts/validate_file_system_size_bytes.rb +37 -0
- data/acceptance/tests/facts/verify_tmpfs_file_system.rb +54 -0
- data/acceptance/tests/facts/windows_os.rb +64 -0
- data/acceptance/tests/load_libfacter.rb +66 -0
- data/acceptance/tests/no_errors_on_stderr.rb +10 -0
- data/acceptance/tests/options/color.rb +16 -0
- data/acceptance/tests/options/config.rb +27 -0
- data/acceptance/tests/options/config_file/blocklist.rb +35 -0
- data/acceptance/tests/options/config_file/blocklist_from_puppet_facts.rb +40 -0
- data/acceptance/tests/options/config_file/custom_dir_overridden_by_cli_custom_dir.rb +56 -0
- data/acceptance/tests/options/config_file/custom_facts.rb +42 -0
- data/acceptance/tests/options/config_file/custom_facts_list.rb +56 -0
- data/acceptance/tests/options/config_file/debug.rb +34 -0
- data/acceptance/tests/options/config_file/debug_override_config_file.rb +34 -0
- data/acceptance/tests/options/config_file/default_file_location.rb +37 -0
- data/acceptance/tests/options/config_file/external_dir_conflicts_with_cli_no_external_facts.rb +37 -0
- data/acceptance/tests/options/config_file/external_dir_overridden_by_cli_external_dir.rb +40 -0
- data/acceptance/tests/options/config_file/external_facts.rb +37 -0
- data/acceptance/tests/options/config_file/external_facts_list.rb +43 -0
- data/acceptance/tests/options/config_file/load_from_ruby.rb +73 -0
- data/acceptance/tests/options/config_file/log_level.rb +35 -0
- data/acceptance/tests/options/config_file/no_custom_facts_and_custom_dir.rb +43 -0
- data/acceptance/tests/options/config_file/no_custom_facts_and_facterlib.rb +43 -0
- data/acceptance/tests/options/config_file/no_custom_facts_and_load_path.rb +49 -0
- data/acceptance/tests/options/config_file/no_external_facts.rb +38 -0
- data/acceptance/tests/options/config_file/no_external_facts_and_external_dir.rb +34 -0
- data/acceptance/tests/options/config_file/no_ruby_disables_custom_facts.rb +52 -0
- data/acceptance/tests/options/config_file/no_ruby_disables_ruby_facts.rb +34 -0
- data/acceptance/tests/options/config_file/trace.rb +48 -0
- data/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_json_output.rb +92 -0
- data/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_text_output.rb +74 -0
- data/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_yaml_output.rb +88 -0
- data/acceptance/tests/options/config_file/ttls_cached_external_json_resolver.rb +79 -0
- data/acceptance/tests/options/config_file/ttls_cached_external_text_resolver.rb +78 -0
- data/acceptance/tests/options/config_file/ttls_cached_external_yaml_resolver.rb +78 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_clear_by_empty_ttls_cache_list.rb +71 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_creates_json_cache_file.rb +48 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_do_not_read_the_old_cached_value.rb +58 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_refresh_the_cached_value.rb +61 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_read_from_the_cached_value.rb +57 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_that_are_corrupt_are_refreshed.rb +53 -0
- data/acceptance/tests/options/config_file/ttls_cached_facts_that_are_empty_return_an_empty_value.rb +53 -0
- data/acceptance/tests/options/config_file/ttls_puppet_facts_creates_json_for_cached_facts.rb +45 -0
- data/acceptance/tests/options/config_file/ttls_puppet_facts_honors_cached_facts.rb +54 -0
- data/acceptance/tests/options/config_file/verbose.rb +34 -0
- data/acceptance/tests/options/custom_facts.rb +34 -0
- data/acceptance/tests/options/custom_facts_facterlib.rb +33 -0
- data/acceptance/tests/options/custom_facts_list.rb +48 -0
- data/acceptance/tests/options/custom_facts_load_path.rb +42 -0
- data/acceptance/tests/options/debug.rb +12 -0
- data/acceptance/tests/options/external_facts.rb +28 -0
- data/acceptance/tests/options/external_facts_list.rb +35 -0
- data/acceptance/tests/options/help.rb +13 -0
- data/acceptance/tests/options/json.rb +43 -0
- data/acceptance/tests/options/list_block_groups.rb +15 -0
- data/acceptance/tests/options/list_block_groups_facter_4.rb +15 -0
- data/acceptance/tests/options/list_cache_groups.rb +65 -0
- data/acceptance/tests/options/log_level.rb +13 -0
- data/acceptance/tests/options/no_block.rb +34 -0
- data/acceptance/tests/options/no_cache_should_not_cache_facts.rb +43 -0
- data/acceptance/tests/options/no_cache_should_not_load_cached_facts.rb +58 -0
- data/acceptance/tests/options/no_cache_should_not_refresh_cached_facts.rb +63 -0
- data/acceptance/tests/options/no_color.rb +16 -0
- data/acceptance/tests/options/no_custom_facts.rb +34 -0
- data/acceptance/tests/options/no_custom_facts_and_custom_dir.rb +19 -0
- data/acceptance/tests/options/no_custom_facts_and_facterlib.rb +34 -0
- data/acceptance/tests/options/no_custom_facts_and_load_path.rb +43 -0
- data/acceptance/tests/options/no_external_facts.rb +28 -0
- data/acceptance/tests/options/no_external_facts_and_external_dir.rb +19 -0
- data/acceptance/tests/options/no_ruby.rb +44 -0
- data/acceptance/tests/options/puppet_facts.rb +37 -0
- data/acceptance/tests/options/show_legacy.rb +18 -0
- data/acceptance/tests/options/strict.rb +11 -0
- data/acceptance/tests/options/trace.rb +36 -0
- data/acceptance/tests/options/verbose.rb +12 -0
- data/acceptance/tests/options/version.rb +12 -0
- data/acceptance/tests/options/yaml.rb +43 -0
- data/acceptance/tests/ticket_1123_facter_with_invalid_locale.rb +23 -0
- data/acceptance/tests/ticket_1238_hostname_fqdn.rb +57 -0
- data/lib/custom_facts/core/execution/base.rb +18 -18
- data/lib/custom_facts/util/collection.rb +2 -7
- data/lib/custom_facts/util/config.rb +1 -1
- data/lib/custom_facts/util/directory_loader.rb +51 -24
- data/lib/custom_facts/util/fact.rb +10 -1
- data/lib/custom_facts/util/resolution.rb +1 -1
- data/lib/facts/aix/aio_agent_version.rb +14 -0
- data/lib/facts/bsd/processors/count.rb +17 -0
- data/lib/facts/bsd/processors/models.rb +23 -0
- data/lib/facts/bsd/processors/speed.rb +17 -0
- data/lib/facts/freebsd/disks.rb +15 -0
- data/lib/facts/freebsd/partitions.rb +15 -0
- data/lib/facts/freebsd/processors/count.rb +17 -0
- data/lib/facts/freebsd/processors/models.rb +23 -0
- data/lib/facts/freebsd/processors/speed.rb +17 -0
- data/lib/facts/linux/aio_agent_version.rb +14 -0
- data/lib/facts/linux/ec2_metadata.rb +47 -0
- data/lib/facts/linux/ec2_userdata.rb +47 -0
- data/lib/facts/linux/is_virtual.rb +2 -5
- data/lib/facts/linux/virtual.rb +1 -5
- data/lib/facts/macosx/aio_agent_version.rb +14 -0
- data/lib/facts/macosx/interfaces.rb +2 -2
- data/lib/facts/macosx/networking/dhcp.rb +17 -0
- data/lib/facts/macosx/networking/interfaces.rb +21 -0
- data/lib/facts/macosx/networking/ip.rb +4 -1
- data/lib/facts/macosx/networking/ip6.rb +21 -0
- data/lib/facts/macosx/networking/mac.rb +4 -1
- data/lib/facts/macosx/networking/mtu.rb +20 -0
- data/lib/facts/macosx/networking/netmask.rb +21 -0
- data/lib/facts/macosx/networking/netmask6.rb +21 -0
- data/lib/facts/macosx/networking/network.rb +21 -0
- data/lib/facts/macosx/networking/network6.rb +21 -0
- data/lib/facts/macosx/networking/primary.rb +17 -0
- data/lib/facts/macosx/networking/scope6.rb +20 -0
- data/lib/facts/solaris/aio_agent_version.rb +14 -0
- data/lib/facts/windows/aio_agent_version.rb +14 -0
- data/lib/facts/windows/ec2_metadata.rb +23 -0
- data/lib/facts/windows/ec2_userdata.rb +23 -0
- data/lib/facts_utils/hypervisors.rb +10 -0
- data/lib/framework/core/cache_manager.rb +42 -18
- data/lib/framework/core/fact/external/external_fact_manager.rb +3 -2
- data/lib/framework/core/fact_loaders/external_fact_loader.rb +3 -2
- data/lib/framework/formatters/legacy_fact_formatter.rb +6 -5
- data/lib/framework/parsers/query_parser.rb +14 -2
- data/lib/models/loaded_fact.rb +3 -1
- data/lib/models/resolved_fact.rb +1 -1
- data/lib/models/searched_fact.rb +1 -0
- data/lib/resolvers/{agent_resolver.rb → aio_agent_version.rb} +4 -3
- data/lib/resolvers/bsd/ffi/ffi_helper.rb +31 -0
- data/lib/resolvers/bsd/processors.rb +47 -0
- data/lib/resolvers/ec2.rb +77 -0
- data/lib/resolvers/freebsd/ffi/ffi_helper.rb +42 -0
- data/lib/resolvers/freebsd/geom_resolver.rb +109 -0
- data/lib/resolvers/freebsd/processors.rb +44 -0
- data/lib/resolvers/macosx/networking.rb +110 -0
- data/lib/resolvers/networking_linux_resolver.rb +8 -30
- data/lib/resolvers/utils/networking.rb +70 -0
- data/lib/resolvers/windows/aio_agent_version.rb +56 -0
- metadata +175 -5
- data/lib/resolvers/macosx/ipaddress_resolver.rb +0 -52
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
module Facter
|
|
2
|
+
module Acceptance
|
|
3
|
+
module UserFactUtils
|
|
4
|
+
|
|
5
|
+
# Determine paths for testing custom and external facts.
|
|
6
|
+
# Paths vary by platform.
|
|
7
|
+
|
|
8
|
+
# Retrieve the path of a non-standard directory for custom or external facts.
|
|
9
|
+
#
|
|
10
|
+
def get_user_fact_dir(platform, version)
|
|
11
|
+
if platform =~ /windows/
|
|
12
|
+
if version < 6.0
|
|
13
|
+
File.join('C:', 'Documents and Settings', 'All Users', 'Application Data', 'PuppetLabs', 'facter', 'custom')
|
|
14
|
+
else
|
|
15
|
+
File.join('C:', 'ProgramData', 'PuppetLabs', 'facter', 'custom')
|
|
16
|
+
end
|
|
17
|
+
else
|
|
18
|
+
File.join('/', 'opt', 'puppetlabs', 'facter', 'custom')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Retrieve the path of the standard facts.d directory.
|
|
23
|
+
#
|
|
24
|
+
def get_factsd_dir(platform, version)
|
|
25
|
+
if platform =~ /windows/
|
|
26
|
+
if version < 6.0
|
|
27
|
+
File.join('C:', 'Documents and Settings', 'All Users', 'Application Data', 'PuppetLabs', 'facter', 'facts.d')
|
|
28
|
+
else
|
|
29
|
+
File.join('C:', 'ProgramData', 'PuppetLabs', 'facter', 'facts.d')
|
|
30
|
+
end
|
|
31
|
+
else
|
|
32
|
+
File.join('/', 'opt', 'puppetlabs', 'facter', 'facts.d')
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Retrieve the path of the standard cached facts directory.
|
|
37
|
+
#
|
|
38
|
+
def get_cached_facts_dir(platform, version)
|
|
39
|
+
if platform =~ /windows/
|
|
40
|
+
if version < 6.0
|
|
41
|
+
File.join('C:', 'Documents and Settings', 'All Users', 'Application Data', 'PuppetLabs', 'facter', 'cache', 'cached_facts')
|
|
42
|
+
else
|
|
43
|
+
File.join('C:', 'ProgramData', 'PuppetLabs', 'facter', 'cache', 'cached_facts')
|
|
44
|
+
end
|
|
45
|
+
else
|
|
46
|
+
File.join('/', 'opt', 'puppetlabs', 'facter', 'cache', 'cached_facts')
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Retrieve the path of the facts.d directory in /etc/facter on Unix systems
|
|
51
|
+
#
|
|
52
|
+
def get_etc_factsd_dir(platform)
|
|
53
|
+
if platform =~ /windows/
|
|
54
|
+
raise "get_etc_factsd_dir: not a supported directory on Windows"
|
|
55
|
+
else
|
|
56
|
+
File.join('/', 'etc', 'facter', 'facts.d')
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Retrieve the path of the facts.d diretory in /etc/puppetlabs/facter on Unix systems
|
|
61
|
+
#
|
|
62
|
+
def get_etc_puppetlabs_factsd_dir(platform)
|
|
63
|
+
if platform =~ /windows/
|
|
64
|
+
raise "get_etc_puppetlabs_factsd_dir: not a supported directory on Windows"
|
|
65
|
+
else
|
|
66
|
+
File.join('/', 'etc', 'puppetlabs', 'facter', 'facts.d')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Retrieve the extension to use for an external fact script.
|
|
71
|
+
# Windows uses '.bat' and everything else uses '.sh'
|
|
72
|
+
def get_external_fact_script_extension(platform)
|
|
73
|
+
if platform =~ /windows/
|
|
74
|
+
'.bat'
|
|
75
|
+
else
|
|
76
|
+
'.sh'
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Retrieve the path to default location of facter.conf file.
|
|
81
|
+
#
|
|
82
|
+
def get_default_fact_dir(platform, version)
|
|
83
|
+
if platform =~ /windows/
|
|
84
|
+
File.join('C:', 'ProgramData', 'PuppetLabs', 'facter', 'etc')
|
|
85
|
+
else
|
|
86
|
+
File.join('/', 'etc', 'puppetlabs', 'facter')
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Return the content for an external fact based on the platform supplied
|
|
91
|
+
#
|
|
92
|
+
def external_fact_content(platform, key='external_fact', value='test_value')
|
|
93
|
+
unix_content = <<EOM
|
|
94
|
+
#!/bin/sh
|
|
95
|
+
echo "#{key}=#{value}"
|
|
96
|
+
EOM
|
|
97
|
+
|
|
98
|
+
win_content = <<EOM
|
|
99
|
+
@echo off
|
|
100
|
+
echo #{key}=#{value}
|
|
101
|
+
EOM
|
|
102
|
+
|
|
103
|
+
if platform =~ /windows/
|
|
104
|
+
win_content
|
|
105
|
+
else
|
|
106
|
+
unix_content
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Return the content for a custom fact
|
|
111
|
+
#
|
|
112
|
+
def custom_fact_content(key='custom_fact', value='custom_value', *args)
|
|
113
|
+
<<-EOM
|
|
114
|
+
Facter.add('#{key}') do
|
|
115
|
+
setcode {'#{value}'}
|
|
116
|
+
#{args.empty? ? '' : args.join('\n')}
|
|
117
|
+
end
|
|
118
|
+
EOM
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Return the correct shell path for Unix system under test
|
|
122
|
+
#
|
|
123
|
+
def user_shell(agent)
|
|
124
|
+
if agent['platform'] =~ /aix/
|
|
125
|
+
'/usr/bin/bash'
|
|
126
|
+
else
|
|
127
|
+
'/bin/bash'
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Puppet
|
|
2
|
+
module Acceptance
|
|
3
|
+
module GitUtils
|
|
4
|
+
def lookup_in_env(env_variable_name, project_name, default)
|
|
5
|
+
project_specific_name = "#{project_name.upcase.gsub("-","_")}_#{env_variable_name}"
|
|
6
|
+
ENV[project_specific_name] || ENV[env_variable_name] || default
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def build_giturl(project_name, git_fork = nil, git_server = nil)
|
|
10
|
+
git_fork ||= lookup_in_env('FORK', project_name, 'puppetlabs')
|
|
11
|
+
git_server ||= lookup_in_env('GIT_SERVER', project_name, 'github.com')
|
|
12
|
+
repo = (git_server == 'github.com') ?
|
|
13
|
+
"#{git_fork}/#{project_name}.git" :
|
|
14
|
+
"#{git_fork}-#{project_name}.git"
|
|
15
|
+
"git://#{git_server}/#{repo}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'open-uri'
|
|
2
|
+
require 'open3'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require 'puppet/acceptance/common_utils'
|
|
5
|
+
|
|
6
|
+
module Puppet
|
|
7
|
+
module Acceptance
|
|
8
|
+
module InstallUtils
|
|
9
|
+
PLATFORM_PATTERNS = {
|
|
10
|
+
:redhat => /fedora|el-|centos/,
|
|
11
|
+
:debian => /debian|ubuntu/,
|
|
12
|
+
:debian_ruby18 => /debian|ubuntu-lucid|ubuntu-precise/,
|
|
13
|
+
:solaris => /solaris/,
|
|
14
|
+
:windows => /windows/,
|
|
15
|
+
}.freeze
|
|
16
|
+
|
|
17
|
+
# Installs packages on the hosts.
|
|
18
|
+
#
|
|
19
|
+
# @param hosts [Array<Host>] Array of hosts to install packages to.
|
|
20
|
+
# @param package_hash [Hash{Symbol=>Array<String,Array<String,String>>}]
|
|
21
|
+
# Keys should be a symbol for a platform in PLATFORM_PATTERNS. Values
|
|
22
|
+
# should be an array of package names to install, or of two element
|
|
23
|
+
# arrays where a[0] is the command we expect to find on the platform
|
|
24
|
+
# and a[1] is the package name (when they are different).
|
|
25
|
+
# @param options [Hash{Symbol=>Boolean}]
|
|
26
|
+
# @option options [Boolean] :check_if_exists First check to see if
|
|
27
|
+
# command is present before installing package. (Default false)
|
|
28
|
+
# @return true
|
|
29
|
+
def install_packages_on(hosts, package_hash, options = {})
|
|
30
|
+
check_if_exists = options[:check_if_exists]
|
|
31
|
+
hosts = [hosts] unless hosts.kind_of?(Array)
|
|
32
|
+
hosts.each do |host|
|
|
33
|
+
package_hash.each do |platform_key,package_list|
|
|
34
|
+
if pattern = PLATFORM_PATTERNS[platform_key]
|
|
35
|
+
if pattern.match(host['platform'])
|
|
36
|
+
package_list.each do |cmd_pkg|
|
|
37
|
+
if cmd_pkg.kind_of?(Array)
|
|
38
|
+
command, package = cmd_pkg
|
|
39
|
+
else
|
|
40
|
+
command = package = cmd_pkg
|
|
41
|
+
end
|
|
42
|
+
if !check_if_exists || !host.check_for_package(command)
|
|
43
|
+
host.logger.notify("Installing #{package}")
|
|
44
|
+
additional_switches = '--allow-unauthenticated' if platform_key == :debian
|
|
45
|
+
host.install_package(package, additional_switches)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
else
|
|
50
|
+
raise("Unknown platform '#{platform_key}' in package_hash")
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
return true
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'open3'
|
|
3
|
+
require 'tmpdir'
|
|
4
|
+
|
|
5
|
+
def create_facter_gem
|
|
6
|
+
temp_dir = Dir.mktmpdir
|
|
7
|
+
Dir.chdir(temp_dir) do
|
|
8
|
+
download_and_build_facter_ng
|
|
9
|
+
|
|
10
|
+
facter_repo_dir = Pathname.new("#{temp_dir}/facter-ng")
|
|
11
|
+
facter_gem_path = Dir.entries(facter_repo_dir).select { |file| file =~ /facter-ng-[0-9]+.[0-9]+.[0-9]+(.pre)?.gem/ }
|
|
12
|
+
File.join(facter_repo_dir, facter_gem_path)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def download_and_build_facter_ng
|
|
17
|
+
branch_name = ENV['FACTER_4_BRANCH']
|
|
18
|
+
puts "Cloning branch #{branch_name}"
|
|
19
|
+
Open3.capture2('echo $PATH')
|
|
20
|
+
|
|
21
|
+
Open3.capture2("git clone https://github.com/puppetlabs/facter-ng.git &&" \
|
|
22
|
+
'cd facter-ng &&' \
|
|
23
|
+
'git fetch &&' \
|
|
24
|
+
"git reset --hard origin/#{branch_name}")
|
|
25
|
+
|
|
26
|
+
Dir.chdir('facter-ng') do
|
|
27
|
+
puts "Latest commit on branch #{branch_name}"
|
|
28
|
+
output, _stderr = Open3.capture2('git log -1')
|
|
29
|
+
puts output
|
|
30
|
+
|
|
31
|
+
Open3.capture2('gem build agent/facter-ng.gemspec')
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def install_facter_gem(agent, facter_gem_path)
|
|
36
|
+
home_dir = on(agent, 'pwd').stdout.chop
|
|
37
|
+
gem_c = gem_command(agent)
|
|
38
|
+
|
|
39
|
+
scp_to(agent, facter_gem_path, home_dir)
|
|
40
|
+
|
|
41
|
+
on(agent, "#{gem_c} uninstall facter-ng")
|
|
42
|
+
on(agent, "#{gem_c} install -f facter-ng-*.gem")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test_name 'Setup for Facter NG' do
|
|
46
|
+
windows_puppet_bin_path = '/cygdrive/c/Program\ Files/Puppet\ Labs/Puppet/bin'
|
|
47
|
+
linux_puppet_bin_path = '/opt/puppetlabs/puppet/bin'
|
|
48
|
+
set_facter_ng_command = 'puppet config set facterng true'
|
|
49
|
+
|
|
50
|
+
puts 'Setting run with facter ng if environment variable FACTER_NG is true.'
|
|
51
|
+
puts "FACTER_NG is #{ENV["FACTER_NG"]}."
|
|
52
|
+
puts "FACTER_NG branch is #{ENV['FACTER_4_BRANCH']}"
|
|
53
|
+
|
|
54
|
+
if ENV["FACTER_NG"] == 'true'
|
|
55
|
+
puts 'Cloning facter ng repository and creating gem file.'
|
|
56
|
+
facter_gem_path = create_facter_gem
|
|
57
|
+
|
|
58
|
+
agents.each do |agent|
|
|
59
|
+
puts 'Installing Facter NG on agent.'
|
|
60
|
+
install_facter_gem(agent, facter_gem_path)
|
|
61
|
+
|
|
62
|
+
puts 'Renaming facter to facter-original and facter-ng to facter.'
|
|
63
|
+
if agent['platform'] =~ /windows/
|
|
64
|
+
on(agent, "cmd /c #{set_facter_ng_command}")
|
|
65
|
+
on(agent, "cd #{windows_puppet_bin_path} && mv facter-ng.bat facter.bat")
|
|
66
|
+
else
|
|
67
|
+
on(agent, "#{set_facter_ng_command} ")
|
|
68
|
+
on(agent, "cd #{linux_puppet_bin_path} && mv facter-ng facter")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
puts 'FACTER VERSION'
|
|
72
|
+
on(agent, "facter -v")
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
test_name 'ttls configured custom facts files creates cache file and reads cache file' do
|
|
2
|
+
tag 'risk:high'
|
|
3
|
+
|
|
4
|
+
require 'facter/acceptance/user_fact_utils'
|
|
5
|
+
extend Facter::Acceptance::UserFactUtils
|
|
6
|
+
|
|
7
|
+
custom_fact_file = 'custom_facts.rb'
|
|
8
|
+
custom_fact_name = 'random_custom_fact'
|
|
9
|
+
custom_fact_value = 'custom fact value'
|
|
10
|
+
|
|
11
|
+
fact_content = <<-CUSTOM_FACT
|
|
12
|
+
Facter.add(:#{custom_fact_name}) do
|
|
13
|
+
setcode do
|
|
14
|
+
"#{custom_fact_value}"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
CUSTOM_FACT
|
|
18
|
+
|
|
19
|
+
cached_file_content = <<~CACHED_FILE
|
|
20
|
+
{
|
|
21
|
+
"#{custom_fact_name}": "#{custom_fact_value}"
|
|
22
|
+
}
|
|
23
|
+
CACHED_FILE
|
|
24
|
+
|
|
25
|
+
config_data = <<~FACTER_CONF
|
|
26
|
+
facts : {
|
|
27
|
+
ttls : [
|
|
28
|
+
{ "cached-custom-facts" : 3 days }
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
fact-groups : {
|
|
32
|
+
cached-custom-facts : ["#{custom_fact_name}"],
|
|
33
|
+
}
|
|
34
|
+
FACTER_CONF
|
|
35
|
+
|
|
36
|
+
agents.each do |agent|
|
|
37
|
+
cache_folder = get_cached_facts_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f)
|
|
38
|
+
fact_dir = agent.tmpdir('facter')
|
|
39
|
+
env = { 'FACTERLIB' => fact_dir }
|
|
40
|
+
|
|
41
|
+
config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f)
|
|
42
|
+
config_file = File.join(config_dir, 'facter.conf')
|
|
43
|
+
|
|
44
|
+
step "Agent #{agent}: create config file" do
|
|
45
|
+
on(agent, "mkdir -p '#{config_dir}'")
|
|
46
|
+
create_remote_file(agent, config_file, config_data)
|
|
47
|
+
fact_file = File.join(fact_dir, custom_fact_file)
|
|
48
|
+
create_remote_file(agent, fact_file, fact_content)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
teardown do
|
|
52
|
+
on(agent, "rm -rf '#{fact_dir}'")
|
|
53
|
+
on(agent, "rm -rf #{cache_folder}/*")
|
|
54
|
+
on(agent, "rm -rf '#{config_file}'")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
step "should log that it creates cache file and it caches custom facts found in facter.conf" do
|
|
58
|
+
on(agent, facter("#{custom_fact_name} --debug", environment: env)) do |facter_result|
|
|
59
|
+
assert_equal(custom_fact_value, facter_result.stdout.chomp, "#{custom_fact_name} value changed")
|
|
60
|
+
assert_match(/facts cache file expired\/missing/, facter_result.stderr,
|
|
61
|
+
'Expected debug message to state that custom facts cache file is missing or expired')
|
|
62
|
+
assert_match(/Saving cached custom facts to ".+"|caching values for cached-custom-facts facts/, facter_result.stderr,
|
|
63
|
+
'Expected debug message to state that custom facts will be cached')
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
step "should create a cached-custom-facts cache file that containt fact information" do
|
|
68
|
+
result = agent.file_exist?("#{cache_folder}/cached-custom-facts")
|
|
69
|
+
assert_equal(true, result)
|
|
70
|
+
on(agent, "cat #{cache_folder}/cached-custom-facts", acceptable_exit_codes: [0]) do |cat_output|
|
|
71
|
+
assert_match(cached_file_content.chomp, cat_output.stdout, 'Expected cached custom fact file to contain fact information')
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
step 'should read from the cached file for a custom fact that has been cached' do
|
|
76
|
+
on(agent, facter("#{custom_fact_name} --debug", environment: env)) do |facter_result|
|
|
77
|
+
assert_match(/Loading cached custom facts from file ".+"|loading cached values for cached-custom-facts facts/, facter_result.stderr,
|
|
78
|
+
'Expected debug message to state that cached custom facts are read from file')
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
test_name 'Facter should appropriately resolve a custom fact when it conflicts with a builtin fact' do
|
|
2
|
+
tag 'risk:medium'
|
|
3
|
+
|
|
4
|
+
def create_custom_fact_on(host, custom_fact_dir, fact_file_name, fact)
|
|
5
|
+
fact_file_contents = <<-CUSTOM_FACT
|
|
6
|
+
Facter.add(:#{fact[:name]}) do
|
|
7
|
+
has_weight #{fact[:weight]}
|
|
8
|
+
setcode do
|
|
9
|
+
#{fact[:value]}
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
CUSTOM_FACT
|
|
13
|
+
|
|
14
|
+
fact_file_path = File.join(custom_fact_dir, fact_file_name)
|
|
15
|
+
create_remote_file(host, fact_file_path, fact_file_contents)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def clear_custom_facts_on(host, custom_fact_dir)
|
|
19
|
+
step "Clean-up the previous test's custom facts" do
|
|
20
|
+
on(agent, "rm -f #{custom_fact_dir}/*")
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
agents.each do |agent|
|
|
25
|
+
custom_fact_dir = agent.tmpdir('facter')
|
|
26
|
+
teardown do
|
|
27
|
+
on(agent, "rm -rf '#{custom_fact_dir}'")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
fact_name = 'timezone'
|
|
31
|
+
builtin_value = on(agent, facter('timezone')).stdout.chomp
|
|
32
|
+
|
|
33
|
+
step "Verify that Facter uses the custom fact's value when its weight is > 0" do
|
|
34
|
+
custom_fact_value = "custom_timezone"
|
|
35
|
+
create_custom_fact_on(
|
|
36
|
+
agent,
|
|
37
|
+
custom_fact_dir,
|
|
38
|
+
'custom_timezone.rb',
|
|
39
|
+
name: fact_name,
|
|
40
|
+
weight: 10,
|
|
41
|
+
value: "'#{custom_fact_value}'"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result|
|
|
45
|
+
assert_match(/#{custom_fact_value}/, result.stdout.chomp, "Facter does not use the custom fact's value when its weight is > 0")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
clear_custom_facts_on(agent, custom_fact_dir)
|
|
50
|
+
|
|
51
|
+
step "Verify that Facter uses the builtin fact's value when all conflicting custom facts fail to resolve" do
|
|
52
|
+
[ 'timezone_one.rb', 'timezone_two.rb'].each do |fact_file|
|
|
53
|
+
create_custom_fact_on(
|
|
54
|
+
agent,
|
|
55
|
+
custom_fact_dir,
|
|
56
|
+
fact_file,
|
|
57
|
+
{ name: fact_name, weight: 10, value: nil }
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result|
|
|
62
|
+
assert_match(/#{builtin_value}/, result.stdout.chomp, "Facter does not use the builtin fact's value when all conflicting custom facts fail to resolve")
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
step "Verify that Facter gives precedence to the builtin fact over zero weight custom facts" do
|
|
67
|
+
step "when all custom facts have zero weight" do
|
|
68
|
+
{
|
|
69
|
+
'timezone_one.rb' => "'timezone_one'",
|
|
70
|
+
'timezone_two.rb' => "'timezone_two'"
|
|
71
|
+
}.each do |fact_file, fact_value|
|
|
72
|
+
create_custom_fact_on(
|
|
73
|
+
agent,
|
|
74
|
+
custom_fact_dir,
|
|
75
|
+
fact_file,
|
|
76
|
+
{ name: fact_name, weight: 0, value: fact_value }
|
|
77
|
+
)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result|
|
|
81
|
+
assert_match(/#{builtin_value}/, result.stdout.chomp, "Facter does not give precedence to the builtin fact when all custom facts have zero weight")
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
clear_custom_facts_on(agent, custom_fact_dir)
|
|
86
|
+
|
|
87
|
+
step "when some custom facts have zero weight" do
|
|
88
|
+
{
|
|
89
|
+
'timezone_one.rb' => { weight: 10, value: nil },
|
|
90
|
+
'timezone_two.rb' => { weight: 0, value: "'timezone_two'" }
|
|
91
|
+
}.each do |fact_file, fact|
|
|
92
|
+
create_custom_fact_on(
|
|
93
|
+
agent,
|
|
94
|
+
custom_fact_dir,
|
|
95
|
+
fact_file,
|
|
96
|
+
fact.merge(name: fact_name)
|
|
97
|
+
)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result|
|
|
101
|
+
assert_match(/#{builtin_value}/, result.stdout.chomp, "Facter does not give precedence to the builtin fact when only some custom facts have zero weight")
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|