bolt 0.20.2 → 0.20.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39bf1a34b5705fc648c41ca2f722631fc9f0c556
4
- data.tar.gz: f401ef340be9a8acb42b9e54547b2560679784da
3
+ metadata.gz: 607e97f4d7609e2927f6e055baec22293cefb698
4
+ data.tar.gz: 7481be4e30655f46ee4908fb735dbcdc6de2383f
5
5
  SHA512:
6
- metadata.gz: 9206ab261f57b68900ed68d3f6d492fde9935b4c232546fbc762a6a6bc80bc1e9b5c011a1d98312c8f4336525dd549f232c50c3d3e823a0709c6a5855976cfca
7
- data.tar.gz: f9b91fa75d5ffe98d10bf21aeda2c86ce62a48af7fbaff18dabc784d9ffbed63af9c64ead474777eee1a32485815d7b68c930551979cbd2df94cb74f6bd9209b
6
+ metadata.gz: 82322ab31eaeddbc94d4d50ec10dd494c107de3837e3eaaee1ce727827133a921f92fe794585fc2e9f79126afc4f9a344e7eaffbd23987f55ff8b88340ddb84f
7
+ data.tar.gz: 1a7918248d6319a32fe7ca5daa73b6c506ea15d5cb66f733f6f562038ffeb228115f725d01e3fdce5a30a3bec20abe02e3ad0f35288d8001995fe801b62a4a8b
@@ -29,10 +29,6 @@ Puppet::Functions.create_function(:puppetdb_fact) do
29
29
  )
30
30
  end
31
31
 
32
- begin
33
- puppetdb_client.facts_for_node(certnames)
34
- rescue StandardError => e
35
- raise Bolt::CLIError, "Could not retrieve targets from PuppetDB: #{e}"
36
- end
32
+ puppetdb_client.facts_for_node(certnames)
37
33
  end
38
34
  end
@@ -307,7 +307,7 @@ Available options are:
307
307
  def read_arg_file(file)
308
308
  File.read(file)
309
309
  rescue StandardError => err
310
- raise Bolt::CLIError, "Error attempting to read #{file}: #{err}"
310
+ raise Bolt::FileError.new("Error attempting to read #{file}: #{err}", file)
311
311
  end
312
312
  end
313
313
 
@@ -481,8 +481,6 @@ Available options are:
481
481
 
482
482
  def query_puppetdb_nodes(query)
483
483
  puppetdb_client.query_certnames(query)
484
- rescue StandardError => e
485
- raise Bolt::CLIError, "Could not retrieve targets from PuppetDB: #{e}"
486
484
  end
487
485
 
488
486
  def execute(options)
@@ -618,12 +616,12 @@ Available options are:
618
616
  stat = file_stat(path)
619
617
 
620
618
  if !stat.readable?
621
- raise Bolt::CLIError, "The #{type} '#{path}' is unreadable"
619
+ raise Bolt::FileError.new("The #{type} '#{path}' is unreadable", path)
622
620
  elsif !stat.file?
623
- raise Bolt::CLIError, "The #{type} '#{path}' is not a file"
621
+ raise Bolt::FileError.new("The #{type} '#{path}' is not a file", path)
624
622
  end
625
623
  rescue Errno::ENOENT
626
- raise Bolt::CLIError, "The #{type} '#{path}' does not exist"
624
+ raise Bolt::FileError.new("The #{type} '#{path}' does not exist", path)
627
625
  end
628
626
 
629
627
  def file_stat(path)
@@ -200,16 +200,16 @@ module Bolt
200
200
  def validate
201
201
  self[:log].each_pair do |name, params|
202
202
  if params.key?(:level) && !Bolt::Logger.valid_level?(params[:level])
203
- raise Bolt::CLIError,
203
+ raise Bolt::ValidationError,
204
204
  "level of log #{name} must be one of: #{Bolt::Logger.levels.join(', ')}; received #{params[:level]}"
205
205
  end
206
206
  if params.key?(:append) && params[:append] != true && params[:append] != false
207
- raise Bolt::CLIError, "append flag of log #{name} must be a Boolean, received #{params[:append]}"
207
+ raise Bolt::ValidationError, "append flag of log #{name} must be a Boolean, received #{params[:append]}"
208
208
  end
209
209
  end
210
210
 
211
211
  unless %w[human json].include? self[:format]
