kafo 6.0.0 → 6.2.1

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: f5cb69151feb9aff8869369e3c3d16b1899bd51248ab4cb8a2cf08f862d78c72
4
- data.tar.gz: f7760b031fb5f00e4ad853d8ac7c139555cc0606dcbd40ba542f340bfbe08135
3
+ metadata.gz: 03c5d65cf1a7ca3fa3676c6a36a7d0c374f24d06c16cebcb4be5f307f1a39695
4
+ data.tar.gz: 295369c378adab5c4587f1177ac87eed3b7c5c8f829118ac7c3e7593e43c4d89
5
5
  SHA512:
6
- metadata.gz: 27baf9be9b11280cd352cc418b62955473396b9d4b3245bc558e9e335e353d209c904acce90936644a9b023e82f60b5fba78ab902eb1aafd8068ae92d34e14ea
7
- data.tar.gz: aa2ff036cca2d1d24fa11003272ffecaa51d1a8a03a482471a2074adf92edbbe94b17b82e998a79134635f207e611056d9e91187a6a4ce88191f36836588dbd1
6
+ metadata.gz: 02e645d54f620a69ff7be17bea01af6d05496a92d1a26e60956d671c7342ccce5382db92552860a908452e00107dae2a0813e960d42b0789d834130528f3e03e
7
+ data.tar.gz: 527eef2b88081ca1084a8e11646c7066060be65ccaa795559d40351f337768fa06e8d67d636e5180d822c31962322e258a64938d4b28ec6bd59643b2e1cfd809
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ load 'tasks/jenkins.rake'
4
4
 
5
5
  Rake::TestTask.new('test:ruby') do |t|
6
6
  t.libs << 'lib' << 'test'
7
- t.test_files = FileList['test/**/*_test.rb']
7
+ t.test_files = FileList['test/**/*_test.rb'] - FileList['test/tmp/**/*_test.rb']
8
8
  t.verbose = true
9
9
  end
10
10
 
@@ -31,6 +31,13 @@ namespace 'test' do
31
31
  end
32
32
  end
33
33
 
34
+ begin
35
+ require 'rubocop/rake_task'
36
+ RuboCop::RakeTask.new
37
+ rescue LoadError
38
+ puts 'Rubocop not loaded'
39
+ end
40
+
34
41
  CLEAN.include 'test/tmp'
35
42
 
36
43
  task :test => ['test:ruby', 'test:puppet_modules']
@@ -3,7 +3,6 @@ require_relative 'definition'
3
3
  module Kafo
4
4
  module AppOption
5
5
  module Declaration
6
-
7
6
  include Clamp::Option::Declaration
8
7
 
9
8
  def app_option(switches, type, description, opts = {}, &block)
@@ -13,7 +12,6 @@ module Kafo
13
12
  declared_options << option
14
13
  end
15
14
  end
16
-
17
15
  end
18
16
  end
19
17
  end
@@ -1,7 +1,6 @@
1
1
  module Kafo
2
2
  module AppOption
3
3
  class Definition < Clamp::Option::Definition
4
-
5
4
  def initialize(switches, type, description, options = {})
6
5
  @advanced = options.fetch(:advanced, false)
7
6
  super(switches, type, description, options)
@@ -10,7 +9,6 @@ module Kafo
10
9
  def advanced?
11
10
  @advanced
12
11
  end
13
-
14
12
  end
15
13
  end
16
14
  end
@@ -1,4 +1,4 @@
1
- require 'highline/import'
1
+ require 'highline'
2
2
 
3
3
  module Kafo
4
4
  class ColorScheme
@@ -7,7 +7,7 @@ module Kafo
7
7
  ::ENV['TERM'] && !`which tput 2> /dev/null`.empty? && `tput colors`.to_i > 0
8
8
  end
9
9
 
10
- def initialize(options={})
10
+ def initialize(options = {})
11
11
  @background = options[:background].nil? ? :dark : options[:background]
12
12
  @colors = options[:colors].nil? ? self.class.colors_possible? : options[:colors]
13
13
  end
@@ -170,7 +170,7 @@ module Kafo
170
170
  save_configuration(app)
171
171
  end
172
172
 
173
- def migrate_configuration(from_config, options={})
173
+ def migrate_configuration(from_config, options = {})
174
174
  keys_to_skip = options.fetch(:skip, [])
175
175
  keys = [:log_dir, :log_name, :log_level, :no_prefix,
176
176
  :colors, :color_of_background, :custom, :verbose_log_level]
@@ -47,13 +47,19 @@ module Kafo
47
47
 
48
48
  def execute(group, log_stage: true)
49
49
  logger = Logger.new(group)
50
- logger.notice "Executing hooks in group #{group}" if log_stage
51
- self.hooks[group].keys.sort_by(&:to_s).each do |name|
50
+ logger.info "Executing hooks in group #{group}" if log_stage
51
+
52
+ sorted_hooks = self.hooks[group].keys.sort do |a, b|
53
+ File.basename(a.to_s) <=> File.basename(b.to_s)
54
+ end
55
+
56
+ sorted_hooks.each do |name|
52
57
  hook = self.hooks[group][name]
53
58
  result = HookContext.execute(self.kafo, logger, &hook)
54
59
  logger.debug "Hook #{name} returned #{result.inspect}"
55
60
  end
56
- logger.notice "All hooks in group #{group} finished" if log_stage
61
+
62
+ logger.info "All hooks in group #{group} finished" if log_stage
57
63
  @group = nil
58
64
  end
59
65
 
@@ -143,7 +143,7 @@ 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])
146
+ Logging.setup(verbose: config.app[:verbose]) unless ARGV.any? { |option| ['--help', '--full-help'].include? option }
147
147
  self.class.set_color_scheme
148
148
 
149
149
  self.class.hooking.execute(:init)
@@ -365,9 +365,9 @@ module Kafo
365
365
  params.sort.each do |param|
366
366
  doc = param.doc.nil? ? 'UNDOCUMENTED' : param.doc.join("\n")
367
367
  app_option parametrize(param), '', doc + " (current: #{param.value_to_s})",
368
- :multivalued => param.multivalued?
368
+ :multivalued => param.multivalued?
369
369
  app_option parametrize(param, 'reset-'), :flag,
370
- "Reset #{param.name} to the default value (#{param.default_to_s})"
370
+ "Reset #{param.name} to the default value (#{param.default_to_s})"
371
371
  end
372
372
  end
373
373
 
@@ -459,13 +459,13 @@ module Kafo
459
459
  execution_env.store_answers
460
460
  puppetconf = execution_env.configure_puppet(
461
461
  'color' => false,
462
- 'evaltrace' => !!@progress_bar,
462
+ 'evaltrace' => true,
463
463
  'noop' => !!noop?,
464
464
  'profile' => !!profile?,
465
465
  'show_diff' => true,
466
466
  )
467
467
 
468
- exit_code = 0
468
+ self.class.exit_handler.exit_code = 0
469
469
  exit_status = nil
470
470
  options = [
471
471
  '--verbose',
@@ -476,7 +476,14 @@ module Kafo
476
476
  command = PuppetCommand.new('include kafo_configure', options, puppetconf).command
477
477
  log_parser = PuppetLogParser.new
478
478
  logger = Logger.new('configure')
479
- logger.notice("Starting system configuration")
479
+
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)
480
487
 
481
488
  PTY.spawn(*PuppetCommand.format_command(command)) do |stdin, stdout, pid|
482
489
  begin
@@ -484,6 +491,13 @@ module Kafo
484
491
  line = normalize_encoding(line)
485
492
  method, message = log_parser.parse(line)
486
493
  progress_log(method, message, logger)
494
+
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.")
498
+ end
499
+ end
500
+
487
501
  @progress_bar.update(line) if @progress_bar
488
502
  end
489
503
  rescue Errno::EIO # we reach end of input
@@ -493,16 +507,16 @@ module Kafo
493
507
  Process.wait(pid)
494
508
  rescue Errno::ECHILD # process could exit meanwhile so we rescue
495
509
  end
496
- exit_code = $?.exitstatus
510
+ self.class.exit_handler.exit_code = $?.exitstatus
497
511
  end
498
512
  end
499
513
  end
500
514
  rescue PTY::ChildExited => e # could be raised by Process.wait on older ruby or by PTY.check
501
- exit_code = e.status.exitstatus
515
+ self.class.exit_handler.exit_code = e.status.exitstatus
502
516
  end
503
517
 
504
518
  @progress_bar.close if @progress_bar
505
- logger.notice "Puppet has finished, bye!"
519
+ logger.notice "System configuration has finished."
506
520
 
507
521
  self.class.hooking.execute(:post)
508
522
  self.class.exit(exit_code)
@@ -46,7 +46,8 @@ module Kafo
46
46
  level: log_level,
47
47
  filename: filename,
48
48
  layout: layout(color: false),
49
- truncate: true
49
+ truncate: true,
50
+ roll_by: 'date'
50
51
  )
51
52
 
52
53
  FileUtils.chown(
@@ -123,12 +123,12 @@ module Kafo
123
123
  @type.multivalued?
124
124
  end
125
125
 
126
- def <=> o
126
+ def <=>(other)
127
127
  unless @module.configuration.app[:no_prefix]
128
- r = self.module_name <=> o.module_name
128
+ r = self.module_name <=> other.module_name
129
129
  return r unless r == 0
130
130
  end
131
- self.name <=> o.name
131
+ self.name <=> other.name
132
132
  end
133
133
 
134
134
  def visible?(context = [])
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ require 'highline'
2
3
  require 'powerbar'
3
4
  require 'ansi/code'
4
5
  require 'set'
@@ -20,7 +21,7 @@ module Kafo
20
21
  @all_lines = 0
21
22
  @total = :unknown
22
23
  @resources = Set.new
23
- @term_width = HighLine::SystemExtensions.terminal_size[0] || 0
24
+ @term_width = terminal_width
24
25
  @bar = PowerBar.new
25
26
  @bar.settings.tty.infinite.template.main = infinite_template
26
27
  @bar.settings.tty.finite.template.main = finite_template
@@ -85,6 +86,17 @@ module Kafo
85
86
 
86
87
  private
87
88
 
89
+ def terminal_width
90
+ # HighLine 2 has Terminal, 1 has SystemExtensions
91
+ terminal_size = if HighLine.respond_to?(:default_instance)
92
+ HighLine.default_instance.terminal.terminal_size
93
+ else
94
+ HighLine::SystemExtensions.terminal_size
95
+ end
96
+
97
+ terminal_size ? (terminal_size[0] || 0) : 0
98
+ end
99
+
88
100
  def done_message
89
101
  text = 'Done'
90
102
  text + (' ' * (50 - text.length))
@@ -43,8 +43,15 @@ module Kafo
43
43
  File.join([bin_path, bin_name].compact)
44
44
  end
45
45
 
46
+ def self.is_aio_puppet?
47
+ puppet_command = search_puppet_path('puppet')
48
+ File.realpath(puppet_command).start_with?('/opt/puppetlabs')
49
+ rescue Errno::ENOENT
50
+ false
51
+ end
52
+
46
53
  def self.format_command(command)
47
- if search_puppet_path('puppet').start_with?('/opt/puppetlabs')
54
+ if is_aio_puppet?
48
55
  [clean_env_vars, command, :unsetenv_others => true]
49
56
  else
50
57
  [::ENV, command, :unsetenv_others => false]
@@ -96,16 +96,16 @@ module Kafo
96
96
  Hash[params.map { |param| [param.name, param.value] }]
97
97
  end
98
98
 
99
- def <=> o
99
+ def <=>(other)
100
100
  @configuration.app[:low_priority_modules].each do |module_name|
101
- return 1 if self.name.include?(module_name) && !o.name.include?(module_name)
102
- return -1 if !self.name.include?(module_name) && o.name.include?(module_name)
103
- if self.name.include?(module_name) && o.name.include?(module_name)
104
- return self.name.sub(/.*#{module_name}/, '') <=> o.name.sub(/.*#{module_name}/, '')
101
+ return 1 if self.name.include?(module_name) && !other.name.include?(module_name)
102
+ return -1 if !self.name.include?(module_name) && other.name.include?(module_name)
103
+ if self.name.include?(module_name) && other.name.include?(module_name)
104
+ return self.name.sub(/.*#{module_name}/, '') <=> other.name.sub(/.*#{module_name}/, '')
105
105
  end
106
106
  end
107
107
 
108
- self.name <=> o.name
108
+ self.name <=> other.name
109
109
  end
110
110
 
111
111
  private
@@ -1,4 +1,5 @@
1
1
  # encoding: UTF-8
2
+ require 'highline/import'
2
3
  require 'kafo_wizards'
3
4
  require 'pathname'
4
5
 
@@ -6,7 +7,7 @@ module Kafo
6
7
  class ScenarioManager
7
8
  attr_reader :config_dir, :last_scenario_link, :previous_scenario
8
9
 
9
- def initialize(config, last_scenario_link_name='last_scenario.yaml')
10
+ def initialize(config, last_scenario_link_name = 'last_scenario.yaml')
10
11
  @logger = Logger.new('scenario_manager')
11
12
  @config_dir = File.file?(config) ? File.dirname(config) : config
12
13
  @last_scenario_link = File.join(config_dir, last_scenario_link_name)
@@ -31,7 +32,7 @@ module Kafo
31
32
  end
32
33
 
33
34
  def list_available_scenarios
34
- say ::HighLine.color("Available scenarios", :notice)
35
+ say ::HighLine.color("Available scenarios", :info)
35
36
  available_scenarios.each do |config_file, content|
36
37
  scenario = File.basename(config_file, '.yaml')
37
38
  use = (File.expand_path(config_file) == @previous_scenario ? 'INSTALLED' : "use: --scenario #{scenario}")
@@ -77,7 +78,7 @@ module Kafo
77
78
  !!(defined?(CONFIG_DIR) && CONFIG_DIR)
78
79
  end
79
80
 
80
- def scenario_from_args(arg_name='--scenario|-S')
81
+ def scenario_from_args(arg_name = '--scenario|-S')
81
82
  # try scenario provided in the args via -S or --scenario
82
83
  ARGV.each_with_index do |arg, index|
83
84
  parsed = arg.match(/^(#{arg_name})($|=(?<scenario>\S+))/)
@@ -111,7 +112,7 @@ module Kafo
111
112
  end
112
113
 
113
114
  def show_scenario_diff(prev_scenario, new_scenario)
114
- say ::HighLine.color("Scenarios are being compared, that may take a while...", :notice)
115
+ say ::HighLine.color("Scenarios are being compared, that may take a while...", :info)
115
116
  prev_conf = load_and_setup_configuration(prev_scenario)
116
117
  new_conf = load_and_setup_configuration(new_scenario)
117
118
  print_scenario_diff(prev_conf, new_conf)
@@ -4,7 +4,7 @@ module Kafo
4
4
  class Store
5
5
  attr_accessor :data
6
6
 
7
- def initialize(path=nil)
7
+ def initialize(path = nil)
8
8
  @data = {}
9
9
  load_path(path) if path
10
10
  end
@@ -18,7 +18,7 @@ module Kafo
18
18
  "#{prefix}#{d(param.name)}"
19
19
  end
20
20
 
21
- def parametrize(param, prefix='')
21
+ def parametrize(param, prefix = '')
22
22
  "--#{prefix}#{with_prefix(param)}"
23
23
  end
24
24
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
3
  PARSER_CACHE_VERSION = 1
4
- VERSION = "6.0.0"
4
+ VERSION = "6.2.1"
5
5
  end
@@ -1,5 +1,6 @@
1
1
  # encoding: UTF-8
2
- require 'highline/import'
2
+ require 'forwardable'
3
+ require 'highline'
3
4
  require 'yaml'
4
5
 
5
6
  module Kafo
@@ -8,14 +9,17 @@ module Kafo
8
9
  Kafo::ENV::LANG =~ /UTF-8\z/
9
10
  end
10
11
 
12
+ extend Forwardable
13
+ def_delegators :@highline, :agree, :ask, :choose, :say
14
+
11
15
  OK = utf_support? ? '✓' : 'y'
12
16
  NO = utf_support? ? '✗' : 'n'
13
17
 
14
- def initialize(kafo)
18
+ def initialize(kafo, input=$stdin, output=$stdout)
15
19
  @kafo = kafo
16
20
  @config = kafo.config
17
21
  @name = @config.app[:name] || 'Kafo'
18
- setup_terminal
22
+ @highline = setup_terminal(input, output)
19
23
  end
20
24
 
21
25
  def run
@@ -68,7 +72,7 @@ END
68
72
 
69
73
  def display_hash
70
74
  data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
71
- say HighLine.color(YAML.dump(data), :notice)
75
+ say HighLine.color(YAML.dump(data), :info)
72
76
  end
73
77
 
74
78
  def configure_module(mod)
@@ -79,7 +83,7 @@ END
79
83
  menu.prompt = 'Choose an option from the menu... '
80
84
  menu.select_by = :index
81
85
 
82
- menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :notice)}") { turn_module(mod) }
86
+ menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :info)}") { turn_module(mod) }
83
87
  if mod.enabled?
84
88
  render_params(mod.primary_parameter_group.params, menu)
85
89
 
@@ -114,7 +118,7 @@ END
114
118
  def render_params(params, menu)
115
119
  params.each do |param|
116
120
  if param.visible?(@kafo.params)
117
- menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :notice)}" do
121
+ menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :info)}" do
118
122
  configure(param)
119
123
  end
120
124
  end
@@ -141,13 +145,13 @@ END
141
145
  end
142
146
 
143
147
  def configure_single(param)
144
- say "\ncurrent value: #{HighLine.color(param.value_to_s, :notice)}"
148
+ say "\ncurrent value: #{HighLine.color(param.value_to_s, :info)}"
145
149
  ask("new value:")
146
150
  end
147
151
 
148
152
  def configure_multi(param)
149
- say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :notice)
150
- say "\ncurrent value: #{HighLine.color(param.value_to_s, :notice)} %>"
153
+ say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :info)
154
+ say "\ncurrent value: #{HighLine.color(param.value_to_s, :info)} %>"
151
155
  ask("new value:") do |q|
152
156
  q.gather = ""
153
157
  end
@@ -164,7 +168,7 @@ END
164
168
  say "\n" + HighLine.color("Resetting parameters of module #{mod.name}", :headline)
165
169
  choose do |menu|
166
170
  mod.params.each do |param|
167
- menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :notice)}, default value: #{HighLine.color(param.default_to_s, :notice)}" do
171
+ menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :info)}, default value: #{HighLine.color(param.default_to_s, :info)}" do
168
172
  reset(param)
169
173
  end if param.visible?(@kafo.params)
170
174
  end
