Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into FACT-2600
Browse files Browse the repository at this point in the history
# Conflicts:
#	lib/framework/core/fact/internal/internal_fact_manager.rb
#	lib/framework/formatters/legacy_fact_formatter.rb
#	spec/framework/core/fact/internal/internal_fact_manager_spec.rb
  • Loading branch information
Andrei Filipovici committed Jun 9, 2020
2 parents 538b6eb + 7f64b49 commit 19248dc
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 21 deletions.
11 changes: 5 additions & 6 deletions .github/actions/presuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def install_facter_3_dependencies
run('bundle install')
end

def install_custom_beaker
def use_custom_beaker
message('USE CUSTOM BEAKER')
beaker_path, _ = run('bundle info beaker --path', FACTER_3_ACCEPTANCE_PATH)
Dir.chdir(beaker_path.split("\n").last) do
Expand All @@ -25,7 +25,7 @@ def initialize_beaker
beaker_platform_with_options = platform_with_options(beaker_platform)

message('BEAKER INITIALIZE')
run("beaker init -h #{beaker_platform_with_options} -o config/aio/options.rb")
run("beaker init -h #{beaker_platform_with_options} -o #{File.join('config', 'aio', 'options.rb')}")

message('BEAKER PROVISION')
run('beaker provision')
Expand All @@ -50,7 +50,7 @@ def install_puppet_agent
message('INSTALL PUPPET AGENT')

beaker_puppet_root, _ = run('bundle info beaker-puppet --path')
presuite_file_path = "#{beaker_puppet_root.chomp}/setup/aio/010_Install_Puppet_Agent.rb"
presuite_file_path = File.join(beaker_puppet_root.chomp, 'setup', 'aio', '010_Install_Puppet_Agent.rb')

run("beaker exec pre-suite --pre-suite #{presuite_file_path} --preserve-state", './', env_path_var)
end
Expand Down Expand Up @@ -86,7 +86,6 @@ def replace_facter_3_with_facter_4

extension = (HOST_PLATFORM.include? 'windows') ? '.bat' : ''
run("mv facter-ng#{extension} facter#{extension}", puppet_bin_dir)
# run("facter -v", puppet_bin_dir)
end


Expand All @@ -104,7 +103,7 @@ def install_latest_facter_4(gem_command)
def run_acceptance_tests
message('RUN ACCEPTANCE TESTS')

run('beaker exec tests', './', env_path_var)
run('beaker exec tests --test-tag-exclude=server,facter_3 --test-tag-or=risk:high,audit:high', './', env_path_var)
end

def message(message)
Expand Down Expand Up @@ -136,7 +135,7 @@ def run(command, dir = './', env = {})
install_bundler

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies }
install_custom_beaker
use_custom_beaker

Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do
initialize_beaker
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/acceptance_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Platform
strategy:
matrix:
os: [windows-2016]
os: [windows-2016, windows-2019, ubuntu-16.04, ubuntu-18.04, macos-10.15]
runs-on: ${{ matrix.os }}
env:
FACTER_3_ROOT: facter_3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
steps:
- name: Checkout current PR
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Commit message checks
uses: ruby/setup-ruby@v1
Expand Down
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,4 @@



\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*


\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
1 change: 0 additions & 1 deletion lib/custom_facts/util/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def load_all
paths = search_path
paths&.each do |dir|
# dir is already an absolute path
dir = dir.gsub(/[\/\\]+/, File::SEPARATOR)
Dir.glob(File.join(dir, '*.rb')).each do |path|
# exclude dirs that end with .rb
load_file(path) if FileTest.file?(path)
Expand Down
3 changes: 3 additions & 0 deletions lib/facter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def resolve_fact(user_query)
user_query = user_query.to_s
resolved_facts = Facter::FactManager.instance.resolve_facts([user_query])
SessionCache.invalidate_all_caches
# we must make a distinction between custom facts that return nil and nil facts
# Nil facts should not be packaged as ResolvedFacts! (add_fact_to_searched_facts packages facts)
resolved_facts = resolved_facts.reject { |fact| fact.type == :nil }
fact_collection = FactCollection.new.build_fact_collection!(resolved_facts)
splitted_user_query = Facter::Utils.split_user_query(user_query)

Expand Down
7 changes: 1 addition & 6 deletions lib/framework/core/fact/internal/internal_fact_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ def resolve_facts(searched_facts)
threads = start_threads(internal_searched_facts)
resolved_facts = join_threads(threads, internal_searched_facts)

