This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from puppetlabs/FACT-1981
(FACT-1981) Detect facts dynamically based on OS.
- Loading branch information
Showing
14 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--format documentation | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
sudo: false | ||
language: ruby | ||
rvm: | ||
- 2.6 | ||
- 2.5 | ||
- 2.4 | ||
- 2.3 | ||
cache: | ||
bundler: true | ||
before_install: | ||
- gem update --system | ||
- gem install bundler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# facter-ng | ||
New version of Puppet Facter written in Ruby | ||
|
||
[![Build Status](https://travis-ci.org/puppetlabs/facter-ng.svg?branch=master)](https://travis-ci.org/puppetlabs/facter-ng?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/puppetlabs/facter-ng/badge.svg?branch=master)](https://coveralls.io/github/puppetlabs/facter-ng?branch=master) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
class FactLoader | ||
def self.load(os) | ||
# load facts/#{os}/*.rb | ||
{ | ||
'networking.ip' => 'NetworkIP', | ||
'networking.interface' => 'NetworkInterface' | ||
} | ||
# Loads all the facts for the operating system Facter is running on. | ||
# Facts are dynamically loaded from facts/#{operating_system}/*.rb | ||
# Returns a hash containing fact name and fact classes | ||
# e.g. | ||
# | ||
# { | ||
# "networking.interface" => Facter::Linux::NetworkInterface, | ||
# "networking.ip" => Facter::Linux::NetworkIP | ||
# } | ||
def self.load(operating_system) | ||
loaded_facts = {} | ||
os = operating_system.capitalize | ||
os_module_name = Module.const_get("Facter::#{os}") | ||
|
||
# select only classes | ||
classes = os_module_name.constants.select { |c| os_module_name.const_get(c).is_a? Class } | ||
|
||
classes.each do |class_name| | ||
klass = Class.const_get("Facter::#{os}::" + class_name.to_s) | ||
fact_name = klass::FACT_NAME | ||
loaded_facts.merge!(fact_name => klass) | ||
end | ||
|
||
loaded_facts | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Facter | ||
class LoadedFact | ||
@fact_name | ||
@fact_class | ||
@fact_attributes | ||
|
||
attr_accessor :fact_name, :fact_class, :filter_tokens | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
describe '.load facts for OS' do | ||
it 'load one fact' do | ||
allow_any_instance_of(Module).to receive(:constants).and_return([:NetworkInterface]) | ||
fact_hash = Facter::FactLoader.load(:linux) | ||
|
||
expect fact_hash.values_at('networking.interface').equal?('Facter::Linux::NetworkInterface') | ||
end | ||
|
||
it 'does not load any fact' do | ||
allow_any_instance_of(Module).to receive(:constants).and_return([]) | ||
fact_hash = Facter::FactLoader.load(:linux) | ||
|
||
expect fact_hash.size.equal?(0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters