kafo 6.2.1 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03c5d65cf1a7ca3fa3676c6a36a7d0c374f24d06c16cebcb4be5f307f1a39695
4
- data.tar.gz: 295369c378adab5c4587f1177ac87eed3b7c5c8f829118ac7c3e7593e43c4d89
3
+ metadata.gz: d246040f3b21a35b8ec0091c61333fbd5b3ecc8af9fb7d6ed666de850a101bf9
4
+ data.tar.gz: 9ab7731a6e46877cebfdffffbd7b06e5c11951821be90ff2743aa726c889c418
5
5
  SHA512:
6
- metadata.gz: 02e645d54f620a69ff7be17bea01af6d05496a92d1a26e60956d671c7342ccce5382db92552860a908452e00107dae2a0813e960d42b0789d834130528f3e03e
7
- data.tar.gz: 527eef2b88081ca1084a8e11646c7066060be65ccaa795559d40351f337768fa06e8d67d636e5180d822c31962322e258a64938d4b28ec6bd59643b2e1cfd809
6
+ metadata.gz: fb5d804b5c587646b9576f4ba6a67c9b0bd3702ddfad877750beb81b61710fd5b104db0fe36b7cf1cfd1f286d1548fb5b48acb9b778652df6c075600176df88d
7
+ data.tar.gz: 406667aac6a714122c3ec8d00a90ec630843bd6939167f23142e94bf465be51c8e098380815e869be64af9090b726a2e6a368542e18137a4fdb2493a52ed6246
@@ -5,43 +5,44 @@ require 'kafo/puppet_module'
5
5
  require 'kafo/color_scheme'
6
6
  require 'kafo/data_type_parser'
7
7
  require 'kafo/execution_environment'
8
+ require 'kafo/scenario_option'
8
9
 
9
10
  module Kafo
10
11
  class Configuration
11
12
  attr_reader :config_file, :answer_file, :scenario_id
12
13
 
13
14
  DEFAULT = {
14
- :name => '',
15
- :description => '',
16
- :enabled => true,
17
- :log_dir => '/var/log/kafo',
18
- :log_owner => nil,
19
- :log_group => nil,
20
- :store_dir => '',
21
- :log_name => 'configuration.log',
22
- :log_level => 'notice',
23
- :no_prefix => false,
24
- :mapping => {},
25
- :answer_file => './config/answers.yaml',
26
- :installer_dir => '.',
27
- :module_dirs => ['./modules'],
28
- :colors => Kafo::ColorScheme.colors_possible?,
29
- :color_of_background => :dark,
30
- :hook_dirs => [],
31
- :check_dirs => nil,
32
- :custom => {},
33
- :facts => {},
34
- :low_priority_modules => [],
35
- :verbose => false,
36
- :verbose_log_level => 'notice',
37
- :skip_puppet_version_check => false,
38
- :parser_cache_path => nil,
39
- :ignore_undocumented => nil,
40
- :order => nil,
41
- :hiera_config => nil,
42
- :kafo_modules_dir => nil,
43
- :config_header_file => nil,
44
- :dont_save_answers => nil,
15
+ ScenarioOption::NAME => '',
16
+ ScenarioOption::DESCRIPTION => '',
17
+ ScenarioOption::ENABLED => true,
18
+ ScenarioOption::LOG_DIR => '/var/log/kafo',
19
+ ScenarioOption::LOG_OWNER => nil,
20
+ ScenarioOption::LOG_GROUP => nil,
21
+ ScenarioOption::STORE_DIR => '',
22
+ ScenarioOption::LOG_NAME => 'configuration.log',
23
+ ScenarioOption::LOG_LEVEL => 'notice',
24
+ ScenarioOption::NO_PREFIX => false,
25
+ ScenarioOption::MAPPING => {},
26
+ ScenarioOption::ANSWER_FILE => './config/answers.yaml',
27
+ ScenarioOption::INSTALLER_DIR => '.',
28
+ ScenarioOption::MODULE_DIRS => ['./modules'],
29
+ ScenarioOption::COLORS => Kafo::ColorScheme.colors_possible?,
30
+ ScenarioOption::COLOR_OF_BACKGROUND => :dark,
31
+ ScenarioOption::HOOK_DIRS => [],
32
+ ScenarioOption::CHECK_DIRS => nil,
33
+ ScenarioOption::CUSTOM => {},
34
+ ScenarioOption::FACTS => {},
35
+ ScenarioOption::LOW_PRIORITY_MODULES => [],
36
+ ScenarioOption::VERBOSE => false,
37
+ ScenarioOption::VERBOSE_LOG_LEVEL => 'notice',
38
+ ScenarioOption::SKIP_PUPPET_VERSION_CHECK => false,
39
+ ScenarioOption::PARSER_CACHE_PATH => nil,
40
+ ScenarioOption::IGNORE_UNDOCUMENTED => nil,
41
+ ScenarioOption::ORDER => nil,
42
+ ScenarioOption::HIERA_CONFIG => nil,
43
+ ScenarioOption::KAFO_MODULES_DIR => nil,
44
+ ScenarioOption::CONFIG_HEADER_FILE => nil,
45
+ ScenarioOption::DONT_SAVE_ANSWERS => nil,
45
46
  }
