From 3be296e2d66d03dde724f63c5da9dc1477a70fcf Mon Sep 17 00:00:00 2001 From: BogdanIrimie Date: Wed, 29 Jul 2020 17:26:01 +0300 Subject: [PATCH] Detect augeas from gem if augparse is not available. --- .github/actions/presuite.rb | 71 ++++++++------- .github/workflows/acceptance_tests.yml | 19 ++-- CHANGELOG.md | 15 ---- acceptance/Gemfile | 2 +- acceptance/config/aio/options.rb | 3 + .../lib/facter/acceptance/base_fact_utils.rb | 2 +- .../lib/facter/acceptance/user_fact_utils.rb | 8 -- .../lib/puppet/acceptance/common_utils.rb | 6 +- .../aio/pre-suite/001_run_with_facter_ng.rb | 75 ++++++++++++++++ .../tests/custom_facts/block_custom_fact.rb | 47 ---------- .../tests/custom_facts/cached_custom_fact.rb | 13 +-- .../conflicts_with_builtin_fact.rb | 14 +-- ...th_10001_weight_overrides_external_fact.rb | 4 +- .../tests/custom_facts/expand_command.rb | 2 +- .../having_multiple_facts_in_one_file.rb | 2 +- .../load_custom_fact_from_lib_facter.rb | 2 +- .../tests/custom_facts/not_expand_command.rb | 2 +- .../using_win32ole_should_not_hang.rb | 6 +- .../weighted_cached_custom_facts.rb | 13 +-- .../windows_not_expand_command.rb | 2 +- .../env_var_overrides_external_fact.rb | 10 +-- ...nal_dir_overrides_default_external_fact.rb | 10 +-- .../external_fact_overrides_custom_fact.rb | 4 +- ...s_custom_fact_with_10000_weight_or_less.rb | 4 +- ...fact_overrides_custom_fact_with_confine.rb | 4 +- ...l_fact_stderr_messages_output_to_stderr.rb | 6 +- .../external_facts_only_run_once.rb | 8 +- .../fact_directory_precedence.rb | 22 +++-- .../handle_same_filename_in_different_dirs.rb | 14 ++- ...t_users_default_external_fact_directory.rb | 29 +++--- .../root_uses_default_external_fact_dir.rb | 6 +- .../structured_executable_facts.rb | 12 +-- .../facts/non_root_users_without_errors.rb | 2 +- ...gsystem_detection_after_clear_on_ubuntu.rb | 2 +- acceptance/tests/facts/ssh_key.rb | 12 ++- .../tests/facts/verify_tmpfs_file_system.rb | 5 +- acceptance/tests/load_libfacter.rb | 4 +- acceptance/tests/options/config.rb | 4 +- .../tests/options/config_file/blocklist.rb | 4 +- .../blocklist_from_puppet_facts.rb | 4 +- ...custom_dir_overridden_by_cli_custom_dir.rb | 8 +- .../tests/options/config_file/custom_facts.rb | 6 +- .../options/config_file/custom_facts_list.rb | 7 +- acceptance/tests/options/config_file/debug.rb | 4 +- .../config_file/debug_override_config_file.rb | 4 +- .../config_file/default_file_location.rb | 10 +-- ...ir_conflicts_with_cli_no_external_facts.rb | 4 +- ...rnal_dir_overridden_by_cli_external_dir.rb | 7 +- .../options/config_file/external_facts.rb | 10 +-- .../config_file/external_facts_list.rb | 10 +-- .../options/config_file/load_from_ruby.rb | 23 ++--- .../tests/options/config_file/log_level.rb | 4 +- .../no_custom_facts_and_custom_dir.rb | 8 +- .../no_custom_facts_and_facterlib.rb | 7 +- .../no_custom_facts_and_load_path.rb | 9 +- .../options/config_file/no_external_facts.rb | 6 +- .../no_external_facts_and_external_dir.rb | 8 +- .../no_ruby_disables_custom_facts.rb | 8 +- .../no_ruby_disables_ruby_facts.rb | 4 +- acceptance/tests/options/config_file/trace.rb | 13 ++- ...nal_execution_resolver_with_json_output.rb | 32 +++---- ...nal_execution_resolver_with_text_output.rb | 23 +++-- ...nal_execution_resolver_with_yaml_output.rb | 32 +++---- .../ttls_cached_external_json_resolver.rb | 21 +++-- .../ttls_cached_external_text_resolver.rb | 21 +++-- .../ttls_cached_external_yaml_resolver.rb | 21 +++-- ...ed_facts_clear_by_empty_ttls_cache_list.rb | 10 +-- ...ls_cached_facts_creates_json_cache_file.rb | 13 +-- ..._facts_do_not_read_the_old_cached_value.rb | 10 +-- ...s_expire_facts_refresh_the_cached_value.rb | 15 ++-- ...cached_facts_read_from_the_cached_value.rb | 8 +- ...ed_facts_that_are_corrupt_are_refreshed.rb | 13 +-- ...ts_that_are_empty_return_an_empty_value.rb | 8 +- ...pet_facts_creates_json_for_cached_facts.rb | 12 +-- .../ttls_puppet_facts_honors_cached_facts.rb | 7 +- .../tests/options/config_file/verbose.rb | 6 +- acceptance/tests/options/custom_facts.rb | 6 +- .../tests/options/custom_facts_facterlib.rb | 7 +- acceptance/tests/options/custom_facts_list.rb | 5 +- .../tests/options/custom_facts_load_path.rb | 4 +- acceptance/tests/options/external_facts.rb | 6 +- .../tests/options/external_facts_list.rb | 8 +- acceptance/tests/options/json.rb | 8 +- acceptance/tests/options/list_block_groups.rb | 2 +- .../options/list_block_groups_facter_4.rb | 15 ++++ acceptance/tests/options/list_cache_groups.rb | 13 ++- acceptance/tests/options/no_block.rb | 4 +- .../no_cache_should_not_cache_facts.rb | 8 +- .../no_cache_should_not_load_cached_facts.rb | 8 +- ...o_cache_should_not_refresh_cached_facts.rb | 15 ++-- acceptance/tests/options/no_custom_facts.rb | 4 +- .../options/no_custom_facts_and_custom_dir.rb | 2 +- .../options/no_custom_facts_and_facterlib.rb | 2 +- .../options/no_custom_facts_and_load_path.rb | 4 +- acceptance/tests/options/no_external_facts.rb | 4 +- .../no_external_facts_and_external_dir.rb | 2 +- acceptance/tests/options/no_ruby.rb | 4 +- acceptance/tests/options/puppet_facts.rb | 9 +- acceptance/tests/options/trace.rb | 10 +-- acceptance/tests/options/yaml.rb | 8 +- agent/facter-ng.gemspec | 2 +- facter.gemspec | 2 +- lib/facter/facts/aix/disks.rb | 17 ---- lib/facter/facts/aix/memory/swap/available.rb | 22 ----- .../facts/aix/memory/swap/available_bytes.rb | 22 ----- lib/facter/facts/aix/memory/swap/capacity.rb | 20 ----- lib/facter/facts/aix/memory/swap/total.rb | 22 ----- .../facts/aix/memory/swap/total_bytes.rb | 22 ----- lib/facter/facts/aix/memory/swap/used.rb | 21 ----- .../facts/aix/memory/swap/used_bytes.rb | 19 ---- .../facts/aix/memory/system/available.rb | 22 ----- .../aix/memory/system/available_bytes.rb | 22 ----- .../facts/aix/memory/system/capacity.rb | 20 ----- lib/facter/facts/aix/memory/system/total.rb | 22 ----- .../facts/aix/memory/system/total_bytes.rb | 22 ----- lib/facter/facts/aix/memory/system/used.rb | 21 ----- .../facts/aix/memory/system/used_bytes.rb | 19 ---- .../core/fact_loaders/fact_loader.rb | 2 - lib/facter/resolvers/aix/disks.rb | 63 ------------- lib/facter/resolvers/aix/memory.rb | 65 -------------- lib/facter/resolvers/aix/partitions.rb | 29 ++++-- .../resolvers/aix/utils/info_extractor.rb | 20 ----- lib/facter/resolvers/augeas_resolver.rb | 21 ++++- lib/facter/version.rb | 2 +- spec/facter/facts/aix/disks_spec.rb | 53 ----------- .../aix/memory/swap/available_bytes_spec.rb | 48 ---------- .../facts/aix/memory/swap/available_spec.rb | 26 ------ .../facts/aix/memory/swap/capacity_spec.rb | 25 ------ .../facts/aix/memory/swap/total_bytes_spec.rb | 37 -------- .../facts/aix/memory/swap/total_spec.rb | 26 ------ .../facts/aix/memory/swap/used_bytes_spec.rb | 25 ------ .../facter/facts/aix/memory/swap/used_spec.rb | 25 ------ .../aix/memory/system/available_bytes_spec.rb | 38 -------- .../facts/aix/memory/system/available_spec.rb | 26 ------ .../facts/aix/memory/system/capacity_spec.rb | 25 ------ .../aix/memory/system/total_bytes_spec.rb | 38 -------- .../facts/aix/memory/system/total_spec.rb | 26 ------ .../aix/memory/system/used_bytes_spec.rb | 25 ------ .../facts/aix/memory/system/used_spec.rb | 25 ------ spec/facter/facts/linux/virtual_spec.rb | 88 ++++++------------- spec/facter/resolvers/aix/disks_spec.rb | 53 ----------- spec/facter/resolvers/aix/memory_spec.rb | 79 ----------------- spec/facter/resolvers/augeas_resolver_spec.rb | 63 +++++++++++-- spec/fixtures/lspv_disk_output | 11 --- spec/fixtures/lspv_output | 1 - spec/fixtures/svmon_content | 13 --- .../core/fact_loaders/fact_loader_spec.rb | 20 ++--- spec/mocks/augeas.rb | 7 ++ spec/mocks/kernel_mock.rb | 2 +- 149 files changed, 648 insertions(+), 1720 deletions(-) create mode 100644 acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb delete mode 100644 acceptance/tests/custom_facts/block_custom_fact.rb create mode 100644 acceptance/tests/options/list_block_groups_facter_4.rb delete mode 100644 lib/facter/facts/aix/disks.rb delete mode 100644 lib/facter/facts/aix/memory/swap/available.rb delete mode 100644 lib/facter/facts/aix/memory/swap/available_bytes.rb delete mode 100644 lib/facter/facts/aix/memory/swap/capacity.rb delete mode 100644 lib/facter/facts/aix/memory/swap/total.rb delete mode 100644 lib/facter/facts/aix/memory/swap/total_bytes.rb delete mode 100644 lib/facter/facts/aix/memory/swap/used.rb delete mode 100644 lib/facter/facts/aix/memory/swap/used_bytes.rb delete mode 100644 lib/facter/facts/aix/memory/system/available.rb delete mode 100644 lib/facter/facts/aix/memory/system/available_bytes.rb delete mode 100644 lib/facter/facts/aix/memory/system/capacity.rb delete mode 100644 lib/facter/facts/aix/memory/system/total.rb delete mode 100644 lib/facter/facts/aix/memory/system/total_bytes.rb delete mode 100644 lib/facter/facts/aix/memory/system/used.rb delete mode 100644 lib/facter/facts/aix/memory/system/used_bytes.rb delete mode 100644 lib/facter/resolvers/aix/disks.rb delete mode 100644 lib/facter/resolvers/aix/memory.rb delete mode 100644 lib/facter/resolvers/aix/utils/info_extractor.rb delete mode 100644 spec/facter/facts/aix/disks_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/available_bytes_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/available_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/capacity_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/total_bytes_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/total_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/used_bytes_spec.rb delete mode 100644 spec/facter/facts/aix/memory/swap/used_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/available_bytes_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/available_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/capacity_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/total_bytes_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/total_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/used_bytes_spec.rb delete mode 100644 spec/facter/facts/aix/memory/system/used_spec.rb delete mode 100644 spec/facter/resolvers/aix/disks_spec.rb delete mode 100644 spec/facter/resolvers/aix/memory_spec.rb delete mode 100644 spec/fixtures/lspv_disk_output delete mode 100644 spec/fixtures/lspv_output delete mode 100644 spec/fixtures/svmon_content create mode 100644 spec/mocks/augeas.rb diff --git a/.github/actions/presuite.rb b/.github/actions/presuite.rb index 9040e134f5..c23a0710e2 100644 --- a/.github/actions/presuite.rb +++ b/.github/actions/presuite.rb @@ -1,15 +1,12 @@ -# frozen_string_literal: true - require 'open3' -require 'fileutils' def install_bundler message('INSTALL BUNDLER') run('gem install bundler') end -def install_facter_acceptance_dependencies - message('INSTALL FACTER ACCEPTANCE DEPENDENCIES') +def install_facter_3_dependencies + message('INSTALL FACTER 3 ACCEPTANCE DEPENDENCIES') run('bundle install') end @@ -25,25 +22,24 @@ def initialize_beaker def beaker_platform { - 'ubuntu-18.04' => 'ubuntu1804-64a', - 'ubuntu-16.04' => 'ubuntu1604-64a', - 'ubuntu-20.04' => 'ubuntu2004-64a', - 'macos-10.15' => 'osx1015-64a', - 'windows-2016' => 'windows2016-64a', - 'windows-2019' => 'windows2019-64a' + 'ubuntu-18.04' => 'ubuntu1804-64a', + 'ubuntu-16.04' => 'ubuntu1604-64a', + 'ubuntu-20.04' => 'ubuntu2004-64a', + 'macos-10.15' => 'osx1015-64a', + 'windows-2016' => 'windows2016-64a', + 'windows-2019' => 'windows2019-64a' }[HOST_PLATFORM] end def platform_with_options(platform) return "\"#{platform}{hypervisor=none,hostname=localhost,is_cygwin=false}\"" if platform.include? 'windows' - "#{platform}{hypervisor=none\\,hostname=localhost}" end def install_puppet_agent message('INSTALL PUPPET AGENT') - beaker_puppet_root, = run('bundle info beaker-puppet --path') + beaker_puppet_root, _ = run('bundle info beaker-puppet --path') 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) @@ -53,34 +49,45 @@ def puppet_bin_dir linux_puppet_bin_dir = '/opt/puppetlabs/puppet/bin' windows_puppet_bin_dir = 'C:\\Program Files\\Puppet Labs\\Puppet\\bin' - HOST_PLATFORM.include?('windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir + (HOST_PLATFORM.include? 'windows') ? windows_puppet_bin_dir : linux_puppet_bin_dir end def puppet_command return '/opt/puppetlabs/puppet/bin/puppet' unless HOST_PLATFORM.include? 'windows' - - '"C:\\Program Files\\Puppet Labs\\Puppet\\bin\\puppet"' + "\"C:\\Program Files\\Puppet Labs\\Puppet\\bin\\puppet\"" end def gem_command return '/opt/puppetlabs/puppet/bin/gem' unless HOST_PLATFORM.include? 'windows' - - '"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem"' + "\"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin\\gem\"" end def env_path_var - HOST_PLATFORM.include?('windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} + (HOST_PLATFORM.include? 'windows') ? { 'PATH' => "#{puppet_bin_dir};#{ENV['PATH']}" } : {} end -def update_facter_lib - facter_lib_windows_path = 'C:/Program Files/Puppet Labs/Puppet/puppet/lib/ruby/vendor_ruby/facter' - facter_lib_linux_path = '/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/facter' +def replace_facter_3_with_facter_4 + message('SET FACTER 4 FLAG TO TRUE') + run("#{puppet_command} config set facterng true") - facter_lib_path = HOST_PLATFORM.include?('windows') ? facter_lib_windows_path : facter_lib_linux_path + install_latest_facter_4(gem_command) - message('OVERWRITE FACTER FILES') - FileUtils.rm_r([facter_lib_path, facter_lib_path + '.rb'], force: true) - run("#{'powershell' if HOST_PLATFORM.include? 'windows'} mv ../lib/* \'#{facter_lib_path.sub('facter', '')}\'") + message('CHANGE FACTER 3 WITH FACTER 4') + + extension = (HOST_PLATFORM.include? 'windows') ? '.bat' : '' + run("mv facter-ng#{extension} facter#{extension}", puppet_bin_dir) +end + + +def install_latest_facter_4(gem_command) + message('BUILD FACTER 4 LATEST AGENT GEM') + run("#{gem_command} build agent/facter-ng.gemspec", ENV['FACTER_4_ROOT']) + + message('UNINSTALL DEFAULT FACTER 4 AGENT GEM') + run("#{gem_command} uninstall facter-ng") + + message('INSTALL FACTER 4 GEM') + run("#{gem_command} install -f facter-ng-*.gem", ENV['FACTER_4_ROOT']) end def run_acceptance_tests @@ -112,17 +119,21 @@ def run(command, dir = './', env = {}) end ENV['DEBIAN_DISABLE_RUBYGEMS_INTEGRATION'] = 'no_warnings' -ACCEPTANCE_PATH = File.join(ENV['FACTER_4_ROOT'], 'acceptance') +FACTER_3_ACCEPTANCE_PATH = File.join(ENV['FACTER_3_ROOT'], 'acceptance') HOST_PLATFORM = ARGV[0] install_bundler -Dir.chdir(ACCEPTANCE_PATH) do - install_facter_acceptance_dependencies +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) { install_facter_3_dependencies } + +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do initialize_beaker install_puppet_agent - update_facter_lib +end + +replace_facter_3_with_facter_4 +Dir.chdir(FACTER_3_ACCEPTANCE_PATH) do _, status = run_acceptance_tests exit(status.exitstatus) end diff --git a/.github/workflows/acceptance_tests.yml b/.github/workflows/acceptance_tests.yml index 621db0f011..a67cba75de 100644 --- a/.github/workflows/acceptance_tests.yml +++ b/.github/workflows/acceptance_tests.yml @@ -17,9 +17,9 @@ jobs: os: [windows-2016, windows-2019, ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15] runs-on: ${{ matrix.os }} env: + FACTER_3_ROOT: facter_3 FACTER_4_ROOT: facter_4 SHA: latest - RELEASE_STREAM: puppet7 steps: - name: Checkout current PR @@ -27,6 +27,13 @@ jobs: with: path: facter_4 + - name: Clone facter 3 repo + uses: actions/checkout@v2 + with: + repository: puppetlabs/facter + ref: github_acceptance_tests + path: facter_3 + - name: Install Ruby 2.6 uses: ruby/setup-ruby@v1 with: @@ -42,19 +49,12 @@ jobs: sudo chmod a-w /home/runner /usr/share && sudo chmod -R a-w /usr/share/rust /home/runner/.config /home/linuxbrew - - name: Install dhclient for Linux + - name: Instal dhclient for Linux if: runner.os == 'Linux' run: | sudo apt install dhcpcd5 sudo dhclient - #Ipv6 is missing on the GitHub OSX machine and we need it for the networking facts tests - - name: Add ipv6 on OSX - if: runner.os == 'macOS' - run: | - primary_interface=`route -n get default | awk '/interface: */{print $NF}'` - sudo ifconfig $primary_interface inet6 add ::1/64 - - name: Run acceptance tests on Linux like platform if: runner.os != 'Windows' run: sudo -E "PATH=$PATH" ruby $FACTER_4_ROOT/.github/actions/presuite.rb ${{ matrix.os }} @@ -62,3 +62,4 @@ jobs: - name: Run acceptance tests on Windows like platform if: runner.os == 'Windows' run: ruby $Env:FACTER_4_ROOT/.github/actions/presuite.rb ${{ matrix.os }} + diff --git a/CHANGELOG.md b/CHANGELOG.md index 72afcfe853..cf40a73b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,3 @@ -## [4.0.31](https://github.com/puppetlabs/facter/tree/4.0.31) (2020-07-29) - -[Full Changelog](https://github.com/puppetlabs/facter/compare/4.0.30...4.0.31) - -### Added -- \(FACT-2718\) Block custom facts [\#1996](https://github.com/puppetlabs/facter/pull/1996) ([IrimieBogdan](https://github.com/IrimieBogdan)) -- \(FACT-2230\) Add Aix memory facts [\#1994](https://github.com/puppetlabs/facter/pull/1994) ([oanatmaria](https://github.com/oanatmaria)) -- \(FACT-2220\) Add Aix disks fact [\#1987](https://github.com/puppetlabs/facter/pull/1987) ([oanatmaria](https://github.com/oanatmaria)) -- \(FACT-2708\) Add man pages [\#1984 ](https://github.com/puppetlabs/facter/pull/1984) ([florindragos](https://github.com/florindragos)) - -### Fixed -- \(FACT-2710\) Correctly display vmware info [\#1988](https://github.com/puppetlabs/facter/pull/1987) ([oanatmaria](https://github.com/oanatmaria)) -- \(FACT-2702\) Fix system_profiler legacy facts [\#1982](https://github.com/puppetlabs/facter/pull/1982) ([oanatmaria](https://github.com/oanatmaria)) -- Handle Time and Symbol in executable facts [\#1977](https://github.com/puppetlabs/facter/pull/1977) ([gimmyxd](https://github.com/gimmyxd)) - ## [4.0.30](https://github.com/puppetlabs/facter/tree/4.0.30) (2020-07-15) [Full Changelog](https://github.com/puppetlabs/facter/compare/4.0.29...4.0.30) diff --git a/acceptance/Gemfile b/acceptance/Gemfile index 5b5edf203e..624e72eb7a 100644 --- a/acceptance/Gemfile +++ b/acceptance/Gemfile @@ -10,7 +10,7 @@ def location_for(place, fake_version = nil) end end -gem "beaker", *location_for(ENV['BEAKER_VERSION'] || "~> 4.24") +gem "beaker", *location_for(ENV['BEAKER_VERSION'] || "~> 4") gem 'beaker-puppet', *location_for(ENV['BEAKER_PUPPET_VERSION'] || '~> 1') gem "beaker-hostgenerator", *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'] || "~> 1.1") gem "beaker-abs", *location_for(ENV['BEAKER_ABS_VERSION'] || "~> 0.5") diff --git a/acceptance/config/aio/options.rb b/acceptance/config/aio/options.rb index bb8918d0e1..e7eba29d82 100644 --- a/acceptance/config/aio/options.rb +++ b/acceptance/config/aio/options.rb @@ -1,3 +1,6 @@ { :type => 'aio', + :pre_suite => [ + 'setup/aio/pre-suite/001_run_with_facter_ng.rb', + ], } diff --git a/acceptance/lib/facter/acceptance/base_fact_utils.rb b/acceptance/lib/facter/acceptance/base_fact_utils.rb index acf784a20c..f216e53533 100644 --- a/acceptance/lib/facter/acceptance/base_fact_utils.rb +++ b/acceptance/lib/facter/acceptance/base_fact_utils.rb @@ -548,7 +548,7 @@ def windows_expected_facts(agent) 'os.name' => 'windows', 'os.release.full' => os_version, 'os.release.major' => os_version, - 'os.windows.system32' => /C:\\(WINDOWS|[Ww]indows)\\(system32|sysnative)/, + 'os.windows.system32' => /C:\\(WINDOWS|Windows)\\(system32|sysnative)/, 'processors.count' => /[1-9]/, 'processors.physicalcount' => /[1-9]/, 'processors.isa' => /x86|x64/, diff --git a/acceptance/lib/facter/acceptance/user_fact_utils.rb b/acceptance/lib/facter/acceptance/user_fact_utils.rb index 7a831d7994..71408cb2e0 100644 --- a/acceptance/lib/facter/acceptance/user_fact_utils.rb +++ b/acceptance/lib/facter/acceptance/user_fact_utils.rb @@ -127,14 +127,6 @@ def user_shell(agent) '/bin/bash' end end - - def escape_paths(host, str) - if host['platform'] =~ /windows/ && !host.is_cygwin? - str.gsub('\\') { '\\\\' } - else - str - end - end end end end diff --git a/acceptance/lib/puppet/acceptance/common_utils.rb b/acceptance/lib/puppet/acceptance/common_utils.rb index 1ffe56f907..c9cec5f56b 100644 --- a/acceptance/lib/puppet/acceptance/common_utils.rb +++ b/acceptance/lib/puppet/acceptance/common_utils.rb @@ -2,11 +2,7 @@ module Puppet module Acceptance module CommandUtils def ruby_command(host) - if host['platform'] =~ /windows/ && !host.is_cygwin? - "cmd /V /C \"set PATH=#{host['privatebindir']};!PATH! && ruby\"" - else - "env PATH=\"#{host['privatebindir']}:${PATH}\" ruby" - end + "env PATH=\"#{host['privatebindir']}:${PATH}\" ruby" end module_function :ruby_command end diff --git a/acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb b/acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb new file mode 100644 index 0000000000..f6a3dfa263 --- /dev/null +++ b/acceptance/setup/aio/pre-suite/001_run_with_facter_ng.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true +require 'open3' +require 'tmpdir' + +def create_facter_gem + temp_dir = Dir.mktmpdir + Dir.chdir(temp_dir) do + download_and_build_facter_ng + + facter_repo_dir = Pathname.new("#{temp_dir}/facter-ng") + facter_gem_path = Dir.entries(facter_repo_dir).select { |file| file =~ /facter-ng-[0-9]+.[0-9]+.[0-9]+(.pre)?.gem/ } + File.join(facter_repo_dir, facter_gem_path) + end +end + +def download_and_build_facter_ng + branch_name = ENV['FACTER_4_BRANCH'] + puts "Cloning branch #{branch_name}" + Open3.capture2('echo $PATH') + + Open3.capture2("git clone https://github.com/puppetlabs/facter-ng.git &&" \ + 'cd facter-ng &&' \ + 'git fetch &&' \ + "git reset --hard origin/#{branch_name}") + + Dir.chdir('facter-ng') do + puts "Latest commit on branch #{branch_name}" + output, _stderr = Open3.capture2('git log -1') + puts output + + Open3.capture2('gem build agent/facter-ng.gemspec') + end +end + +def install_facter_gem(agent, facter_gem_path) + home_dir = on(agent, 'pwd').stdout.chop + gem_c = gem_command(agent) + + scp_to(agent, facter_gem_path, home_dir) + + on(agent, "#{gem_c} uninstall facter-ng") + on(agent, "#{gem_c} install -f facter-ng-*.gem") +end + +test_name 'Setup for Facter NG' do + windows_puppet_bin_path = '/cygdrive/c/Program\ Files/Puppet\ Labs/Puppet/bin' + linux_puppet_bin_path = '/opt/puppetlabs/puppet/bin' + set_facter_ng_command = 'puppet config set facterng true' + + puts 'Setting run with facter ng if environment variable FACTER_NG is true.' + puts "FACTER_NG is #{ENV["FACTER_NG"]}." + puts "FACTER_NG branch is #{ENV['FACTER_4_BRANCH']}" + + if ENV["FACTER_NG"] == 'true' + puts 'Cloning facter ng repository and creating gem file.' + facter_gem_path = create_facter_gem + + agents.each do |agent| + puts 'Installing Facter NG on agent.' + install_facter_gem(agent, facter_gem_path) + + puts 'Renaming facter to facter-original and facter-ng to facter.' + if agent['platform'] =~ /windows/ + on(agent, "cmd /c #{set_facter_ng_command}") + on(agent, "cd #{windows_puppet_bin_path} && mv facter-ng.bat facter.bat") + else + on(agent, "#{set_facter_ng_command} ") + on(agent, "cd #{linux_puppet_bin_path} && mv facter-ng facter") + end + + puts 'FACTER VERSION' + on(agent, "facter -v") + end + end +end diff --git a/acceptance/tests/custom_facts/block_custom_fact.rb b/acceptance/tests/custom_facts/block_custom_fact.rb deleted file mode 100644 index bb10f9fd5b..0000000000 --- a/acceptance/tests/custom_facts/block_custom_fact.rb +++ /dev/null @@ -1,47 +0,0 @@ -test_name 'custom facts included in blocklist will not be displayed' do - tag 'risk:high' - - require 'facter/acceptance/user_fact_utils' - extend Facter::Acceptance::UserFactUtils - - custom_fact_file = 'custom_facts.rb' - custom_fact_name = "my_custom_fact" - custom_fact_value = "custom_fact_value" - - fact_content = <<-CUSTOM_FACT - Facter.add(:#{custom_fact_name}) do - setcode do - "#{custom_fact_value}" - end - end - CUSTOM_FACT - - config_data = <<~FACTER_CONF - facts : { - blocklist : [ "#{custom_fact_name}" ], - } - FACTER_CONF - - agents.each do |agent| - fact_dir = agent.tmpdir('custom_facts') - fact_file = File.join(fact_dir, custom_fact_file) - - config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) - config_file = File.join(config_dir, 'facter.conf') - - agent.mkdir_p(config_dir) - create_remote_file(agent, fact_file, fact_content) - create_remote_file(agent, config_file, config_data) - - teardown do - agent.rm_rf(fact_dir) - agent.rm_rf(config_dir) - end - - step "Facter: Verify that the blocked custom fact is not displayed" do - on(agent, facter("--custom-dir=#{fact_dir} my_custom_fact")) do |facter_output| - assert_equal("", facter_output.stdout.chomp) - end - end - end -end diff --git a/acceptance/tests/custom_facts/cached_custom_fact.rb b/acceptance/tests/custom_facts/cached_custom_fact.rb index 0f7a452548..3d08d110ac 100644 --- a/acceptance/tests/custom_facts/cached_custom_fact.rb +++ b/acceptance/tests/custom_facts/cached_custom_fact.rb @@ -42,16 +42,16 @@ config_file = File.join(config_dir, 'facter.conf') step "Agent #{agent}: create config file" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config_data) fact_file = File.join(fact_dir, custom_fact_file) create_remote_file(agent, fact_file, fact_content) end teardown do - agent.rm_rf(fact_dir) - agent.rm_rf("#{cache_folder}/*") - agent.rm_rf(config_file) + on(agent, "rm -rf '#{fact_dir}'") + on(agent, "rm -rf #{cache_folder}/*") + on(agent, "rm -rf '#{config_file}'") end step "should log that it creates cache file and it caches custom facts found in facter.conf" do @@ -67,8 +67,9 @@ step "should create a cached-custom-facts cache file that containt fact information" do result = agent.file_exist?("#{cache_folder}/cached-custom-facts") assert_equal(true, result) - cat_output = agent.cat("#{cache_folder}/cached-custom-facts") - assert_match(cached_file_content.chomp, cat_output.strip, 'Expected cached custom fact file to contain fact information') + on(agent, "cat #{cache_folder}/cached-custom-facts", acceptable_exit_codes: [0]) do |cat_output| + assert_match(cached_file_content.chomp, cat_output.stdout, 'Expected cached custom fact file to contain fact information') + end end step 'should read from the cached file for a custom fact that has been cached' do diff --git a/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb b/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb index 8803d7f118..34c5e615bf 100644 --- a/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb +++ b/acceptance/tests/custom_facts/conflicts_with_builtin_fact.rb @@ -11,20 +11,20 @@ def create_custom_fact_on(host, custom_fact_dir, fact_file_name, fact) end CUSTOM_FACT - fact_file_path = File.join(custom_fact_dir, fact_file_name) + fact_file_path = File.join(custom_fact_dir, fact_file_name) create_remote_file(host, fact_file_path, fact_file_contents) end def clear_custom_facts_on(host, custom_fact_dir) step "Clean-up the previous test's custom facts" do - agent.rm_rf("#{custom_fact_dir}/*") + on(agent, "rm -f #{custom_fact_dir}/*") end end agents.each do |agent| custom_fact_dir = agent.tmpdir('facter') teardown do - agent.rm_rf(custom_fact_dir) + on(agent, "rm -rf '#{custom_fact_dir}'") end fact_name = 'timezone' @@ -41,7 +41,7 @@ def clear_custom_facts_on(host, custom_fact_dir) value: "'#{custom_fact_value}'" ) - on(agent, facter("--custom-dir \"#{custom_fact_dir}\" timezone")) do |result| + on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result| assert_match(/#{custom_fact_value}/, result.stdout.chomp, "Facter does not use the custom fact's value when its weight is > 0") end end @@ -58,7 +58,7 @@ def clear_custom_facts_on(host, custom_fact_dir) ) end - on(agent, facter("--custom-dir \"#{custom_fact_dir}\" timezone")) do |result| + on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result| assert_match(/#{builtin_value}/, result.stdout.chomp, "Facter does not use the builtin fact's value when all conflicting custom facts fail to resolve") end end @@ -77,7 +77,7 @@ def clear_custom_facts_on(host, custom_fact_dir) ) end - on(agent, facter("--custom-dir \"#{custom_fact_dir}\" timezone")) do |result| + on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result| assert_match(/#{builtin_value}/, result.stdout.chomp, "Facter does not give precedence to the builtin fact when all custom facts have zero weight") end end @@ -97,7 +97,7 @@ def clear_custom_facts_on(host, custom_fact_dir) ) end - on(agent, facter("--custom-dir \"#{custom_fact_dir}\" timezone")) do |result| + on(agent, facter("--custom-dir=#{custom_fact_dir} timezone")) do |result| assert_match(/#{builtin_value}/, result.stdout.chomp, "Facter does not give precedence to the builtin fact when only some custom facts have zero weight") end end diff --git a/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb b/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb index 773310b8b2..4750935786 100644 --- a/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb +++ b/acceptance/tests/custom_facts/custom_fact_with_10001_weight_overrides_external_fact.rb @@ -16,12 +16,12 @@ create_remote_file(agent, cust_fact_path, custom_fact_content(fact_name, 'CUSTOM', "has_weight 10001")) teardown do - agent.rm_rf(facts_dir) + on(agent, "rm -rf '#{facts_dir}'") end # Custom fact with weight >= 10001 should override an external fact step "Agent #{agent}: resolve a custom fact with weight of 10001 overriding the external fact" do - on(agent, facter("--external-dir \"#{facts_dir}\" --custom-dir=#{facts_dir} test")) do |facter_output| + on(agent, facter("--external-dir=#{facts_dir} --custom-dir=#{facts_dir} test")) do |facter_output| assert_equal("CUSTOM", facter_output.stdout.chomp) end end diff --git a/acceptance/tests/custom_facts/expand_command.rb b/acceptance/tests/custom_facts/expand_command.rb index d885e3d9ef..3cb46a8b25 100644 --- a/acceptance/tests/custom_facts/expand_command.rb +++ b/acceptance/tests/custom_facts/expand_command.rb @@ -18,7 +18,7 @@ env = {'FACTERLIB' => fact_dir} teardown do - agent.rm_rf(fact_dir) + on(agent, "rm -rf '#{fact_dir}'") end step "Agent: Verify that command is expanded" do diff --git a/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb b/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb index 80d80a576d..efbec00cbb 100644 --- a/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb +++ b/acceptance/tests/custom_facts/having_multiple_facts_in_one_file.rb @@ -22,7 +22,7 @@ env = {'FACTERLIB' => fact_dir} teardown do - agent.rm_rf(fact_dir) + on(agent, "rm -rf '#{fact_dir}'") end step "Agent: Verify test_fact1 from #{fact_file}" do diff --git a/acceptance/tests/custom_facts/load_custom_fact_from_lib_facter.rb b/acceptance/tests/custom_facts/load_custom_fact_from_lib_facter.rb index 243b943a45..851669e085 100644 --- a/acceptance/tests/custom_facts/load_custom_fact_from_lib_facter.rb +++ b/acceptance/tests/custom_facts/load_custom_fact_from_lib_facter.rb @@ -40,7 +40,7 @@ test_script_dir = agent.tmpdir('test_script') fact_dir = Pathname.new("#{fact_temp_dir}/lib/facter") - agent.mkdir_p(fact_dir.to_s) + agent.mkdir_p(fact_dir) fact_file = File.join(fact_dir, 'custom_fact.rb') test_script_file = File.join(test_script_dir, 'test_script.rb') diff --git a/acceptance/tests/custom_facts/not_expand_command.rb b/acceptance/tests/custom_facts/not_expand_command.rb index b069d88395..3ae071ac51 100644 --- a/acceptance/tests/custom_facts/not_expand_command.rb +++ b/acceptance/tests/custom_facts/not_expand_command.rb @@ -18,7 +18,7 @@ env = {'FACTERLIB' => fact_dir} teardown do - agent.rm_rf(fact_dir) + on(agent, "rm -rf '#{fact_dir}'") end step "Agent: Verify that command is not expanded" do diff --git a/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb b/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb index 8e369cdd0b..42e4c9bc1f 100644 --- a/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb +++ b/acceptance/tests/custom_facts/using_win32ole_should_not_hang.rb @@ -5,7 +5,7 @@ require 'timeout' content = <<-EOM - Facter.add('custom_fact_ole') do + Facter.add('custom_fact') do setcode do require 'win32ole' locator = WIN32OLE.new('WbemScripting.SWbemLocator') @@ -20,12 +20,12 @@ create_remote_file(agent, custom_fact, content) teardown do - agent.rm_rf(custom_dir) + on(agent, "rm -rf '#{custom_dir}'") end # Test is assumed to have hung if it takes longer than 5 seconds. Timeout::timeout(5) do - on agent, facter('--custom-dir', custom_dir, 'custom_fact_ole') do |facter_result| + on agent, facter('--custom-dir', custom_dir, 'custom_fact') do |facter_result| assert_match(/#/, facter_result.stdout.chomp, 'Custom fact output does not match expected output') end end diff --git a/acceptance/tests/custom_facts/weighted_cached_custom_facts.rb b/acceptance/tests/custom_facts/weighted_cached_custom_facts.rb index dcd9a363ea..c9acf5f9a3 100644 --- a/acceptance/tests/custom_facts/weighted_cached_custom_facts.rb +++ b/acceptance/tests/custom_facts/weighted_cached_custom_facts.rb @@ -54,16 +54,16 @@ config_file = File.join(config_dir, 'facter.conf') step "Agent #{agent}: create config file" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config_data) fact_file = File.join(fact_dir, custom_fact_file) create_remote_file(agent, fact_file, fact_content) end teardown do - agent.rm_rf(fact_dir) - agent.rm_rf("#{cache_folder}/*") - agent.rm_rf("#{config_dir}/facter.conf") + on(agent, "rm -rf '#{fact_dir}'") + on(agent, "rm -rf #{cache_folder}/*") + on(agent, "rm -rf #{config_dir}/facter.conf") end step "should log that it creates cache file and it caches custom facts found in facter.conf with the highest weight" do @@ -79,8 +79,9 @@ step "should create a cached-custom-facts cache file that containt fact information from the highest weight fact" do result = agent.file_exist?("#{cache_folder}/cached-custom-facts") assert_equal(true, result) - cat_output = agent.cat("#{cache_folder}/cached-custom-facts") - assert_match(cached_file_content_highest_weight.chomp, cat_output.strip, 'Expected cached custom fact file to contain fact information from the highest weight fact') + on(agent, "cat #{cache_folder}/cached-custom-facts", acceptable_exit_codes: [0]) do |cat_output| + assert_match(cached_file_content_highest_weight.chomp, cat_output.stdout, 'Expected cached custom fact file to contain fact information from the highest weight fact') + end end step 'should read from the cached file for a custom fact that has been cached' do diff --git a/acceptance/tests/custom_facts/windows_not_expand_command.rb b/acceptance/tests/custom_facts/windows_not_expand_command.rb index 6200523642..17cc168599 100644 --- a/acceptance/tests/custom_facts/windows_not_expand_command.rb +++ b/acceptance/tests/custom_facts/windows_not_expand_command.rb @@ -18,7 +18,7 @@ env = {'FACTERLIB' => fact_dir} teardown do - agent.rm_rf(fact_dir) + on(agent, "rm -rf '#{fact_dir}'") end step "Agent: Verify that exception is raised" do diff --git a/acceptance/tests/external_facts/env_var_overrides_external_fact.rb b/acceptance/tests/external_facts/env_var_overrides_external_fact.rb index 5043286c19..7a7229ed3b 100644 --- a/acceptance/tests/external_facts/env_var_overrides_external_fact.rb +++ b/acceptance/tests/external_facts/env_var_overrides_external_fact.rb @@ -13,19 +13,19 @@ "#{fact_name}#{get_external_fact_script_extension(agent['platform'])}") teardown do - agent.rm_rf(external_dir) + on(agent, "rm -rf '#{external_dir}'") end step "Agent #{agent}: setup external fact" do - agent.mkdir_p(external_dir) + on(agent, "mkdir -p '#{external_dir}'") create_remote_file(agent, fact_file, external_fact_content(agent['platform'], fact_name, fact_value)) - agent.chmod('+x', fact_file) + on(agent, "chmod +x '#{fact_file}'") end step "Agent: #{agent}: ensure external fact resolves correctly" do - on(agent, facter("--external-dir \"#{external_dir}\" #{fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' #{fact_name}")) do |facter_output| assert_equal(fact_value, facter_output.stdout.chomp, 'Expected external fact to resolve as defined in script') @@ -33,7 +33,7 @@ end step "Agent #{agent}: the fact value from FACTER_ env var should override the external fact value" do - on(agent, facter("--external-dir \"#{external_dir}\" #{fact_name}", + on(agent, facter("--external-dir '#{external_dir}' #{fact_name}", :environment => { "FACTER_#{fact_name}" => override_value })) do |facter_output| assert_equal(override_value, facter_output.stdout.chomp, diff --git a/acceptance/tests/external_facts/external_dir_overrides_default_external_fact.rb b/acceptance/tests/external_facts/external_dir_overrides_default_external_fact.rb index c8e6f573e3..81d6c82fc7 100644 --- a/acceptance/tests/external_facts/external_dir_overrides_default_external_fact.rb +++ b/acceptance/tests/external_facts/external_dir_overrides_default_external_fact.rb @@ -15,20 +15,18 @@ override_content = external_fact_content(agent['platform'], 'external_fact', 'OVERRIDE_value') teardown do - agent.rm_rf(fact_file) - agent.rm_rf(override_fact_file) + on(agent, "rm -f '#{fact_file}' '#{override_fact_file}'") end step "Agent #{agent}: setup default external facts directories and the test facts" do - agent.mkdir_p(factsd) + on(agent, "mkdir -p '#{factsd}'") create_remote_file(agent, fact_file, content) create_remote_file(agent, override_fact_file, override_content) - agent.chmod('+x', fact_file) - agent.chmod('+x', override_fact_file) + on(agent, "chmod +x '#{fact_file}' '#{override_fact_file}'") end step "Agent #{agent}: the fact value from the custom external dir should override that of facts.d" do - on(agent, facter("--external-dir \"#{external_dir}\" external_fact")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' external_fact")) do |facter_output| assert_equal('OVERRIDE_value', facter_output.stdout.chomp, 'Expected to resolve override version of the external_fact') end end diff --git a/acceptance/tests/external_facts/external_fact_overrides_custom_fact.rb b/acceptance/tests/external_facts/external_fact_overrides_custom_fact.rb index 8296e08b87..6a0f7f3c0a 100644 --- a/acceptance/tests/external_facts/external_fact_overrides_custom_fact.rb +++ b/acceptance/tests/external_facts/external_fact_overrides_custom_fact.rb @@ -16,11 +16,11 @@ create_remote_file(agent, ext_fact_path, ext_fact) teardown do - agent.rm_rf(facts_dir) + on(agent, "rm -rf '#{facts_dir}'") end step "Agent #{agent}: resolve an external fact over a custom fact" do - on(agent, facter("--external-dir \"#{facts_dir}\" --custom-dir=#{facts_dir} #{fact_name}")) do |facter_output| + on(agent, facter("--external-dir=#{facts_dir} --custom-dir=#{facts_dir} #{fact_name}")) do |facter_output| assert_equal("EXTERNAL", facter_output.stdout.chomp) end end diff --git a/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_10000_weight_or_less.rb b/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_10000_weight_or_less.rb index 619b11fc72..b1c12fbf4c 100644 --- a/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_10000_weight_or_less.rb +++ b/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_10000_weight_or_less.rb @@ -16,12 +16,12 @@ create_remote_file(agent, cust_fact_path, custom_fact_content(fact_name, 'CUSTOM', "has_weight 10000")) teardown do - agent.rm_rf(facts_dir) + on(agent, "rm -rf '#{facts_dir}'") end # Custom fact with weight <= 10000 should give precedence to the EXTERNAL fact step "Agent #{agent}: resolve an external fact over the custom fact with a weight of 10000" do - on(agent, facter("--external-dir \"#{facts_dir}\" --custom-dir \"#{facts_dir}\" #{fact_name}")) do |facter_output| + on(agent, facter("--external-dir=#{facts_dir} --custom-dir=#{facts_dir} #{fact_name}")) do |facter_output| assert_equal("EXTERNAL", facter_output.stdout.chomp) end end diff --git a/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_confine.rb b/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_confine.rb index 3d132268fc..f6111804df 100644 --- a/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_confine.rb +++ b/acceptance/tests/external_facts/external_fact_overrides_custom_fact_with_confine.rb @@ -20,13 +20,13 @@ custom_fact_content(fact_name, 'CUSTOM', "confine :kernel=>'#{agent_kernel}'")) teardown do - agent.rm_rf(facts_dir) + on(agent, "rm -rf '#{facts_dir}'") end # External fact should take precedence over a custom fact with a confine # (from FACT-1413) step "Agent #{agent}: resolve external fact over a custom fact with a confine" do - on(agent, facter("--external-dir \"#{facts_dir}\" --custom-dir \"#{facts_dir}\" test")) do |facter_output| + on(agent, facter("--external-dir=#{facts_dir} --custom-dir=#{facts_dir} test")) do |facter_output| assert_equal("EXTERNAL", facter_output.stdout.chomp) end end diff --git a/acceptance/tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb b/acceptance/tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb index b36f5b3a06..fd44be2cb8 100644 --- a/acceptance/tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb +++ b/acceptance/tests/external_facts/external_fact_stderr_messages_output_to_stderr.rb @@ -23,13 +23,13 @@ end teardown do - agent.rm_rf(ext_fact) + on(agent, "rm -f '#{ext_fact}'") end step "Agent #{agent}: create facts.d directory and fact" do - agent.mkdir_p(factsd) + on(agent, "mkdir -p '#{factsd}'") create_remote_file(agent, ext_fact, content) - agent.chmod('+x', ext_fact) + on(agent, "chmod +x '#{ext_fact}'") end step "Agent #{agent}: external fact stderr messages should appear on stderr from facter" do diff --git a/acceptance/tests/external_facts/external_facts_only_run_once.rb b/acceptance/tests/external_facts/external_facts_only_run_once.rb index 0790706e0f..61cea72694 100644 --- a/acceptance/tests/external_facts/external_facts_only_run_once.rb +++ b/acceptance/tests/external_facts/external_facts_only_run_once.rb @@ -23,13 +23,13 @@ end teardown do - agent.rm_rf(ext_fact) + on(agent, "rm -f '#{ext_fact}'") end step "Agent #{agent}: create facts.d directory and fact" do - agent.mkdir_p(factsd) + on(agent, "mkdir -p '#{factsd}'") create_remote_file(agent, ext_fact, content) - agent.chmod('+x', ext_fact) + on(agent, "chmod +x '#{ext_fact}'") end step "Agent #{agent}: ensure the fact is only executed once" do @@ -40,4 +40,4 @@ end end end -end +end \ No newline at end of file diff --git a/acceptance/tests/external_facts/fact_directory_precedence.rb b/acceptance/tests/external_facts/fact_directory_precedence.rb index 2b802e27a6..a5c563dc7e 100644 --- a/acceptance/tests/external_facts/fact_directory_precedence.rb +++ b/acceptance/tests/external_facts/fact_directory_precedence.rb @@ -28,15 +28,13 @@ def ext_fact(value='BASIC') etc_puppetlabs_factsd_path = "#{etc_puppetlabs_factsd_dir}/test.yaml" teardown do - agent.rm_rf(factsd_dir) - agent.rm_rf(etc_factsd_dir) - agent.rm_rf(etc_puppetlabs_factsd_dir) + on(agent, "rm -rf '#{factsd_dir}' '#{etc_factsd_dir}' '#{etc_puppetlabs_factsd_dir}'") end # ensure the fact directory we want to use exists step "Agent #{agent}: create facts directory (#{etc_puppetlabs_factsd_dir})" do - agent.rm_rf(etc_puppetlabs_factsd_dir) - agent.mkdir_p(etc_puppetlabs_factsd_dir) + on(agent, "rm -rf '#{etc_puppetlabs_factsd_dir}'") + on(agent, "mkdir -p '#{etc_puppetlabs_factsd_dir}'") end # A fact in the etc_puppetlabs_factsd_dir directory should resolve to the fact @@ -49,13 +47,13 @@ def ext_fact(value='BASIC') # remove the fact step "Agent #{agent}: remove the fact in #{etc_puppetlabs_factsd_dir}" do - agent.rm_rf(etc_puppetlabs_factsd_path) + on(agent, "rm -f '#{etc_puppetlabs_factsd_path}'") end # ensure the fact directory we want to use exists step "Agent #{agent}: create facts directory (#{etc_factsd_dir})" do - agent.rm_rf(etc_factsd_dir) - agent.mkdir_p(etc_factsd_dir) + on(agent, "rm -rf '#{etc_factsd_dir}'") + on(agent, "mkdir -p '#{etc_factsd_dir}'") end # A fact in the etc_factsd_dir directory should resolve to the fact @@ -68,13 +66,13 @@ def ext_fact(value='BASIC') # remove the fact step "Agent #{agent}: remove the fact in #{etc_factsd_dir}" do - agent.rm_rf(etc_factsd_path) + on(agent, "rm -f '#{etc_factsd_path}'") end # ensure the fact directory we want to use exists step "Agent #{agent}: create facts directory (#{factsd_dir})" do - agent.rm_rf(factsd_dir) - agent.mkdir_p(factsd_dir) + on(agent, "rm -rf '#{factsd_dir}'") + on(agent, "mkdir -p '#{factsd_dir}'") end # A fact in the factsd_dir directory should resolve to the fact @@ -87,7 +85,7 @@ def ext_fact(value='BASIC') # remove the fact step "Agent #{agent}: remove the fact in #{factsd_dir}" do - agent.rm_rf(factsd_path) + on(agent, "rm -f '#{factsd_path}'") end # A fact in the etc_factsd_dir directory should take precedence over the same fact in factsd_dir diff --git a/acceptance/tests/external_facts/handle_same_filename_in_different_dirs.rb b/acceptance/tests/external_facts/handle_same_filename_in_different_dirs.rb index 62082a4ff8..c80e1330f2 100644 --- a/acceptance/tests/external_facts/handle_same_filename_in_different_dirs.rb +++ b/acceptance/tests/external_facts/handle_same_filename_in_different_dirs.rb @@ -16,9 +16,9 @@ fact1_value = 'fact1_value' fact2_value = 'fact2_value' external_filename = 'text.yaml' - external_dir1 = agent.tmpdir('external_dir1') + external_dir1 = agent.tmpdir('external_dir') external_fact_file1 = File.join(external_dir1, external_filename) - external_dir2 = agent.tmpdir('external_dir2') + external_dir2 = agent.tmpdir('external_dir') external_fact_file2 = File.join(external_dir2, external_filename) create_remote_file(agent, external_fact_file1, "#{fact1}: #{fact1_value}") create_remote_file(agent, external_fact_file2, "#{fact2}: #{fact2_value}") @@ -27,13 +27,11 @@ config_file = File.join(config_dir, 'facter.conf') teardown do - agent.rm_rf(external_dir1) - agent.rm_rf(external_dir2) - agent.rm_rf(config_file) + on(agent, "rm -rf '#{external_dir1}' '#{external_dir2}' '#{config_file}'") end step 'works if ttl is not enabled' do - on(agent, facter("--external-dir \"#{external_dir1}\" --external-dir \"#{external_dir2}\" --debug #{fact1} #{fact2}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir1}' --external-dir '#{external_dir2}' --debug #{fact1} #{fact2}")) do |facter_output| assert_match(/#{fact1} => #{fact1_value}/, stdout, 'Expected fact to match first fact') assert_match(/#{fact2} => #{fact2_value}/, stdout, 'Expected fact to match second fact') end @@ -47,9 +45,9 @@ ] } EOM - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) - on(agent, facter("--external-dir \"#{external_dir1}\" --external-dir \"#{external_dir2}\" --debug #{fact1} #{fact2}"), :acceptable_exit_codes => 1) do |facter_output| + on(agent, facter("--external-dir '#{external_dir1}' --external-dir '#{external_dir2}' --debug #{fact1} #{fact2}"), :acceptable_exit_codes => 1) do |facter_output| assert_match(/ERROR.*Caching is enabled for group "#{external_filename}" while there are at least two external facts files with the same filename/, stderr, 'Expected error message') assert_match(/#{fact1} => #{fact1_value}/, stdout, 'Expected fact to match first fact') assert_not_match(/#{fact2} => #{fact2_value}/, stdout, 'Expected fact not to match second fact') diff --git a/acceptance/tests/external_facts/non_root_users_default_external_fact_directory.rb b/acceptance/tests/external_facts/non_root_users_default_external_fact_directory.rb index 3603fb0ef1..ed9a079bae 100644 --- a/acceptance/tests/external_facts/non_root_users_default_external_fact_directory.rb +++ b/acceptance/tests/external_facts/non_root_users_default_external_fact_directory.rb @@ -72,17 +72,16 @@ def get_home_dir(host, user_name) user_puppetlabs_facts_path = "#{user_puppetlabs_facts_dir}/test.yaml" step "Agent #{agent}: figure out facter program location" - facter_path = agent.which('facter').chomp + facter_path = on(agent, "which facter").stdout.chomp teardown do - agent.rm_rf(user_base_facts_dir) - agent.rm_rf(user_base_puppetlabs_dir) + on(agent, "rm -rf '#{user_base_facts_dir}' '#{user_base_puppetlabs_dir}'") on(agent, puppet("resource user #{non_root_user} ensure=absent managehome=true")) end step "Agent #{agent}: create facts directory (#{user_facts_dir})" do - agent.rm_rf(user_facts_dir) - agent.mkdir_p(user_facts_dir) + on(agent, "rm -rf '#{user_facts_dir}'") + on(agent, "mkdir -p '#{user_facts_dir}'") end step "Agent #{agent}: create and resolve a custom fact in #{user_facts_dir}" do @@ -90,8 +89,8 @@ def get_home_dir(host, user_name) end step "Agent #{agent}: chown and chmod the facts to the user #{non_root_user}" do - agent.chown(non_root_user, user_base_facts_dir, true) - agent.chmod('a+rx', user_base_facts_dir, true) + on(agent, "chown -R #{non_root_user} '#{user_base_facts_dir}'") + on(agent, "chmod -R a+rx '#{user_base_facts_dir}'") end step "Agent #{agent}: run facter as #{non_root_user} and make sure we get the fact" do @@ -101,12 +100,12 @@ def get_home_dir(host, user_name) end step "Agent #{agent}: remove #{user_facts_path}" do - agent.rm_rf(user_facts_path) + on(agent, "rm -rf '#{user_facts_path}'") end step "Agent #{agent}: create facts directory (#{user_puppetlabs_facts_dir})" do - agent.rm_rf(user_puppetlabs_facts_dir) - agent.mkdir_p(user_puppetlabs_facts_dir) + on(agent, "rm -rf '#{user_puppetlabs_facts_dir}'") + on(agent, "mkdir -p '#{user_puppetlabs_facts_dir}'") end step "Agent #{agent}: create and resolve a custom fact in #{user_puppetlabs_facts_dir}" do @@ -114,8 +113,8 @@ def get_home_dir(host, user_name) end step "Agent #{agent}: chown and chmod the facts to the user #{non_root_user}" do - agent.chown(non_root_user, user_base_puppetlabs_dir, true) - agent.chmod('a+rx', user_base_puppetlabs_dir, true) + on(agent, "chown -R #{non_root_user} '#{user_base_puppetlabs_dir}'") + on(agent, "chmod -R a+rx '#{user_base_puppetlabs_dir}'") end step "Agent #{agent}: run facter as #{non_root_user} and make sure we get the fact" do @@ -130,10 +129,8 @@ def get_home_dir(host, user_name) end step "Agent #{agent}: chown and chmod the facts to the user #{non_root_user}" do - agent.chown(non_root_user, user_base_facts_dir, true) - agent.chown(non_root_user, user_base_puppetlabs_dir, true) - agent.chmod('a+rx', user_base_facts_dir, true) - agent.chmod('a+rx', user_base_puppetlabs_dir, true) + on(agent, "chown -R #{non_root_user} '#{user_base_facts_dir}' '#{user_base_puppetlabs_dir}'") + on(agent, "chmod -R a+rx '#{user_base_facts_dir}' '#{user_base_puppetlabs_dir}'") end step "Agent #{agent}: run facter as #{non_root_user} and .facter will take precedence over .puppetlabs" do diff --git a/acceptance/tests/external_facts/root_uses_default_external_fact_dir.rb b/acceptance/tests/external_facts/root_uses_default_external_fact_dir.rb index 494e8aec92..3ed8abd2be 100644 --- a/acceptance/tests/external_facts/root_uses_default_external_fact_dir.rb +++ b/acceptance/tests/external_facts/root_uses_default_external_fact_dir.rb @@ -16,13 +16,13 @@ content = external_fact_content(agent['platform'], 'external_fact', 'external_value') teardown do - agent.rm_rf(fact_file) + on(agent, "rm -f '#{fact_file}'") end step "Agent #{agent}: setup default external facts directory and fact" do - agent.mkdir_p(factsd) + on(agent, "mkdir -p '#{factsd}'") create_remote_file(agent, fact_file, content) - agent.chmod('+x', fact_file) + on(agent, "chmod +x '#{fact_file}'") end step "agent #{agent}: resolve the external fact" do diff --git a/acceptance/tests/external_facts/structured_executable_facts.rb b/acceptance/tests/external_facts/structured_executable_facts.rb index 99e51da310..a50ae1dee5 100644 --- a/acceptance/tests/external_facts/structured_executable_facts.rb +++ b/acceptance/tests/external_facts/structured_executable_facts.rb @@ -81,17 +81,17 @@ end step "Agent #{agent}: setup default external facts directory (facts.d)" do - agent.mkdir_p(factsd) + on(agent, "mkdir -p '#{factsd}'") end teardown do - agent.rm_rf(factsd) + on(agent, "rm -rf '#{factsd}'") end step "Agent #{agent}: create an executable yaml fact in default facts.d" do yaml_fact = File.join(factsd, "yaml_fact#{ext}") create_remote_file(agent, yaml_fact, yaml_content) - agent.chmod('+x', yaml_fact) + on(agent, "chmod +x '#{yaml_fact}'") step "YAML output should produce a structured fact" do on(agent, facter("yaml_fact")) do @@ -103,7 +103,7 @@ step "Agent #{agent}: create an executable json fact in default facts.d" do json_fact = File.join(factsd, "json_fact#{ext}") create_remote_file(agent, json_fact, json_content) - agent.chmod('+x', json_fact) + on(agent, "chmod +x '#{json_fact}'") step "JSON output should produce a structured fact" do on(agent, facter("json_fact")) do @@ -115,7 +115,7 @@ step "Agent #{agent}: create an executable key-value fact in default facts.d" do kv_fact = File.join(factsd, "kv_fact#{ext}") create_remote_file(agent, kv_fact, kv_content) - agent.chmod('+x', kv_fact) + on(agent, "chmod +x '#{kv_fact}'") step "output that is neither yaml nor json should not produce a structured fact" do on(agent, facter("kv_fact")) do @@ -127,7 +127,7 @@ step "Agent #{agent}: create a malformed executable fact in default facts.d" do bad_fact = File.join(factsd, "bad_fact#{ext}") create_remote_file(agent, bad_fact, bad_fact_content) - agent.chmod('+x', bad_fact) + on(agent, "chmod +x '#{bad_fact}'") step "should error when output is not in a supported format" do on(agent, facter("bad_fact --debug")) do diff --git a/acceptance/tests/facts/non_root_users_without_errors.rb b/acceptance/tests/facts/non_root_users_without_errors.rb index 05593c6bbf..4f73faaf8b 100644 --- a/acceptance/tests/facts/non_root_users_without_errors.rb +++ b/acceptance/tests/facts/non_root_users_without_errors.rb @@ -13,7 +13,7 @@ agents.each do |agent| non_root_user = "nonroot" - facter_path = agent.which('facter').chomp + facter_path = on(agent, "which facter").stdout.chomp step "Agent #{agent}: create a #{non_root_user} user to run facter with" do on(agent, "puppet resource user #{non_root_user} ensure=present shell='#{user_shell(agent)}'") diff --git a/acceptance/tests/facts/operatingsystem_detection_after_clear_on_ubuntu.rb b/acceptance/tests/facts/operatingsystem_detection_after_clear_on_ubuntu.rb index be83460e01..dac09f1e85 100644 --- a/acceptance/tests/facts/operatingsystem_detection_after_clear_on_ubuntu.rb +++ b/acceptance/tests/facts/operatingsystem_detection_after_clear_on_ubuntu.rb @@ -18,7 +18,7 @@ create_remote_file(agent, script_name, script_contents) teardown do - agent.rm_rf(script_dir) + on(agent, "rm -rf '#{script_dir}'") end on(agent, "#{Puppet::Acceptance::CommandUtils.ruby_command(agent)} #{script_name}", :acceptable_exit_codes => 0) diff --git a/acceptance/tests/facts/ssh_key.rb b/acceptance/tests/facts/ssh_key.rb index b83ac96c00..19c5caf498 100644 --- a/acceptance/tests/facts/ssh_key.rb +++ b/acceptance/tests/facts/ssh_key.rb @@ -26,11 +26,19 @@ ) if rc.exit_code == 0 # It's present, so restore the original - agent.mv(ssh_tmp_host_rsa_key_file, ssh_host_rsa_key_file) + on( + agent, + "mv -fv #{ssh_tmp_host_rsa_key_file} #{ssh_host_rsa_key_file}", + accept_all_exit_codes: true, + ) else # It's missing, which means there wasn't one to backup; just # delete the one we laid down - agent.rm_rf(ssh_host_rsa_key_file) + on( + agent, + "rm -fv #{ssh_host_rsa_key_file}", + accept_all_exit_codes: true, + ) end end diff --git a/acceptance/tests/facts/verify_tmpfs_file_system.rb b/acceptance/tests/facts/verify_tmpfs_file_system.rb index 366ecf3706..3a83942757 100644 --- a/acceptance/tests/facts/verify_tmpfs_file_system.rb +++ b/acceptance/tests/facts/verify_tmpfs_file_system.rb @@ -28,13 +28,12 @@ atboot => true, } FILE - agent.mkdir_p(mount_point) + on(agent, "mkdir -p #{mount_point}") create_remote_file(agent, manifest, manifest_content) teardown do on(agent, "umount #{mount_point}") - agent.rm_rf(mount_point) - agent.rm_rf(manifest_dir) + on(agent, "rm -rf #{mount_point} #{manifest_dir}") end step "Apply the manifest to mount directory '#{mount_point}'" do diff --git a/acceptance/tests/load_libfacter.rb b/acceptance/tests/load_libfacter.rb index 1bc61ffd16..35e651b453 100644 --- a/acceptance/tests/load_libfacter.rb +++ b/acceptance/tests/load_libfacter.rb @@ -39,10 +39,10 @@ def puppet_ruby_path_to_puppet_install_dir(puppet_ruby_path) create_remote_file(agent, fact_program, fact_content) teardown do - agent.rm_rf(fact_dir) + on(agent, "rm -rf '#{fact_dir}'") end - if agent['platform'] =~ /windows/ && agent.is_cygwin? + if agent['platform'] =~ /windows/ # on Windows we have to figure out where facter.rb is so we can include the path # figure out the root of the Puppet installation puppet_ruby_path = on(agent, "env PATH=\"#{agent['privatebindir']}:${PATH}\" which ruby").stdout.chomp diff --git a/acceptance/tests/options/config.rb b/acceptance/tests/options/config.rb index e7e8b4ba1d..606ae54207 100644 --- a/acceptance/tests/options/config.rb +++ b/acceptance/tests/options/config.rb @@ -14,11 +14,11 @@ FILE teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) end step "setting --config should cause the config file to be loaded from the specified location" do - on(agent, facter("--config \"#{config_file}\"")) do |facter_output| + on(agent, facter("--config '#{config_file}'")) do |facter_output| assert_match(/DEBUG/, facter_output.stderr, "Expected debug output on stderr") end end diff --git a/acceptance/tests/options/config_file/blocklist.rb b/acceptance/tests/options/config_file/blocklist.rb index 21bd4ceb5c..85d4f4ce99 100644 --- a/acceptance/tests/options/config_file/blocklist.rb +++ b/acceptance/tests/options/config_file/blocklist.rb @@ -16,11 +16,11 @@ FILE teardown do - agent.rm_rf(custom_conf_dir) + on(agent, "rm -rf '#{custom_conf_dir}'", :acceptable_exit_codes => [0, 1]) end step "blocked facts should not be resolved" do - on(agent, facter("--config \"#{config_file}\"")) do |facter_output| + on(agent, facter("--config '#{config_file}'")) do |facter_output| # every platform attempts to resolve at least EC2 facts assert_match(/blocking collection of .+ facts/, facter_output.stderr, "Expected stderr to contain statement about blocking fact collection") diff --git a/acceptance/tests/options/config_file/blocklist_from_puppet_facts.rb b/acceptance/tests/options/config_file/blocklist_from_puppet_facts.rb index 2fd09bb65b..38033ac92d 100644 --- a/acceptance/tests/options/config_file/blocklist_from_puppet_facts.rb +++ b/acceptance/tests/options/config_file/blocklist_from_puppet_facts.rb @@ -13,12 +13,12 @@ facter_conf_default_path = File.join(facter_conf_default_dir, "facter.conf") teardown do - agent.rm_rf(facter_conf_default_dir) + on(agent, "rm -rf '#{facter_conf_default_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create default config file" do # create the directories - agent.mkdir_p(facter_conf_default_dir) + on(agent, "mkdir -p '#{facter_conf_default_dir}'") create_remote_file(agent, facter_conf_default_path, <<-FILE) facts : { blocklist : [ "file system", "EC2" ] } FILE diff --git a/acceptance/tests/options/config_file/custom_dir_overridden_by_cli_custom_dir.rb b/acceptance/tests/options/config_file/custom_dir_overridden_by_cli_custom_dir.rb index 1ad6b22ded..ebe97ca839 100644 --- a/acceptance/tests/options/config_file/custom_dir_overridden_by_cli_custom_dir.rb +++ b/acceptance/tests/options/config_file/custom_dir_overridden_by_cli_custom_dir.rb @@ -38,18 +38,14 @@ custom-dir : "#{custom_config_dir}", } EOM - - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(custom_config_dir) - agent.rm_rf(custom_cli_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{custom_config_dir}' '#{custom_cli_dir}' '#{config_dir}'") end step "Agent #{agent}: resolve a fact from the command line custom-dir and not the config file" do - on(agent, facter("--config \"#{config_file}\" --custom-dir \"#{custom_cli_dir}\" --json")) do |facter_output| + on(agent, facter("--config '#{config_file}' --custom-dir '#{custom_cli_dir}' --json")) do |facter_output| results = JSON.parse(facter_output.stdout) assert_equal("cli_value", results['cli_fact'], "Incorrect custom fact value for cli_fact") assert_nil(results['config_fact'], "Config fact should not resolve and be nil") diff --git a/acceptance/tests/options/config_file/custom_facts.rb b/acceptance/tests/options/config_file/custom_facts.rb index 9089e03369..f64e953195 100644 --- a/acceptance/tests/options/config_file/custom_facts.rb +++ b/acceptance/tests/options/config_file/custom_facts.rb @@ -26,16 +26,14 @@ custom-dir : "#{custom_dir}", } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(custom_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{custom_dir}' '#{config_dir}'") end step "Agent #{agent}: resolve a fact from the configured custom-dir path" do - on(agent, facter("--config \"#{config_file}\" config_fact")) do |facter_output| + on(agent, facter("--config '#{config_file}' config_fact")) do |facter_output| assert_equal("config_value", facter_output.stdout.chomp, "Incorrect custom fact value") end end diff --git a/acceptance/tests/options/config_file/custom_facts_list.rb b/acceptance/tests/options/config_file/custom_facts_list.rb index a6b32f23f7..fe558acb5a 100644 --- a/acceptance/tests/options/config_file/custom_facts_list.rb +++ b/acceptance/tests/options/config_file/custom_facts_list.rb @@ -38,17 +38,14 @@ custom-dir : [ "#{custom_dir_1}", "#{custom_dir_2}" ], } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(custom_dir_1) - agent.rm_rf(custom_dir_2) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{custom_dir_1}' '#{custom_dir_2}' '#{config_dir}'") end step "Agent #{agent}: resolve a fact from each configured custom-dir path" do - on(agent, facter("--config \"#{config_file}\" --json")) do |facter_output| + on(agent, facter("--config '#{config_file}' --json")) do |facter_output| results = JSON.parse(facter_output.stdout) assert_equal("config_value_1", results['config_fact_1'], "Incorrect custom fact value for config_fact_1") assert_equal("config_value_2", results['config_fact_2'], "Incorrect custom fact value for config_fact_2") diff --git a/acceptance/tests/options/config_file/debug.rb b/acceptance/tests/options/config_file/debug.rb index 4bd17b797e..461efc840a 100644 --- a/acceptance/tests/options/config_file/debug.rb +++ b/acceptance/tests/options/config_file/debug.rb @@ -16,11 +16,11 @@ step "Agent #{agent}: create config file" do config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) config_file = File.join(config_dir, "facter.conf") - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0,1]) end step "debug output should print when config file is loaded" do diff --git a/acceptance/tests/options/config_file/debug_override_config_file.rb b/acceptance/tests/options/config_file/debug_override_config_file.rb index bf6e06690b..8061da0260 100644 --- a/acceptance/tests/options/config_file/debug_override_config_file.rb +++ b/acceptance/tests/options/config_file/debug_override_config_file.rb @@ -17,11 +17,11 @@ config_file = File.join(config_dir, "facter.conf") teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file in default location" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) end diff --git a/acceptance/tests/options/config_file/default_file_location.rb b/acceptance/tests/options/config_file/default_file_location.rb index c0b0812461..c7a388ab91 100644 --- a/acceptance/tests/options/config_file/default_file_location.rb +++ b/acceptance/tests/options/config_file/default_file_location.rb @@ -15,18 +15,16 @@ step "Agent #{agent}: create config file" do if agent['platform'] =~ /windows/ config_dir = 'C:\\ProgramData\\PuppetLabs\\facter\\etc' - config_file = "#{config_dir}\\facter.conf" else - config_dir = '/etc/puppetlabs/facter' - config_file = "#{config_dir}/facter.conf" + config_dir = "/etc/puppetlabs/facter" end - agent.mkdir_p(config_dir) - + on(agent, "mkdir -p '#{config_dir}'") + config_file = File.join(config_dir, "facter.conf") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0,1]) end step "config file should be loaded automatically and turn DEBUG output on" do diff --git a/acceptance/tests/options/config_file/external_dir_conflicts_with_cli_no_external_facts.rb b/acceptance/tests/options/config_file/external_dir_conflicts_with_cli_no_external_facts.rb index e855df2e42..93a13c3a95 100644 --- a/acceptance/tests/options/config_file/external_dir_conflicts_with_cli_no_external_facts.rb +++ b/acceptance/tests/options/config_file/external_dir_conflicts_with_cli_no_external_facts.rb @@ -20,11 +20,11 @@ config_file = File.join(config_dir, "facter.conf") teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file in default location" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) end diff --git a/acceptance/tests/options/config_file/external_dir_overridden_by_cli_external_dir.rb b/acceptance/tests/options/config_file/external_dir_overridden_by_cli_external_dir.rb index f2ce75a7ee..9d02cd0274 100644 --- a/acceptance/tests/options/config_file/external_dir_overridden_by_cli_external_dir.rb +++ b/acceptance/tests/options/config_file/external_dir_overridden_by_cli_external_dir.rb @@ -22,17 +22,14 @@ external-dir : "#{external_config_dir}", } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(external_config_dir) - agent.rm_rf(external_cli_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{external_config_dir}' '#{external_cli_dir}' '#{config_dir}'") end step "Agent #{agent}: resolve a fact from the command line external-dir and not the config file" do - on(agent, facter("--config \"#{config_file}\" --external-dir \"#{external_cli_dir}\" --json")) do |facter_output| + on(agent, facter("--config '#{config_file}' --external-dir '#{external_cli_dir}' --json")) do |facter_output| results = JSON.parse(facter_output.stdout) assert_equal("cli_value", results['cli_fact'], "Incorrect custom fact value for cli_fact") assert_nil(results['config_fact'], "Config fact should not resolve and be nil") diff --git a/acceptance/tests/options/config_file/external_facts.rb b/acceptance/tests/options/config_file/external_facts.rb index 698aad814c..4929370ef4 100644 --- a/acceptance/tests/options/config_file/external_facts.rb +++ b/acceptance/tests/options/config_file/external_facts.rb @@ -12,7 +12,7 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "external_fact#{ext}") create_remote_file(agent, external_fact, external_fact_content(agent['platform'], 'single_fact', 'external_value')) - agent.chmod('+x', external_fact) + on(agent, "chmod +x '#{external_fact}'") config_dir = agent.tmpdir("config_dir") config_file = File.join(config_dir, "facter.conf") @@ -21,19 +21,17 @@ external-dir : "#{external_dir}", } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(external_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{external_dir}' '#{config_dir}'") end step "Agent #{agent}: resolve a fact in the external-dir in the configuration file" do - on(agent, facter("--config \"#{config_file}\" single_fact")) do |facter_output| + on(agent, facter("--config '#{config_file}' single_fact")) do |facter_output| assert_equal("external_value", facter_output.stdout.chomp, "Incorrect external fact value") end end end end -end +end \ No newline at end of file diff --git a/acceptance/tests/options/config_file/external_facts_list.rb b/acceptance/tests/options/config_file/external_facts_list.rb index 3380dafac9..eb48274538 100644 --- a/acceptance/tests/options/config_file/external_facts_list.rb +++ b/acceptance/tests/options/config_file/external_facts_list.rb @@ -16,8 +16,7 @@ external_fact_2 = File.join(external_dir_2, "external_fact#{ext}") create_remote_file(agent, external_fact_1, external_fact_content(agent['platform'], 'external_fact_1', 'external_value_1')) create_remote_file(agent, external_fact_2, external_fact_content(agent['platform'], 'external_fact_2', 'external_value_2')) - agent.chmod('+x', external_fact_1) - agent.chmod('+x', external_fact_2) + on(agent, "chmod +x '#{external_fact_1}' '#{external_fact_2}'") config_dir = agent.tmpdir("config_dir") config_file = File.join(config_dir, "facter.conf") @@ -26,17 +25,14 @@ external-dir : [ "#{external_dir_1}", "#{external_dir_2}" ], } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(external_dir_1) - agent.rm_rf(external_dir_2) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{external_dir_1}' '#{external_dir_2}' '#{config_dir}'") end step "Agent #{agent}: resolve a fact from each configured external-dir path" do - on(agent, facter("--config \"#{config_file}\" --json")) do |facter_output| + on(agent, facter("--config '#{config_file}' --json")) do |facter_output| results = JSON.parse(facter_output.stdout) assert_equal("external_value_1", results['external_fact_1'], "Incorrect external fact value for external_fact_1") assert_equal("external_value_2", results['external_fact_2'], "Incorrect external fact value for external_fact_2") diff --git a/acceptance/tests/options/config_file/load_from_ruby.rb b/acceptance/tests/options/config_file/load_from_ruby.rb index fe36974c3e..2bc16294a9 100644 --- a/acceptance/tests/options/config_file/load_from_ruby.rb +++ b/acceptance/tests/options/config_file/load_from_ruby.rb @@ -29,28 +29,22 @@ cust_path = File.join(cust_fact_dir, "custom_fact.rb") teardown do - agent.rm_rf(facter_conf_default_dir) - agent.rm_rf(ext_fact_dir1) - agent.rm_rf(ext_fact_dir2) - agent.rm_rf(cust_fact_dir) + on(agent, "rm -rf '#{facter_conf_default_dir}' '#{ext_fact_dir1}' '#{ext_fact_dir2}' '#{cust_fact_dir}'", + :acceptable_exit_codes => [0,1]) end # create the directories - [facter_conf_default_dir, ext_fact_dir1, ext_fact_dir2, cust_fact_dir].each do |dir| - agent.mkdir_p(dir) - end + on(agent, "mkdir -p '#{facter_conf_default_dir}' '#{ext_fact_dir1}' '#{ext_fact_dir2}' '#{cust_fact_dir}'") step "Agent #{agent}: create facter.conf, external fact, and custom fact files" do - config_content = <<-FILE + + create_remote_file(agent, facter_conf_default_path, <<-FILE) global : { external-dir : ["#{ext_fact_dir1}", "#{ext_fact_dir2}"], custom-dir : ["#{cust_fact_dir}"] } FILE - config_content = escape_paths(agent, config_content) - create_remote_file(agent, facter_conf_default_path, config_content) - create_remote_file(agent, ext_path1, <<-FILE) externalfact1: 'This is external fact 1 in #{ext_fact_dir1} directory' FILE @@ -70,10 +64,9 @@ step "running `puppet facts` should load the config file automatically and search all external-dir and custom-dir paths" do on(agent, puppet('facts')) do |puppet_facts_output| - - assert_match(/This is external fact 1 in #{escape_paths(agent, ext_fact_dir1)} directory/, puppet_facts_output.stdout.gsub('\\\\', '\\'), "Expected external fact") - assert_match(/This is external fact 2 in #{escape_paths(agent, ext_fact_dir2)} directory/, puppet_facts_output.stdout.gsub('\\\\', '\\'), "Expected external fact") - assert_match(/This is a custom fact in #{escape_paths(agent, cust_fact_dir)} directory/, puppet_facts_output.stdout.gsub('\\\\', '\\'), "Expected custom fact") + assert_match(/This is external fact 1 in #{ext_fact_dir1} directory/, puppet_facts_output.stdout, "Expected external fact") + assert_match(/This is external fact 2 in #{ext_fact_dir2} directory/, puppet_facts_output.stdout, "Expected external fact") + assert_match(/This is a custom fact in #{cust_fact_dir} directory/, puppet_facts_output.stdout, "Expected custom fact") end end end diff --git a/acceptance/tests/options/config_file/log_level.rb b/acceptance/tests/options/config_file/log_level.rb index 8aef792aab..cf5b915e8d 100644 --- a/acceptance/tests/options/config_file/log_level.rb +++ b/acceptance/tests/options/config_file/log_level.rb @@ -17,11 +17,11 @@ step "Agent #{agent}: create config file" do config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) config_file = File.join(config_dir, "facter.conf") - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) end step "log-level set to debug should print DEBUG output to stderr" do diff --git a/acceptance/tests/options/config_file/no_custom_facts_and_custom_dir.rb b/acceptance/tests/options/config_file/no_custom_facts_and_custom_dir.rb index 49fb23de5e..46a1121328 100644 --- a/acceptance/tests/options/config_file/no_custom_facts_and_custom_dir.rb +++ b/acceptance/tests/options/config_file/no_custom_facts_and_custom_dir.rb @@ -27,19 +27,17 @@ no-custom-facts : true, } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(custom_fact) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{custom_fact}' '#{config_dir}'") end step "Agent #{agent}: config option no-custom-facts : true and custom-dir should result in an options conflict error" do - on(agent, facter("--config \"#{config_file}\""), :acceptable_exit_codes => 1) do |facter_output| + on(agent, facter("--config '#{config_file}'"), :acceptable_exit_codes => 1) do |facter_output| assert_match(/options conflict/, facter_output.stderr, "Output does not contain error string") end end end end -end +end \ No newline at end of file diff --git a/acceptance/tests/options/config_file/no_custom_facts_and_facterlib.rb b/acceptance/tests/options/config_file/no_custom_facts_and_facterlib.rb index 59904ed88c..f88291bc65 100644 --- a/acceptance/tests/options/config_file/no_custom_facts_and_facterlib.rb +++ b/acceptance/tests/options/config_file/no_custom_facts_and_facterlib.rb @@ -30,15 +30,14 @@ create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(facterlib_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{facterlib_dir}' '#{config_dir}'") end step "Agent #{agent}: no-custom-facts should ignore the FACTERLIB environment variable" do - on(agent, facter("--config \"#{config_file}\" custom_fact", :environment => {'FACTERLIB' => facterlib_dir})) do |facter_output| + on(agent, facter("--config '#{config_file}' custom_fact", :environment => {'FACTERLIB' => facterlib_dir})) do |facter_output| assert_equal("", facter_output.stdout.chomp, "Custom fact in FACTERLIB should not have resolved") end end end end -end +end \ No newline at end of file diff --git a/acceptance/tests/options/config_file/no_custom_facts_and_load_path.rb b/acceptance/tests/options/config_file/no_custom_facts_and_load_path.rb index ff6eb62bf0..6a54b32382 100644 --- a/acceptance/tests/options/config_file/no_custom_facts_and_load_path.rb +++ b/acceptance/tests/options/config_file/no_custom_facts_and_load_path.rb @@ -22,7 +22,7 @@ step("Agent #{agent}: determine the load path and create a custom facter directory on it and a config file") do ruby_path = on(agent, "#{ruby_command(agent)} -e 'puts $LOAD_PATH[0]'").stdout.chomp load_path_facter_dir = File.join(ruby_path, 'facter') - agent.mkdir_p(load_path_facter_dir) + on(agent, "mkdir -p \"#{load_path_facter_dir}\"") custom_fact = File.join(load_path_facter_dir, 'custom_fact.rb') create_remote_file(agent, custom_fact, content) @@ -36,15 +36,14 @@ create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(load_path_facter_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{load_path_facter_dir}' '#{config_dir}'") end step("Agent #{agent}: using config no-custom-facts : true should not resolve facts in facter directories on the $LOAD_PATH") do - on(agent, facter("--config \"#{config_file}\" custom_fact")) do |facter_output| + on(agent, facter("--config '#{config_file}' custom_fact")) do |facter_output| assert_equal("", facter_output.stdout.chomp, "Custom fact in $LOAD_PATH/facter should not have resolved") end end end end -end +end \ No newline at end of file diff --git a/acceptance/tests/options/config_file/no_external_facts.rb b/acceptance/tests/options/config_file/no_external_facts.rb index c6d004511c..8ac6a1dae8 100644 --- a/acceptance/tests/options/config_file/no_external_facts.rb +++ b/acceptance/tests/options/config_file/no_external_facts.rb @@ -12,7 +12,7 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "external_fact#{ext}") create_remote_file(agent, external_fact, external_fact_content(agent['platform'], 'external_fact', 'external_value')) - agent.chmod('+x', external_fact) + on(agent, "chmod +x '#{external_fact}'") config_dir = agent.tmpdir("config_dir") config_file = File.join(config_dir, "facter.conf") @@ -23,9 +23,9 @@ EOM create_remote_file(agent, config_file, config_content) + teardown do - agent.rm_rf(external_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{external_dir}' '#{config_dir}'") end step "Agent #{agent}: --no-external-facts option should not load external facts" do diff --git a/acceptance/tests/options/config_file/no_external_facts_and_external_dir.rb b/acceptance/tests/options/config_file/no_external_facts_and_external_dir.rb index a516fdd72d..971b870525 100644 --- a/acceptance/tests/options/config_file/no_external_facts_and_external_dir.rb +++ b/acceptance/tests/options/config_file/no_external_facts_and_external_dir.rb @@ -18,19 +18,17 @@ no-external-facts : true, } EOM - config_content = escape_paths(agent, config_content) create_remote_file(agent, config_file, config_content) teardown do - agent.rm_rf(external_dir) - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{external_dir}' '#{config_dir}'") end step "Agent #{agent}: config option no-external-facts : true and external-dir should result in an options conflict error" do - on(agent, facter("--config \"#{config_file}\""), :acceptable_exit_codes => 1) do |facter_output| + on(agent, facter("--config '#{config_file}'"), :acceptable_exit_codes => 1) do |facter_output| assert_match(/options conflict/, facter_output.stderr, "Output does not contain error string") end end end end -end +end \ No newline at end of file diff --git a/acceptance/tests/options/config_file/no_ruby_disables_custom_facts.rb b/acceptance/tests/options/config_file/no_ruby_disables_custom_facts.rb index 432ff43fad..e8520f9f48 100644 --- a/acceptance/tests/options/config_file/no_ruby_disables_custom_facts.rb +++ b/acceptance/tests/options/config_file/no_ruby_disables_custom_facts.rb @@ -24,22 +24,22 @@ step "Agent #{agent}: create config file" do config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) config_file = File.join(config_dir, "facter.conf") - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0,1]) end step "no-ruby option should disable custom facts" do step "Agent #{agent}: create custom fact directory and custom fact" do custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) - agent.mkdir_p(custom_dir) + on(agent, "mkdir -p '#{custom_dir}'") custom_fact = File.join(custom_dir, 'custom_fact.rb') create_remote_file(agent, custom_fact, custom_fact_content) teardown do - agent.rm_rf(custom_dir) + on(agent, "rm -rf '#{custom_dir}'", :acceptable_exit_codes => [0,1]) end on(agent, facter("custom_fact", :environment => { 'FACTERLIB' => custom_dir })) do |facter_output| diff --git a/acceptance/tests/options/config_file/no_ruby_disables_ruby_facts.rb b/acceptance/tests/options/config_file/no_ruby_disables_ruby_facts.rb index c5a5dc6740..11484b5063 100644 --- a/acceptance/tests/options/config_file/no_ruby_disables_ruby_facts.rb +++ b/acceptance/tests/options/config_file/no_ruby_disables_ruby_facts.rb @@ -16,11 +16,11 @@ step "Agent #{agent}: create config file" do config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) config_file = File.join(config_dir, "facter.conf") - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0,1]) end step "no-ruby option should disable Ruby and facts requiring Ruby" do diff --git a/acceptance/tests/options/config_file/trace.rb b/acceptance/tests/options/config_file/trace.rb index e76e2d062b..c59af90057 100644 --- a/acceptance/tests/options/config_file/trace.rb +++ b/acceptance/tests/options/config_file/trace.rb @@ -7,7 +7,7 @@ extend Facter::Acceptance::UserFactUtils erroring_custom_fact = < [0, 1]) end step "trace setting should provide a backtrace for a custom fact with errors" do - on(agent, facter("--custom-dir \"#{custom_dir}\" custom_fact_with_trace"), :acceptable_exit_codes => [1]) do |facter_output| + on(agent, facter("--custom-dir '#{custom_dir}' custom_fact"), :acceptable_exit_codes => [1]) do |facter_output| assert_match(/backtrace:\s+#{custom_fact}/, facter_output.stderr, "Expected a backtrace for erroneous custom fact") end end diff --git a/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_json_output.rb b/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_json_output.rb index a2214a9abb..534626350a 100644 --- a/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_json_output.rb +++ b/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_json_output.rb @@ -19,7 +19,6 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "#{external_cachegroup}#{ext}") if agent['platform'] =~ /windows/ - if agent.is_cygwin? external_fact_content = < [0]) do |cat_output| + assert_match(/#{cached_fact_name}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end step "should read from a cached JSON file for a fact that has been cached" do - agent.rm_rf(cached_facts_dir) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) + on(agent, "rm -rf '#{cached_facts_dir}'") + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) create_remote_file(agent, cached_fact_file, cached_fact_content) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) do |facter_output| assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") end diff --git a/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_text_output.rb b/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_text_output.rb index 9bdcae9075..d1828d14e1 100644 --- a/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_text_output.rb +++ b/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_text_output.rb @@ -19,7 +19,7 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "#{external_cachegroup}#{ext}") create_remote_file(agent, external_fact, external_fact_content(agent['platform'], cached_fact_name, initial_fact_value)) - agent.chmod('+x', external_fact) + on(agent, "chmod +x '#{external_fact}'") config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) config_file = File.join(config_dir, "facter.conf") @@ -28,7 +28,7 @@ cached_fact_file = File.join(cached_facts_dir, "#{external_cachegroup}#{ext}") # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") cached_fact_content = < [0]) do |cat_output| + assert_match(/#{cached_fact_name}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end step "should read from a cached JSON file for a fact that has been cached" do - agent.rm_rf(cached_facts_dir) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) + on(agent, "rm -rf '#{cached_facts_dir}'") + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) create_remote_file(agent, cached_fact_file, cached_fact_content) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) do |facter_output| assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") end diff --git a/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_yaml_output.rb b/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_yaml_output.rb index 231f03b95f..8f69d1253b 100644 --- a/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_yaml_output.rb +++ b/acceptance/tests/options/config_file/ttls_cached_external_execution_resolver_with_yaml_output.rb @@ -19,20 +19,11 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "#{external_cachegroup}#{ext}") if agent['platform'] =~ /windows/ - if agent.is_cygwin? external_fact_content = < [0]) do |cat_output| + assert_match(/#{cached_fact_name}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end step "should read from a cached JSON file for a fact that has been cached" do - agent.rm_rf(cached_facts_dir) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) + on(agent, "rm -rf '#{cached_facts_dir}'") + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) create_remote_file(agent, cached_fact_file, cached_fact_content) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) do |facter_output| assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") end diff --git a/acceptance/tests/options/config_file/ttls_cached_external_json_resolver.rb b/acceptance/tests/options/config_file/ttls_cached_external_json_resolver.rb index 38c35232c1..592e95401f 100644 --- a/acceptance/tests/options/config_file/ttls_cached_external_json_resolver.rb +++ b/acceptance/tests/options/config_file/ttls_cached_external_json_resolver.rb @@ -33,7 +33,7 @@ cached_fact_file = File.join(cached_facts_dir, "#{external_cachegroup}#{ext}") # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") cached_fact_content = < [0]) do |cat_output| + assert_match(/#{cached_fact_name}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end step "should read from a cached JSON file for a fact that has been cached" do - agent.rm_rf(cached_facts_dir) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) + on(agent, "rm -rf '#{cached_facts_dir}'") + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) create_remote_file(agent, cached_fact_file, cached_fact_content) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) do |facter_output| assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") end diff --git a/acceptance/tests/options/config_file/ttls_cached_external_text_resolver.rb b/acceptance/tests/options/config_file/ttls_cached_external_text_resolver.rb index ffc61c49f7..f7deb867b1 100644 --- a/acceptance/tests/options/config_file/ttls_cached_external_text_resolver.rb +++ b/acceptance/tests/options/config_file/ttls_cached_external_text_resolver.rb @@ -32,7 +32,7 @@ cached_fact_file = File.join(cached_facts_dir, "#{external_cachegroup}#{ext}") # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") cached_fact_content = < [0]) do |cat_output| + assert_match(/#{cached_fact_name}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end step "should read from a cached JSON file for a fact that has been cached" do - agent.rm_rf(cached_facts_dir) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) + on(agent, "rm -rf '#{cached_facts_dir}'") + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) create_remote_file(agent, cached_fact_file, cached_fact_content) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) do |facter_output| assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") end diff --git a/acceptance/tests/options/config_file/ttls_cached_external_yaml_resolver.rb b/acceptance/tests/options/config_file/ttls_cached_external_yaml_resolver.rb index 51c7e95e66..3ec14d81f6 100644 --- a/acceptance/tests/options/config_file/ttls_cached_external_yaml_resolver.rb +++ b/acceptance/tests/options/config_file/ttls_cached_external_yaml_resolver.rb @@ -32,7 +32,7 @@ cached_fact_file = File.join(cached_facts_dir, "#{external_cachegroup}#{ext}") # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") cached_fact_content = < [0]) do |cat_output| + assert_match(/#{cached_fact_name}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end step "should read from a cached JSON file for a fact that has been cached" do - agent.rm_rf(cached_facts_dir) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) + on(agent, "rm -rf '#{cached_facts_dir}'") + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) create_remote_file(agent, cached_fact_file, cached_fact_content) - on(agent, facter("--external-dir \"#{external_dir}\" --debug #{cached_fact_name}")) do |facter_output| + on(agent, facter("--external-dir '#{external_dir}' --debug #{cached_fact_name}")) do |facter_output| assert_match(/loading cached values for .+ facts/, stderr, "Expected debug message to state that values are read from cache") assert_match(/#{cached_fact_value}/, stdout, "Expected fact to match the cached fact file") end diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_clear_by_empty_ttls_cache_list.rb b/acceptance/tests/options/config_file/ttls_cached_facts_clear_by_empty_ttls_cache_list.rb index ed4b669f05..baf2ce13f5 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_clear_by_empty_ttls_cache_list.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_clear_by_empty_ttls_cache_list.rb @@ -39,17 +39,17 @@ cached_fact_file = File.join(cached_facts_dir, cached_fact_name) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file with no cached facts" do # Set up a known cached fact - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("")) create_remote_file(agent, cached_fact_file, cached_fact_content) end @@ -59,7 +59,7 @@ no_cache_config_file = File.join(config_dir, "no-cache.conf") create_remote_file(agent, no_cache_config_file, config_no_cache) - on(agent, facter("--config \"#{no_cache_config_file}\"")) do |facter_output| + on(agent, facter("--config '#{no_cache_config_file}'")) do |facter_output| assert_no_match(/#{cached_fact_value}/, facter_output.stdout, "Expected to not see the cached fact value") end diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_creates_json_cache_file.rb b/acceptance/tests/options/config_file/ttls_cached_facts_creates_json_cache_file.rb index 6a7f1253a0..c13123db2f 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_creates_json_cache_file.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_creates_json_cache_file.rb @@ -26,21 +26,22 @@ cached_fact_file = File.join(cached_facts_dir, cached_factname) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "should create a JSON file for a fact that is to be cached" do - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("--debug")) do |facter_output| assert_match(/caching values for .+ facts/, facter_output.stderr, "Expected debug message to state that values will be cached") end - cat_output = agent.cat(cached_fact_file) - assert_match(/#{cached_factname}/, cat_output.strip, "Expected cached fact file to contain fact information") + on(agent, "cat #{cached_fact_file}", :acceptable_exit_codes => [0]) do |cat_output| + assert_match(/#{cached_factname}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end end end diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_do_not_read_the_old_cached_value.rb b/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_do_not_read_the_old_cached_value.rb index 60f0a8f0cd..b154416ccf 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_do_not_read_the_old_cached_value.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_do_not_read_the_old_cached_value.rb @@ -33,21 +33,21 @@ cached_fact_file = File.join(cached_facts_dir, cached_factname) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "should not read from a cached JSON file for a fact that has been cached but the TTL expired" do # Setup a known cached fact - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("")) create_remote_file(agent, cached_fact_file, cached_fact_content) # Change the modified date to sometime in the far distant past - agent.modified_at(cached_fact_file, '198001010000') + on(agent, "touch -mt 198001010000 '#{cached_fact_file}'") on(agent, facter("#{cached_factname}")) do |facter_output| assert_not_match(/#{cached_fact_value}/, facter_output.stdout, "Expected fact to not match the cached fact file") diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_refresh_the_cached_value.rb b/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_refresh_the_cached_value.rb index f6dc65e143..c0955f5d3c 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_refresh_the_cached_value.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_expire_facts_refresh_the_cached_value.rb @@ -33,27 +33,28 @@ cached_fact_file = File.join(cached_facts_dir, cached_factname) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "should refresh an expired cached fact" do # Setup a known cached fact - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("")) create_remote_file(agent, cached_fact_file, cached_fact_content) # Change the modified date to sometime in the far distant past - agent.modified_at(cached_fact_file, '198001010000') + on(agent, "touch -mt 198001010000 '#{cached_fact_file}'") # Force facter to recache on(agent, facter("#{cached_factname}")) # Read cached fact file content - cat_output = agent.cat(cached_fact_file) - assert_no_match(/#{cached_fact_value}/, cat_output.strip, "Expected cached fact file to be refreshed") + on(agent, "cat #{cached_fact_file}", :acceptable_exit_codes => [0]) do |cat_output| + assert_no_match(/#{cached_fact_value}/, cat_output.stdout, "Expected cached fact file to be refreshed") + end end end end diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_read_from_the_cached_value.rb b/acceptance/tests/options/config_file/ttls_cached_facts_read_from_the_cached_value.rb index 47c251bf17..c48247bbcc 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_read_from_the_cached_value.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_read_from_the_cached_value.rb @@ -33,17 +33,17 @@ cached_fact_file = File.join(cached_facts_dir, cached_factname) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "should read from a cached JSON file for a fact that has been cached" do # Setup a known cached fact - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("")) create_remote_file(agent, cached_fact_file, cached_fact_content) diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_that_are_corrupt_are_refreshed.rb b/acceptance/tests/options/config_file/ttls_cached_facts_that_are_corrupt_are_refreshed.rb index b9d47d091d..d72311d3fc 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_that_are_corrupt_are_refreshed.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_that_are_corrupt_are_refreshed.rb @@ -26,17 +26,17 @@ cached_fact_file = File.join(cached_facts_dir, cached_factname) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "should refresh a cached fact if cache file is corrupt" do # Setup a known cached fact - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("")) # Corrupt the cached fact file create_remote_file(agent, cached_fact_file, 'ThisIsNotvalidJSON') @@ -44,8 +44,9 @@ on(agent, facter("#{cached_factname}")) do assert_match(/.+/, stdout, "Expected fact to be resolved") end - cat_output = agent.cat(cached_fact_file) - assert_match(/#{cached_factname}/, cat_output.strip, "Expected cachced fact to contain the fact name") + on(agent, "cat #{cached_fact_file}", :acceptable_exit_codes => [0]) do |cat_output| + assert_match(/#{cached_factname}/, cat_output.stdout, "Expected cachced fact to contain the fact name") + end end end end diff --git a/acceptance/tests/options/config_file/ttls_cached_facts_that_are_empty_return_an_empty_value.rb b/acceptance/tests/options/config_file/ttls_cached_facts_that_are_empty_return_an_empty_value.rb index 74f06951cb..fae19a9b1b 100644 --- a/acceptance/tests/options/config_file/ttls_cached_facts_that_are_empty_return_an_empty_value.rb +++ b/acceptance/tests/options/config_file/ttls_cached_facts_that_are_empty_return_an_empty_value.rb @@ -30,17 +30,17 @@ cached_fact_file = File.join(cached_facts_dir, cached_factname) # Setup facter conf - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "should return an empty string for an empty JSON document" do # Setup a known cached fact - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, facter("")) create_remote_file(agent, cached_fact_file, empty_cached_fact_content) diff --git a/acceptance/tests/options/config_file/ttls_puppet_facts_creates_json_for_cached_facts.rb b/acceptance/tests/options/config_file/ttls_puppet_facts_creates_json_for_cached_facts.rb index 77d0bbbdd2..a244aec47f 100644 --- a/acceptance/tests/options/config_file/ttls_puppet_facts_creates_json_for_cached_facts.rb +++ b/acceptance/tests/options/config_file/ttls_puppet_facts_creates_json_for_cached_facts.rb @@ -24,21 +24,21 @@ cached_facts_dir = get_cached_facts_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) cached_fact_file = File.join(cached_facts_dir, cached_factname) - agent.mkdir_p(facter_conf_default_dir) + on(agent, "mkdir -p '#{facter_conf_default_dir}'") create_remote_file(agent, facter_conf_default_path, config) teardown do - agent.rm_rf(facter_conf_default_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}' '#{facter_conf_default_dir}'", :acceptable_exit_codes => [0, 1]) end step "should create a JSON file for a fact that is to be cached" do - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, puppet("facts --debug")) do |pupppet_fact_output| assert_match(/caching values for .+ facts/, pupppet_fact_output.stdout, "Expected debug message to state that values will be cached") end - cat_output = agent.cat(cached_fact_file) - assert_match(/#{cached_factname}/, cat_output.strip, "Expected cached fact file to contain fact information") + on(agent, "cat #{cached_fact_file}", :acceptable_exit_codes => [0]) do |cat_output| + assert_match(/#{cached_factname}/, cat_output.stdout, "Expected cached fact file to contain fact information") + end end end end diff --git a/acceptance/tests/options/config_file/ttls_puppet_facts_honors_cached_facts.rb b/acceptance/tests/options/config_file/ttls_puppet_facts_honors_cached_facts.rb index 8bbe523e25..2caf70a6d7 100644 --- a/acceptance/tests/options/config_file/ttls_puppet_facts_honors_cached_facts.rb +++ b/acceptance/tests/options/config_file/ttls_puppet_facts_honors_cached_facts.rb @@ -30,17 +30,16 @@ cached_facts_dir = get_cached_facts_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) cached_fact_file = File.join(cached_facts_dir, cached_factname) - agent.mkdir_p(facter_conf_default_dir) + on(agent, "mkdir -p '#{facter_conf_default_dir}'") create_remote_file(agent, facter_conf_default_path, config) teardown do - agent.rm_rf(cached_facts_dir) - agent.rm_rf(facter_conf_default_dir) + on(agent, "rm -rf '#{cached_facts_dir}' '#{facter_conf_default_dir}'", :acceptable_exit_codes => [0, 1]) end step "should read from a cached JSON file for a fact that has been cached" do step "call puppet facts to setup the cached fact" do - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) on(agent, puppet("facts")) create_remote_file(agent, cached_fact_file, cached_fact_content) end diff --git a/acceptance/tests/options/config_file/verbose.rb b/acceptance/tests/options/config_file/verbose.rb index d00632cac7..da835f80af 100644 --- a/acceptance/tests/options/config_file/verbose.rb +++ b/acceptance/tests/options/config_file/verbose.rb @@ -1,4 +1,4 @@ -# This test is intended to demonstrate that setting cli.verbose to true in the +# This test is intended to demonstrate that setting cli.verbose to true in the # config file causes INFO level logging to output to stderr. test_name "C99989: verbose config field prints verbose information to stderr" do tag 'risk:medium' @@ -16,11 +16,11 @@ step "Agent #{agent}: create config file" do config_dir = get_default_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) config_file = File.join(config_dir, "facter.conf") - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) teardown do - agent.rm_rf(config_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0,1]) end step "debug output should print when config file is loaded" do diff --git a/acceptance/tests/options/custom_facts.rb b/acceptance/tests/options/custom_facts.rb index 30798cedfe..4c0ce6f09c 100644 --- a/acceptance/tests/options/custom_facts.rb +++ b/acceptance/tests/options/custom_facts.rb @@ -7,7 +7,7 @@ extend Facter::Acceptance::UserFactUtils content = < { 'FACTERLIB' => custom_dir })) do |facter_output| + on(agent, facter('custom_fact', :environment => { 'FACTERLIB' => custom_dir })) do |facter_output| assert_equal("facterlib", facter_output.stdout.chomp, "Incorrect custom fact value for fact in FACTERLIB") end end diff --git a/acceptance/tests/options/custom_facts_list.rb b/acceptance/tests/options/custom_facts_list.rb index 8e549a2f49..a71683e0c9 100644 --- a/acceptance/tests/options/custom_facts_list.rb +++ b/acceptance/tests/options/custom_facts_list.rb @@ -33,12 +33,11 @@ create_remote_file(agent, custom_fact_2, content_2) teardown do - agent.rm_rf(custom_dir_1) - agent.rm_rf(custom_dir_2) + on(agent, "rm -rf '#{custom_dir_1}' '#{custom_dir_2}'") end step "Agent #{agent}: resolve a fact from each specified --custom-dir option" do - on(agent, facter("--custom-dir \"#{custom_dir_1}\" --custom-dir \"#{custom_dir_2}\" --json")) do |facter_output| + on(agent, facter("--custom-dir #{custom_dir_1} --custom-dir #{custom_dir_2} --json")) do |facter_output| results = JSON.parse(facter_output.stdout) assert_equal("testvalue_1", results['custom_fact_1'], "Incorrect custom fact value for custom_fact_1") assert_equal("testvalue_2", results['custom_fact_2'], "Incorrect custom fact value for custom_fact_2") diff --git a/acceptance/tests/options/custom_facts_load_path.rb b/acceptance/tests/options/custom_facts_load_path.rb index 2fe3cb3664..8e991110db 100644 --- a/acceptance/tests/options/custom_facts_load_path.rb +++ b/acceptance/tests/options/custom_facts_load_path.rb @@ -25,12 +25,12 @@ step "Agent #{agent}: determine $LOAD_PATH and create custom fact" do on(agent, "#{ruby_command(agent)} -e 'puts $LOAD_PATH[0]'") load_path_facter_dir = File.join(stdout.chomp, 'facter') - agent.mkdir_p(load_path_facter_dir) + on(agent, "mkdir -p \"#{load_path_facter_dir}\"") custom_fact = File.join(load_path_facter_dir, 'custom_fact.rb') create_remote_file(agent, custom_fact, content) teardown do - agent.rm_rf(load_path_facter_dir) + on(agent, "rm -rf '#{load_path_facter_dir}'") end step("Agent #{agent}: resolve the custom fact that is in a facter directory on the $LOAD_PATH") diff --git a/acceptance/tests/options/external_facts.rb b/acceptance/tests/options/external_facts.rb index 79b27f6f88..461cb1f617 100644 --- a/acceptance/tests/options/external_facts.rb +++ b/acceptance/tests/options/external_facts.rb @@ -12,14 +12,14 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "external_fact#{ext}") create_remote_file(agent, external_fact, external_fact_content(agent['platform'], 'single_fact', 'external_value')) - agent.chmod('+x', external_fact) + on(agent, "chmod +x '#{external_fact}'") teardown do - agent.rm_rf(external_dir) + on(agent, "rm -rf '#{external_dir}'") end step "Agent #{agent}: resolve a fact from each specified --external_dir option" do - on(agent, facter("--external-dir \"#{external_dir}\" single_fact")) do |facter_output| + on(agent, facter("--external-dir #{external_dir} single_fact")) do |facter_output| assert_equal("external_value", facter_output.stdout.chomp, "Incorrect external fact value") end end diff --git a/acceptance/tests/options/external_facts_list.rb b/acceptance/tests/options/external_facts_list.rb index aa1daada1d..5627530a38 100644 --- a/acceptance/tests/options/external_facts_list.rb +++ b/acceptance/tests/options/external_facts_list.rb @@ -17,16 +17,14 @@ external_fact_2 = File.join(external_dir_2, "external_fact#{ext}") create_remote_file(agent, external_fact_1, external_fact_content(agent['platform'], 'external_fact_1', 'external_value_1')) create_remote_file(agent, external_fact_2, external_fact_content(agent['platform'], 'external_fact_2', 'external_value_2')) - agent.chmod('+x', external_fact_1) - agent.chmod('+x', external_fact_2) + on(agent, "chmod +x '#{external_fact_1}' '#{external_fact_2}'") teardown do - agent.rm_rf(external_dir_1) - agent.rm_rf(external_dir_2) + on(agent, "rm -rf '#{external_dir_1}' '#{external_dir_2}'") end step "Agent #{agent}: resolve a fact from each specified --external_dir option" do - on(agent, facter("--external-dir \"#{external_dir_1}\" --external-dir \"#{external_dir_2}\" --json")) do |facter_output| + on(agent, facter("--external-dir #{external_dir_1} --external-dir #{external_dir_2} --json")) do |facter_output| results = JSON.parse(facter_output.stdout) assert_equal("external_value_1", results['external_fact_1'], "Incorrect external fact value for external_fact_1") assert_equal("external_value_2", results['external_fact_2'], "Incorrect external fact value for external_fact_2") diff --git a/acceptance/tests/options/json.rb b/acceptance/tests/options/json.rb index 1c57d3e2d7..ccbbf3de49 100644 --- a/acceptance/tests/options/json.rb +++ b/acceptance/tests/options/json.rb @@ -20,16 +20,16 @@ step "Agent #{agent}: create a structured custom fact" do custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) custom_fact = File.join(custom_dir, 'custom_fact.rb') - agent.mkdir_p(custom_dir) + on(agent, "mkdir -p '#{custom_dir}'") create_remote_file(agent, custom_fact, content) - agent.chmod('+x', custom_fact) + on(agent, "chmod +x '#{custom_fact}'") teardown do - agent.rm_rf(custom_fact) + on(agent, "rm -f '#{custom_fact}'") end step "Agent #{agent}: retrieve output using the --json option" do - on(agent, facter("--custom-dir \"#{custom_dir}\" --json structured_fact")) do + on(agent, facter("--custom-dir '#{custom_dir}' --json structured_fact")) do begin expected = {"structured_fact" => {"foo" => {"nested" => "value1"}, "bar" => "value2", "baz" => "value3", "true" => true, "false" => false}} assert_equal(expected, JSON.parse(stdout.chomp), "JSON output does not match expected output") diff --git a/acceptance/tests/options/list_block_groups.rb b/acceptance/tests/options/list_block_groups.rb index 47c8c9ec21..c1bd7998b5 100644 --- a/acceptance/tests/options/list_block_groups.rb +++ b/acceptance/tests/options/list_block_groups.rb @@ -2,7 +2,7 @@ # will cause the names of blockable resolvers to be printed to stdout. It should not list # any resolver name that is not blockable. test_name "C99969: the `--list-block-groups` command line flag prints available block groups to stdout" do - tag 'risk:medium' + tag 'risk:medium', 'facter_3' agents.each do |agent| step "the EC2 blockgroup should be listed" do diff --git a/acceptance/tests/options/list_block_groups_facter_4.rb b/acceptance/tests/options/list_block_groups_facter_4.rb new file mode 100644 index 0000000000..223a258e51 --- /dev/null +++ b/acceptance/tests/options/list_block_groups_facter_4.rb @@ -0,0 +1,15 @@ +# This tests is intended to verify that passing the `--list-block-groups` flag +# will cause the names of blockable resolvers to be printed to stdout. It should not list +# any resolver name that is not blockable. +test_name "the `--list-block-groups` command line flag prints available block groups to stdout" do + tag 'risk:medium' + + agents.each do |agent| + step "the EC2 blockgroup should be listed" do + on(agent, facter("--list-block-groups")) do |facter_output| + assert_match(/EC2/, facter_output.stdout, "Expected the EC2 group to be listed") + assert_match(/ec2_metadata/, facter_output.stdout, "Expected the EC2 group's facts to be listed") + end + end + end +end diff --git a/acceptance/tests/options/list_cache_groups.rb b/acceptance/tests/options/list_cache_groups.rb index 1cb057cf07..7915e52afc 100644 --- a/acceptance/tests/options/list_cache_groups.rb +++ b/acceptance/tests/options/list_cache_groups.rb @@ -13,8 +13,7 @@ etc_factsd_path = "#{etc_factsd_dir}/#{filename}" teardown do - agent.rm_rf(external_dir) - agent.rm_rf(etc_factsd_path) + on(agent, "rm -rf '#{external_dir}' '#{etc_factsd_path}'") end step "the various cache groups should be listed" do @@ -31,7 +30,7 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact_script = File.join(external_dir, "#{external_filename}#{ext}") create_remote_file(agent, external_fact_script, external_fact_content(agent['platform'], "a", "b")) - agent.chmod('+x', external_fact_script) + on(agent, "chmod +x '#{external_fact_script}'") external_fact_script_txt = File.join(external_dir, "#{external_filename}.txt") create_remote_file(agent, external_fact_script_txt, '') @@ -42,17 +41,17 @@ external_fact_script_yaml = File.join(external_dir, "#{external_filename}.yaml") create_remote_file(agent, external_fact_script_yaml, '') - on(agent, facter("--external-dir \"#{external_dir}\" --list-cache-groups")) do |facter_output| + on(agent, facter("--external-dir #{external_dir} --list-cache-groups")) do |facter_output| assert_match(/#{external_filename}#{ext}/, facter_output.stdout, "external facts script files should be listed as cacheable") assert_match(/#{external_filename}.txt/, facter_output.stdout, "external facts txt files should be listed as cacheable") assert_match(/#{external_filename}.json/, facter_output.stdout, "external facts json files should be listed as cacheable") assert_match(/#{external_filename}.yaml/, facter_output.stdout, "external facts yaml files should be listed as cacheable") end - agent.rm_rf(external_dir) + on(agent, "rm -rf '#{external_dir}'") end step "external facts groups should be listed only without --no-external-facts" do - agent.mkdir_p(etc_factsd_dir) + on(agent, "mkdir -p '#{etc_factsd_dir}'") create_remote_file(agent, etc_factsd_path, 'test_fact: test_value') on(agent, facter("--list-cache-groups")) do |facter_output| assert_match(/#{filename}/, facter_output.stdout, "external facts script files should be listed as cacheable") @@ -60,7 +59,7 @@ on(agent, facter("--list-cache-groups --no-external-facts")) do |facter_output| assert_no_match(/#{filename}/, facter_output.stdout, "external facts script files should now be listed as cacheable when --no-external-facts is used") end - agent.rm_rf(etc_factsd_path) + on(agent, "rm -f '#{etc_factsd_path}'") end end end diff --git a/acceptance/tests/options/no_block.rb b/acceptance/tests/options/no_block.rb index d1471a0365..fe513636fa 100644 --- a/acceptance/tests/options/no_block.rb +++ b/acceptance/tests/options/no_block.rb @@ -12,11 +12,11 @@ facter_conf_default_path = File.join(facter_conf_default_dir, "facter.conf") teardown do - agent.rm_rf(facter_conf_default_dir) + on(agent, "rm -rf '#{facter_conf_default_dir}'", :acceptable_exit_codes => [0, 1]) end # create the directories - agent.mkdir_p(facter_conf_default_dir) + on(agent, "mkdir -p '#{facter_conf_default_dir}'") step "Agent #{agent}: create config file" do create_remote_file(agent, facter_conf_default_path, <<-FILE) diff --git a/acceptance/tests/options/no_cache_should_not_cache_facts.rb b/acceptance/tests/options/no_cache_should_not_cache_facts.rb index 96a3aa7838..87460e6453 100644 --- a/acceptance/tests/options/no_cache_should_not_cache_facts.rb +++ b/acceptance/tests/options/no_cache_should_not_cache_facts.rb @@ -22,15 +22,15 @@ cached_facts_dir = get_cached_facts_dir(agent['platform'], kernel_version) cached_fact_file = File.join(cached_facts_dir, cached_fact_name) - agent.rm_rf(cached_fact_file) + on(agent, "rm -f '#{cached_fact_file}'", :acceptable_exit_codes => [0, 1]) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file in default location" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) end diff --git a/acceptance/tests/options/no_cache_should_not_load_cached_facts.rb b/acceptance/tests/options/no_cache_should_not_load_cached_facts.rb index a2ee77cd99..da65a39fc6 100644 --- a/acceptance/tests/options/no_cache_should_not_load_cached_facts.rb +++ b/acceptance/tests/options/no_cache_should_not_load_cached_facts.rb @@ -31,18 +31,18 @@ cached_fact_file = File.join(cached_facts_dir, cached_fact_name) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file in default location" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) end step "facter should not load facts from the cache when --no-cache is specified" do # clear the fact cache - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) # run once to cache the uptime fact on(agent, facter("")) diff --git a/acceptance/tests/options/no_cache_should_not_refresh_cached_facts.rb b/acceptance/tests/options/no_cache_should_not_refresh_cached_facts.rb index f827d35d7e..2da9ed27ad 100644 --- a/acceptance/tests/options/no_cache_should_not_refresh_cached_facts.rb +++ b/acceptance/tests/options/no_cache_should_not_refresh_cached_facts.rb @@ -30,18 +30,18 @@ cached_fact_file = File.join(cached_facts_dir, cached_fact_name) teardown do - agent.rm_rf(config_dir) - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{config_dir}'", :acceptable_exit_codes => [0, 1]) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file in default location" do - agent.mkdir_p(config_dir) + on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) end step "facter should not refresh an expired cache when --no-cache is specified" do # clear the fact cache - agent.rm_rf(cached_facts_dir) + on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) # run once to cache the uptime fact on(agent, facter("")) @@ -49,14 +49,15 @@ # override cached content create_remote_file(agent, cached_fact_file, bad_cached_content) # update the modify time on the new cached fact to prompt a refresh - agent.modified_at(cached_fact_file, '198001010000') + on(agent, "touch -mt 0301010000 '#{cached_fact_file}'") on(agent, facter("--no-cache")) do |facter_output| assert_no_match(/caching/, facter_output.stderr, "facter should not have tried to refresh the cache") end - cat_output = agent.cat(cached_fact_file) - assert_match(/#{bad_cached_content.chomp}/, cat_output.strip, "facter should not have updated the cached value") + on(agent, "cat '#{cached_fact_file}'", :acceptable_exit_codes => [0]) do |cat_output| + assert_match(/#{bad_cached_content}/, cat_output.stdout, "facter should not have updated the cached value") + end end end end diff --git a/acceptance/tests/options/no_custom_facts.rb b/acceptance/tests/options/no_custom_facts.rb index 79a899c7fd..e75a6d2586 100644 --- a/acceptance/tests/options/no_custom_facts.rb +++ b/acceptance/tests/options/no_custom_facts.rb @@ -16,12 +16,12 @@ agents.each do |agent| step "Agent #{agent}: create custom fact directory and custom fact" do custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) - agent.mkdir_p(custom_dir) + on(agent, "mkdir -p '#{custom_dir}'") custom_fact = File.join(custom_dir, 'custom_fact.rb') create_remote_file(agent, custom_fact, content) teardown do - agent.rm_rf(custom_fact) + on(agent, "rm -f '#{custom_fact}'") end step "Agent #{agent}: --no-custom-facts option should not load custom facts" do diff --git a/acceptance/tests/options/no_custom_facts_and_custom_dir.rb b/acceptance/tests/options/no_custom_facts_and_custom_dir.rb index 1ab4b5154b..dd3e324afd 100644 --- a/acceptance/tests/options/no_custom_facts_and_custom_dir.rb +++ b/acceptance/tests/options/no_custom_facts_and_custom_dir.rb @@ -7,7 +7,7 @@ custom_dir = agent.tmpdir('custom_dir') teardown do - agent.rm_rf(custom_dir) + on(agent, "rm -rf '#{custom_dir}'") end step "Agent #{agent}: --no-custom-facts and --custom-dir options should result in a error" do diff --git a/acceptance/tests/options/no_custom_facts_and_facterlib.rb b/acceptance/tests/options/no_custom_facts_and_facterlib.rb index a5672a42dd..0e7dd09658 100644 --- a/acceptance/tests/options/no_custom_facts_and_facterlib.rb +++ b/acceptance/tests/options/no_custom_facts_and_facterlib.rb @@ -21,7 +21,7 @@ create_remote_file(agent, custom_fact, content) teardown do - agent.rm_rf(facterlib_dir) + on(agent, "rm -rf '#{facterlib_dir}'") end step "Agent #{agent}: --no-custom-facts should ignore the FACTERLIB environment variable" do diff --git a/acceptance/tests/options/no_custom_facts_and_load_path.rb b/acceptance/tests/options/no_custom_facts_and_load_path.rb index 1bc6570a7d..8af4c0bc21 100644 --- a/acceptance/tests/options/no_custom_facts_and_load_path.rb +++ b/acceptance/tests/options/no_custom_facts_and_load_path.rb @@ -25,12 +25,12 @@ step("Agent #{agent}: determine the load path and create a custom facter directory on it") do on(agent, "#{ruby_command(agent)} -e 'puts $LOAD_PATH[0]'") load_path_facter_dir = File.join(stdout.chomp, 'facter') - agent.mkdir_p(load_path_facter_dir) + on(agent, "mkdir -p \"#{load_path_facter_dir}\"") custom_fact = File.join(load_path_facter_dir, 'custom_fact.rb') create_remote_file(agent, custom_fact, content) teardown do - agent.rm_rf(load_path_facter_dir) + on(agent, "rm -rf '#{load_path_facter_dir}'") end step("Agent #{agent}: using --no-custom-facts should not resolve facts on the $LOAD_PATH") do diff --git a/acceptance/tests/options/no_external_facts.rb b/acceptance/tests/options/no_external_facts.rb index a0bc2cc42b..c69a342c7c 100644 --- a/acceptance/tests/options/no_external_facts.rb +++ b/acceptance/tests/options/no_external_facts.rb @@ -12,10 +12,10 @@ ext = get_external_fact_script_extension(agent['platform']) external_fact = File.join(external_dir, "external_fact#{ext}") create_remote_file(agent, external_fact, external_fact_content(agent['platform'], 'external_fact', 'external_value')) - agent.chmod('+x', external_fact) + on(agent, "chmod +x '#{external_fact}'") teardown do - agent.rm_rf(external_dir) + on(agent, "rm -rf '#{external_dir}'") end step "Agent #{agent}: --no-external-facts option should not load external facts" do diff --git a/acceptance/tests/options/no_external_facts_and_external_dir.rb b/acceptance/tests/options/no_external_facts_and_external_dir.rb index 1dc5d1b25f..fa9fb8224f 100644 --- a/acceptance/tests/options/no_external_facts_and_external_dir.rb +++ b/acceptance/tests/options/no_external_facts_and_external_dir.rb @@ -7,7 +7,7 @@ external_dir = agent.tmpdir('external_dir') teardown do - agent.rm_rf(external_dir) + on(agent, "rm -rf '#{external_dir}'") end step "Agent #{agent}: --no-external-facts and --external-dir options should result in a error" do diff --git a/acceptance/tests/options/no_ruby.rb b/acceptance/tests/options/no_ruby.rb index 8707913fdd..4308177d90 100644 --- a/acceptance/tests/options/no_ruby.rb +++ b/acceptance/tests/options/no_ruby.rb @@ -27,12 +27,12 @@ step "--no-ruby option should disable custom facts" do step "Agent #{agent}: create custom fact directory and custom fact" do custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) - agent.mkdir_p(custom_dir) + on(agent, "mkdir -p '#{custom_dir}'") custom_fact = File.join(custom_dir, 'custom_fact.rb') create_remote_file(agent, custom_fact, content) teardown do - agent.rm_rf(custom_fact) + on(agent, "rm -f '#{custom_fact}'") end on(agent, facter('--no-ruby custom_fact', :environment => { 'FACTERLIB' => custom_dir })) do diff --git a/acceptance/tests/options/puppet_facts.rb b/acceptance/tests/options/puppet_facts.rb index 26a06515db..5f9e388781 100644 --- a/acceptance/tests/options/puppet_facts.rb +++ b/acceptance/tests/options/puppet_facts.rb @@ -8,20 +8,19 @@ external_dir = agent.puppet['pluginfactdest'] external_file = File.join(external_dir, "external.txt") custom_dir = File.join(agent.puppet['plugindest'], "facter") - custom_file = File.join(custom_dir, 'custom.rb') + custom_file = "#{custom_dir}/custom.rb" teardown do - agent.rm_rf(external_file) - agent.rm_rf(custom_dir) + on agent, "rm -f '#{external_file}' '#{custom_file}'" end step "Agent #{agent}: create external fact" do - agent.mkdir_p(external_dir) + on agent, "mkdir -p '#{external_dir}'" create_remote_file(agent, external_file, "external=external") end step "Agent #{agent}: create custom fact" do - agent.mkdir_p(custom_dir) + on agent, "mkdir -p '#{custom_dir}'" create_remote_file(agent, custom_file, "Facter.add(:custom) { setcode { 'custom' } }") end diff --git a/acceptance/tests/options/trace.rb b/acceptance/tests/options/trace.rb index 000ffec974..2ea1b868b7 100644 --- a/acceptance/tests/options/trace.rb +++ b/acceptance/tests/options/trace.rb @@ -7,7 +7,7 @@ extend Facter::Acceptance::UserFactUtils content = < [1]) do + on(agent, facter("--custom-dir '#{custom_dir}' --trace custom_fact"), :acceptable_exit_codes => [1]) do assert_match(/backtrace:\s+#{custom_fact}/, stderr, "Expected a backtrace for erroneous custom fact") end end diff --git a/acceptance/tests/options/yaml.rb b/acceptance/tests/options/yaml.rb index f265c8d034..ee13cb4736 100644 --- a/acceptance/tests/options/yaml.rb +++ b/acceptance/tests/options/yaml.rb @@ -20,16 +20,16 @@ step "Agent #{agent}: create a structured custom fact" do custom_dir = get_user_fact_dir(agent['platform'], on(agent, facter('kernelmajversion')).stdout.chomp.to_f) custom_fact = File.join(custom_dir, 'custom_fact.rb') - agent.mkdir_p(custom_dir) + on(agent, "mkdir -p '#{custom_dir}'") create_remote_file(agent, custom_fact, content) - agent.chmod('+x', custom_fact) + on(agent, "chmod +x '#{custom_fact}'") teardown do - agent.rm_rf(custom_fact) + on(agent, "rm -f '#{custom_fact}'") end step "Agent #{agent}: retrieve output using the --yaml option" do - on(agent, facter("--custom-dir \"#{custom_dir}\" --yaml structured_fact")) do + on(agent, facter("--custom-dir '#{custom_dir}' --yaml structured_fact")) do begin expected = {"structured_fact" => {"foo" => {"nested" => "value1"}, "bar" => "value2", "baz" => "value3" }} assert_equal(expected, YAML.load(stdout), "YAML output does not match expected output") diff --git a/agent/facter-ng.gemspec b/agent/facter-ng.gemspec index a1dabcc196..0523308a19 100644 --- a/agent/facter-ng.gemspec +++ b/agent/facter-ng.gemspec @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| spec.name = 'facter-ng' - spec.version = '4.0.31' + spec.version = '4.0.30' spec.authors = ['Puppet'] spec.email = ['team-nw@puppet.com'] diff --git a/facter.gemspec b/facter.gemspec index c57a2ea5bd..85d6177ce3 100644 --- a/facter.gemspec +++ b/facter.gemspec @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) Gem::Specification.new do |spec| spec.name = 'facter' - spec.version = '4.0.31' + spec.version = '4.0.30' spec.authors = ['Puppet'] spec.email = ['team-nw@puppet.com'] diff --git a/lib/facter/facts/aix/disks.rb b/lib/facter/facts/aix/disks.rb deleted file mode 100644 index 4a2a1f24b4..0000000000 --- a/lib/facter/facts/aix/disks.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - class Disks - FACT_NAME = 'disks' - - def call_the_resolver - disks = Facter::Resolvers::Aix::Disks.resolve(:disks) - - disks = disks&.empty? ? nil : disks - - Facter::ResolvedFact.new(FACT_NAME, disks) - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/available.rb b/lib/facter/facts/aix/memory/swap/available.rb deleted file mode 100644 index 5db3513f85..0000000000 --- a/lib/facter/facts/aix/memory/swap/available.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class Available - FACT_NAME = 'memory.swap.available' - ALIASES = 'swapfree' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - if fact_value - fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:available_bytes]) - end - [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/available_bytes.rb b/lib/facter/facts/aix/memory/swap/available_bytes.rb deleted file mode 100644 index 61675516d0..0000000000 --- a/lib/facter/facts/aix/memory/swap/available_bytes.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class AvailableBytes - FACT_NAME = 'memory.swap.available_bytes' - ALIASES = 'swapfree_mb' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - fact_value = fact_value[:available_bytes] if fact_value - - [Facter::ResolvedFact.new(FACT_NAME, fact_value), - Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/capacity.rb b/lib/facter/facts/aix/memory/swap/capacity.rb deleted file mode 100644 index db04285948..0000000000 --- a/lib/facter/facts/aix/memory/swap/capacity.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class Capacity - FACT_NAME = 'memory.swap.capacity' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - fact_value = fact_value[:capacity] if fact_value - - Facter::ResolvedFact.new(FACT_NAME, fact_value) - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/total.rb b/lib/facter/facts/aix/memory/swap/total.rb deleted file mode 100644 index da368241df..0000000000 --- a/lib/facter/facts/aix/memory/swap/total.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class Total - FACT_NAME = 'memory.swap.total' - ALIASES = 'swapsize' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - if fact_value - fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:total_bytes]) - end - [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/total_bytes.rb b/lib/facter/facts/aix/memory/swap/total_bytes.rb deleted file mode 100644 index a6950d60f9..0000000000 --- a/lib/facter/facts/aix/memory/swap/total_bytes.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class TotalBytes - FACT_NAME = 'memory.swap.total_bytes' - ALIASES = 'swapsize_mb' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - fact_value = fact_value[:total_bytes] if fact_value - - [Facter::ResolvedFact.new(FACT_NAME, fact_value), - Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/used.rb b/lib/facter/facts/aix/memory/swap/used.rb deleted file mode 100644 index 7d30f51614..0000000000 --- a/lib/facter/facts/aix/memory/swap/used.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class Used - FACT_NAME = 'memory.swap.used' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - if fact_value - fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:used_bytes]) - end - Facter::ResolvedFact.new(FACT_NAME, fact_value) - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/swap/used_bytes.rb b/lib/facter/facts/aix/memory/swap/used_bytes.rb deleted file mode 100644 index b80ab584f5..0000000000 --- a/lib/facter/facts/aix/memory/swap/used_bytes.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module Swap - class UsedBytes - FACT_NAME = 'memory.swap.used_bytes' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:swap) - fact_value = fact_value[:used_bytes] if fact_value - Facter::ResolvedFact.new(FACT_NAME, fact_value) - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/available.rb b/lib/facter/facts/aix/memory/system/available.rb deleted file mode 100644 index f4a2ae2b04..0000000000 --- a/lib/facter/facts/aix/memory/system/available.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class Available - FACT_NAME = 'memory.system.available' - ALIASES = 'memoryfree' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - if fact_value - fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:available_bytes]) - end - [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/available_bytes.rb b/lib/facter/facts/aix/memory/system/available_bytes.rb deleted file mode 100644 index cdfb3f9ae3..0000000000 --- a/lib/facter/facts/aix/memory/system/available_bytes.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class AvailableBytes - FACT_NAME = 'memory.system.available_bytes' - ALIASES = 'memoryfree_mb' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - fact_value = fact_value[:available_bytes] if fact_value - - [Facter::ResolvedFact.new(FACT_NAME, fact_value), - Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/capacity.rb b/lib/facter/facts/aix/memory/system/capacity.rb deleted file mode 100644 index 6d6f42f0ac..0000000000 --- a/lib/facter/facts/aix/memory/system/capacity.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class Capacity - FACT_NAME = 'memory.system.capacity' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - fact_value = fact_value[:capacity] if fact_value - - Facter::ResolvedFact.new(FACT_NAME, fact_value) - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/total.rb b/lib/facter/facts/aix/memory/system/total.rb deleted file mode 100644 index a7b61e573e..0000000000 --- a/lib/facter/facts/aix/memory/system/total.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class Total - FACT_NAME = 'memory.system.total' - ALIASES = 'memorysize' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - if fact_value - fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:total_bytes]) - end - [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/total_bytes.rb b/lib/facter/facts/aix/memory/system/total_bytes.rb deleted file mode 100644 index 6694567f86..0000000000 --- a/lib/facter/facts/aix/memory/system/total_bytes.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class TotalBytes - FACT_NAME = 'memory.system.total_bytes' - ALIASES = 'memorysize_mb' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - fact_value = fact_value[:total_bytes] if fact_value - - [Facter::ResolvedFact.new(FACT_NAME, fact_value), - Facter::ResolvedFact.new(ALIASES, Facter::FactsUtils::UnitConverter.bytes_to_mb(fact_value), :legacy)] - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/used.rb b/lib/facter/facts/aix/memory/system/used.rb deleted file mode 100644 index 6ce1808cd5..0000000000 --- a/lib/facter/facts/aix/memory/system/used.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class Used - FACT_NAME = 'memory.system.used' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - if fact_value - fact_value = Facter::FactsUtils::UnitConverter.bytes_to_human_readable(fact_value[:used_bytes]) - end - Facter::ResolvedFact.new(FACT_NAME, fact_value) - end - end - end - end - end -end diff --git a/lib/facter/facts/aix/memory/system/used_bytes.rb b/lib/facter/facts/aix/memory/system/used_bytes.rb deleted file mode 100644 index 68f146d602..0000000000 --- a/lib/facter/facts/aix/memory/system/used_bytes.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -module Facts - module Aix - module Memory - module System - class UsedBytes - FACT_NAME = 'memory.system.used_bytes' - - def call_the_resolver - fact_value = Facter::Resolvers::Aix::Memory.resolve(:system) - fact_value = fact_value[:used_bytes] if fact_value - Facter::ResolvedFact.new(FACT_NAME, fact_value) - end - end - end - end - end -end diff --git a/lib/facter/framework/core/fact_loaders/fact_loader.rb b/lib/facter/framework/core/fact_loaders/fact_loader.rb index 292264a9de..297fc1e23d 100644 --- a/lib/facter/framework/core/fact_loaders/fact_loader.rb +++ b/lib/facter/framework/core/fact_loaders/fact_loader.rb @@ -51,8 +51,6 @@ def load_external_facts(options) @external_facts.concat(@external_fact_loader.custom_facts) end - @external_facts = block_facts(@external_facts, options) - if options[:external_facts] @log.debug('Loading external facts') @external_facts.concat(@external_fact_loader.external_facts) diff --git a/lib/facter/resolvers/aix/disks.rb b/lib/facter/resolvers/aix/disks.rb deleted file mode 100644 index 11a2bc4a2c..0000000000 --- a/lib/facter/resolvers/aix/disks.rb +++ /dev/null @@ -1,63 +0,0 @@ -# frozen_string_literal: true - -module Facter - module Resolvers - module Aix - class Disks < BaseResolver - @semaphore = Mutex.new - @fact_list ||= {} - class << self - private - - def post_resolve(fact_name) - @fact_list.fetch(fact_name) { execute_lspv(fact_name) } - end - - def execute_lspv(fact_name) - @fact_list[:disks] = {} - - result = Facter::Core::Execution.execute('lspv', logger: log) - - return if result.empty? - - result.each_line do |line| - disk_name = line.split(' ')[0].strip - size = find_size(disk_name) - @fact_list[:disks][disk_name] = size if size - end - - @fact_list[fact_name] - end - - def find_size(name) - stdout = Facter::Core::Execution.execute("lspv #{name}", logger: log) - - return if stdout.empty? - - info_size = InfoExtractor.extract(stdout, /PP SIZE:|TOTAL PPs:|FREE PPs:|PV STATE:/) - - return unless info_size['PV STATE'] - - size_bytes = compute_size(info_size) - - { - size_bytes: size_bytes, - size: Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes) - } - end - - def compute_size(size_hash) - physical_partitions = size_hash['TOTAL PPs'].to_i + size_hash['FREE PPs'].to_i - size_physical_partition = size_hash['PP SIZE'] - exp = if size_physical_partition[/mega/] - InfoExtractor::MEGABYTES_EXPONENT - else - InfoExtractor::GIGABYTES_EXPONENT - end - size_physical_partition.to_i * physical_partitions * exp - end - end - end - end - end -end diff --git a/lib/facter/resolvers/aix/memory.rb b/lib/facter/resolvers/aix/memory.rb deleted file mode 100644 index 70d3381d9a..0000000000 --- a/lib/facter/resolvers/aix/memory.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -module Facter - module Resolvers - module Aix - class Memory < BaseResolver - # :hardware - @semaphore = Mutex.new - @fact_list ||= {} - class << self - private - - def post_resolve(fact_name) - @fact_list.fetch(fact_name) { execute_svmon(fact_name) } - end - - def execute_svmon(fact_name) - result = Facter::Core::Execution.execute('svmon', logger: log) - return if result.empty? - - @fact_list[:system] = @fact_list[:swap] = {} - - pagesize = call_pagesize.to_i - return if pagesize.zero? - - result.each_line do |line| - @fact_list[:system] = populate_system(line, pagesize) if line.include?('memory') - @fact_list[:swap] = populate_swap(line, pagesize) if line =~ /pg\sspace/ - end - - @fact_list[fact_name] - end - - def call_pagesize - Facter::Core::Execution.execute('pagesize', logger: log).strip - end - - def populate_system(content, pagesize) - content = content.split(' ') - - total = content[1].to_i * pagesize - used = content[2].to_i * pagesize - - { available_bytes: content[3].to_i * pagesize, - total_bytes: total, - used_bytes: used, - capacity: FilesystemHelper.compute_capacity(used, total) } - end - - def populate_swap(content, pagesize) - content = content.split(' ') - - total = content[2].to_i * pagesize - used = content[3].to_i * pagesize - - { available_bytes: total - used, - total_bytes: total, - used_bytes: used, - capacity: FilesystemHelper.compute_capacity(used, total) } - end - end - end - end - end -end diff --git a/lib/facter/resolvers/aix/partitions.rb b/lib/facter/resolvers/aix/partitions.rb index 2901f7c52a..61c47107dd 100644 --- a/lib/facter/resolvers/aix/partitions.rb +++ b/lib/facter/resolvers/aix/partitions.rb @@ -9,6 +9,9 @@ class Partitions < BaseResolver class << self private + MEGABYTES_EXPONENT = 1024**2 + GIGABYTES_EXPONENT = 1024**3 + def post_resolve(fact_name) @fact_list.fetch(fact_name) { query_cudv(fact_name) } end @@ -40,7 +43,7 @@ def populate_from_lslv(name) return if stdout.empty? - info_hash = InfoExtractor.extract(stdout, /PPs:|PP SIZE|TYPE:|LABEL:|MOUNT/) + info_hash = extract_info(stdout) size_bytes = compute_size(info_hash) part_info = { @@ -48,21 +51,29 @@ def populate_from_lslv(name) size_bytes: size_bytes, size: Facter::FactsUtils::UnitConverter.bytes_to_human_readable(size_bytes) } - mount = info_hash['MOUNT POINT'] + mount = info_hash['MOUNTPOINT'] label = info_hash['LABEL'] part_info[:mount] = mount unless %r{N/A} =~ mount - part_info[:label] = label.strip unless /None/ =~ label + part_info[:label] = label unless /None/ =~ label part_info end + def extract_info(lsl_content) + lsl_content = lsl_content.strip.split("\n").map do |line| + next unless /PPs:|PP SIZE|TYPE:|LABEL:|MOUNT/ =~ line + + line.split(/:|\s\s/).reject(&:empty?) + end + + lsl_content.flatten!.select! { |elem| elem }.map! { |elem| elem.delete("\s") } + + Hash[*lsl_content] + end + def compute_size(info_hash) physical_partitions = info_hash['PPs'].to_i - size_physical_partition = info_hash['PP SIZE'] - exp = if size_physical_partition[/mega/] - InfoExtractor::MEGABYTES_EXPONENT - else - InfoExtractor::GIGABYTES_EXPONENT - end + size_physical_partition = info_hash['PPSIZE'] + exp = size_physical_partition[/mega/] ? MEGABYTES_EXPONENT : GIGABYTES_EXPONENT size_physical_partition.to_i * physical_partitions * exp end end diff --git a/lib/facter/resolvers/aix/utils/info_extractor.rb b/lib/facter/resolvers/aix/utils/info_extractor.rb deleted file mode 100644 index 457c2a6628..0000000000 --- a/lib/facter/resolvers/aix/utils/info_extractor.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -module Facter - module InfoExtractor - MEGABYTES_EXPONENT = 1024**2 - GIGABYTES_EXPONENT = 1024**3 - - def self.extract(content, regex) - content = content.each_line.map do |line| - next unless regex =~ line - - line.split(/:\s*|\s{2,}/) - end - - content.flatten!.reject!(&:nil?) - - Hash[*content] - end - end -end diff --git a/lib/facter/resolvers/augeas_resolver.rb b/lib/facter/resolvers/augeas_resolver.rb index 2e1ee7bc11..0e21e61e5e 100644 --- a/lib/facter/resolvers/augeas_resolver.rb +++ b/lib/facter/resolvers/augeas_resolver.rb @@ -14,10 +14,27 @@ def post_resolve(fact_name) end def read_augeas_version(fact_name) - output = Facter::Core::Execution.execute('augparse --version 2>&1', logger: log) - @fact_list[:augeas_version] = Regexp.last_match(1) if output =~ /^augparse (\d+\.\d+\.\d+)/ + @fact_list[:augeas_version] = read_augeas_from_cli + @fact_list[:augeas_version] ||= read_augeas_from_gem + @fact_list[fact_name] end + + def read_augeas_from_cli + output = Facter::Core::Execution.execute('augparse --version 2>&1', logger: log) + Regexp.last_match(1) if output =~ /^augparse (\d+\.\d+\.\d+)/ + end + + def read_augeas_from_gem + require 'augeas' + + if Gem.loaded_specs['augeas'] + ::Augeas.create { |aug| aug.get('/augeas/version') } + else + # it is used for legacy augeas <= 0.5.0 (ruby-augeas gem) + ::Augeas.open { |aug| aug.get('/augeas/version') } + end + end end end end diff --git a/lib/facter/version.rb b/lib/facter/version.rb index 42dfefd8cb..cc6eb848d4 100644 --- a/lib/facter/version.rb +++ b/lib/facter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Facter - VERSION = '4.0.31' unless defined?(VERSION) + VERSION = '4.0.30' unless defined?(VERSION) end diff --git a/spec/facter/facts/aix/disks_spec.rb b/spec/facter/facts/aix/disks_spec.rb deleted file mode 100644 index 6b35dc9f39..0000000000 --- a/spec/facter/facts/aix/disks_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Disks do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Disks.new } - - let(:disk) do - { - 'disks' => { - 'hdisk0' => { - 'size' => '20.00 GiB', - 'size_bytes' => 21_474_836_480 - } - } - } - end - - before do - allow(Facter::Resolvers::Aix::Disks).to receive(:resolve).with(:disks).and_return(disk) - end - - it 'calls Facter::Resolvers::Aix::Disk' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Disks).to have_received(:resolve).with(:disks) - end - - it 'returns resolved fact with name disk and value' do - expect(fact.call_the_resolver) - .to be_an_instance_of(Facter::ResolvedFact) - .and have_attributes(name: 'disks', value: disk) - end - - context 'when resolver returns empty hash' do - let(:disk) { {} } - - it 'returns nil fact' do - expect(fact.call_the_resolver) - .to be_an_instance_of(Facter::ResolvedFact) - .and have_attributes(name: 'disks', value: nil) - end - end - - context 'when resolver returns nil' do - let(:disk) { nil } - - it 'returns nil fact' do - expect(fact.call_the_resolver) - .to be_an_instance_of(Facter::ResolvedFact) - .and have_attributes(name: 'disks', value: nil) - end - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/available_bytes_spec.rb b/spec/facter/facts/aix/memory/swap/available_bytes_spec.rb deleted file mode 100644 index 20901430ef..0000000000 --- a/spec/facter/facts/aix/memory/swap/available_bytes_spec.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::AvailableBytes do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::AvailableBytes.new } - - let(:value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:result) { 2_332_425 } - let(:value_mb) { 2.22 } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap available bytes fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.available_bytes', value: result), - an_object_having_attributes(name: 'swapfree_mb', value: value_mb, type: :legacy)) - end - - context 'when resolver returns nil' do - let(:value) { nil } - - it 'returns swap available memory in bytes fact as nil' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.available_bytes', value: value), - an_object_having_attributes(name: 'swapfree_mb', value: value, type: :legacy)) - end - end - - context 'when resolver returns empty hash' do - let(:value) { {} } - let(:result) { nil } - - it 'returns swap available memory in bytes fact as nil' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.available_bytes', value: result), - an_object_having_attributes(name: 'swapfree_mb', value: result, type: :legacy)) - end - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/available_spec.rb b/spec/facter/facts/aix/memory/swap/available_spec.rb deleted file mode 100644 index 67a3d5213b..0000000000 --- a/spec/facter/facts/aix/memory/swap/available_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::Available do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::Available.new } - - let(:value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:result) { '2.22 MiB' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap available memory fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.available', value: result), - an_object_having_attributes(name: 'swapfree', value: result, type: :legacy)) - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/capacity_spec.rb b/spec/facter/facts/aix/memory/swap/capacity_spec.rb deleted file mode 100644 index 4cb563eed7..0000000000 --- a/spec/facter/facts/aix/memory/swap/capacity_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::Capacity do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::Capacity.new } - - let(:value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024, capacity: '7,9%' } } - let(:result) { '7,9%' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap memory capacity fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'memory.swap.capacity', value: result) - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/total_bytes_spec.rb b/spec/facter/facts/aix/memory/swap/total_bytes_spec.rb deleted file mode 100644 index 94d5b8d171..0000000000 --- a/spec/facter/facts/aix/memory/swap/total_bytes_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::TotalBytes do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::TotalBytes.new } - - let(:value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:result) { 2_332_999 } - let(:value_mb) { 2.22 } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap total memory in bytes fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.total_bytes', value: result), - an_object_having_attributes(name: 'swapsize_mb', value: value_mb, type: :legacy)) - end - - context 'when resolver returns nil' do - let(:value) { nil } - - it 'returns swap total memory in bytes fact as nil' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.total_bytes', value: value), - an_object_having_attributes(name: 'swapsize_mb', value: value, type: :legacy)) - end - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/total_spec.rb b/spec/facter/facts/aix/memory/swap/total_spec.rb deleted file mode 100644 index aec06dc71b..0000000000 --- a/spec/facter/facts/aix/memory/swap/total_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::Total do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::Total.new } - - let(:value) { { available_bytes: 24, total_bytes: 1024, used_bytes: 1000 } } - let(:result) { '1.00 KiB' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap total memory fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.swap.total', value: result), - an_object_having_attributes(name: 'swapsize', value: result, type: :legacy)) - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/used_bytes_spec.rb b/spec/facter/facts/aix/memory/swap/used_bytes_spec.rb deleted file mode 100644 index 8a78fc584d..0000000000 --- a/spec/facter/facts/aix/memory/swap/used_bytes_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::UsedBytes do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::UsedBytes.new } - - let(:value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:result) { 1024 } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap used memory in bytes fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'memory.swap.used_bytes', value: result) - end - end -end diff --git a/spec/facter/facts/aix/memory/swap/used_spec.rb b/spec/facter/facts/aix/memory/swap/used_spec.rb deleted file mode 100644 index 62631f64c3..0000000000 --- a/spec/facter/facts/aix/memory/swap/used_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::Swap::Used do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::Swap::Used.new } - - let(:resolver_value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { '1.00 KiB' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:swap).and_return(resolver_value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:swap) - end - - it 'returns swap used memory fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'memory.swap.used', value: value) - end - end -end diff --git a/spec/facter/facts/aix/memory/system/available_bytes_spec.rb b/spec/facter/facts/aix/memory/system/available_bytes_spec.rb deleted file mode 100644 index ae941871c5..0000000000 --- a/spec/facter/facts/aix/memory/system/available_bytes_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::AvailableBytes do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::AvailableBytes.new } - - let(:resolver_output) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { 2_332_425 } - let(:value_mb) { 2.22 } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_output) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system available memory in bytes fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.system.available_bytes', value: value), - an_object_having_attributes(name: 'memoryfree_mb', value: value_mb, type: :legacy)) - end - - context 'when resolver returns nil' do - let(:value) { nil } - let(:resolver_output) { nil } - - it 'returns system available memory in bytes fact as nil' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.system.available_bytes', value: value), - an_object_having_attributes(name: 'memoryfree_mb', value: value, type: :legacy)) - end - end - end -end diff --git a/spec/facter/facts/aix/memory/system/available_spec.rb b/spec/facter/facts/aix/memory/system/available_spec.rb deleted file mode 100644 index d77b93b5a3..0000000000 --- a/spec/facter/facts/aix/memory/system/available_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::Available do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::Available.new } - - let(:resolver_value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { '2.22 MiB' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system available memory fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.system.available', value: value), - an_object_having_attributes(name: 'memoryfree', value: value, type: :legacy)) - end - end -end diff --git a/spec/facter/facts/aix/memory/system/capacity_spec.rb b/spec/facter/facts/aix/memory/system/capacity_spec.rb deleted file mode 100644 index 8d988dacd2..0000000000 --- a/spec/facter/facts/aix/memory/system/capacity_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::Capacity do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::Capacity.new } - - let(:resolver_output) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024, capacity: '5.3%' } } - let(:value) { '5.3%' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_output) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system memory capacity fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'memory.system.capacity', value: value) - end - end -end diff --git a/spec/facter/facts/aix/memory/system/total_bytes_spec.rb b/spec/facter/facts/aix/memory/system/total_bytes_spec.rb deleted file mode 100644 index c32bff6df4..0000000000 --- a/spec/facter/facts/aix/memory/system/total_bytes_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::TotalBytes do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::TotalBytes.new } - - let(:resolver_output) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { 2_332_999 } - let(:value_mb) { 2.22 } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_output) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system total memory in bytes fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.system.total_bytes', value: value), - an_object_having_attributes(name: 'memorysize_mb', value: value_mb, type: :legacy)) - end - - context 'when resolver returns nil' do - let(:value) { nil } - let(:resolver_output) { nil } - - it 'returns system total memory in bytes fact as nil' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.system.total_bytes', value: value), - an_object_having_attributes(name: 'memorysize_mb', value: value, type: :legacy)) - end - end - end -end diff --git a/spec/facter/facts/aix/memory/system/total_spec.rb b/spec/facter/facts/aix/memory/system/total_spec.rb deleted file mode 100644 index f2311f2016..0000000000 --- a/spec/facter/facts/aix/memory/system/total_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::Total do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::Total.new } - - let(:resolver_value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { '2.22 MiB' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system total memory fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'memory.system.total', value: value), - an_object_having_attributes(name: 'memorysize', value: value, type: :legacy)) - end - end -end diff --git a/spec/facter/facts/aix/memory/system/used_bytes_spec.rb b/spec/facter/facts/aix/memory/system/used_bytes_spec.rb deleted file mode 100644 index 24b14dbd71..0000000000 --- a/spec/facter/facts/aix/memory/system/used_bytes_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::UsedBytes do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::UsedBytes.new } - - let(:resolver_output) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { 1024 } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_output) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system used memory in bytes fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'memory.system.used_bytes', value: value) - end - end -end diff --git a/spec/facter/facts/aix/memory/system/used_spec.rb b/spec/facter/facts/aix/memory/system/used_spec.rb deleted file mode 100644 index aed45c06e4..0000000000 --- a/spec/facter/facts/aix/memory/system/used_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -describe Facts::Aix::Memory::System::Used do - describe '#call_the_resolver' do - subject(:fact) { Facts::Aix::Memory::System::Used.new } - - let(:resolver_value) { { available_bytes: 2_332_425, total_bytes: 2_332_999, used_bytes: 1024 } } - let(:value) { '1.00 KiB' } - - before do - allow(Facter::Resolvers::Aix::Memory).to \ - receive(:resolve).with(:system).and_return(resolver_value) - end - - it 'calls Facter::Resolvers::Aix::Memory' do - fact.call_the_resolver - expect(Facter::Resolvers::Aix::Memory).to have_received(:resolve).with(:system) - end - - it 'returns system used memory fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'memory.system.used', value: value) - end - end -end diff --git a/spec/facter/facts/linux/virtual_spec.rb b/spec/facter/facts/linux/virtual_spec.rb index 4a8e151871..b559a4f2be 100644 --- a/spec/facter/facts/linux/virtual_spec.rb +++ b/spec/facter/facts/linux/virtual_spec.rb @@ -4,29 +4,27 @@ describe '#call_the_resolver' do subject(:fact) { Facts::Linux::Virtual.new } - context 'when is docker' do - let(:vm) { 'docker' } + let(:vm) { 'docker' } - before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(vm) - end + before do + allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(vm) + end - it 'calls Facter::Resolvers::Containers' do - fact.call_the_resolver - expect(Facter::Resolvers::Containers).to have_received(:resolve).with(:vm) - end + it 'calls Facter::Resolvers::Containers' do + fact.call_the_resolver + expect(Facter::Resolvers::Containers).to have_received(:resolve).with(:vm) + end - it 'returns virtual fact' do - expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ - have_attributes(name: 'virtual', value: vm) - end + it 'returns virtual fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \ + have_attributes(name: 'virtual', value: vm) end context 'when is gce' do + let(:vm) { nil } let(:value) { 'gce' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return('Google Engine') end @@ -36,13 +34,12 @@ end end - context 'when is xen-hvm' do - let(:value) { 'xenhvm' } + context 'when is vmware' do + let(:vm) { nil } + let(:value) { 'vmware_fusion' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(value) + allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(value) end it 'returns virtual fact' do @@ -51,14 +48,13 @@ end end - context 'when is vmware' do - let(:value) { 'vmware_fusion' } + context 'when is xen-hvm' do + let(:vm) { nil } + let(:value) { 'xenhvm' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(value) + allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(value) end it 'returns virtual fact' do @@ -68,13 +64,10 @@ end context 'when is openVz' do + let(:vm) { nil } let(:value) { 'openvzve' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(value) end @@ -85,14 +78,11 @@ end context 'when is vserver' do + let(:vm) { nil } let(:value) { 'vserver_host' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(value) end @@ -103,15 +93,10 @@ end context 'when is xen priviledged' do + let(:vm) { nil } let(:value) { 'xen0' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil) allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(value) end @@ -122,15 +107,10 @@ end context 'when is bochs discovered with dmi product_name' do + let(:vm) { nil } let(:value) { 'bochs' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil) - allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('Bochs Machine') end @@ -142,17 +122,10 @@ end context 'when is hyper-v discovered with lspci' do + let(:vm) { nil } let(:value) { 'hyperv' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil) - allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) - allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return(nil) allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return(value) end @@ -166,12 +139,6 @@ let(:vm) { 'physical' } before do - allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil) - allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return(nil) allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return(nil) @@ -188,11 +155,6 @@ before do allow(Facter::Resolvers::Containers).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::Vmware).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::OpenVz).to receive(:resolve).with(:vm).and_return(nil) - allow(Facter::Resolvers::VirtWhat).to receive(:resolve).with(:vserver).and_return(nil) - allow(Facter::Resolvers::Xen).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Lspci).to receive(:resolve).with(:vm).and_return(nil) allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:bios_vendor).and_return('unknown') allow(Facter::Resolvers::Linux::DmiBios).to receive(:resolve).with(:product_name).and_return('unknown') diff --git a/spec/facter/resolvers/aix/disks_spec.rb b/spec/facter/resolvers/aix/disks_spec.rb deleted file mode 100644 index 56fb04206a..0000000000 --- a/spec/facter/resolvers/aix/disks_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -describe Facter::Resolvers::Aix::Disks do - subject(:resolver) { Facter::Resolvers::Aix::Disks } - - let(:logger_spy) { instance_spy(Facter::Log) } - - before do - resolver.instance_variable_set(:@log, logger_spy) - allow(Facter::Core::Execution).to receive(:execute).with('lspv', logger: logger_spy) - .and_return(result) - end - - after do - resolver.invalidate_cache - end - - context 'when retrieving disks name fails' do - let(:result) { '' } - - it 'returns nil' do - expect(resolver.resolve(:disks)).to be_nil - end - end - - context 'when lspv is successful' do - let(:result) { load_fixture('lspv_output').read } - - let(:disks) do - { 'hdisk0' => { size: '30.00 GiB', size_bytes: 32_212_254_720 } } - end - - before do - allow(Facter::Core::Execution).to receive(:execute).with('lspv hdisk0', logger: logger_spy) - .and_return(load_fixture('lspv_disk_output').read) - end - - it 'returns disks informations' do - expect(resolver.resolve(:disks)).to eql(disks) - end - - context 'when second lspv call fails' do - before do - allow(Facter::Core::Execution).to receive(:execute).with('lspv hdisk0', logger: logger_spy) - .and_return('') - end - - it 'returns disks informations' do - expect(resolver.resolve(:disks)).to eq({}) - end - end - end -end diff --git a/spec/facter/resolvers/aix/memory_spec.rb b/spec/facter/resolvers/aix/memory_spec.rb deleted file mode 100644 index eea0a78a24..0000000000 --- a/spec/facter/resolvers/aix/memory_spec.rb +++ /dev/null @@ -1,79 +0,0 @@ -# frozen_string_literal: true - -describe Facter::Resolvers::Aix::Memory do - subject(:resolver) { Facter::Resolvers::Aix::Memory } - - let(:log_spy) { instance_spy(Facter::Log) } - - before do - resolver.instance_variable_set(:@log, log_spy) - allow(Facter::Core::Execution).to receive(:execute).with('svmon', logger: log_spy) - .and_return(svmon_content) - allow(Facter::Core::Execution).to receive(:execute).with('pagesize', logger: log_spy) - .and_return(pagesize_content) - end - - after do - resolver.invalidate_cache - end - - context 'when svmon call fails' do - let(:svmon_content) { '' } - let(:pagesize_content) { '' } - - it 'returns nil for system' do - expect(resolver.resolve(:system)).to be_nil - end - - it 'returns nil for swap' do - expect(resolver.resolve(:swap)).to be_nil - end - end - - context 'when pagesize call fails' do - let(:svmon_content) { load_fixture('svmon_content').read } - let(:pagesize_content) { '' } - - it 'returns nil for system' do - expect(resolver.resolve(:system)).to be_nil - end - - it 'returns nil for swap' do - expect(resolver.resolve(:swap)).to be_nil - end - end - - context 'when svmon returns invalid content' do - let(:svmon_content) { 'some_errors_on_stdout' } - let(:pagesize_content) { '4096' } - - it 'returns empty hash for system' do - expect(resolver.resolve(:system)).to be_a(Hash).and contain_exactly - end - - it 'returns empty hash for swap' do - expect(resolver.resolve(:swap)).to be_a(Hash).and contain_exactly - end - end - - context 'when all calls return valid content' do - let(:svmon_content) { load_fixture('svmon_content').read } - let(:pagesize_content) { '4096' } - - let(:system_memory) do - { available_bytes: 4_966_027_264, capacity: '42.19%', total_bytes: 8_589_934_592, used_bytes: 3_623_907_328 } - end - - let(:swap_memory) do - { available_bytes: 525_660_160, capacity: '2.09%', total_bytes: 536_870_912, used_bytes: 11_210_752 } - end - - it 'returns facts for system memory' do - expect(resolver.resolve(:system)).to eq(system_memory) - end - - it 'returns facts for swap memory' do - expect(resolver.resolve(:swap)).to eq(swap_memory) - end - end -end diff --git a/spec/facter/resolvers/augeas_resolver_spec.rb b/spec/facter/resolvers/augeas_resolver_spec.rb index feefda5046..eec11b108b 100644 --- a/spec/facter/resolvers/augeas_resolver_spec.rb +++ b/spec/facter/resolvers/augeas_resolver_spec.rb @@ -7,12 +7,65 @@ before do augeas.instance_variable_set(:@log, log_spy) - allow(Facter::Core::Execution).to receive(:execute) - .with('augparse --version 2>&1', logger: log_spy) - .and_return('augparse 1.12.0 ') end - it 'returns build' do - expect(augeas.resolve(:augeas_version)).to eq('1.12.0') + after do + augeas.invalidate_cache + end + + context 'when augparse is installed' do + before do + allow(Facter::Core::Execution).to receive(:execute) + .with('augparse --version 2>&1', logger: log_spy) + .and_return('augparse 1.12.0 ') + end + + it 'returns build' do + expect(augeas.resolve(:augeas_version)).to eq('1.12.0') + end + end + + context 'when augparse is not installed' do + before do + allow(Facter::Core::Execution).to receive(:execute) + .with('augparse --version 2>&1', logger: log_spy) + .and_return('sh: augparse: command not found') + end + + context 'when augeas gem > 0.5.0 is installed' do + before do + allow(Gem).to receive(:loaded_specs).and_return({ 'augeas' => true }) + allow(Augeas).to receive(:create).and_return('1.12.0') + end + + it 'returns build' do + expect(augeas.resolve(:augeas_version)).to eq('1.12.0') + end + end + + context 'when augeas gem <= 0.5.0 is installed' do + before do + allow(Gem).to receive(:loaded_specs).and_return({}) + allow(Augeas).to receive(:open).and_return('1.12.0') + end + + it 'returns build' do + expect(augeas.resolve(:augeas_version)).to eq('1.12.0') + end + end + + context 'when augeas gem is not installed' do + let(:exception) { LoadError.new('load_error_message') } + + before do + allow(Facter::Resolvers::Augeas).to receive(:require).with('augeas').and_raise(exception) + end + + it 'raises a LoadError error' do + augeas.resolve(:augeas_version) + + expect(log_spy).to have_received(:debug).with('resolving fact augeas_version, but load_error_message') + end + end end end diff --git a/spec/fixtures/lspv_disk_output b/spec/fixtures/lspv_disk_output deleted file mode 100644 index ca10826801..0000000000 --- a/spec/fixtures/lspv_disk_output +++ /dev/null @@ -1,11 +0,0 @@ -PHYSICAL VOLUME: hdisk0 VOLUME GROUP: rootvg -PV IDENTIFIER: 00f9280c31fc0ae6 VG IDENTIFIER 00f9280c00004c00000001737084c416 -PV STATE: active -STALE PARTITIONS: 0 ALLOCATABLE: yes -PP SIZE: 32 megabyte(s) LOGICAL VOLUMES: 12 -TOTAL PPs: 959 (30688 megabytes) VG DESCRIPTORS: 2 -FREE PPs: 1 (32 megabytes) HOT SPARE: no -USED PPs: 958 (30656 megabytes) MAX REQUEST: 256 kilobytes -FREE DISTRIBUTION: 00..00..00..00..01 -USED DISTRIBUTION: 192..192..191..192..191 -MIRROR POOL: None \ No newline at end of file diff --git a/spec/fixtures/lspv_output b/spec/fixtures/lspv_output deleted file mode 100644 index 7a38e28fd9..0000000000 --- a/spec/fixtures/lspv_output +++ /dev/null @@ -1 +0,0 @@ -hdisk0 testid0998 rootvg active \ No newline at end of file diff --git a/spec/fixtures/svmon_content b/spec/fixtures/svmon_content deleted file mode 100644 index 7a5b9c5245..0000000000 --- a/spec/fixtures/svmon_content +++ /dev/null @@ -1,13 +0,0 @@ - size inuse free pin virtual mmode -memory 2097152 884743 1212409 381480 454093 Ded -pg space 131072 2737 - - work pers clnt other -pin 245356 0 2108 134016 -in use 454093 0 430650 - -PageSize PoolSize inuse pgsp pin virtual -s 4 KB - 638055 2737 198376 207405 -m 64 KB - 15418 0 11444 15418 -L 16 MB - 0 0 0 0 -S 16 GB - 0 0 0 0 \ No newline at end of file diff --git a/spec/framework/core/fact_loaders/fact_loader_spec.rb b/spec/framework/core/fact_loaders/fact_loader_spec.rb index c3d08cc7a5..0e7501d5d7 100644 --- a/spec/framework/core/fact_loaders/fact_loader_spec.rb +++ b/spec/framework/core/fact_loaders/fact_loader_spec.rb @@ -60,21 +60,17 @@ expect(loaded_facts.size).to eq(0) end - context 'when blocking custom facts' do - before do - facts_to_load = [loaded_fact_custom_fact] + it 'does not blocks external facts' do + options = { custom_facts: true, blocked_facts: ['custom_fact'] } - allow(internal_fact_loader_double).to receive(:core_facts).and_return([]) - allow(external_fact_loader_double).to receive(:custom_facts).and_return(facts_to_load) - allow(external_fact_loader_double).to receive(:external_facts).and_return([]) - end + facts_to_load = [loaded_fact_custom_fact] - it 'blocks one custom fact' do - options = { custom_facts: true, blocked_facts: ['custom_fact'] } - loaded_facts = Facter::FactLoader.instance.load(options) + allow(internal_fact_loader_double).to receive(:core_facts).and_return([]) + allow(external_fact_loader_double).to receive(:custom_facts).and_return(facts_to_load) + allow(external_fact_loader_double).to receive(:external_facts).and_return([]) - expect(loaded_facts.size).to eq(0) - end + loaded_facts = Facter::FactLoader.instance.load(options) + expect(loaded_facts).to eq(facts_to_load) end it 'loads the same amount of core facts everytime' do diff --git a/spec/mocks/augeas.rb b/spec/mocks/augeas.rb new file mode 100644 index 0000000000..d6b61af045 --- /dev/null +++ b/spec/mocks/augeas.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Augeas + def self.create(opts = {}, &block); end + + def self.open(root = nil, loadpath = nil, flags = NONE, &block); end +end diff --git a/spec/mocks/kernel_mock.rb b/spec/mocks/kernel_mock.rb index 245f2ac90e..9df9cef4b6 100644 --- a/spec/mocks/kernel_mock.rb +++ b/spec/mocks/kernel_mock.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -LIBS_TO_SKIP = %w[win32ole ffi win32/registry sys/filesystem].freeze +LIBS_TO_SKIP = %w[win32ole ffi win32/registry sys/filesystem augeas].freeze module Kernel alias old_require require def require(path)