kafo 0.8.1 → 0.8.2

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: c7f465dd70caa686f0ecd2259d8a5accdddcc616
4
- data.tar.gz: 5eb7cf114773117e01350bab8793a543aca5ca0c
3
+ metadata.gz: 13fc7c4d5d0d30aa719d2af9047ed92bf5a6c93c
4
+ data.tar.gz: cc7e5c57c7e3f5e888c8db5e963d43bdb505dc01
5
5
  SHA512:
6
- metadata.gz: f7469af81693f8f61e36a0a7aa54bf9e8ff3ee00cda2298f2c46ae0827a64fa768673f5de79681148c3536ea374a82605e6d65c483312cf7a32d513eea4cf289
7
- data.tar.gz: 0313549df4f32927870c1a55a91a37a0b43b897be9c364f80435d086380bd4faefa6f51ea7aa7e2b4984dbf3b86de6cc97aafb368565132c8f41aead30b510a1
6
+ metadata.gz: 0065c3f73debd2dc8056185c91bc5a48c822b5baaa31e47f84d9758e59ceca260c735953060bc5628188ecb14d9ece380709c695483faaa32954e21cc45eef6d
7
+ data.tar.gz: c58bf1204a85e7bd5c9273baec1a93e5f6f5a8ced3bbc2bfc027f54840d42930cb891720a9e182fd5e57a17c0020f1f10d471893f27d3b8af54c645147bfc2c9
data/README.md CHANGED
@@ -507,6 +507,25 @@ as key:value.
507
507
  When parsing the value, the first colon divides key and value. All other
508
508
  colons are ignored.
509
509
 
510
+ ## Resetting an argument
511
+
512
+ Existing stored parameters can be reset back to their default value from the
513
+ command line or interactive mode. This deletes the stored value in the answers
514
+ file and stores the default from the Puppet manifest in its place.
515
+
516
+ The default value is the value set in, or computed by the Puppet params
517
+ manifest. This will _not_ reset to any defaults specified in the answers file
518
+ before running the Kafo-based installer, they are not kept.
519
+
520
+ Using the CLI, a --reset option is available for every parameter, e.g.
521
+
522
+ ```bash
523
+ bin/foreman-installer --reset-puppet-server-git-branch-map
524
+ ```
525
+
526
+ The parameter can also be reset to the default in interactive mode, via the
527
+ reset parameters sub-menu under each module.
528
+
510
529
  ## Grouping in interactive mode
511
530
 
512
531
  If your module has too many parameters you may find the grouping feature useful.
@@ -139,7 +139,7 @@ module Kafo
139
139
  temp_dir = Dir.mktmpdir(nil, app[:default_values_dir])
140
140
  KafoConfigure.exit_handler.register_cleanup_path temp_dir
141
141
  @logger.info 'Loading default values from puppet modules...'
142
- command = PuppetCommand.new("$temp_dir=\"#{temp_dir}\" #{includes} dump_values(#{params_to_dump})", ['--noop'], self).append('2>&1').command
142
+ command = PuppetCommand.new("$temp_dir=\"#{temp_dir}\" #{includes} dump_values(#{params_to_dump})", ['--noop', '--reports='], self).append('2>&1').command
143
143
  result = `#{command}`
144
144
  @logger.debug result
145
145
  unless $?.exitstatus == 0
@@ -82,7 +82,11 @@ module Kafo
82
82
  end
83
83
 
84
84
  def parametrization
85
- @parametrization ||= Hash[@params.map { |p| [parametrize(p), p] }]
85
+ @parametrization ||= begin
86
+ @params.inject({}) do |h,p|
87
+ h.update(parametrize(p) => p, parametrize(p, 'reset-') => p)
88
+ end
89
+ end
86
90
  end
87
91
  end
88
92
  end
@@ -4,9 +4,15 @@ module Kafo
4
4
  module HelpBuilders
5
5
  class Basic < Base
6
6
  def add_module(name, items)
7
- data = by_parameter_groups(items)
7
+ data = by_parameter_groups(except_resets(items))
8
8
  add_list(module_header(name), data['Basic'])
9
9
  end
10
+
11
+ private
12
+
13
+ def except_resets(items)
14
+ items.select { |i| !i.help.first.strip.start_with?('--reset-') || !i.help.last.strip.end_with?('to the default value') }
15
+ end
10
16
  end
11
17
  end
12
18
  end
@@ -301,6 +301,8 @@ module Kafo
301
301
  doc = param.doc.nil? ? 'UNDOCUMENTED' : param.doc.join("\n")
302
302
  self.class.option parametrize(param), '', doc,
303
303
  :default => param.value, :multivalued => param.multivalued?
304
+ self.class.option parametrize(param, 'reset-'), :flag,
305
+ "Reset #{param.name} to the default value"
304
306
  end
305
307
  end
306
308
 
@@ -345,8 +347,11 @@ module Kafo
345
347
  # enable/disable modules according to CLI
346
348
  config.modules.each { |mod| send("enable_#{mod.name}?") ? mod.enable : mod.disable }
347
349
 
348
- # set values coming from CLI arguments
350
+ # set and reset values coming from CLI arguments
349
351
  params.each do |param|
352
+ if send("reset_#{u(with_prefix(param))}?")
353
+ param.unset_value
354
+ end
350
355
  variable_name = u(with_prefix(param))
351
356
  variable_name += '_list' if param.multivalued?
352
357
  cli_value = instance_variable_get("@#{variable_name}")
@@ -380,6 +385,7 @@ module Kafo
380
385
  '--color=false',
381
386
  '--show_diff',
382
387
  '--detailed-exitcodes',
388
+ '--reports=',
383
389
  ]
384
390
  options.push '--noop' if noop?
385
391
  options.push '--profile' if profile?
data/lib/kafo/param.rb CHANGED
@@ -23,9 +23,15 @@ module Kafo
23
23
 
24
24
  def value=(value)
25
25
  @value_set = true
26
+ value = value.to_s if value.is_a?(::HighLine::String) # don't persist highline extensions
26
27
  @value = value == 'UNDEF' ? nil : value
27
28
  end
28
29
 
30
+ def unset_value
31
+ @value_set = false
32
+ @value = nil
33
+ end
34
+
29
35
  def dump_default
30
36
  default
31
37
  end
@@ -40,7 +46,7 @@ module Kafo
40
46
 
41
47
  def set_default(defaults)
42
48
  if default == 'UNSET'
43
- self.value = nil
49
+ self.default = nil
44
50
  else
45
51
  if defaults.has_key?(default)
46
52
  value = defaults[default]
@@ -48,21 +54,19 @@ module Kafo
48
54
  when :undef
49
55
  # value can be set to :undef if value is not defined
50
56
  # (e.g. puppetmaster = $::puppetmaster which is not defined yet)
51
- self.value = nil
57
+ self.default = nil
52
58
  when :undefined
53
59
  # in puppet 2.7 :undefined means that it's param which value is
54
60
  # not set by another parameter (e.g. foreman_group = 'something')
55
61
  # which means, default is sensible unlike dumped default
56
62
  # newer puppet has default dump in format 'value' => 'value' so
57
63
  # it's handled correctly by else branch
58
- self.value = self.default
59
64
  else
60
- self.value = value
65
+ self.default = value
61
66
  end
62
- # if we don't have default value from dump (can happen for modules added from hooks)
63
- # we fallback to their own default values which must be sensible
64
- else
65
- self.value = self.default
67
+ # if we don't have default value from dump (can happen for modules added from hooks,
68
+ # or without using a params class), the existing default value from the manifest will
69
+ # be used. On calling #value, the default will be returned if no overriding value is set.
66
70
  end
67
71
  end
68
72
  end
@@ -18,8 +18,8 @@ module Kafo
18
18
  "#{prefix}#{d(param.name)}"
19
19
  end
20
20
 
21
- def parametrize(param)
22
- "--#{with_prefix(param)}"
21
+ def parametrize(param, prefix='')
22
+ "--#{prefix}#{with_prefix(param)}"
23
23
  end
24
24
  end
25
25
  end
data/lib/kafo/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
- VERSION = "0.8.1"
3
+ VERSION = "0.8.2"
4
4
  end
data/lib/kafo/wizard.rb CHANGED
@@ -87,6 +87,7 @@ END
87
87
  others.each do |group|
88
88
  menu.choice("Configure #{group.formatted_name}") { configure_group(group) }
89
89
  end
90
+ menu.choice("Reset a parameter to its default value") { reset_module_params(mod) }
90
91
  end
91
92
  menu.choice("Back to main menu") { go_back = true }
92
93
  end
@@ -153,6 +154,26 @@ END
153
154
  agree("Enable #{mod.name} module? (y/n) ") ? mod.enable : mod.disable
154
155
  end
155
156
 
157
+ def reset_module_params(mod)
158
+ go_back = false
159
+ until go_back
160
+ say "\n" + HighLine.color("Resetting parameters of module #{mod.name}", :headline)
161
+ choose do |menu|
162
+ mod.params.each do |param|
163
+ 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
164
+ reset(param)
165
+ end if param.visible?(@kafo.params)
166
+ end
167
+ menu.choice("Back to parent menu") { go_back = true }
168
+ end
169
+ end
170
+ end
171
+
172
+ def reset(param)
173
+ param.unset_value
174
+ say "\n" + HighLine.color("Value for #{param.name} reset to default", :important)
175
+ end
176
+
156
177
  def setup_terminal