46
47
 
47
48
  def self.get_scenario_id(filename)
@@ -197,7 +198,7 @@ module Kafo
197
198
  }
198
199
  EOS
199
200
 
200
- @logger.notice 'Loading default values from puppet modules...'
201
+ @logger.info "Loading default values from puppet modules..."
201
202
  command = PuppetCommand.new(dump_manifest, [], puppetconf, self).command
202
203
  stdout, stderr, status = Open3.capture3(*PuppetCommand.format_command(command))
203
204
 
@@ -222,7 +223,7 @@ EOS
222
223
  end
223
224
  end
224
225
 
225
- @logger.notice "... finished"
226
+ @logger.info "... finished loading default values from puppet modules."
226
227
 
227
228
  load_yaml_from_output(stdout.split($/))
228
229
  end
@@ -19,7 +19,9 @@ module Kafo
19
19
  end
20
20
 
21
21
  def typecast(value)
22
- value =~ /\d+/ ? value.to_i : value
22
+ Integer(value)
23
+ rescue TypeError, ArgumentError
24
+ value
23
25
  end
24
26
 
25
27
  def valid?(input, errors = [])
@@ -2,7 +2,9 @@ module Kafo
2
2
  module DataTypes
3
3
  class Numeric < DataType
4
4
  def typecast(value)
5
- value =~ /\d+/ ? value.to_f : value
5
+ Float(value)
6
+ rescue TypeError, ArgumentError
7
+ value
6
8
  end
7
9
 
8
10
  def valid?(input, errors = [])
@@ -8,7 +8,4 @@ module Kafo
8
8
 
9
9
  class ParserError < StandardError
10
10
  end
11
-
12
- class TypeError < StandardError
13
- end
14
11
  end
@@ -143,7 +143,14 @@ module Kafo
143
143
  # so we limit parsing only to app config options (because of --help and later defined params)
144
144
  parse clamp_app_arguments
145
145
  parse_app_arguments # set values from ARGS to config.app
146
- Logging.setup(verbose: config.app[:verbose]) unless ARGV.any? { |option| ['--help', '--full-help'].include? option }
146
+
147
+ if ARGV.any? { |option| ['--help', '--full-help'].include? option }
148
+ Logging.setup_verbose(level: :error)
149
+ else
150
+ Logging.setup(verbose: config.app[:verbose])
151
+ end
152
+
153
+ logger.notice("Loading installer configuration. This will take some time.")
147
154
  self.class.set_color_scheme
148
155
 
149
156
  self.class.hooking.execute(:init)
@@ -166,6 +173,10 @@ module Kafo
166
173
  def run(*args)
167
174
  started_at = Time.now
168
175
  logger.debug("Running installer with args #{args.inspect}")
176
+ if config.app[:verbose]
177
+ logger.notice("Running installer with log based terminal output at level #{config.app[:verbose_log_level].upcase}.")
178
+ logger.notice("Use -l to set the terminal output log level to ERROR, WARN, NOTICE, INFO, or DEBUG. See --full-help for definitions.")
179
+ end
169
180
  super
170
181
  ensure
171
182
  logger.debug("Installer finished in #{Time.now - started_at} seconds")
@@ -311,6 +322,25 @@ module Kafo
311
322
  self.class.app_option(*args, &block)
312
323
  end
313
324
 
325
+ def terminal_log_levels_message
326
+ if ARGV.include?('--full-help')
327
+ <<~HEREDOC.chomp
328
+ Log level for log based terminal output.
329
+ The available levels are
330
+ ERROR - Only show errors which prevented the installer from completing successfully.
331
+ WARN - Deprecation warnings and other information users may want to be aware of.
332
+ NOTICE - High level information about installer execution and progress.
333
+ INFO - More detailed information about execution and progress. Also shows when the installer makes a change to system configuration.
334
+ DEBUG - Show all information about execution, including configuration items where no change was needed.
335
+ HEREDOC
336
+ else
337
+ <<~HEREDOC.chomp
338
+ Log level for log based terminal output.
339
+ The available levels are ERROR, WARN, NOTICE, INFO, DEBUG. See --full-help for definitions.
340
+ HEREDOC
341
+ end
342
+ end
343
+
314
344
  def set_app_options
315
345
  app_option ['--[no-]colors'], :flag, 'Use color output on STDOUT',
316
346
  :default => config.app[:colors], :advanced => true
@@ -333,7 +363,7 @@ module Kafo
333
363
  :default => false, :advanced => true
334
364
  app_option ['-v', '--[no-]verbose'], :flag, 'Display log on STDOUT instead of progressbar',
335
365
  :default => config.app[:verbose]
336
- app_option ['-l', '--verbose-log-level'], 'LEVEL', 'Log level for verbose mode output',
366
+ app_option ['-l', '--verbose-log-level'], 'LEVEL', terminal_log_levels_message,
337
367
  :default => 'notice'
338
368
  app_option ['-S', '--scenario'], 'SCENARIO', 'Use installation scenario'
339
369
  app_option ['--disable-scenario'], 'SCENARIO', 'Disable installation scenario',
@@ -440,7 +470,7 @@ module Kafo
440
470
  end
441
471
 
442
472
  def validate_all(logging = true)
443
- logger.notice 'Running validation checks'
473
+ logger.info "Running validation checks."
444
474
  results = enabled_params.map do |param|
445
475
  result = param.valid?
446
476
  errors = param.validation_errors.join(', ')
@@ -477,13 +507,7 @@ module Kafo
477
507
  log_parser = PuppetLogParser.new
478
508
  logger = Logger.new('configure')
479
509
 
480
- start_message = <<-HEREDOC
481
- Starting system configuration.
482
- The total number of configuration tasks may increase during the run.
483
- Observe logs or specify --verbose-log-level to see individual configuration tasks.
484
- HEREDOC
485
-
486
- logger.notice(start_message.chomp)
510
+ logger.notice("Starting system configuration.")
487
511
 
488
512
  PTY.spawn(*PuppetCommand.format_command(command)) do |stdin, stdout, pid|
489
513
  begin
@@ -492,9 +516,9 @@ HEREDOC
492
516
  method, message = log_parser.parse(line)
493
517
  progress_log(method, message, logger)
494
518
 
495
- if (output = line.match(%r{(.+\]): Starting to evaluate the resource( \((?<count>\d+) of (?<total>\d+)\))?}))
496
- if (output[:count].to_i % 100) == 1 && output[:count].to_i != 1
497
- logger.notice("#{output[:count].to_i - 1} out of #{output[:total]} done.")
519
+ if (output = line.match(/(.+\]): Starting to evaluate the resource( \((?<count>\d+) of (?<total>\d+)\))?/))
520
+ if (output[:count].to_i % 250) == 1 && output[:count].to_i != 1
521
+ logger.notice("#{output[:count].to_i - 1} configuration steps out of #{output[:total]} steps complete.")
498
522
  end
499
523
  end
500
524
 
@@ -0,0 +1,92 @@
1
+ module Kafo
2
+ # A class containing constants for all scenario options
3
+ class ScenarioOption
4
+ # @group Basic
5
+
6
+ # Human readable scenario name
7
+ NAME = :name
8
+
9
+ # Description of the installer scenario and its purpose
10
+ DESCRIPTION = :description
11
+
12
+ # Path to answer file, if the file does not exist a $pwd/config/answers.yaml is used as a fallback
13
+ ANSWER_FILE = :answer_file
14
+
15
+ # Enable colors? If you don't touch this, we'll autodetect terminal capabilities
16
+ COLORS = :colors
17
+ # Color scheme, we support :bright and :dark (first is better for white background, dark for black background)
18
+ COLOR_OF_BACKGROUND = :color_of_background
19
+
20
+ # @group Logging
21
+
22
+ # Destination for the log files
23
+ LOG_DIR = :log_dir
24
+ LOG_NAME = :log_name
25
+ LOG_LEVEL = :log_level
26
+ LOG_OWNER = :log_owner
27
+ LOG_GROUP = :log_group
28
+
29
+ # Whether verbose logging is enabled
30
+ VERBOSE = :verbose
31
+
32
+ # When verbose logging is enabled, which level (and up) is shown.
33
+ VERBOSE_LOG_LEVEL = :verbose_log_level
34
+
35
+ # @group State
36
+
37
+ # Custom storage is handy if you use hooks and you must store some
38
+ # configuration which should persist among installer runs. It can be also
39
+ # used for passing value from one hook to another.
40
+ CUSTOM = :custom
41
+
42
+ FACTS = :facts
43
+
44
+ # @group Advanced
45
+
46
+ # Checks, implemented as executable files, are loaded from the listed
47
+ # directories.
48
+ CHECK_DIRS = :check_dirs
49
+
50
+ # Hooks in these extra directories will be loaded, by default they are
51
+ # loaded from $installer_dir/hooks/$type when you specify your directory,
52
+ # it will be search for $yourdir/$type/*.rb
53
+ HOOK_DIRS = :hook_dirs
54
+
55
+ # Option to load puppet modules from a specific path. Optional and
56
+ # $pwd/modules is used by default, multiple dirs are allowed
57
+ MODULE_DIRS = :module_dirs
58
+
59
+ # Kafo has a cache for information parsed from Puppet modules. This
60
+ # determines the location where that information is stored.
61
+ PARSER_CACHE_PATH = :parser_cache_path
62
+
63
+ # By default all module parameters must be documented or an error is
64
+ # raised. This can be used to not raise an error when undocumented
65
+ # parameters are found.
66
+ IGNORE_UNDOCUMENTED = :ignore_undocumented
67
+
68
+ # Kafo tuning, customization of core functionality
69
+
70
+ # An optional mapping of classes
71
+ MAPPING = :mapping
72
+ NO_PREFIX = :no_prefix
73
+ ORDER = :order
74
+ LOW_PRIORITY_MODULES = :low_priority_modules
75
+ HIERA_CONFIG = :hiera_config
76
+ KAFO_MODULES_DIR = :kafo_modules_dir
77
+ CONFIG_HEADER_FILE = :config_header_file
78
+ DONT_SAVE_ANSWERS = :dont_save_answers
79
+
80
+ # These options are in DEFAULT but not in kafo.yaml.example
81
+
82
+ # Whether the scenario is enabled or not
83
+ ENABLED = :enabled
84
+ STORE_DIR = :store_dir
85
+ INSTALLER_DIR = :installer_dir
86
+
87
+ # Puppet modules declare the Puppet version they're compatible with. Kafo
88
+ # implements checks to verify this is correct with the Puppet version
89
+ # that's running. This can be used to bypass the checks
90
+ SKIP_PUPPET_VERSION_CHECK = :skip_puppet_version_check
91
+ end
92
+ end
data/lib/kafo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
3
  PARSER_CACHE_VERSION = 1
4
- VERSION = "6.2.1"
4
+ VERSION = "6.3.0"
5
5
  end
data/lib/kafo/wizard.rb CHANGED
@@ -15,7 +15,7 @@ module Kafo
15
15
  OK = utf_support? ? '✓' : 'y'
16
16
  NO = utf_support? ? '✗' : 'n'
17
17
 
18
- def initialize(kafo, input=$stdin, output=$stdout)
18
+ def initialize(kafo, input = $stdin, output = $stdout)
19
19
  @kafo = kafo
20
20
  @config = kafo.config
21
21
  @name = @config.app[:name] || 'Kafo'
@@ -9,7 +9,7 @@
9
9
  "requirements": [
10
10
  {
11
11
  "name": "puppet",
12
- "version_requirement": ">= 4.5.0 < 7.0.0"
12
+ "version_requirement": ">= 4.5.0 < 8.0.0"
13
13
  }
14
14
  ]
15
15
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kafo
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.1
4
+ version: 6.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -275,6 +275,7 @@ files:
275
275
  - lib/kafo/puppet_log_parser.rb
276
276
  - lib/kafo/puppet_module.rb
277
277
  - lib/kafo/scenario_manager.rb
278
+ - lib/kafo/scenario_option.rb
278
279
  - lib/kafo/store.rb
279
280
  - lib/kafo/string_helper.rb
280
281
  - lib/kafo/system_checker.rb