facter 3.11.6.cfacter.20181031 → 3.12.0.cfacter.20180918

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 (41) hide show
  1. checksums.yaml +5 -5
  2. data/ext/facter/cpp-hocon/CMakeLists.txt +1 -1
  3. data/ext/facter/cpp-hocon/lib/inc/hocon/types.hpp +6 -0
  4. data/ext/facter/cpp-hocon/lib/src/parseable.cc +3 -0
  5. data/ext/facter/facter/CMakeLists.txt +1 -1
  6. data/ext/facter/facter/acceptance/lib/facter/acceptance/base_fact_utils.rb +1 -3
  7. data/ext/facter/facter/acceptance/tests/facts/dmi.rb +1 -1
  8. data/ext/facter/facter/appveyor.yml +17 -14
  9. data/ext/facter/facter/exe/facter.cc +1 -2
  10. data/ext/facter/facter/lib/CMakeLists.txt +17 -1
  11. data/ext/facter/facter/lib/Doxyfile +1 -1
  12. data/ext/facter/facter/lib/inc/facter/facts/os.hpp +8 -0
  13. data/ext/facter/facter/lib/inc/facter/ruby/ruby.hpp +0 -11
  14. data/ext/facter/facter/lib/inc/internal/facts/freebsd/disk_resolver.hpp +25 -0
  15. data/ext/facter/facter/lib/inc/internal/facts/freebsd/filesystem_resolver.hpp +25 -0
  16. data/ext/facter/facter/lib/inc/internal/util/freebsd/geom.hpp +149 -0
  17. data/ext/facter/facter/lib/src/facts/collection.cc +0 -2
  18. data/ext/facter/facter/lib/src/facts/freebsd/collection.cc +4 -2
  19. data/ext/facter/facter/lib/src/facts/freebsd/disk_resolver.cc +34 -0
  20. data/ext/facter/facter/lib/src/facts/freebsd/filesystem_resolver.cc +37 -0
  21. data/ext/facter/facter/lib/src/facts/linux/os_linux.cc +4 -0
  22. data/ext/facter/facter/lib/src/facts/windows/dmi_resolver.cc +2 -3
  23. data/ext/facter/facter/lib/src/facts/windows/operating_system_resolver.cc +1 -23
  24. data/ext/facter/facter/lib/src/ruby/fact.cc +41 -57
  25. data/ext/facter/facter/lib/src/ruby/ruby.cc +3 -35
  26. data/ext/facter/facter/lib/src/util/freebsd/geom.cc +130 -0
  27. data/ext/facter/facter/lib/tests/CMakeLists.txt +25 -9
  28. data/ext/facter/facter/lib/tests/facts/collection.cc +1 -1
  29. data/ext/facter/facter/lib/tests/fixtures.cc +1 -0
  30. data/ext/facter/facter/locales/FACTER.pot +18 -18
  31. data/ext/facter/leatherman/CMakeLists.txt +1 -1
  32. data/ext/facter/leatherman/cmake/cflags.cmake +2 -2
  33. data/ext/facter/leatherman/dynamic_library/CMakeLists.txt +1 -1
  34. data/ext/facter/leatherman/locale/src/locale.cc +1 -0
  35. data/ext/facter/leatherman/ruby/inc/leatherman/ruby/api.hpp +0 -4
  36. data/ext/facter/leatherman/ruby/src/api.cc +0 -1
  37. data/ext/facter/leatherman/util/inc/leatherman/util/strings.hpp +3 -0
  38. data/ext/facter/leatherman/windows/CMakeLists.txt +1 -1
  39. data/ext/facter/leatherman/windows/inc/leatherman/windows/wmi.hpp +0 -5
  40. metadata +9 -4
  41. data/ext/facter/facter/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb +0 -106