212
- raise Bolt::CLIError, "Unsupported format: '#{self[:format]}'"
212
+ raise Bolt::ValidationError, "Unsupported format: '#{self[:format]}'"
213
213
  end
214
214
 
215
215
  unless self[:transport].nil? || Bolt::TRANSPORTS.include?(self[:transport].to_sym)
@@ -64,6 +64,7 @@ module Bolt
64
64
  end
65
65
  end
66
66
 
67
+ # This class is used to treat a Puppet Error datatype as a ruby error outside PAL
67
68
  class PuppetError < Error
68
69
  def self.from_error(err)
69
70
  new(err.msg, err.kind, err.details, err.issue_code)
@@ -78,4 +79,16 @@ module Bolt
78
79
  'result_string' => result_str })
79
80
  end
80
81
  end
82
+
83
+ class ValidationError < Bolt::Error
84
+ def initialize(msg)
85
+ super(msg, 'bolt.transport/validation-error')
86
+ end
87
+ end
88
+
89
+ class FileError < Bolt::Error
90
+ def initialize(msg, path)
91
+ super(msg, 'bolt/file-error', { "path" => path })
92
+ end
93
+ end
81
94
  end
@@ -27,7 +27,7 @@ module Bolt
27
27
 
28
28
  @noop = noop
29
29
  @run_as = nil
30
- @pool = Concurrent::CachedThreadPool.new(max_threads: @config[:concurrency])
30
+ @pool = Concurrent::ThreadPoolExecutor.new(max_threads: @config[:concurrency])
31
31
  @logger.debug { "Started with #{@config[:concurrency]} max thread(s)" }
32
32
  @notifier = Bolt::Notifier.new
33
33
  end
@@ -45,7 +45,7 @@ module Bolt
45
45
  begin
46
46
  data = YAML.safe_load(ENV[ENVIRONMENT_VAR])
47
47
  rescue Psych::Exception
48
- raise Bolt::CLIError, "Could not parse inventory from $#{ENVIRONMENT_VAR}"
48
+ raise Bolt::Error.new("Could not parse inventory from $#{ENVIRONMENT_VAR}", 'bolt/parse-error')
49
49
  end
50
50
  else
51
51
  data = Bolt::Util.read_config_file(config[:inventoryfile], default_paths, 'inventory')
@@ -56,7 +56,7 @@ module Bolt
56
56
  level: default_level
57
57
  )
58
58
  rescue ArgumentError => e
59
- raise Bolt::CLIError, "Failed to open log #{name}: #{e.message}"
59
+ raise Bolt::Error.new("Failed to open log #{name}: #{e.message}", 'bolt/log-error')
60
60
  end
61
61
 
62
62
  root_logger.add_appenders appender
@@ -161,22 +161,12 @@ module Bolt
161
161
  @stream.puts(plan_info)
162
162
  end
163
163
 
164
- # @param [Hash] A hash representing the plan result
165
- def print_plan_result(result)
166
- if result.nil?
164
+ # @param [Bolt::PlanResult] A PlanResult object
165
+ def print_plan_result(plan_result)
166
+ if plan_result.value.nil?
167
167
  @stream.puts("Plan completed successfully with no result")
168
- # Otherwise if object has a json representation display it
169
- elsif result.respond_to?(:to_json)
170
- # Guard against to_json methods that don't accept options
171
- # and don't print empty results on multiple lines
172
- if result.method(:to_json).arity == 0 ||
173
- (result.respond_to?(:empty?) && result.empty?)
174
- @stream.puts(result.to_json)
175
- else
176
- @stream.puts(::JSON.pretty_generate(result, quirks_mode: true))
177
- end
178
168
  else
179
- @stream.puts result.to_s
169
+ @stream.puts(::JSON.pretty_generate(plan_result, quirks_mode: true))
180
170
  end
181
171
  end
182
172
 
@@ -9,6 +9,31 @@ module Bolt
9
9
  BOLTLIB_PATH = File.join(__FILE__, '../../../bolt-modules')
10
10
  MODULES_PATH = File.join(__FILE__, '../../../modules')
11
11
 
