facter 3.11.5.cfacter.20181022 → 3.11.6.cfacter.20181031
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afe360c36458b45cc2a34eef17d00a04bb36133c
|
4
|
+
data.tar.gz: 17e96e89e110a7111e8f48086f8164640db13bbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d906bb20920e66c5a9cd6e42dc82cc261371d3d36cc161e16681a1ef59da89d77de50d0ffa79a04aa722580ed1fca1b9418a2fa43b0d7751cf73d88a7ed0d61
|
7
|
+
data.tar.gz: fe980db4156cc3a91639d38d85059b989cf5745e439d17dced82a28c92bd646878df2088e165873487f05a5c1ad76c8d40b5ef2159dad1ca5c03e58fb533e489
|
@@ -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
|
@@ -38,7 +38,7 @@ PROJECT_NAME = facter
|
|
38
38
|
# could be handy for archiving the generated documentation or if some version
|
39
39
|
# control system is used.
|
40
40
|
|
41
|
-
PROJECT_NUMBER = 3.11.
|
41
|
+
PROJECT_NUMBER = 3.11.6
|
42
42
|
|
43
43
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
44
44
|
# for a project that appears at the top of each page and should give viewer a
|
@@ -83,53 +83,69 @@ namespace facter { namespace ruby {
|
|
83
83
|
});
|
84
84
|
|
85
85
|
_resolving = true;
|
86
|
-
|
87
|
-
// If no resolutions or the top resolution has a weight of 0, first check the native collection for the fact
|
88
|
-
// This way we treat the "built-in" as implicitly having a resolution with weight 0
|
89
86
|
bool add = true;
|
90
|
-
if (_resolutions.empty() || ruby.to_native<resolution>(_resolutions.front())->weight() == 0) {
|
91
|
-
// Check to see the value is in the collection
|
92
|
-
auto value = facts[ruby.to_string(_name)];
|
93
|
-
if (value) {
|
94
|
-
// Already in collection, do not add
|
95
|
-
add = false;
|
96
|
-
_value = facter->to_ruby(value);
|
97
|
-
_weight = value->weight();
|
98
|
-
}
|
99
|
-
}
|
100
87
|
|
101
|
-
|
102
|
-
|
103
|
-
ruby.
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
break;
|
117
|
-
}
|
88
|
+
vector<VALUE>::iterator it;
|
89
|
+
ruby.rescue([&]() {
|
90
|
+
volatile VALUE value = ruby.nil_value();
|
91
|
+
size_t weight = 0;
|
92
|
+
|
93
|
+
// Look through the resolutions and find the first allowed resolution that resolves
|
94
|
+
for (it = _resolutions.begin(); it != _resolutions.end(); ++it) {
|
95
|
+
auto res = ruby.to_native<resolution>(*it);
|
96
|
+
if (!res->suitable(*facter)) {
|
97
|
+
continue;
|
98
|
+
}
|
99
|
+
value = res->value();
|
100
|
+
if (!ruby.is_nil(value)) {
|
101
|
+
weight = res->weight();
|
102
|
+
break;
|
118
103
|
}
|
104
|
+
}
|
119
105
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
return 0;
|
124
|
-
}, [&](VALUE ex) {
|
125
|
-
LOG_ERROR("error while resolving custom fact \"{1}\": {2}", ruby.rb_string_value_ptr(&_name), ruby.exception_to_string(ex));
|
106
|
+
// Set the value to what was resolved
|
107
|
+
_value = value;
|
108
|
+
_weight = weight;
|
126
109
|
|
127
|
-
|
128
|
-
_value = ruby.nil_value();
|
129
|
-
_weight = 0;
|
110
|
+
if (! ruby.is_nil(_value) && _weight != 0) {
|
130
111
|
return 0;
|
131
|
-
}
|
132
|
-
|
112
|
+
}
|
113
|
+
|
114
|
+
// There's two possibilities here:
|
115
|
+
// 1. None of our resolvers could resolve the value
|
116
|
+
// 2. A resolver of weight 0 resolved the value
|
117
|
+
//
|
118
|
+
// In both cases, we attempt to use the "built-in" fact's
|
119
|
+
// value. This serves as a fallback resolver for Case (1)
|
120
|
+
// while for Case (2), we want built-in values to take
|
121
|
+
// precedence over 0-weight custom facts.
|
122
|
+
|
123
|
+
auto builtin_value = facts[ruby.to_string(_name)];
|
124
|
+
if (! builtin_value) {
|
125
|
+
return 0;
|
126
|
+
}
|
127
|
+
auto builtin_ruby_value = facter->to_ruby(builtin_value);
|
128
|
+
|
129
|
+
// We need this check for Case (2). Otherwise, we risk
|
130
|
+
// overwriting our resolved value in the small chance
|
131
|
+
// that builtin_value exists, but its ruby value is
|
132
|
+
// nil.
|
133
|
+
if (! ruby.is_nil(builtin_ruby_value)) {
|
134
|
+
// Already in collection, do not add
|
135
|
+
add = false;
|
136
|
+
_value = builtin_ruby_value;
|
137
|
+
_weight = builtin_value->weight();
|
138
|
+
}
|
139
|
+
|
140
|
+
return 0;
|
141
|
+
}, [&](VALUE ex) {
|
142
|
+
LOG_ERROR("error while resolving custom fact \"{1}\": {2}", ruby.rb_string_value_ptr(&_name), ruby.exception_to_string(ex));
|
143
|
+
|
144
|
+
// Failed, so set to nil
|
145
|
+
_value = ruby.nil_value();
|
146
|
+
_weight = 0;
|
147
|
+
return 0;
|
148
|
+
});
|
133
149
|
|
134
150
|
if (add) {
|
135
151
|
facts.add_custom(ruby.to_string(_name), ruby.is_nil(_value) ? nullptr : make_value<ruby::ruby_value>(_value), _weight);
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: facter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.11.
|
4
|
+
version: 3.11.6.cfacter.20181031
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-10-
|
12
|
+
date: 2018-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email: info@puppet.com
|
@@ -203,6 +203,7 @@ files:
|
|
203
203
|
- ext/facter/facter/acceptance/lib/puppet/acceptance/common_utils.rb
|
204
204
|
- ext/facter/facter/acceptance/lib/puppet/acceptance/git_utils.rb
|
205
205
|
- ext/facter/facter/acceptance/lib/puppet/acceptance/install_utils.rb
|
206
|
+
- ext/facter/facter/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb
|
206
207
|
- ext/facter/facter/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb
|
207
208
|
- ext/facter/facter/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb
|
208
209
|
- ext/facter/facter/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb
|