@@ -309,8 +309,6 @@ namespace facter { namespace facts {
309
309
  {
310
310
  resolve_facts();
311
311
 
312
- // We intentionally are using find_if with no return value as a "map until" construct.
313
- // cppcheck-suppress ignoredReturnValue
314
312
  find_if(begin(_facts), end(_facts), [&func](map<string, unique_ptr<value>>::value_type const& it) {
315
313
  return !func(it.first, it.second.get());
316
314
  });
@@ -1,5 +1,5 @@
1
1
  #include <facter/facts/collection.hpp>
2
- #include <internal/facts/bsd/filesystem_resolver.hpp>
2
+ #include <internal/facts/freebsd/filesystem_resolver.hpp>
3
3
  #include <internal/facts/bsd/uptime_resolver.hpp>
4
4
  #include <internal/facts/glib/load_average_resolver.hpp>
5
5
  #include <internal/facts/freebsd/processor_resolver.hpp>
@@ -14,6 +14,7 @@
14
14
  #include <internal/facts/freebsd/zpool_resolver.hpp>
15
15
  #include <internal/facts/freebsd/virtualization_resolver.hpp>
16
16
  #include <internal/facts/freebsd/memory_resolver.hpp>
17
+ #include <internal/facts/freebsd/disk_resolver.hpp>
17
18
 
18
19
  using namespace std;
19
20
 
@@ -25,7 +26,7 @@ namespace facter { namespace facts {
25
26
  add(make_shared<freebsd::operating_system_resolver>());
26
27
  add(make_shared<freebsd::networking_resolver>());
27
28
  add(make_shared<bsd::uptime_resolver>());
28
- add(make_shared<bsd::filesystem_resolver>());
29
+ add(make_shared<freebsd::filesystem_resolver>());
29
30
  add(make_shared<posix::ssh_resolver>());
30
31
  add(make_shared<posix::identity_resolver>());
31
32
  add(make_shared<posix::timezone_resolver>());
@@ -36,6 +37,7 @@ namespace facter { namespace facts {
36
37
  add(make_shared<freebsd::zpool_resolver>());
37
38
  add(make_shared<freebsd::virtualization_resolver>());
38
39
  add(make_shared<freebsd::memory_resolver>());
40
+ add(make_shared<freebsd::disk_resolver>());
39
41
  }
40
42
 
41
43
  }} // namespace facter::facts
@@ -0,0 +1,34 @@
1
+ #include <internal/facts/freebsd/disk_resolver.hpp>
2
+ #include <internal/util/freebsd/geom.hpp>
3
+ #include <leatherman/logging/logging.hpp>
4
+
5
+ #include <libgeom.h>
6
+
7
+ using namespace std;
8
+
9
+ namespace facter { namespace facts { namespace freebsd {
10
+
11
+ disk_resolver::data disk_resolver::collect_data(collection& facts)
12
+ {
13
+ data result;
14
+
15
+ try {
16
+ facter::util::freebsd::geom_class disks("DISK");
17
+
18
+ for (auto& geom : disks.geoms) {
19
+ for (auto& provider : geom.providers) {
20
+ disk d;
21
+ d.name = provider.name();
22
+ d.size = provider.mediasize();
23
+ d.model = provider.config("descr");
24
+ result.disks.push_back(move(d));
25
+ }
26
+ }
27
+ } catch (util::freebsd::geom_exception const &e) {
28
+ LOG_ERROR(e.what());
29
+ }
30
+
31
+ return result;
32
+ }
33
+
34
+ }}} // namespace facter::facts::freebsd
@@ -0,0 +1,37 @@
1
+ #include <internal/facts/freebsd/filesystem_resolver.hpp>
2
+ #include <internal/util/freebsd/geom.hpp>
3
+ #include <leatherman/logging/logging.hpp>
4
+
5
+ #include <libgeom.h>
6
+
7
+ using namespace std;
8
+
9
+ namespace facter { namespace facts { namespace freebsd {
10
+
11
+ filesystem_resolver::data filesystem_resolver::collect_data(collection& facts)
12
+ {
13
+ data result = bsd::filesystem_resolver::collect_data(facts);
14
+
15
+ try {
16
+ facter::util::freebsd::geom_class disks("PART");
17
+
18
+ for (auto& geom : disks.geoms) {
19
+ for (auto& provider : geom.providers) {
20
+ partition p;
21
+ p.name = provider.name();
22
+ p.size = provider.mediasize();
23
+ if (geom.config("scheme") == "GPT") {
24
+ p.partition_label = provider.config("label");
25
+ p.partition_uuid = provider.config("rawuuid");
26
+ }
27
+ result.partitions.push_back(move(p));
28
+ }
29
+ }
30
+ } catch (util::freebsd::geom_exception const& e) {
31
+ LOG_ERROR(e.what());
32
+ }
33
+
34
+ return result;
35
+ }
36
+
37
+ }}} // namespace facter::facts::freebsd
@@ -84,8 +84,10 @@ namespace facter { namespace facts { namespace linux {
84
84
  make_tuple(boost::regex("(?i)scientific linux CERN"), string(os::scientific_cern)),
85
85
  make_tuple(boost::regex("(?i)scientific linux release"), string(os::scientific)),
86
86
  make_tuple(boost::regex("(?im)^cloudlinux"), string(os::cloud_linux)),
87
+ make_tuple(boost::regex("(?im)^virtuozzo linux"), string(os::virtuozzo_linux)),
87
88
  make_tuple(boost::regex("(?i)Ascendos"), string(os::ascendos)),
88
89
  make_tuple(boost::regex("(?im)^XenServer"), string(os::xen_server)),
90
+ make_tuple(boost::regex("(?im)^XCP-ng"), string(os::xcp_ng)),
89
91
  make_tuple(boost::regex("XCP"), string(os::zen_cloud_platform)),
90
92
  make_tuple(boost::regex("(?im)^Parallels Server Bare Metal"), string(os::psbm)),
91
93
  make_tuple(boost::regex("(?m)^Fedora release"), string(os::fedora)),
@@ -228,6 +230,7 @@ namespace facter { namespace facts { namespace linux {
228
230
  { string(os::oracle_enterprise_linux), string(os_family::redhat) },
229
231
  { string(os::amazon), string(os_family::redhat) },
230
232
  { string(os::xen_server), string(os_family::redhat) },
233
+ { string(os::xcp_ng), string(os_family::redhat) },
231
234
  { string(os::photon_os), string(os_family::redhat) },
232
235
  { string(os::huawei), string(os_family::debian) },
233
236
  { string(os::linux_mint), string(os_family::debian) },
@@ -265,6 +268,7 @@ namespace facter { namespace facts { namespace linux {
265
268
  { string(os::cloud_linux), string(release_file::redhat) },
266
269
  { string(os::psbm), string(release_file::redhat) },
267
270
  { string(os::xen_server), string(release_file::redhat) },
271
+ { string(os::xcp_ng), string(release_file::redhat) },
268
272
  { string(os::fedora), string(release_file::fedora) },
269
273
  { string(os::meego), string(release_file::meego) },
270
274
  { string(os::oracle_linux), string(release_file::oracle_linux) },
@@ -17,12 +17,11 @@ namespace facter { namespace facts { namespace windows {
17
17
  {
18
18
  data result;
19
19
 
20
- auto vals = _wmi->query(wmi::computersystemproduct, {wmi::name, wmi::uuid});
20
+ auto vals = _wmi->query(wmi::computersystemproduct, {wmi::name});
21
21
  if (vals.empty()) {
22
- LOG_DEBUG("WMI query returned no results for {1} with values {2} and {3}.", wmi::computersystemproduct, wmi::name, wmi::uuid);
22
+ LOG_DEBUG("WMI query returned no results for {1} with value {2}.", wmi::computersystemproduct, wmi::name);
23
23
  } else {
24
24
  result.product_name = wmi::get(vals, wmi::name);
25
- result.uuid = wmi::get(vals, wmi::uuid);
26
25
  }
27
26
 
28
27
  vals = _wmi->query(wmi::bios, {wmi::manufacturer, wmi::serialnumber});
@@ -2,9 +2,7 @@
2
2
  #include <leatherman/windows/system_error.hpp>
3
3
  #include <leatherman/windows/wmi.hpp>
4
4
  #include <leatherman/windows/windows.hpp>
5
- #include <facter/facts/fact.hpp>
6
5
  #include <facter/facts/collection.hpp>
7
- #include <facter/facts/scalar_value.hpp>
8
6
  #include <facter/facts/os_family.hpp>
9
7
  #include <leatherman/logging/logging.hpp>
10
8
  #include <leatherman/util/regex.hpp>
@@ -12,7 +10,6 @@
12
10
  #include <winnt.h>
13
11
  #include <Shlobj.h>
14
12
  #include <map>
15
- #include <string>
16
13
  #include <boost/filesystem.hpp>
17
14
 
18
15
  using namespace std;
@@ -104,26 +101,7 @@ namespace facter { namespace facts { namespace windows {
104
101
  auto version = result.release.substr(0, lastDot);
105
102
  bool consumerrel = (wmi::get(vals, wmi::producttype) == "1");
106
103
  if (version == "10.0") {
107
- // Calculate the build number to distinguish between
108
- // Windows Server 2016 and 2019. Note that the kernel
109
- // version is written as <major>.<minor>.<build_number>
110
- auto kernel_version_fact = facts.get<string_value>(fact::kernel_version);
111
- if (! kernel_version_fact) {
112
- LOG_DEBUG("Could not resolve the OS release and OS major version facts from the kernel version fact");
113
- return result;
114
- }
115
- auto kernel_version = kernel_version_fact->value();
116
- auto build_number_as_str = kernel_version.substr(
117
- kernel_version.find_last_of('.') + 1);
118
- auto build_number = stol(build_number_as_str);
119
-
120
- if (consumerrel) {
121
- result.release = "10";
122
- } else if (build_number >= 17623L) {
123
- result.release = "2019";
124
- } else {
125
- result.release = "2016";
126
- }
104
+ result.release = consumerrel ? "10" : "2016";
127
105
  } else if (version == "6.3") {
128
106
  result.release = consumerrel ? "8.1" : "2012 R2";
129
107
  } else if (version == "6.2") {
@@ -83,69 +83,53 @@ namespace facter { namespace ruby {
83
83
  });
84
84
 
85
85
  _resolving = true;
86
- bool add = true;
87
-
88
- vector<VALUE>::iterator it;
89
- ruby.rescue([&]() {
90
- volatile VALUE value = ruby.nil_value();
91
- size_t weight = 0;
92
86
 
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;
103
- }
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
+ 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();
104
98
  }
99
+ }
105
100
 
106
- // Set the value to what was resolved
107
- _value = value;
108
- _weight = weight;
101
+ if (ruby.is_nil(_value)) {
102
+ vector<VALUE>::iterator it;
103
+ ruby.rescue([&]() {
104
+ volatile VALUE value = ruby.nil_value();
105
+ size_t weight = 0;
106
+
107
+ // Look through the resolutions and find the first allowed resolution that resolves
108
+ for (it = _resolutions.begin(); it != _resolutions.end(); ++it) {
109
+ auto res = ruby.to_native<resolution>(*it);
110
+ if (!res->suitable(*facter)) {
111
+ continue;
112
+ }
113
+ value = res->value();
114
+ if (!ruby.is_nil(value)) {
115
+ weight = res->weight();
116
+ break;
117
+ }
118
+ }
109
119
 
110
- if (! ruby.is_nil(_value) && _weight != 0) {
120
+ // Set the value to what was resolved
121
+ _value = value;
122
+ _weight = weight;
111
123
  return 0;
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));
124
+ }, [&](VALUE ex) {
125
+ LOG_ERROR("error while resolving custom fact \"{1}\": {2}", ruby.rb_string_value_ptr(&_name), ruby.exception_to_string(ex));
143
126
 
144
- // Failed, so set to nil
145
- _value = ruby.nil_value();
146
- _weight = 0;
147
- return 0;
148
- });
127
+ // Failed, so set to nil
128
+ _value = ruby.nil_value();
129
+ _weight = 0;
130
+ return 0;
131
+ });
132
+ }
149
133
 
150
134
  if (add) {
151
135
  facts.add_custom(ruby.to_string(_name), ruby.is_nil(_value) ? nullptr : make_value<ruby::ruby_value>(_value), _weight);
@@ -30,27 +30,6 @@ static const char load_puppet[] =
30
30
  " end\n"
31
31
  "end\n";
32
32
 
33
- // This struct redirects stdout to stderr in the ruby runtime for the
34
- // duration of its lifetime. We use this to ensure that any custom
35
- // facts writing to stdout during their initialization or execution
36
- // won't corrupt json/yaml output from the facter executable.
37
- struct RbStdoutGuard {
38
- VALUE old_stdout;
39
- api& ruby;
40
-
41
- RbStdoutGuard(api& ruby) :ruby(ruby) {
42
- LOG_DEBUG("Redirecting ruby's stdout to stderr");
43
- auto rb_stderr = ruby.rb_gv_get("$stderr");
44
- old_stdout = ruby.rb_gv_get("$stdout");
45
- ruby.rb_gv_set("$stdout", rb_stderr);
46
- }
47
-
48
- ~RbStdoutGuard() {
49
- LOG_DEBUG("Restoring Ruby's stdout");
50
- ruby.rb_gv_set("$stdout", old_stdout);
51
- }
52
- };
53
-
54
33
  namespace facter { namespace ruby {
55
34
 
56
35
  bool initialize(bool include_stack_trace)
@@ -69,7 +48,7 @@ namespace facter { namespace ruby {
69
48
  return true;
70
49
  }
71
50
 
72
- void load_custom_facts(collection& facts, bool initialize_puppet, bool redirect_stdout, vector<string> const& paths)
51
+ void load_custom_facts(collection& facts, bool initialize_puppet, vector<string> const& paths)
73
52
  {
74
53
  #ifdef _WIN32
75
54
  // Initialize WSA before resolving custom facts. The Ruby runtime does this only when running
@@ -88,23 +67,12 @@ namespace facter { namespace ruby {
88
67
  }
89
68
  }
90
69
  mod.search(paths);
91
- if (redirect_stdout) {
92
- // Redirect stdout->stderr for custom facts.
93
- RbStdoutGuard stdout_guard{ruby};
94
- mod.resolve_facts();
95
- } else {
96
- mod.resolve_facts();
97
- }
70
+ mod.resolve_facts();
98
71
  }
99
72
 
100
73
  void load_custom_facts(collection& facts, vector<string> const& paths)
101
74
  {
102
- load_custom_facts(facts, false, false, paths);
103
- }
104
-
105
- void load_custom_facts(collection& facts, bool initialize_puppet, vector<string> const& paths)
106
- {
107
- load_custom_facts(facts, initialize_puppet, false, paths);
75
+ load_custom_facts(facts, false, paths);
108
76
  }
109
77
 
110
78
  value const* lookup(value const* value, vector<string>::iterator segment, vector<string>::iterator end) {
@@ -0,0 +1,130 @@
1
+ #include <internal/util/freebsd/geom.hpp>
2
+ #include <leatherman/locale/locale.hpp>
3
+ #include <leatherman/logging/logging.hpp>
4
+
5
+ using leatherman::locale::_;
6
+
7
+ using namespace std;
8
+
9
+ namespace facter { namespace util { namespace freebsd {
10
+
11
+ geom_exception::geom_exception(std::string const& message) :
12
+ runtime_error(message)
13
+ {
14
+ }
15
+
16
+
17
+
18
+ geom_config::geom_config(string name, string value)
19
+ {
20
+ _name = name;
21
+ _value = value;
22
+ }
23
+
24
+ string
25
+ geom_config::name()
26
+ {
27
+ return _name;
28
+ }
29
+
30
+ string
31
+ geom_config::value()
32
+ {
33
+ return _value;
34
+ }
35
+
36
+
37
+
38
+ geom_object_with_config::geom_object_with_config(struct gconf *conf)
39
+ {
40
+ struct gconfig *config;
41
+ LIST_FOREACH(config, conf, lg_config) {
42
+ if (!config->lg_val) {
43
+ LOG_DEBUG(_("Skipping config {1} because it has a null value", config->lg_name));
44
+ continue;
45
+ }
46
+ _configs.push_back(geom_config(config->lg_name, config->lg_val));
47
+ }
48
+ }
49
+
50
+ string
51
+ geom_object_with_config::config(string name) {
52
+ for (auto config : _configs) {
53
+ if (config.name() == name)
54
+ return config.value();
55
+ }
56
+ return "";
57
+ }
58
+
59
+
60
+
61
+ geom_provider::geom_provider(struct gprovider* provider) :
62
+ geom_object_with_config(&provider->lg_config)
63
+ {
64
+ _name = provider->lg_name;
65
+ _mode = provider->lg_mode;
66
+ _mediasize = provider->lg_mediasize;
67
+ _sectorsize = provider->lg_sectorsize;
68
+ _stripeoffset = provider->lg_stripeoffset;
69
+ _stripesize = provider->lg_stripesize;
70
+ }
71
+
72
+ string
73
+ geom_provider::name()
74
+ {
75
+ return _name;
76
+ }
77
+
78
+ off_t
79
+ geom_provider::mediasize()
80
+ {
81
+ return _mediasize;
82
+ }
83
+
84
+
85
+
86
+ geom_geom::geom_geom(struct ggeom *geom) :
87
+ geom_object_with_config(&geom->lg_config)
88
+ {
89
+ _name = geom->lg_name;
90
+ struct gprovider *provider;
91
+ LIST_FOREACH(provider, &geom->lg_provider, lg_provider) {
92
+ providers.push_back(geom_provider(provider));
93
+ }
94
+ }
95
+
96
+ string
97
+ geom_geom::name()
98
+ {
99
+ return _name;
100
+ }
101
+
102
+
103
+
104
+ geom_class::geom_class(string type)
105
+ {
106
+ if (geom_gettree(&_mesh) < 0) {
107
+ throw geom_exception(_("Unable to get GEOM tree"));
108
+ }
109
+
110
+ LIST_FOREACH(_class, &(_mesh.lg_class), lg_class) {
111
+ if (type == string(_class->lg_name))
112
+ break;
113
+ }
114
+
115
+ if (!_class) {
116
+ throw geom_exception(_("The GEOM class \"{1}\" was not found", type));
117
+ }
118
+
119
+ struct ggeom *geom;
120
+ LIST_FOREACH(geom, &(_class->lg_geom), lg_geom) {
121
+ geoms.push_back(geom_geom(geom));
122
+ }
123
+ }
124
+
125
+ geom_class::~geom_class()
126
+ {
127
+ geom_deletetree(&_mesh);
128
+ }
129
+
130
+ }}} // namespace facter::util::freebsd