12
+ # PALError is used to convert errors from executing puppet code into
13
+ # Bolt::Errors
14
+ class PALError < Bolt::Error
15
+ # Puppet sometimes rescues exceptions notes the location and reraises.
16
+ # Return the original error.
17
+ def self.from_preformatted_error(err)
18
+ if err.cause&.is_a? Bolt::Error
19
+ err.cause
20
+ else
21
+ from_error(err.cause || err)
22
+ end
23
+ end
24
+
25
+ # Generate a Bolt::Pal::PALError for non-bolt errors
26
+ def self.from_error(err)
27
+ e = new(err.message)
28
+ e.set_backtrace(err.backtrace)
29
+ e
30
+ end
31
+
32
+ def initialize(msg)
33
+ super(msg, 'bolt/pal-error')
34
+ end
35
+ end
36
+
12
37
  def initialize(config)
13
38
  # Nothing works without initialized this global state. Reinitializing
14
39
  # is safe and in practice only happen in tests
@@ -40,7 +65,7 @@ module Bolt
40
65
  begin
41
66
  require_relative '../../vendored/require_vendored'
42
67
  rescue LoadError
43
- raise Bolt::CLIError, "Puppet must be installed to execute tasks"
68
+ raise Bolt::Error.new("Puppet must be installed to execute tasks", "bolt/puppet-missing")
44
69
  end
45
70
 
46
71
  require 'bolt/pal/logging'
@@ -72,25 +97,9 @@ module Bolt
72
97
  begin
73
98
  yield compiler
74
99
  rescue Puppet::PreformattedError => err
75
- # Puppet sometimes rescues exceptions notes the location and reraises.
76
- # Return the original error.
77
- if err.cause
78
- if err.cause.is_a? Bolt::Error
79
- err.cause
80
- else
81
- e = Bolt::CLIError.new(err.cause.message)
82
- e.set_backtrace(err.cause.backtrace)
83
- e
84
- end
85
- else
86
- e = Bolt::CLIError.new(err.message)
87
- e.set_backtrace(err.backtrace)
88
- e
89
- end
100
+ PALError.from_preformatted_error(err)
90
101
  rescue StandardError => err
91
- e = Bolt::CLIError.new(err.message)
92
- e.set_backtrace(err.backtrace)
93
- e
102
+ PALError.from_preformatted_error(err)
94
103
  end
95
104
  end
96
105
  end
@@ -188,7 +197,7 @@ module Bolt
188
197
  end
189
198
 
190
199
  if task.nil?
191
- raise Bolt::CLIError, Bolt::Error.unknown_task(task_name)
200
+ raise Bolt::Error.new(Bolt::Error.unknown_task(task_name), 'bolt/unknown-task')
192
201
  end
193
202
 
194
203
  task.task_hash
@@ -222,7 +231,7 @@ module Bolt
222
231
  end
223
232
 
224
233
  if plan_info.nil?
225
- raise Bolt::CLIError, Bolt::Error.unknown_plan(plan_name)
234
+ raise Bolt::Error.new(Bolt::Error.unknown_plan(plan_name), 'bolt/unknown-plan')
226
235
  end
227
236
  plan_info
228
237
  end
@@ -25,7 +25,7 @@ module Bolt
25
25
  def self.validate(options)
26
26
  validation_flag = options['local-validation']
27
27
  unless !!validation_flag == validation_flag
28
- raise Bolt::CLIError, 'local-validation option must be a Boolean true or false'
28
+ raise Bolt::ValidationError, 'local-validation option must be a Boolean true or false'
29
29
  end
30
30
  end
31
31
 
@@ -23,11 +23,11 @@ module Bolt
23
23
  client_opts = client_keys.each_with_object({}) do |k, acc|
24
24
  acc[k] = opts[k] if opts.include?(k)
25
25
  end
26
+ client_opts['User-Agent'] = "Bolt/#{VERSION}"
26
27
  logger.debug("Creating orchestrator client for #{client_opts}")
27
28
 
28
29
  @client = OrchestratorClient.new(client_opts, true)
29
30
  @plan_job = start_plan(plan_context)
30
-
31
31
  @environment = opts["task-environment"]
32
32
  end
33
33
 
@@ -22,12 +22,12 @@ module Bolt
22
22
 
23
23
  host_key = options['host-key-check']
24
24
  unless !!host_key == host_key
25
- raise Bolt::CLIError, 'host-key-check option must be a Boolean true or false'
25
+ raise Bolt::ValidationError, 'host-key-check option must be a Boolean true or false'
26
26
  end
27
27
 
28
28
  if (key_opt = options['private-key'])
29
29
  unless key_opt.instance_of?(String) || (key_opt.instance_of?(Hash) && key_opt.include?('key-data'))
