Skip to content

Commit

Permalink
Trusted facts, first try
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Macchi committed Mar 23, 2018
1 parent 47dde98 commit dab772e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/onceover/controlrepo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ def self.config
end

def self.facts(filter = nil)
@@existing_controlrepo.facts(filter)
@@existing_controlrepo.facts(filter, 'values')
end

def self.trusted_facts(filter = nil)
@@existing_controlrepo.facts(filter, 'trusted')
end

def self.hiera_config_file
Expand Down Expand Up @@ -170,12 +174,13 @@ def classes
classes.flatten
end

def facts(filter = nil)
def facts(filter = nil, key = 'values')
# Returns an array facts hashes
all_facts = []
logger.debug "Reading factsets"
@facts_files.each do |file|
all_facts << read_facts(file)['values']
logger.debug "########### Retrieving #{key} for #{file} ############"
all_facts << read_facts(file)[key]
end
if filter
# Allow us to pass a hash of facts to filter by
Expand Down Expand Up @@ -579,7 +584,7 @@ def read_facts(facts_file)
begin
result = JSON.parse(file)
rescue JSON::ParserError
raise "Could not parse the JSON file, check that it is valid JSON and that the encoding is correct"
raise "Could not parse the file #{facts_file}, check that it is valid JSON and that the encoding is correct"
end
result
end
Expand Down
4 changes: 4 additions & 0 deletions lib/onceover/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Node
attr_accessor :name
attr_accessor :beaker_node
attr_accessor :fact_set
attr_accessor :trusted_set

def initialize(name)
@name = name
Expand All @@ -19,9 +20,12 @@ def initialize(name)
File.basename(facts_file, '.json') == name
}
@fact_set = Onceover::Controlrepo.facts[facts_file_index]
@trusted_set = Onceover::Controlrepo.trusted_facts[facts_file_index]
rescue TypeError
@fact_set = nil
@trusted_set = nil
end

@@all << self

end
Expand Down
2 changes: 2 additions & 0 deletions templates/test_spec.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ let!(:<%= function %>) { MockFunction.new('<%= function %>') { |f|
<% test.nodes.each do |node| -%>
context "using fact set <%= node.name %>" do
node_facts = <%= node.fact_set %>
trusted_facts = <%= node.trusted_set %>
let(:facts) { node_facts }
let(:trusted_facts) { trusted_facts }
<% if @before_conditions -%>
before :each do
<% @before_conditions.each do |function| -%>
Expand Down

0 comments on commit dab772e

Please sign in to comment.