kafo 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 442ba70002fba70bca91ba81955e85c7a6205c50
4
- data.tar.gz: 35cb1e2184a1381bbea5af20a12186df94c86c4e
3
+ metadata.gz: bb73eb4c71ae5aad0d0c3dc4b891a0ef33af1c8a
4
+ data.tar.gz: a63a799798654d67bc245630d0f95cc52b379b64
5
5
  SHA512:
6
- metadata.gz: dd7e866ea43f64da01f75085328350f011ee88c3062626a0b0116007c439c43c7e151203aa967752278491b90df95f533db4172d06147db5af82baa879abb8d2
7
- data.tar.gz: e6f21ddca839a279544d842cf6beb6bde61de0b3584c41ba2ec24c127b2c780b0d55ad567ab0b944367e63de0b29e6858ae65f51f422e1ab968b1697160e9f23
6
+ metadata.gz: 819bf86e16679ab8fbc15015bf8562cd415ad9f854ceb031503facf9f6dcd0ea1e978071c69de011e7e9b68bb9a8d20a56bc92ac73ed4e96407e2669c253cef1
7
+ data.tar.gz: 9e82f85dabf51876b18f8306de913ac93342c3b0ce4ad257dbde7f65ada6de27fcaf529abe870c843f66c1fdf28900181bbb3d2e338482d9d07c7c46a3718386
data/README.md CHANGED
@@ -1125,6 +1125,7 @@ Other exit codes that can be returned:
1125
1125
  * '27' means that kafo found found scenario configuration error that prevents installation from continuing
1126
1126
  * '28' means that a value is missing for a parameter given on the command line
1127
1127
  * '29' means that effective user that ran the installer does not have permission to update the answer file
1128
+ * '30' means that the version of Puppet is incompatible with a module, according to its [metadata.json](https://docs.puppet.com/puppet/latest/modules_metadata.html)
1128
1129
  * '130' user interrupt (^C)
1129
1130
 
1130
1131
  ## Running Puppet Profiling
@@ -0,0 +1,35 @@
1
+ module Kafo
2
+ class BaseContext
3
+ def facts
4
+ self.class.facts
5
+ end
6
+
7
+ private
8
+
9
+ def self.symbolize(data)
10
+ case data
11
+ when Hash
12
+ Hash[data.map { |key, value| [key.to_sym, symbolize(value)] }]
13
+ when Array
14
+ data.map { |v| symbolize(v) }
15
+ else
16
+ data
17
+ end
18
+ end
19
+
20
+ def self.clear_caches
21
+ @facts = nil
22
+ @facter_path = nil
23
+ end
24
+
25
+ def self.facts
26
+ @facts ||= begin
27
+ symbolize(JSON.load(`#{facter_path} --json`) || {})
28
+ end
29
+ end
30
+
31
+ def self.facter_path
32
+ @facter_path ||= PuppetCommand.search_puppet_path('facter')
33
+ end
34
+ end
35
+ end
@@ -29,7 +29,8 @@ module Kafo
29
29
  :hook_dirs => [],
30
30
  :custom => {},
31
31
  :low_priority_modules => [],
32
- :verbose_log_level => 'info'
32
+ :verbose_log_level => 'info',
33
+ :skip_puppet_version_check => false
33
34
  }
34
35
 
35
36
  def initialize(file, persist = true)
@@ -166,11 +167,19 @@ EOS
166
167
  @logger.debug result
167
168
  unless $?.exitstatus == 0
168
169
  log = app[:log_dir] + '/' + app[:log_name]
169
- puts "Could not get default values, check log file at #{log} for more information"
170
- @logger.error command
171
- @logger.error result
172
- @logger.error 'Could not get default values, cannot continue'
173
- KafoConfigure.exit(:defaults_error)
170
+ if (version_mismatch = /kafo_configure::puppet_version_failure: (.+?\))/.match(result))
171
+ puts version_mismatch[1]
172
+ puts "Cannot continue due to incompatible version of Puppet. Use --skip-puppet-version-check to disable this check."
173
+ @logger.error version_mismatch[1]
174
+ @logger.error 'Incompatible version of Puppet used, cannot continue'
175
+ KafoConfigure.exit(:puppet_version_error)
176
+ else
177
+ puts "Could not get default values, check log file at #{log} for more information"
178
+ @logger.error command
179
+ @logger.error result
180
+ @logger.error 'Could not get default values, cannot continue'
181
+ KafoConfigure.exit(:defaults_error)
182
+ end
174
183
  end