30
- raise Bolt::CLIError,
30
+ raise Bolt::ValidationError,
31
31
  "private-key option must be the path to a private key file or a hash containing the 'key-data'"
32
32
  end
33
33
  end
@@ -35,7 +35,7 @@ module Bolt
35
35
  timeout_value = options['connect-timeout']
36
36
  unless timeout_value.is_a?(Integer) || timeout_value.nil?
37
37
  error_msg = "connect-timeout value must be an Integer, received #{timeout_value}:#{timeout_value.class}"
38
- raise Bolt::CLIError, error_msg
38
+ raise Bolt::ValidationError, error_msg
39
39
  end
40
40
  end
41
41
 
@@ -16,18 +16,18 @@ module Bolt
16
16
  def self.validate(options)
17
17
  ssl_flag = options['ssl']
18
18
  unless !!ssl_flag == ssl_flag
19
- raise Bolt::CLIError, 'ssl option must be a Boolean true or false'
19
+ raise Bolt::ValidationError, 'ssl option must be a Boolean true or false'
20
20
  end
21
21
 
22
22
  ssl_verify_flag = options['ssl-verify']
23
23
  unless !!ssl_verify_flag == ssl_verify_flag
24
- raise Bolt::CLIError, 'ssl-verify option must be a Boolean true or false'
24
+ raise Bolt::ValidationError, 'ssl-verify option must be a Boolean true or false'
25
25
  end
26
26
 
27
27
  timeout_value = options['connect-timeout']
28
28
  unless timeout_value.is_a?(Integer) || timeout_value.nil?
29
29
  error_msg = "connect-timeout value must be an Integer, received #{timeout_value}:#{timeout_value.class}"
30
- raise Bolt::CLIError, error_msg
30
+ raise Bolt::ValidationError, error_msg
31
31
  end
32
32
  end
33
33
 
@@ -20,12 +20,12 @@ module Bolt
20
20
  File.open(path, "r:UTF-8") { |f| YAML.safe_load(f.read) }
21
21
  rescue Errno::ENOENT
22
22
  if path_passed
23
- raise Bolt::CLIError, "Could not read #{file_name} file: #{path}"
23
+ raise Bolt::FileError.new("Could not read #{file_name} file: #{path}", path)
24
24
  end
25
25
  rescue Psych::Exception
26
- raise Bolt::CLIError, "Could not parse #{file_name} file: #{path}"
26
+ raise Bolt::FileError.new("Could not parse #{file_name} file: #{path}", path)
27
27
  rescue IOError, SystemCallError
28
- raise Bolt::CLIError, "Could not read #{file_name} file: #{path}"
28
+ raise Bolt::FileError.new("Could not read #{file_name} file: #{path}", path)
29
29
  end
30
30
 
31
31
  def deep_merge(hash1, hash2)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bolt
4
- VERSION = '0.20.2'
4
+ VERSION = '0.20.3'
5
5
  end
@@ -29,6 +29,24 @@ if [ -z "${name}" ]; then
29
29
  fi
30
30
  fi
31
31
 
32
+ # if lsb not available try os-release
33
+ if [ -z "${name}" ]; then
34
+ if [ -e /etc/os-release ]; then
35
+ name=$(grep "^NAME" /etc/os-release | cut -d'=' -f2 | sed "s/\"//g")
36
+ release=$(grep "^VERSION_ID" /etc/os-release | cut -d'=' -f2 | sed "s/\"//g")
37
+ elif [-e /usr/lib/os-release ]; then
38
+ name=$(grep "^NAME" /usr/lib/os-release | cut -d'=' -f2 | sed "s/\"//g")
39
+ release=$(grep "^VERSION_ID" /usr/lib/os-release | cut -d'=' -f2 | sed "s/\"//g")
40
+ fi
41
+ if [ -n "${name}" ]; then
42
+ if echo "${name}" | egrep -iq "(.*red)(.*hat)"; then
43
+ name="RedHat"
44
+ elif echo "${name}" | egrep -iq "debian"; then
45
+ name="Debian"
46
+ fi
47
+ fi
48
+ fi
49
+
32
50
  if [ -z "${name}" ]; then
33
51
  name=$(uname)
34
52
  release=$(uname -r)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.2
4
+ version: 0.20.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-18 00:00:00.000000000 Z
11
+ date: 2018-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable