openbolt 9.0.0.pre.rc1 → 9.0.0

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Puppetfile +5 -5
  3. data/bolt-modules/boltlib/lib/puppet/datatypes/result.rb +1 -1
  4. data/bolt-modules/boltlib/lib/puppet/datatypes/resultset.rb +2 -2
  5. data/bolt-modules/boltlib/lib/puppet/datatypes/target.rb +2 -2
  6. data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +2 -2
  7. data/bolt-modules/boltlib/lib/puppet/functions/background.rb +1 -1
  8. data/bolt-modules/boltlib/lib/puppet/functions/fail_plan.rb +1 -1
  9. data/bolt-modules/boltlib/lib/puppet/functions/get_resources.rb +1 -1
  10. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_command.rb +1 -1
  11. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +1 -1
  12. data/bolt-modules/boltlib/lib/puppet/functions/run_plan.rb +27 -4
  13. data/bolt-modules/boltlib/lib/puppet/functions/wait.rb +2 -2
  14. data/bolt-modules/file/lib/puppet/functions/file/delete.rb +1 -1
  15. data/bolt-modules/file/lib/puppet/functions/file/exists.rb +1 -1
  16. data/bolt-modules/file/lib/puppet/functions/file/read.rb +1 -1
  17. data/bolt-modules/file/lib/puppet/functions/file/readable.rb +1 -1
  18. data/bolt-modules/file/lib/puppet/functions/file/write.rb +1 -1
  19. data/bolt-modules/log/lib/puppet/functions/log/debug.rb +1 -1
  20. data/bolt-modules/log/lib/puppet/functions/log/error.rb +1 -1
  21. data/bolt-modules/log/lib/puppet/functions/log/fatal.rb +1 -1
  22. data/bolt-modules/log/lib/puppet/functions/log/info.rb +1 -1
  23. data/bolt-modules/log/lib/puppet/functions/log/trace.rb +1 -1
  24. data/bolt-modules/log/lib/puppet/functions/log/warn.rb +1 -1
  25. data/guides/targets.yaml +2 -0
  26. data/lib/bolt/bolt_option_parser.rb +53 -53
  27. data/lib/bolt/cli.rb +21 -2
  28. data/lib/bolt/config/options.rb +18 -18
  29. data/lib/bolt/config/transport/choria.rb +3 -0
  30. data/lib/bolt/config/transport/options.rb +34 -11
  31. data/lib/bolt/executor.rb +4 -0
  32. data/lib/bolt/fiber_executor.rb +46 -2
  33. data/lib/bolt/inventory/options.rb +1 -1
  34. data/lib/bolt/plan_future.rb +5 -1
  35. data/lib/bolt/shell/bash.rb +5 -3
  36. data/lib/bolt/shell/powershell/snippets.rb +20 -1
  37. data/lib/bolt/shell/powershell.rb +2 -2
  38. data/lib/bolt/transport/base.rb +9 -4
  39. data/lib/bolt/transport/choria/agent_discovery.rb +32 -14
  40. data/lib/bolt/transport/choria/bolt_tasks.rb +64 -40
  41. data/lib/bolt/transport/choria/client.rb +66 -49
  42. data/lib/bolt/transport/choria/command_builders.rb +144 -24
  43. data/lib/bolt/transport/choria/file_transfer.rb +134 -0
  44. data/lib/bolt/transport/choria/helpers.rb +25 -20
  45. data/lib/bolt/transport/choria/shell.rb +255 -148
  46. data/lib/bolt/transport/choria.rb +96 -27
  47. data/lib/bolt/util.rb +13 -0
  48. data/lib/bolt/version.rb +1 -1
  49. data/lib/bolt_spec/plans/mock_executor.rb +4 -0
  50. data/libexec/apply_catalog.rb +3 -0
  51. metadata +5 -4
@@ -14,7 +14,7 @@ module Bolt
14
14
  WINDOWS_PATH_REGEX = %r{\A[A-Za-z]:[\\/]}
15
15
 
16
16
  def target_count(targets)
17
- count = targets.is_a?(Hash) ? targets.size : targets.length
17
+ count = targets.size
18
18
  "#{count} #{count == 1 ? 'target' : 'targets'}"
19
19
  end
20
20
 
@@ -26,11 +26,11 @@ module Bolt
26
26
  #
27
27
  # @param targets [Array, Hash] Initial targets to poll (duped internally)
28
28
  # @param timeout [Numeric] Maximum seconds before exiting
29
- # @param context [String] Label for log messages
29
+ # @param context [String] Label for log and error messages
30
30
  # @return [Hash] with keys:
31
- # - :completed [Hash{Target => Hash}] All finished target outputs
32
- # - :remaining [Array, Hash] Targets still pending when the loop exited
33
- # - :rpc_persistent_failure [Boolean] True if loop exited due to persistent RPC failures
31
+ # - :completed [Hash{Target => Hash}] All finished target outputs, plus a poll
32
+ # error for each pending target after RPC_FAILURE_RETRIES failed polls in a row
33
+ # - :remaining [Array, Hash] Targets still pending at the deadline
34
34
  def poll_with_retries(targets, timeout, context)
35
35
  deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout
36
36
  remaining = targets.dup
@@ -62,8 +62,17 @@ module Bolt
62
62
  break if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
63
63
  end
64
64
 
65
- { completed: completed, remaining: remaining,
66
- rpc_persistent_failure: poll_failures >= RPC_FAILURE_RETRIES }
65
+ if poll_failures >= RPC_FAILURE_RETRIES
66
+ (remaining.is_a?(Hash) ? remaining.keys : remaining).each do |target|
67
+ completed[target] = error_output(
68
+ "RPC requests to poll #{context} on #{target.safe_name} failed persistently",
69
+ 'bolt/choria-poll-failed'
70
+ )
71
+ end
72
+ remaining.clear
73
+ end
74
+
75
+ { completed: completed, remaining: remaining }
67
76
  end
68
77
 
69
78
  # Build a Bolt::Result from an output hash. Handles both success and
@@ -100,19 +109,16 @@ module Bolt
100
109
  end
101
110
 
102
111
  # Convert a hash of { target => output } into Results, fire callbacks,
103
- # and return the Results array. When fire_node_start is true, fires a
104
- # :node_start callback before each :node_result.
112
+ # and return the Results array.
105
113
  #
106
114
  # @param target_outputs [Hash{Bolt::Target => Hash}] Map of targets to output hashes
107
115
  # @param action [String] One of 'task', 'command', or 'script'
108
116
  # @param name [String] Task/command/script name for result metadata
109
117
  # @param position [Array] Positional info for result tracking
110
- # @param fire_node_start [Boolean] Whether to emit :node_start before each result
111
- # @param callback [Proc] Called with :node_start and :node_result events
118
+ # @param callback [Proc] Called with :node_result events
112
119
  # @return [Array<Bolt::Result>] Results for all targets in the hash
113
- def emit_results(target_outputs, action:, name:, position:, fire_node_start: false, &callback)
120
+ def emit_results(target_outputs, action:, name:, position:, &callback)
114
121
  target_outputs.map do |target, data|
115
- callback&.call(type: :node_start, target: target) if fire_node_start
116
122
  result = build_result(target, data, action: action, name: name, position: position)
117
123
  callback&.call(type: :node_result, result: result)
118
124
  result
@@ -120,8 +126,8 @@ module Bolt
120
126
  end
121
127
 
122
128
  # Build an output hash from command/task output.
123
- def output(stdout: nil, stderr: nil, exitcode: nil)
124
- { stdout: stdout || '', stderr: stderr || '', exitcode: exitcode || 0 }
129
+ def output(stdout:, stderr:, exitcode:)
130
+ { stdout: stdout || '', stderr: stderr || '', exitcode: exitcode }
125
131
  end
126
132
 
127
133
  # Build an error output hash. When actual output is available (e.g.
@@ -131,15 +137,14 @@ module Bolt
131
137
  .merge(error: message, error_kind: kind)
132
138
  end
133
139
 
134
- # Extract exit code from RPC response data, defaulting to 1 with a
140
+ # Return the exit code an agent reported, defaulting to 1 with a
135
141
  # warning if the agent returned nil.
136
142
  #
137
- # @param data [Hash] RPC response data containing :exitcode
143
+ # @param exitcode [Integer, nil] The exit code from the RPC response data
138
144
  # @param target [Bolt::Target] Target for logging context
139
145
  # @param context [String] Human-readable label for the log message
140
- # @return [Integer] The exit code from the data, or 1 if nil
141
- def exitcode_from(data, target, context)
142
- exitcode = data[:exitcode] || data['exitcode']
146
+ # @return [Integer] The exit code, or 1 if nil
147
+ def exitcode_from(exitcode, target, context)
143
148
  if exitcode.nil?
144
149
  logger.warn {
145
150
  "Agent on #{target.safe_name} returned no exit code for #{context}. " \