157
178
  $terminal = HighLine.new
158
179
  data = HighLine::SystemExtensions.terminal_size
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Kafo
2
4
  module Puppet
3
5
  class ReportWrapper
@@ -7,6 +9,7 @@ module Kafo
7
9
  @transaction = transaction
8
10
  @report = report
9
11
  @supported = true
12
+ @resources_seen = Set.new
10
13
  end
11
14
 
12
15
  # Needed to fool Puppet's logging framework
@@ -16,8 +19,9 @@ module Kafo
16
19
 
17
20
  def add_resource_status(status, *args, &block)
18
21
  if @supported && report.respond_to?(:resource_statuses) && report.resource_statuses.is_a?(Hash)
19
- if transaction.in_main_catalog && report.resource_statuses[status.resource.to_s] && transaction.is_interesting?(status.resource)
22
+ if transaction.in_main_catalog && report.resource_statuses[status.resource.to_s] && transaction.tracked_resources.include?(status.resource) && !@resources_seen.include?(status.resource)
20
23
  ::Puppet.info "RESOURCE #{status.resource}"
24
+ @resources_seen << status.resource
21
25
  end
22
26
  report.add_resource_status(status, *args, &block)
23
27
  else
@@ -2,33 +2,36 @@ require 'kafo_configure/lib/kafo/puppet/report_wrapper'
2
2
 
3
3
  module Puppet::Parser::Functions
4
4
  newfunction(:add_progress) do |args|
5
- supported = %w(2.6. 2.7. 3.0. 3.1. 3.2. 3.3. 3.4. 3.5. 3.6. 3.7. 3.8.)
6
- if supported.any? { |version| Puppet::PUPPETVERSION.start_with?(version) }
7
- # Monkey patch the transaction to put our wrapper around the report object
5
+ loaded = false
6
+ begin
8
7
  require 'puppet/transaction'
8
+ loaded = true
9
+ rescue LoadError
10
+ ::Puppet.warning 'Unable to load puppet/transaction for progress bar support, this version may not be supported'
11
+ end
12
+
13
+ if loaded
14
+ # Monkey patch the transaction to put our wrapper around the report object
9
15
  class Puppet::Transaction
10
16
  attr_accessor :in_main_catalog
11
17
 
12
18
  def is_interesting?(resource)
13
- ![:schedule, :class, :stage, :filebucket].include?(resource.to_s.split('[')[0].downcase.to_sym)
19
+ ![:schedule, :class, :stage, :filebucket, :anchor, :'kafo_configure::yaml_to_class'].include?(resource.to_s.split('[')[0].downcase.to_sym)
14
20
  end
15
21
 
16
- def resource_count
17
- catalog.vertices.select { |resource| is_interesting?(resource) }.size
22
+ def tracked_resources
23
+ @tracked_resources ||= catalog.vertices.select { |resource| is_interesting?(resource) }.map(&:to_s)
18
24
  end
19
25
 
20
26
  def evaluate_with_trigger(*args, &block)
21
27
  if catalog.version
22
28
  self.in_main_catalog = true
23
- ::Puppet.info "START #{resource_count}"
29
+ ::Puppet.info "START #{tracked_resources.size}"
24
30
  end
25
31
  evaluate_without_trigger(*args, &block)
26
32
  self.in_main_catalog = false if catalog.version
27
33
  end
28
34
 
29
- alias_method :evaluate_without_trigger, :evaluate
30
- alias_method :evaluate, :evaluate_with_trigger
31
-
32
35
  def report_with_wrapper
33
36
  unless @report_wrapper
34
37
  @report_wrapper = Kafo::Puppet::ReportWrapper.new(self, report_without_wrapper)
@@ -36,11 +39,15 @@ module Puppet::Parser::Functions
36
39
  @report_wrapper
37
40
  end
38
41
 
39
- alias_method :report_without_wrapper, :report
40
- alias_method :report, :report_with_wrapper
42
+ if method_defined?(:evaluate) && method_defined?(:report)
43
+ alias_method :evaluate_without_trigger, :evaluate
44
+ alias_method :evaluate, :evaluate_with_trigger
45
+ alias_method :report_without_wrapper, :report
46
+ alias_method :report, :report_with_wrapper
47
+ else
48
+ ::Puppet.warning 'Unable to patch Puppet transactions for progress bar support, this version may not be supported'
49
+ end
41
50
  end
42
- else
43
- ::Puppet.warning 'Your puppet version does not support progress bar'
44
51
  end
45
52
  end
46
53
  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: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Hulan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler