kafo 4.1.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +619 -9
- data/README.md +3 -2
- data/doc/kafo_run.png +0 -0
- data/doc/kafo_run.uml +2 -0
- data/doc/plantuml.jar +0 -0
- data/lib/kafo/app_option/declaration.rb +19 -0
- data/lib/kafo/app_option/definition.rb +16 -0
- data/lib/kafo/configuration.rb +29 -7
- data/lib/kafo/exit_handler.rb +1 -1
- data/lib/kafo/help_builders/base.rb +5 -3
- data/lib/kafo/help_builders/basic.rb +13 -2
- data/lib/kafo/hook_context.rb +101 -26
- data/lib/kafo/hooking.rb +20 -13
- data/lib/kafo/kafo_configure.rb +145 -121
- data/lib/kafo/logger.rb +13 -123
- data/lib/kafo/logging.rb +128 -0
- data/lib/kafo/puppet_log_parser.rb +11 -5
- data/lib/kafo/scenario_manager.rb +22 -16
- data/lib/kafo/system_checker.rb +1 -1
- data/lib/kafo/version.rb +1 -1
- data/lib/kafo/wizard.rb +7 -7
- data/modules/kafo_configure/spec/fixtures/manifests/site.pp +0 -0
- metadata +12 -7
data/lib/kafo/logging.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'logging'
|
5
|
+
|
6
|
+
module Kafo
|
7
|
+
class Logging
|
8
|
+
|
9
|
+
LOG_LEVELS = [:debug, :info, :notice, :warn, :error, :fatal]
|
10
|
+
|
11
|
+
if ::Logging::LEVELS.keys.map(&:to_symbol) != LOG_LEVELS
|
12
|
+
::Logging.init(:debug, :info, :notice, :warn, :error, :fatal)
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def root_logger
|
17
|
+
@root_logger ||= ::Logging.logger.root
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup(verbose: false)
|
21
|
+
set_color_scheme
|
22
|
+
|
23
|
+
level = KafoConfigure.config.app[:log_level]
|
24
|
+
|
25
|
+
setup_file_logging(
|
26
|
+
level,
|
27
|
+
KafoConfigure.config.app[:log_dir],
|
28
|
+
KafoConfigure.config.app[:log_owner],
|
29
|
+
KafoConfigure.config.app[:log_group]
|
30
|
+
)
|
31
|
+
setup_verbose(level: KafoConfigure.config.app[:verbose_log_level] || level) if verbose
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup_file_logging(log_level, log_dir, log_owner, log_group)
|
35
|
+
filename = KafoConfigure.config.log_file
|
36
|
+
|
37
|
+
begin
|
38
|
+
FileUtils.mkdir_p(log_dir, :mode => 0750)
|
39
|
+
rescue Errno::EACCES
|
40
|
+
puts "No permissions to create log dir #{log_dir}"
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
root_logger.appenders = ::Logging.appenders.rolling_file(
|
45
|
+
'configure',
|
46
|
+
level: log_level,
|
47
|
+
filename: filename,
|
48
|
+
layout: layout(color: false),
|
49
|
+
truncate: true,
|
50
|
+
roll_by: 'date'
|
51
|
+
)
|
52
|
+
|
53
|
+
FileUtils.chown(
|
54
|
+
log_owner,
|
55
|
+
log_group,
|
56
|
+
filename
|
57
|
+
)
|
58
|
+
rescue ArgumentError
|
59
|
+
puts "File #{filename} not writeable, won't log anything to file!"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def set_color_scheme
|
64
|
+
::Logging.color_scheme(
|
65
|
+
'bright',
|
66
|
+
:levels => {
|
67
|
+
:info => :cyan,
|
68
|
+
:notice => :green,
|
69
|
+
:warn => :yellow,
|
70
|
+
:error => :red,
|
71
|
+
:fatal => [:white, :on_red]
|
72
|
+
},
|
73
|
+
:date => :blue,
|
74
|
+
:logger => :cyan,
|
75
|
+
:line => :yellow,
|
76
|
+
:file => :yellow,
|
77
|
+
:method => :yellow
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
def layout(color: false)
|
82
|
+
::Logging::Layouts::Pattern.new(
|
83
|
+
pattern: "%d [%-6l] [%c] %m\n",
|
84
|
+
color_scheme: color ? 'bright' : nil,
|
85
|
+
date_pattern: '%Y-%m-%d %H:%M:%S'
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_logger(name)
|
90
|
+
::Logging.logger[name]
|
91
|
+
end
|
92
|
+
|
93
|
+
def setup_verbose(level: :notice)
|
94
|
+
root_logger.add_appenders(
|
95
|
+
::Logging.appenders.stdout(
|
96
|
+
'verbose',
|
97
|
+
layout: layout(color: KafoConfigure.use_colors?),
|
98
|
+
level: level
|
99
|
+
)
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
def buffer
|
104
|
+
@buffer ||= []
|
105
|
+
end
|
106
|
+
|
107
|
+
def buffering?
|
108
|
+
root_logger.appenders.empty?
|
109
|
+
end
|
110
|
+
|
111
|
+
def dump_needed?
|
112
|
+
!buffer.empty?
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_buffer(*args)
|
116
|
+
buffer << args
|
117
|
+
end
|
118
|
+
|
119
|
+
def dump_buffer
|
120
|
+
@buffer.each do |log|
|
121
|
+
::Logging.logger[log[0]].send(log[1], *([log[2]].flatten(2)), &log[3])
|
122
|
+
end
|
123
|
+
@buffer.clear
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
@@ -8,18 +8,24 @@ module Kafo
|
|
8
8
|
method, message = case
|
9
9
|
when line =~ /^Error:(.*)/i || line =~ /^Err:(.*)/i
|
10
10
|
[:error, $1]
|
11
|
-
when line =~ /^
|
12
|
-
[:warn, $1]
|
13
|
-
when line =~ /^Info:(.*)/i
|
11
|
+
when line =~ /^Notice:(.*)/i
|
14
12
|
[:info, $1]
|
15
|
-
when line =~ /^Debug:(.*)/i
|
13
|
+
when line =~ /^Warning:(.*)/i || line =~ /^Debug:(.*)/i || line =~ /^Info:(.*)/i
|
16
14
|
[:debug, $1]
|
17
15
|
else
|
18
16
|
[@last_level.nil? ? :info : @last_level, line]
|
19
17
|
end
|
20
18
|
|
19
|
+
if message.include?('Loading facts') && method != :error
|
20
|
+
method = :debug
|
21
|
+
end
|
22
|
+
|
23
|
+
if message.include?('Applying configuration version')
|
24
|
+
method = :debug
|
25
|
+
end
|
26
|
+
|
21
27
|
@last_level = method
|
22
|
-
return [method, message.chomp]
|
28
|
+
return [method, message.chomp.strip]
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -7,6 +7,7 @@ module Kafo
|
|
7
7
|
attr_reader :config_dir, :last_scenario_link, :previous_scenario
|
8
8
|
|
9
9
|
def initialize(config, last_scenario_link_name='last_scenario.yaml')
|
10
|
+
@logger = Logger.new('scenario_manager')
|
10
11
|
@config_dir = File.file?(config) ? File.dirname(config) : config
|
11
12
|
@last_scenario_link = File.join(config_dir, last_scenario_link_name)
|
12
13
|
@previous_scenario = File.exist?(last_scenario_link) ? Pathname.new(last_scenario_link).realpath.to_s : nil
|
@@ -30,7 +31,7 @@ module Kafo
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def list_available_scenarios
|
33
|
-
say ::HighLine.color("Available scenarios", :
|
34
|
+
say ::HighLine.color("Available scenarios", :notice)
|
34
35
|
available_scenarios.each do |config_file, content|
|
35
36
|
scenario = File.basename(config_file, '.yaml')
|
36
37
|
use = (File.expand_path(config_file) == @previous_scenario ? 'INSTALLED' : "use: --scenario #{scenario}")
|
@@ -78,12 +79,19 @@ module Kafo
|
|
78
79
|
|
79
80
|
def scenario_from_args(arg_name='--scenario|-S')
|
80
81
|
# try scenario provided in the args via -S or --scenario
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
ARGV.each_with_index do |arg, index|
|
83
|
+
parsed = arg.match(/^(#{arg_name})($|=(?<scenario>\S+))/)
|
84
|
+
if parsed
|
85
|
+
scenario = parsed[:scenario] || ARGV[index + 1]
|
86
|
+
next unless scenario
|
87
|
+
|
88
|
+
scenario_file = File.join(config_dir, "#{scenario}.yaml")
|
89
|
+
return scenario_file if File.exist?(scenario_file)
|
90
|
+
fail_now("Scenario (#{scenario_file}) was not found, can not continue", :unset_scenario)
|
91
|
+
end
|
86
92
|
end
|
93
|
+
|
94
|
+
nil
|
87
95
|
end
|
88
96
|
|
89
97
|
def select_scenario
|
@@ -103,7 +111,7 @@ module Kafo
|
|
103
111
|
end
|
104
112
|
|
105
113
|
def show_scenario_diff(prev_scenario, new_scenario)
|
106
|
-
say ::HighLine.color("Scenarios are being compared, that may take a while...", :
|
114
|
+
say ::HighLine.color("Scenarios are being compared, that may take a while...", :notice)
|
107
115
|
prev_conf = load_and_setup_configuration(prev_scenario)
|
108
116
|
new_conf = load_and_setup_configuration(new_scenario)
|
109
117
|
print_scenario_diff(prev_conf, new_conf)
|
@@ -116,7 +124,7 @@ module Kafo
|
|
116
124
|
dump_log_and_exit(0)
|
117
125
|
else
|
118
126
|
confirm_scenario_change(scenario)
|
119
|
-
|
127
|
+
@logger.notice "Scenario #{scenario} was selected"
|
120
128
|
end
|
121
129
|
end
|
122
130
|
end
|
@@ -159,7 +167,7 @@ module Kafo
|
|
159
167
|
elsif !ARGV.include?('--force') && !KafoConfigure.in_help_mode?
|
160
168
|
message = "You are trying to replace existing installation with different scenario. This may lead to unpredictable states. " +
|
161
169
|
"Use --force to override. You can use --compare-scenarios to see the differences"
|
162
|
-
|
170
|
+
@logger.error(message)
|
163
171
|
dump_log_and_exit(:scenario_error)
|
164
172
|
end
|
165
173
|
true
|
@@ -218,19 +226,17 @@ module Kafo
|
|
218
226
|
|
219
227
|
def fail_now(message, exit_code)
|
220
228
|
$stderr.puts "ERROR: #{message}"
|
221
|
-
|
229
|
+
@logger.error message
|
222
230
|
KafoConfigure.exit(exit_code)
|
223
231
|
end
|
224
232
|
|
225
233
|
def dump_log_and_exit(code)
|
226
|
-
if
|
227
|
-
Logger.setup_verbose
|
228
|
-
KafoConfigure.verbose = true
|
234
|
+
if Logging.buffering? && Logging.buffer.any?
|
229
235
|
if !KafoConfigure.config.nil?
|
230
|
-
|
231
|
-
|
236
|
+
Logging.setup(verbose: true)
|
237
|
+
@logger.notice("Log was be written to #{KafoConfigure.config.log_file}")
|
232
238
|
end
|
233
|
-
|
239
|
+
@logger.notice('Logs flushed')
|
234
240
|
end
|
235
241
|
KafoConfigure.exit(code)
|
236
242
|
end
|
data/lib/kafo/system_checker.rb
CHANGED
data/lib/kafo/version.rb
CHANGED
data/lib/kafo/wizard.rb
CHANGED
@@ -68,7 +68,7 @@ END
|
|
68
68
|
|
69
69
|
def display_hash
|
70
70
|
data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
|
71
|
-
say HighLine.color(YAML.dump(data), :
|
71
|
+
say HighLine.color(YAML.dump(data), :notice)
|
72
72
|
end
|
73
73
|
|
74
74
|
def configure_module(mod)
|
@@ -79,7 +79,7 @@ END
|
|
79
79
|
menu.prompt = 'Choose an option from the menu... '
|
80
80
|
menu.select_by = :index
|
81
81
|
|
82
|
-
menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :
|
82
|
+
menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :notice)}") { turn_module(mod) }
|
83
83
|
if mod.enabled?
|
84
84
|
render_params(mod.primary_parameter_group.params, menu)
|
85
85
|
|
@@ -114,7 +114,7 @@ END
|
|
114
114
|
def render_params(params, menu)
|
115
115
|
params.each do |param|
|
116
116
|
if param.visible?(@kafo.params)
|
117
|
-
menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :
|
117
|
+
menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :notice)}" do
|
118
118
|
configure(param)
|
119
119
|
end
|
120
120
|
end
|
@@ -141,13 +141,13 @@ END
|
|
141
141
|
end
|
142
142
|
|
143
143
|
def configure_single(param)
|
144
|
-
say "\ncurrent value: #{HighLine.color(param.value_to_s, :
|
144
|
+
say "\ncurrent value: #{HighLine.color(param.value_to_s, :notice)}"
|
145
145
|
ask("new value:")
|
146
146
|
end
|
147
147
|
|
148
148
|
def configure_multi(param)
|
149
|
-
say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :
|
150
|
-
say "\ncurrent value: #{HighLine.color(param.value_to_s, :
|
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)} %>"
|
151
151
|
ask("new value:") do |q|
|
152
152
|
q.gather = ""
|
153
153
|
end
|
@@ -164,7 +164,7 @@ END
|
|
164
164
|
say "\n" + HighLine.color("Resetting parameters of module #{mod.name}", :headline)
|
165
165
|
choose do |menu|
|
166
166
|
mod.params.each do |param|
|
167
|
-
menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :
|
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
|
168
168
|
reset(param)
|
169
169
|
end if param.visible?(@kafo.params)
|
170
170
|
end
|
File without changes
|
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:
|
4
|
+
version: 6.1.0
|
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-
|
11
|
+
date: 2020-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -217,7 +217,10 @@ files:
|
|
217
217
|
- config/kafo.yaml.example
|
218
218
|
- doc/kafo_run.png
|
219
219
|
- doc/kafo_run.uml
|
220
|
+
- doc/plantuml.jar
|
220
221
|
- lib/kafo.rb
|
222
|
+
- lib/kafo/app_option/declaration.rb
|
223
|
+
- lib/kafo/app_option/definition.rb
|
221
224
|
- lib/kafo/base_context.rb
|
222
225
|
- lib/kafo/color_scheme.rb
|
223
226
|
- lib/kafo/condition.rb
|
@@ -257,6 +260,7 @@ files:
|
|
257
260
|
- lib/kafo/hooking.rb
|
258
261
|
- lib/kafo/kafo_configure.rb
|
259
262
|
- lib/kafo/logger.rb
|
263
|
+
- lib/kafo/logging.rb
|
260
264
|
- lib/kafo/migration_context.rb
|
261
265
|
- lib/kafo/migrations.rb
|
262
266
|
- lib/kafo/param.rb
|
@@ -290,6 +294,7 @@ files:
|
|
290
294
|
- modules/kafo_configure/spec/classes/init_spec.rb
|
291
295
|
- modules/kafo_configure/spec/fixtures/hiera/hiera.yaml
|
292
296
|
- modules/kafo_configure/spec/fixtures/hiera/test.yaml
|
297
|
+
- modules/kafo_configure/spec/fixtures/manifests/site.pp
|
293
298
|
- modules/kafo_configure/spec/fixtures/modules/dummy/manifests/init.pp
|
294
299
|
- modules/kafo_configure/spec/fixtures/modules/dummy/manifests/params.pp
|
295
300
|
- modules/kafo_configure/spec/functions/dump_lookups_spec.rb
|
@@ -300,7 +305,7 @@ homepage: https://github.com/theforeman/kafo
|
|
300
305
|
licenses:
|
301
306
|
- GPL-3.0+
|
302
307
|
metadata: {}
|
303
|
-
post_install_message:
|
308
|
+
post_install_message:
|
304
309
|
rdoc_options: []
|
305
310
|
require_paths:
|
306
311
|
- lib
|
@@ -308,15 +313,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
308
313
|
requirements:
|
309
314
|
- - ">="
|
310
315
|
- !ruby/object:Gem::Version
|
311
|
-
version: 2.
|
316
|
+
version: 2.4.0
|
312
317
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
313
318
|
requirements:
|
314
319
|
- - ">="
|
315
320
|
- !ruby/object:Gem::Version
|
316
321
|
version: '0'
|
317
322
|
requirements: []
|
318
|
-
rubygems_version: 3.
|
319
|
-
signing_key:
|
323
|
+
rubygems_version: 3.1.4
|
324
|
+
signing_key:
|
320
325
|
specification_version: 4
|
321
326
|
summary: A gem for making installations based on puppet user friendly
|
322
327
|
test_files: []
|