@@ -178,11 +182,17 @@ END
178
182
  say "\n" + HighLine.color("Value for #{param.name} reset to default", :important)
179
183
  end
180
184
 
181
- def setup_terminal
182
- $terminal = HighLine.new
183
- data = HighLine::SystemExtensions.terminal_size
184
- $terminal.wrap_at = data.first > 80 ? 80 : data.first if data.first
185
- $terminal.page_at = data.last if data.last
185
+ def setup_terminal(input, output)
186
+ highline = HighLine.new(input, output)
187
+ # HighLine 2 vs 1
188
+ data = if highline.respond_to?(:terminal)
189
+ highline.terminal.terminal_size
190
+ else
191
+ HighLine::SystemExtensions.terminal_size
192
+ end
193
+ highline.wrap_at = data.first > 80 ? 80 : data.first if data.first
194
+ highline.page_at = data.last if data.last
195
+ highline
186
196
  end
187
197
  end
188
198
  end
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.0.0
4
+ version: 6.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-28 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -171,7 +171,7 @@ dependencies:
171
171
  version: 1.6.21
172
172
  - - "<"
173
173
  - !ruby/object:Gem::Version
174
- version: '2.0'
174
+ version: '3.0'
175
175
  type: :runtime
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
@@ -181,7 +181,7 @@ dependencies:
181
181
  version: 1.6.21
182
182
  - - "<"
183
183
  - !ruby/object:Gem::Version
184
- version: '2.0'
184
+ version: '3.0'
185
185
  - !ruby/object:Gem::Dependency
186
186
  name: powerbar
187
187
  requirement: !ruby/object:Gem::Requirement
@@ -217,7 +217,6 @@ files:
217
217
  - config/kafo.yaml.example
218
218
  - doc/kafo_run.png
219
219
  - doc/kafo_run.uml
220
- - doc/plantuml.jar
221
220
  - lib/kafo.rb
222
221
  - lib/kafo/app_option/declaration.rb
223
222
  - lib/kafo/app_option/definition.rb
@@ -294,7 +293,6 @@ files:
294
293
  - modules/kafo_configure/spec/classes/init_spec.rb
295
294
  - modules/kafo_configure/spec/fixtures/hiera/hiera.yaml
296
295
  - modules/kafo_configure/spec/fixtures/hiera/test.yaml
297
- - modules/kafo_configure/spec/fixtures/manifests/site.pp
298
296
  - modules/kafo_configure/spec/fixtures/modules/dummy/manifests/init.pp
299
297
  - modules/kafo_configure/spec/fixtures/modules/dummy/manifests/params.pp
300
298
  - modules/kafo_configure/spec/functions/dump_lookups_spec.rb
@@ -305,7 +303,7 @@ homepage: https://github.com/theforeman/kafo
305
303
  licenses:
306
304
  - GPL-3.0+
307
305
  metadata: {}
308
- post_install_message:
306
+ post_install_message:
309
307
  rdoc_options: []
310
308
  require_paths:
311
309
  - lib
@@ -321,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
319
  version: '0'
322
320
  requirements: []
323
321
  rubygems_version: 3.1.4
324
- signing_key:
322
+ signing_key:
325
323
  specification_version: 4
326
324
  summary: A gem for making installations based on puppet user friendly
327
325
  test_files: []
Binary file