From 17b264ba81d7fd78c74b19658440e837c7011bc7 Mon Sep 17 00:00:00 2001 From: Chris Tessmer Date: Fri, 12 Aug 2016 20:51:43 -0400 Subject: [PATCH 1/3] (maint) Add `rake table` task + update README.md Before this patch, it wasn't clear which versions of each OS had data for any given version of facter. This patch addresses that problem by adding a **Facter version and Operating System coverage** table to the `README.md`. The markdown for the table can be maintained using the new rake task, `rake table`. Glenn Sarti: This commit is based on the work by op-ct --- README.md | 146 ++++++++++++++++++++++++++++++------------------------ Rakefile | 67 +++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 66 deletions(-) diff --git a/README.md b/README.md index 16bdcea1..57f92029 100644 --- a/README.md +++ b/README.md @@ -56,69 +56,83 @@ require 'facterdb' FacterDB::get_facts('osfamily=Debian') ``` -## Facter versions supported - -* 1.6 -* 1.7 -* 2.0 -* 2.1 -* 2.2 -* 2.3 -* 2.4 -* 3.0 -* 3.1 -* 3.3 -* 3.4 -* 3.5 -* 3.6 -* 3.7 -* 3.8 - -## Operating Systems supported - -* AIX -* ArchLinux -* CentOS 5 -* CentOS 6 -* CentOS 7 -* Debian 6 -* Debian 7 -* Debian 8 -* Fedora 19 -* Fedora 22 -* Fedora 23 -* Fedora 24 -* FreeBSD 9 -* FreeBSD 10 -* Gentoo -* OpenBSD 5.7 -* OpenBSD 5.8 -* OpenBSD 5.9 -* OpenBSD 6.0 -* OpenSuse 12 -* OpenSuse 13 -* Oracle 5 -* Oracle 6 -* Oracle 7 -* RedHat 5 -* RedHat 6 -* RedHat 7 -* Scientific 5 -* Scientific 6 -* Scientific 7 -* SLES 11 -* SLES 12 -* Solaris 11 -* OSX 10.10 -* Ubuntu 10.04 -* Ubuntu 12.04 -* Ubuntu 14.04 -* Ubuntu 14.10 -* Ubuntu 15.04 -* Ubuntu 15.10 -* Ubuntu 16.04 -* Windows 2012 r2 -* Windows 7 +## Facter version and Operating System coverage + +| operating system | 1.6 | 1.7 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 3.0 | 3.1 | 3.2 | 3.3 | 3.4 | 3.5 | 3.6 | 3.7 | 3.8 | 3.9 | +| ------------------ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| AIX 5300 | | | | | | | | | | | 1 | | | | | | | | +| AIX 6100 | | | | | | | | | | | 1 | | | | | | | | +| AIX 7100 | | | | | | | | | | | 1 | | | | | | | 1 | +| Amazon | 2 | | | | | | | | | | | | | | | | | | +| Amazon 2017 | | | | | 1 | 1 | 1 | | | | | | | | 1 | | | | +| Amazon 4 | | 1 | 1 | 1 | | | | | 1 | 1 | | 1 | | | | | | | +| Archlinux | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | | | | | | | | | | 1 | +| CentOS 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| CentOS 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| CentOS 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| Darwin | | | 2 | 2 | | | | | | | | | | | | | | | +| Darwin 14 | | | 2 | 2 | 2 | 2 | 2 | 1 | | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Darwin 15 | | | | | 1 | 1 | 1 | 1 | | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Darwin 16 | | | | | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | | +| Debian 1 | | | | | | 1 | | | | | | | | | | | | | +| Debian 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | | | | | | | | | +| Debian 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Debian 8 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Debian 9 | | | 2 | 2 | 2 | 1 | 2 | 2 | | | | | | | | | 2 | | +| Fedora 19 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Fedora 20 | | 11 | | | | | | | | | | | | | | | | | +| Fedora 21 | | | | | | | 11 | | | | | | | | | | | | +| Fedora 22 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | 2 | | | | | | | | | +| Fedora 23 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | 2 | | | | | | | | | +| Fedora 24 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | | | | 2 | 2 | 2 | 2 | 2 | | | +| Fedora 25 | | | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | 2 | 2 | 2 | | +| Fedora 26 | | | | | | | 11 | | | | | | | | | | | | +| FreeBSD 10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | | | | | | | | | | 1 | +| FreeBSD 11 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | | | | | | 1 | +| FreeBSD 9 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Gentoo | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| LinuxMint 18 | | | | | | | | | | 1 | | 1 | | | | | | | +| OpenBSD 5.7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenBSD 5.8 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenBSD 5.9 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenBSD 6.0 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenSuSE 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenSuSE 13 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenSuSE 42 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | 1 | +| OracleLinux 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| OracleLinux 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| OracleLinux 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| RedHat 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| RedHat 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 3 | 2 | 2 | | +| RedHat 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| SLES 11 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | 2 | 2 | 2 | 2 | 2 | | +| SLES 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | | +| Scientific 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Scientific 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Scientific 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| Solaris | | | | | | | | | | | | | | | | | | 2 | +| Solaris 1 | | | | | | | | 1 | | | | | | | | | | | +| Solaris 11 | 2 | 2 | | | | | | | | | | | | | | | | | +| Solaris 2 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 10.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 12.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | | | | | +| Ubuntu 14.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Ubuntu 14.10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 15.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 15.10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | | 2 | 2 | 2 | | | | | +| Ubuntu 16.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Ubuntu 16.10 | | | | | | | | | | | | | | | 2 | | | | +| windows 10 | | | | | | | | 2 | | | | | 2 | 2 | 2 | 2 | 2 | | +| windows 10.0.14393 | | | | 3 | 3 | 3 | 3 | 1 | 3 | 3 | | 3 | | | | | | | +| windows 2008 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| windows 2008 R2 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| windows 2012 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| windows 2012 R2 | | | | 3 | 3 | 2 | 3 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| windows 2016 | | | | | | | | | | | | | 1 | 1 | 1 | 1 | 1 | | +| windows 7 | | | | 1 | 1 | 1 | 2 | 1 | 2 | 2 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| windows 8.1 | | | | | | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | + +Where the number (1, 2 etc.) are the number of factsets for that OS and facter combination (e.g., x86_64 and i386 architectures) ## Add new Operating System support @@ -146,13 +160,13 @@ for file in facts/*/centos-*.facts; do cat $file | sed -e 's/CentOS/OracleLinux/ The default facts are great for many things but there will be times when you need to have facterdb search custom fact sets that only make sense in your environment or might contain sensitive information. -This can be useful when combined with [rspec_puppet_facts](https://github.com/mcanevet/rspec-puppet-facts) or the [puppet-debugger](https://github.com/nwops/puppet-debugger) which both use this gem. +This can be useful when combined with [rspec_puppet_facts](https://github.com/mcanevet/rspec-puppet-facts) or the [puppet-debugger](https://github.com/nwops/puppet-debugger) which both use this gem. To supply external facts to facterdb just set the `FACTERDB_SEARCH_PATHS` environment variable with one or more paths to your facts. Do this any time facterdb is used directly or indirectly. -When separating paths please use the default path separator character supported by your OS. -* Unix/Linux/OSX = `:` +When separating paths please use the default path separator character supported by your OS. +* Unix/Linux/OSX = `:` * Windows = `;` Each fact set you create must meet the following requirements: diff --git a/Rakefile b/Rakefile index f7855250..e1477b5e 100644 --- a/Rakefile +++ b/Rakefile @@ -21,3 +21,70 @@ rescue LoadError raise 'Install github_changelog_generator to get access to automatic changelog generation' end end + + +# Generate a human-friendly OS label based on a given factset +def factset_to_os_label(fs) + os_rel = '???' + os_name = '????' + if fs.key?(:os) && (fs[:os]['release']['major'] =~ /\d/) + os_name = fs[:os]['name'] + os_rel = fs[:os]['release']['major'] + os__rel = fs[:os]['release']['full'] + elsif fs.key? :operatingsystem + os_name = fs[:operatingsystem] + os_rel = fs.fetch(:operatingsystemmajrelease, fs.fetch(:lsbmajdistrelease, nil)) + os__rel = fs.fetch(:lsbdistrelease, fs.fetch(:operatingsystemrelease, '@@@')) + else + require 'pp' + pp fs + fail( 'ERROR: unrecognized facterset format' ) + end + + # Sanitize OS names to match the formats used in the facterdb README + label = "#{os_name} #{os_rel}" + if os_name =~ /^(Archlinux|Gentoo)$/ + label = os_name + elsif os_name =~ /^(SLES|FreeBSD|OpenSuSE)$/ || + (os_name =~ /^(RedHat|Scientific|OracleLinux|CentOS)/ && os_rel.nil?) + label = "#{os_name} #{os__rel.split('.').first}" + elsif os_name =~ /^(OpenBSD|Ubuntu|Fedora)$/ + label = "#{os_name} #{os__rel}" + elsif os_name =~ /^(Solaris)/ + label = "#{os_name} #{os__rel.split('.')[1]}" + elsif os_name =~ /^windows$/ + label = "#{os_name} #{os__rel.sub('6.3.9600','2012 R2').sub('6.1.7600','2008 R2')}" + end + + label +end + +desc 'generate a markdown table of Facter/OS coverage (for the README)' +task :table do + require_relative 'lib/facterdb' + factsets = FacterDB.get_facts() + facter_versions = factsets.map{ |x| x[:facterversion][0..2] }.uniq.sort + os_facter_matrix = {} + + # Process the facts and create a hash of all the OS and facter combinations + factsets.each do |facts| + fv = facts[:facterversion][0..2] + label = factset_to_os_label(facts) + os_facter_matrix[label] ||= {} + os_facter_matrix[label][fv] ||= 0 + os_facter_matrix[label][fv] += 1 + end + # Extract the OS list + os_versions = os_facter_matrix.keys.uniq.sort + + # Write out a nice table + os_version_width = (os_versions.map{|x| x.size } + [17]).max + puts "| #{'operating system'.center(os_version_width)} |#{facter_versions.map{|x| " #{x} |" }.join}" + puts "| #{'-' * (os_version_width)} |#{facter_versions.map{|x| " --- |" }.join}" + os_versions.each do |label| + fvs = facter_versions.map{ |facter_version| os_facter_matrix[label][facter_version] || 0 } + row = "| #{label.ljust(os_version_width)} |" + fvs.each { |fv| row += (fv > 0? " #{fv.to_s.center(3)} |" : " |" ) } + puts row + end +end From 431fa7dce6557c27bc27886bec61f41e712f8267 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Mon, 26 Mar 2018 11:51:40 +0800 Subject: [PATCH 2/3] (maint) Add better support for Windows detection using source injection Previously the fact information was not enough to determine the Windows version. This is due to deficiencies in the facter facts not so much this gem. This commit adds a helper into the fact reading to record the filename used to load the factsets. This is then used as a hint when generating the README table. This is enabled using an environment variable, and is off by default. This is because these facts would not exist in a normal factset for a system of that type. --- README.md | 186 +++++++++++++++++++++++++++++------------------- Rakefile | 21 +++++- lib/facterdb.rb | 21 +++++- 3 files changed, 153 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index 57f92029..894807e5 100644 --- a/README.md +++ b/README.md @@ -58,79 +58,81 @@ FacterDB::get_facts('osfamily=Debian') ## Facter version and Operating System coverage -| operating system | 1.6 | 1.7 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 3.0 | 3.1 | 3.2 | 3.3 | 3.4 | 3.5 | 3.6 | 3.7 | 3.8 | 3.9 | -| ------------------ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| AIX 5300 | | | | | | | | | | | 1 | | | | | | | | -| AIX 6100 | | | | | | | | | | | 1 | | | | | | | | -| AIX 7100 | | | | | | | | | | | 1 | | | | | | | 1 | -| Amazon | 2 | | | | | | | | | | | | | | | | | | -| Amazon 2017 | | | | | 1 | 1 | 1 | | | | | | | | 1 | | | | -| Amazon 4 | | 1 | 1 | 1 | | | | | 1 | 1 | | 1 | | | | | | | -| Archlinux | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | | | | | | | | | | 1 | -| CentOS 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| CentOS 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| CentOS 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | -| Darwin | | | 2 | 2 | | | | | | | | | | | | | | | -| Darwin 14 | | | 2 | 2 | 2 | 2 | 2 | 1 | | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | -| Darwin 15 | | | | | 1 | 1 | 1 | 1 | | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | -| Darwin 16 | | | | | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | | -| Debian 1 | | | | | | 1 | | | | | | | | | | | | | -| Debian 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | | | | | | | | | -| Debian 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| Debian 8 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| Debian 9 | | | 2 | 2 | 2 | 1 | 2 | 2 | | | | | | | | | 2 | | -| Fedora 19 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| Fedora 20 | | 11 | | | | | | | | | | | | | | | | | -| Fedora 21 | | | | | | | 11 | | | | | | | | | | | | -| Fedora 22 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | 2 | | | | | | | | | -| Fedora 23 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | 2 | | | | | | | | | -| Fedora 24 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | | | | 2 | 2 | 2 | 2 | 2 | | | -| Fedora 25 | | | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | 2 | 2 | 2 | | -| Fedora 26 | | | | | | | 11 | | | | | | | | | | | | -| FreeBSD 10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | | | | | | | | | | 1 | -| FreeBSD 11 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | | | | | | 1 | -| FreeBSD 9 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| Gentoo | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| LinuxMint 18 | | | | | | | | | | 1 | | 1 | | | | | | | -| OpenBSD 5.7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| OpenBSD 5.8 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| OpenBSD 5.9 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| OpenBSD 6.0 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| OpenSuSE 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| OpenSuSE 13 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| OpenSuSE 42 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | 1 | -| OracleLinux 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| OracleLinux 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| OracleLinux 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | -| RedHat 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| RedHat 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 3 | 2 | 2 | | -| RedHat 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | -| SLES 11 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | 2 | 2 | 2 | 2 | 2 | | -| SLES 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | | -| Scientific 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| Scientific 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| Scientific 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | -| Solaris | | | | | | | | | | | | | | | | | | 2 | -| Solaris 1 | | | | | | | | 1 | | | | | | | | | | | -| Solaris 11 | 2 | 2 | | | | | | | | | | | | | | | | | -| Solaris 2 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| Ubuntu 10.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| Ubuntu 12.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | | | | | -| Ubuntu 14.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| Ubuntu 14.10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| Ubuntu 15.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | -| Ubuntu 15.10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | | 2 | 2 | 2 | | | | | -| Ubuntu 16.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| Ubuntu 16.10 | | | | | | | | | | | | | | | 2 | | | | -| windows 10 | | | | | | | | 2 | | | | | 2 | 2 | 2 | 2 | 2 | | -| windows 10.0.14393 | | | | 3 | 3 | 3 | 3 | 1 | 3 | 3 | | 3 | | | | | | | -| windows 2008 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | -| windows 2008 R2 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | -| windows 2012 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | -| windows 2012 R2 | | | | 3 | 3 | 2 | 3 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | -| windows 2016 | | | | | | | | | | | | | 1 | 1 | 1 | 1 | 1 | | -| windows 7 | | | | 1 | 1 | 1 | 2 | 1 | 2 | 2 | | 1 | 1 | 1 | 1 | 1 | 1 | | -| windows 8.1 | | | | | | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| operating system | 1.6 | 1.7 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 3.0 | 3.1 | 3.2 | 3.3 | 3.4 | 3.5 | 3.6 | 3.7 | 3.8 | 3.9 | +| --------------------------- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| AIX 5300 | | | | | | | | | | | 1 | | | | | | | | +| AIX 6100 | | | | | | | | | | | 1 | | | | | | | | +| AIX 7100 | | | | | | | | | | | 1 | | | | | | | 1 | +| Amazon | 2 | | | | | | | | | | | | | | | | | | +| Amazon 2017 | | | | | 1 | 1 | 1 | | | | | | | | 1 | | | | +| Amazon 4 | | 1 | 1 | 1 | | | | | 1 | 1 | | 1 | | | | | | | +| Archlinux | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | | | | | | | | | | 1 | +| CentOS 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| CentOS 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| CentOS 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| Darwin | | | 2 | 2 | | | | | | | | | | | | | | | +| Darwin 14 | | | 2 | 2 | 2 | 2 | 2 | 1 | | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Darwin 15 | | | | | 1 | 1 | 1 | 1 | | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Darwin 16 | | | | | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | | +| Debian 1 | | | | | | 1 | | | | | | | | | | | | | +| Debian 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | | | | | | | | | +| Debian 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Debian 8 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Debian 9 | | | 2 | 2 | 2 | 1 | 2 | 2 | | | | | | | | | 2 | | +| Fedora 19 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Fedora 20 | | 11 | | | | | | | | | | | | | | | | | +| Fedora 21 | | | | | | | 11 | | | | | | | | | | | | +| Fedora 22 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | 2 | | | | | | | | | +| Fedora 23 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | 2 | | | | | | | | | +| Fedora 24 | 1 | 1 | 2 | 2 | 2 | 2 | 2 | 2 | | | | 2 | 2 | 2 | 2 | 2 | | | +| Fedora 25 | | | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | 2 | 2 | 2 | | +| Fedora 26 | | | | | | | 11 | | | | | | | | | | | | +| FreeBSD 10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | | | | | | | | | | 1 | +| FreeBSD 11 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | | | | | | 1 | +| FreeBSD 9 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Gentoo | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| LinuxMint 18 | | | | | | | | | | 1 | | 1 | | | | | | | +| OpenBSD 5.7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenBSD 5.8 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenBSD 5.9 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenBSD 6.0 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenSuSE 12 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenSuSE 13 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| OpenSuSE 42 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | 1 | +| OracleLinux 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| OracleLinux 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| OracleLinux 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| RedHat 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| RedHat 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 3 | 2 | 2 | | +| RedHat 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| SLES 11 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | 2 | 2 | 2 | 2 | 2 | | +| SLES 12 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | | | | 1 | 1 | 1 | 1 | 1 | | +| Scientific 5 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Scientific 6 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Scientific 7 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | 2 | 2 | | 2 | 1 | 1 | 2 | 1 | 1 | | +| Solaris | | | | | | | | | | | | | | | | | | 2 | +| Solaris 1 | | | | | | | | 1 | | | | | | | | | | | +| Solaris 11 | 2 | 2 | | | | | | | | | | | | | | | | | +| Solaris 2 | | | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 10.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 12.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | | | | | +| Ubuntu 14.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Ubuntu 14.10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 15.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | | | | | | | | | | | +| Ubuntu 15.10 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | 2 | | 2 | 2 | 2 | | | | | +| Ubuntu 16.04 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | 2 | | 2 | | 2 | 2 | 2 | 2 | 2 | 2 | | +| Ubuntu 16.10 | | | | | | | | | | | | | | | 2 | | | | +| Windows 10 | | | | | | | | 2 | | | | | 2 | 2 | 2 | 2 | 2 | | +| Windows 10.0.14393 | | | | 2 | 2 | 2 | 2 | | 2 | 2 | | 2 | | | | | | | +| Windows 7 | | | | 1 | 1 | 1 | 2 | 1 | 2 | 2 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows 8.1 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows Server 10.0.14393 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | | | | | | | +| Windows Server 2008 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows Server 2008 R2 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows Server 2012 | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows Server 2012 R2 | | | | 1 | 1 | 1 | 2 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows Server 2012 R2 Core | | | | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | 1 | 1 | 1 | 1 | 1 | 1 | | +| Windows Server 2016 | | | | | | | | | | | | | 1 | 1 | 1 | 1 | 1 | | Where the number (1, 2 etc.) are the number of factsets for that OS and facter combination (e.g., x86_64 and i386 architectures) @@ -208,6 +210,44 @@ FACTERDB_SEARCH_PATHS="/var/opt/lib/custom_facts:/tmp/custom_facts:/home/user1/c FACTERDB_SKIP_DEFAULTDB='yes' ``` +## Debugging fact sets + +By setting the environment variable `FACTERDB_INJECT_SOURCE` the following facts are injected into all fact sets: + +`_facterdb_path` : The base name of the file used to load this fact set e.g. `centos-5-i386.facts` + +`_facterdb_filename` : The full path of the file used to load this fact set e.g. `/project/facter-db/centos-5-i386.facts` + + +``` json +{ + "_facterdb_path": "centos-5-i386.facts", + "_facterdb_filename": "/project/facter-db/centos-5-i386.facts", + "aio_agent_version": "1.8.3", + "architecture": "i386", + "augeas": { + "version": "1.4.0" + }, + "augeasversion": "1.4.0", + "bios_release_date": "07/30/2013", + "bios_vendor": "Phoenix Technologies LTD", + "bios_version": "6.00", + "blockdevice_fd0_size": 4096, + "blockdevice_hdc_size": 4294965248, + "blockdevice_sda_model": "Virtual disk", + ... +``` + +To set the environment variable use; + +``` bash +bash> FACTERDB_INJECT_SOURCE='true' +``` +or on Windows +``` powershell +powershell> $ENV:FACTERDB_INJECT_SOURCE = 'true' +``` + # Contributing Please submit issues at https://github.com/camptocamp/facterdb/issues or PRs in the same repository. diff --git a/Rakefile b/Rakefile index e1477b5e..2a017ba1 100644 --- a/Rakefile +++ b/Rakefile @@ -53,7 +53,20 @@ def factset_to_os_label(fs) elsif os_name =~ /^(Solaris)/ label = "#{os_name} #{os__rel.split('.')[1]}" elsif os_name =~ /^windows$/ - label = "#{os_name} #{os__rel.sub('6.3.9600','2012 R2').sub('6.1.7600','2008 R2')}" + db_filename = fs[:_facterdb_filename] || 'there_is_no_filename' + if db_filename =~ /windows-10-/ + label = "Windows #{os__rel}" + elsif db_filename =~ /windows-7-/ + label = "Windows 7" + elsif db_filename =~ /windows-8[\d.]*-/ + label = "Windows #{os__rel.sub('6.2.9200','8').sub('6.3.9600','8.1')}" + elsif db_filename =~ /windows-.+-core-/ + label = "Windows Server #{os__rel.sub('6.3.9600','2012 R2')} Core" + elsif db_filename =~ /windows-2008/ || db_filename =~ /windows-2012/ || db_filename =~ /windows-2016/ + label = "Windows Server #{os__rel.sub('6.1.7600','2008 R2').sub('6.3.9600','2012 R2')}" + else + label = "#{os_name} #{os__rel}" + end end label @@ -62,7 +75,13 @@ end desc 'generate a markdown table of Facter/OS coverage (for the README)' task :table do require_relative 'lib/facterdb' + # Turn on the source injection + old_env = ENV['FACTERDB_INJECT_SOURCE'] + ENV['FACTERDB_INJECT_SOURCE'] = 'true' factsets = FacterDB.get_facts() + # Restore the source injection + ENV['FACTERDB_INJECT_SOURCE'] = old_env + facter_versions = factsets.map{ |x| x[:facterversion][0..2] }.uniq.sort os_facter_matrix = {} diff --git a/lib/facterdb.rb b/lib/facterdb.rb index dd68fe80..0ed03ae6 100644 --- a/lib/facterdb.rb +++ b/lib/facterdb.rb @@ -5,7 +5,7 @@ module FacterDB # @return [String] - returns a giant incomprehensible string of concatenated json data def self.database - @database ||= "[#{facterdb_fact_files.map { |f| File.read(f) }.join(',')}]\n" + @database ||= "[#{facterdb_fact_files.map { |f| read_json_file(f) }.join(',')}]\n" end # @return [Boolean] - returns true if we should use the default facterdb database, false otherwise @@ -15,6 +15,25 @@ def self.use_defaultdb? ENV['FACTERDB_SKIP_DEFAULTDB'].nil? end + # @return [Boolean] - returns true if we should inject the source file name and file path into the json factsets. + # The default is false. + def self.inject_source? + !ENV['FACTERDB_INJECT_SOURCE'].nil? + end + + def self.read_json_file(f) + content = File.read(f) + return content unless inject_source? + # Find the opening brace + first_brace = content.index('{') + return content if first_brace.nil? + # Inject source file information + json_injection = "\"_facterdb_filename\": #{File.basename(f).to_json}, " + json_injection += "\"_facterdb_path\": #{File.expand_path(f).to_json}, " + content.insert(first_brace + 1, json_injection) + end + private_class_method :read_json_file + # @return [Array[String]] - list of all files found in the default facterdb facts path def self.default_fact_files return [] unless use_defaultdb? From e964a0556138da00a821d24b800ff03105cdf780 Mon Sep 17 00:00:00 2001 From: Glenn Sarti Date: Mon, 26 Mar 2018 12:17:17 +0800 Subject: [PATCH 3/3] (maint) Allow spec tests to be run on Windows Previously the spec tests could not be run on Windows due to an errant stub which always enforce unix path separators. This commit removes the stub as it is not required. --- spec/facterdb_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/facterdb_spec.rb b/spec/facterdb_spec.rb index 087fc69e..a1ccfe00 100644 --- a/spec/facterdb_spec.rb +++ b/spec/facterdb_spec.rb @@ -5,7 +5,6 @@ describe 'database' do before(:each) do - stub_const("File::PATH_SEPARATOR", ":") ENV['FACTERDB_SKIP_DEFAULTDB'] = nil FacterDB.instance_variable_set(:@database, nil) end