Skip to content

Commit

Permalink
Merge pull request #76 from glennsarti/modify-readme-table
Browse files Browse the repository at this point in the history
(maint) Add `rake table` task + update README.md + better Windows detection
  • Loading branch information
DavidS committed Mar 26, 2018
2 parents 4287a8c + e964a05 commit f0bf8ea
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 68 deletions.
186 changes: 120 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,69 +56,85 @@ 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 | | | | 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)

## Add new Operating System support

Expand Down Expand Up @@ -146,13 +162,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:
Expand Down Expand Up @@ -194,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.
Expand Down
86 changes: 86 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,89 @@ 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$/
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
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 = {}

# 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
21 changes: 20 additions & 1 deletion lib/facterdb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?
Expand Down
1 change: 0 additions & 1 deletion spec/facterdb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f0bf8ea

Please sign in to comment.