175
184
  @logger.info "... finished"
176
185
 
@@ -19,7 +19,8 @@ module Kafo
19
19
  :unset_scenario => 26,
20
20
  :scenario_error => 27,
21
21
  :missing_argument => 28,
22
- :insufficient_permissions => 29
22
+ :insufficient_permissions => 29,
23
+ :puppet_version_error => 30
23
24
  }
24
25
  end
25
26
 
@@ -33,7 +34,7 @@ module Kafo
33
34
  end
34
35
 
35
36
  def translate_exit_code(code)
36
- return code if code.is_a?(Fixnum)
37
+ return code if code.is_a?(Integer)
37
38
  if error_codes.has_key?(code)
38
39
  return error_codes[code]
39
40
  else
@@ -1,7 +1,8 @@
1
1
  require 'kafo/data_type'
2
+ require 'kafo/base_context'
2
3
 
3
4
  module Kafo
4
- class HookContext
5
+ class HookContext < BaseContext
5
6
  attr_reader :kafo
6
7
 
7
8
  def self.execute(kafo, &hook)
@@ -77,7 +78,7 @@ module Kafo
77
78
  # exit(0)
78
79
  # exit(:manifest_error)
79
80
  def exit(code)
80
- self.kafo.exit(code)
81
+ self.kafo.class.exit(code)
81
82
  end
82
83
 
83
84
  # You can load a custom config value that has been saved using store_custom_config
@@ -90,5 +91,15 @@ module Kafo
90
91
  def store_custom_config(key, value)
91
92
  self.kafo.config.set_custom(key, value)
92
93
  end
94
+
95
+ # Return the path to the current scenario
96
+ def scenario_path
97
+ self.kafo.class.scenario_manager.select_scenario
98
+ end
99
+
100
+ # Return the actual data in the current scenario
101
+ def scenario_data
102
+ YAML.load(File.read(scenario_path))
103
+ end
93
104
  end
94
105
  end
@@ -24,7 +24,7 @@ module Kafo
24
24
  end
25
25
 
26
26
  def load
27
- base_dirs = [File.join([KafoConfigure.root_dir, 'hooks']), KafoConfigure.config.app[:hook_dirs]]
27
+ base_dirs = [File.join([KafoConfigure.root_dir, 'hooks']), KafoConfigure.config.app[:hook_dirs]].flatten
28
28
  base_dirs.each do |base_dir|
29
29
  TYPES.each do |hook_type|
30
30
  dir = File.join(base_dir, hook_type.to_s)
@@ -308,6 +308,7 @@ module Kafo
308
308
  self.class.app_option ['-p', '--profile'], :flag, 'Run puppet in profile mode?',
309
309
  :default => false
310
310
  self.class.app_option ['-s', '--skip-checks-i-know-better'], :flag, 'Skip all system checks', :default => false
311
+ self.class.app_option ['--skip-puppet-version-check'], :flag, 'Skip check for compatible Puppet versions', :default => false
311
312
  self.class.app_option ['-v', '--verbose'], :flag, 'Display log on STDOUT instead of progressbar'
312
313
  self.class.app_option ['-l', '--verbose-log-level'], 'LEVEL', 'Log level for verbose mode output',
313
314
  :default => 'info'
@@ -1,5 +1,7 @@
1
+ require 'kafo/base_context'
2
+
1
3
  module Kafo
2
- class MigrationContext
4
+ class MigrationContext < BaseContext
3
5
 
4
6
  attr_accessor :scenario, :answers
5
7
 
@@ -17,21 +19,5 @@ module Kafo
17
19
  def logger
18
20
  KafoConfigure.logger
19
21
  end
20
-
21
- def facts
22
- self.class.facts
23
- end
24
-
25
- private
26
-
27
- def self.facts
28
- @facts ||= begin
29
- YAML.load(`#{facter_path} --yaml`).inject({}) { |facts,(k,v)| facts.update(k.to_sym => v) }
30
- end
31
- end
32
-
33
- def self.facter_path
34
- @facter_path ||= PuppetCommand.search_puppet_path('facter')
35
- end
36
22
  end
37
23
  end
@@ -6,22 +6,16 @@ module Kafo
6
6
  @command = command
7
7
  @puppet_config = puppet_config
8
8
 
9
- # Expand the modules_path to work around the fact that Puppet doesn't
10
- # allow modulepath to contain relative (i.e ..) directory references as
11
- # of 2.7.23.
12
- @options = options.push("--modulepath #{File.expand_path(modules_path)}")
9
+ @options = options.push("--modulepath #{modules_path.join(':')}")
13
10
  @options.push("--config=#{puppet_config.config_path}") if puppet_config
14
11
  @logger = KafoConfigure.logger
15
- end
16
-
17
- def add_progress
18
- %{$kafo_add_progress="#{!KafoConfigure.verbose}"}
12
+ @puppet_version_check = !configuration.app[:skip_puppet_version_check]
19
13
  end
20
14
 
21
15
  def command
22
16
  @puppet_config.write_config if @puppet_config
23
17
  result = [
24
- "echo '$kafo_config_file=\"#{@configuration.config_file}\" #{add_progress} #{@command}'",
18
+ manifest,
25
19
  '|',
26
20
  "RUBYLIB=#{[@configuration.kafo_modules_dir, ::ENV['RUBYLIB']].join(File::PATH_SEPARATOR)}",
27
21
  "#{puppet_path} apply #{@options.join(' ')} #{@suffix}",
@@ -44,11 +38,65 @@ module Kafo
44
38
 
45
39
  private
46
40
 
41
+ def manifest
42
+ %{echo '
43
+ $kafo_config_file="#{@configuration.config_file}"
44
+ #{add_progress}
45
+ #{generate_version_checks.join("\n") if @puppet_version_check}
46
+ #{@command}
47
+ '}
48
+ end
49
+
50
+ def add_progress
51
+ %{$kafo_add_progress="#{!KafoConfigure.verbose}"}
52
+ end
53
+
54
+ def generate_version_checks
55
+ checks = []
56
+ modules_path.each do |modulepath|
57
+ Dir[File.join(modulepath, '*', 'metadata.json')].sort.each do |metadata_json|
58
+ metadata = JSON.load(File.read(metadata_json))
59
+ next unless metadata['requirements'] && metadata['requirements'].is_a?(Array)
60
+
61
+ metadata['requirements'].select { |req| req['name'] == 'puppet' && req['version_requirement'] }.each do |req|
62
+ checks << versioncmp(metadata['name'], req['version_requirement'])
63
+ end
64
+ end
65
+ end
66
+ checks
67
+ end
68
+
69
+ def versioncmp(id, version_req)
70
+ # Parse the common ">= x.y < x.y" version requirement to support pre-Puppet 4.5
71
+ # checks with versioncmp. Newer versions use SemVerRange for full support.
72
+ if (version_match = /\A>=\s*([0-9\.]+)(?:\s+<\s*([0-9\.]+))?/.match(version_req))
73
+ minimum = %{minimum => "#{version_match[1]}",}
74
+ maximum = version_match[2] ? %{maximum => "#{version_match[2]}",} : ''
75
+ else
76
+ minimum = ''
77
+ maximum = ''
78
+ end
79
+
80
+ # SemVerRange is isolated inside a defined type to prevent parse errors on old versions
81
+ <<-EOS
82
+ if versioncmp($::puppetversion, "4.5.0") >= 0 {
83
+ kafo_configure::puppet_version_semver { "#{id}":
84
+ requirement => "#{version_req}",
85
+ }
86
+ } else {
87
+ kafo_configure::puppet_version_versioncmp { "#{id}":
88
+ #{minimum}
89
+ #{maximum}
90
+ }
91
+ }
92
+ EOS
93
+ end
94
+
47
95
  def modules_path
48
96
  [
49
97
  @configuration.module_dirs,
50
98
  @configuration.kafo_modules_dir,
51
- ].flatten.join(':')
99
+ ].flatten
52
100
  end
53
101
 
54
102
  def puppet_path
@@ -217,7 +217,7 @@ module Kafo
217
217
  private
218
218
 
219
219
  def fail_now(message, exit_code)
220
- say "ERROR: #{message}"
220
+ $stderr.puts "ERROR: #{message}"
221
221
  KafoConfigure.logger.error message
222
222
  KafoConfigure.exit(exit_code)
223
223
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
3
  PARSER_CACHE_VERSION = 1
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -2,7 +2,7 @@
2
2
  # document marker.
3
3
  #
4
4
  module Puppet::Parser::Functions
5
- newfunction(:to_yaml, :type => :rvalue) do |args|
5
+ newfunction(:foreman_to_yaml, :type => :rvalue) do |args|
6
6
  dump = if args.all? { |a| a.is_a?(Hash) }
7
7
  args.inject({}) { |m,a| m.merge(a) }
8
8
  else
@@ -12,9 +12,9 @@ class kafo_configure::dump_values($variables, $lookups) {
12
12
  # default/undef instead of an empty hash.
13
13
  if versioncmp($::puppetversion, '4.5') >= 0 {
14
14
  $dumped_lookups = dump_lookups($lookups)
15
- $dumped = to_yaml($dumped_vars, $dumped_lookups)
15
+ $dumped = foreman_to_yaml($dumped_vars, $dumped_lookups)
16
16
  } else {
17
- $dumped = to_yaml($dumped_vars)
17
+ $dumped = foreman_to_yaml($dumped_vars)
18
18
  }
19
19
 
20
20
  notice("\n${dumped}")
@@ -0,0 +1,5 @@
1
+ define kafo_configure::puppet_version_semver($requirement) {
2
+ unless SemVer($facts['puppetversion']) =~ SemVerRange($requirement) {
3
+ fail("kafo_configure::puppet_version_failure: Puppet ${facts['puppetversion']} does not meet requirements for ${title} ($requirement)")
4
+ }
5
+ }
@@ -0,0 +1,9 @@
1
+ define kafo_configure::puppet_version_versioncmp($minimum = undef, $maximum = undef) {
2
+ if $minimum and versioncmp($minimum, $::puppetversion) > 0 {
3
+ fail("kafo_configure::puppet_version_failure: Puppet ${puppetversion} does not meet minimum requirement for ${title} (version $minimum)")
4
+ }
5
+
6
+ if $maximum and versioncmp($maximum, $::puppetversion) < 0 {
7
+ fail("kafo_configure::puppet_version_failure: Puppet ${puppetversion} does not meet maximum requirement for ${title} (version $maximum)")
8
+ }
9
+ }
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: 2.0.2
4
+ version: 2.1.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: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -205,6 +205,7 @@ files:
205
205
  - doc/kafo_run.png
206
206
  - doc/kafo_run.uml
207
207
  - lib/kafo.rb
208
+ - lib/kafo/base_context.rb
208
209
  - lib/kafo/color_scheme.rb
209
210
  - lib/kafo/condition.rb
210
211
  - lib/kafo/configuration.rb
@@ -268,10 +269,12 @@ files:
268
269
  - modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
269
270
  - modules/kafo_configure/lib/puppet/parser/functions/decrypt.rb
270
271
  - modules/kafo_configure/lib/puppet/parser/functions/dump_values.rb
272
+ - modules/kafo_configure/lib/puppet/parser/functions/foreman_to_yaml.rb
271
273
  - modules/kafo_configure/lib/puppet/parser/functions/load_kafo_password.rb
272
- - modules/kafo_configure/lib/puppet/parser/functions/to_yaml.rb
273
274
  - modules/kafo_configure/manifests/dump_values.pp
274
275
  - modules/kafo_configure/manifests/init.pp
276
+ - modules/kafo_configure/manifests/puppet_version_semver.pp
277
+ - modules/kafo_configure/manifests/puppet_version_versioncmp.pp
275
278
  homepage: https://github.com/theforeman/kafo
276
279
  licenses:
277
280
  - GPLv3+
@@ -292,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
295
  version: '0'
293
296
  requirements: []
294
297
  rubyforge_project:
295
- rubygems_version: 2.4.5
298
+ rubygems_version: 2.6.8
296
299
  signing_key:
297
300
  specification_version: 4
298
301
  summary: If you write puppet modules for installing your software, you can use kafo