Skip to content

Commit

Permalink
Add an option run checks only and exit
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Apr 18, 2024
1 parent 2008150 commit 713d777
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
13 changes: 10 additions & 3 deletions lib/kafo/kafo_configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,18 @@ def execute
@progress_bar = config.app[:colors] ? ProgressBars::Colored.new : ProgressBars::BlackWhite.new
end

unless skip_checks_i_know_better?
unless SystemChecker.check
puts "Your system does not meet configuration criteria"
if checks_only? || !skip_checks_i_know_better?
logger = Logger.new('checks')
if SystemChecker.check
logger.notice("System checks passed")
else
logger.error("Your system does not meet configuration criteria")
self.class.exit(:invalid_system)
end
end

self.class.exit(0) if checks_only?

self.class.hooking.execute(:pre_validations)
if interactive?
wizard = Wizard.new(self)
Expand Down Expand Up @@ -363,6 +368,8 @@ def set_app_options
:default => false, :advanced => true
app_option ['-s', '--skip-checks-i-know-better'], :flag, 'Skip all system checks',
:default => false
app_option ['--checks-only'], :flag, 'Run only system checks and exit',
:default => false
app_option ['--skip-puppet-version-check'], :flag, 'Skip check for compatible Puppet versions',
:default => false, :advanced => true
app_option ['-v', '--[no-]verbose'], :flag, 'Display log on STDOUT instead of progressbar',
Expand Down
20 changes: 19 additions & 1 deletion test/acceptance/kafo_configure_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ module Kafo
end
end

describe '--checks-only' do
it 'runs only checks and exits' do
FileUtils.mkdir_p "#{INSTALLER_HOME}/checks"
FileUtils.cp File.expand_path('../../fixtures/checks/pass/pass.sh', __FILE__), "#{INSTALLER_HOME}/checks"
code, out, err = run_command '../bin/kafo-configure --checks-only --verbose --no-colors'
_(code).must_equal 0, err
_(out).must_include "[checks] System checks passed"
end

it 'runs only checks and exits with failure for failing checks' do
FileUtils.mkdir_p "#{INSTALLER_HOME}/checks"
FileUtils.cp File.expand_path('../../fixtures/checks/fail/fail.sh', __FILE__), "#{INSTALLER_HOME}/checks"
code, out, err = run_command '../bin/kafo-configure --checks-only --verbose --no-colors'
_(code.exitstatus).must_equal 20, err
_(out).must_include "[checks] Your system does not meet configuration criteria"
end
end

describe 'default args' do
it 'must create file' do
code, _, err = run_command '../bin/kafo-configure'
Expand All @@ -82,7 +100,7 @@ module Kafo
end

it 'must fail if system checks fail' do
FileUtils.mkdir "#{INSTALLER_HOME}/checks"
FileUtils.mkdir_p "#{INSTALLER_HOME}/checks"
FileUtils.cp File.expand_path('../../fixtures/checks/fail/fail.sh', __FILE__), "#{INSTALLER_HOME}/checks"
code, _, err = run_command '../bin/kafo-configure'
_(code.exitstatus).must_equal 20, err
Expand Down

0 comments on commit 713d777

Please sign in to comment.