nil_searched_facts = filter_nil_facts(searched_facts)
nil_resolved_facts = resolve_nil_facts(nil_searched_facts)
nil_resolved_facts = resolve_nil_facts(searched_facts)

resolved_facts.concat(nil_resolved_facts)
end
Expand All @@ -21,10 +20,6 @@ def filter_internal_facts(searched_facts)
searched_facts.select { |searched_fact| %i[core legacy].include? searched_fact.type }
end

def filter_nil_facts(searched_facts)
searched_facts.select { |searched_fact| %i[nil].include? searched_fact.type }
end

def resolve_nil_facts(searched_facts)
resolved_facts = []
searched_facts.select { |fact| fact.type == :nil }.each do |fact|
Expand Down
2 changes: 1 addition & 1 deletion lib/framework/formatters/legacy_fact_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def hash_to_facter_format(facts_hash)
pretty_json = JSON.pretty_generate(facts_hash)

@log.debug('Change key value delimiter from : to =>')
# pretty_json.gsub!(/^(.*?)(:)/, '\1 =>')
pretty_json.gsub!(/":/, '" =>')

@log.debug('Remove quotes from parent nodes')
Expand All @@ -85,6 +84,7 @@ def remove_enclosing_accolades(pretty_fact_json)
end

def remove_comma_and_quation(output)
# quotation marks that come after \ are not removed
@log.debug('Remove unnecessary comma and quotation marks on root facts')
output.split("\n")
.map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|(?<!\\)\"/, '').gsub('\\"', '"') }.join("\n")
Expand Down
18 changes: 18 additions & 0 deletions spec/facter/facter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ def mock_collection(method, os_name = nil, error = nil)

expect(Facter.fact('os.name')).to be_nil
end

context 'when there is a resolved fact with type nil' do
before do
allow(fact_manager_spy).to receive(:resolve_facts).and_return([missing_fact])
allow(fact_collection_spy).to receive(:build_fact_collection!).with([]).and_return(empty_fact_collection)
allow(fact_collection_spy).to receive(:value).and_raise(KeyError)
end

it 'is rejected' do
Facter.fact('missing_fact')

expect(fact_collection_spy).to have_received(:build_fact_collection!).with([])
end

it 'returns nil' do
expect(Facter.fact('missing_fact')).to be_nil
end
end
end

describe '#[]' do
Expand Down
12 changes: 12 additions & 0 deletions spec/facter/query_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,17 @@
expect(matched_facts).to be_an_instance_of(Array).and \
contain_exactly(an_instance_of(Facter::SearchedFact).and(having_attributes(fact_class: path_class)))
end

context 'when fact does not exist' do
let(:query_list) { ['non_existing_fact'] }
let(:loaded_facts) { [] }

it 'creates a nil fact' do
matched_facts = Facter::QueryParser.parse(query_list, loaded_facts)
expect(matched_facts).to be_an_instance_of(Array).and contain_exactly(
an_object_having_attributes(name: 'non_existing_fact', user_query: 'non_existing_fact', type: :nil)
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
expect(resolved_facts).to eq([resolved_fact])
end

context 'when resolved fac is of type nil' do
context 'when resolved fact is of type nil' do
let(:searched_fact) do
instance_spy(Facter::SearchedFact, name: 'missing_fact', fact_class: nil,
filter_tokens: [], user_query: '', type: :nil)
Expand Down
4 changes: 2 additions & 2 deletions tasks/commits.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ task(:commits) do
# populated with the range of commits the PR contains. If not available, this
# falls back to `master..HEAD` as a next best bet as `master` is unlikely to
# ever be absent.
commit_range = ENV['TRAVIS_COMMIT_RANGE'].nil? ? 'master..HEAD' : ENV['TRAVIS_COMMIT_RANGE'].sub(/\.\.\./, '..')
commit_range = 'HEAD^..HEAD'
puts "Checking commits #{commit_range}"
`git log --no-merges --pretty=%s #{commit_range}`.each_line do |commit_summary|
# This regex tests for the currently supported commit summary tokens: maint, doc, gem, or fact-<number>.
# The exception tries to explain it in more full.
if /^\((maint|doc|docs|gem|fact-\d+)\)|revert/i.match(commit_summary).nil?
if /^\((maint|doc|docs|gem|fact-\d+)\)|revert|merge/i.match(commit_summary).nil?
raise "\n\n\n\tThis commit summary didn't match CONTRIBUTING.md guidelines:\n" \
"\n\t\t#{commit_summary}\n" \
"\tThe commit summary (i.e. the first line of the commit message) should start with one of:\n" \
Expand Down

0 comments on commit 19248dc

Please sign in to comment.