lib/bolt_spec/run.rb in bolt-1.14.0 vs lib/bolt_spec/run.rb in bolt-1.15.0
- old
+ new
@@ -10,18 +10,34 @@
# This is intended to provide a relatively stable method of executing bolt in process from tests.
module BoltSpec
module Run
def run_task(task_name, targets, params, config: nil, inventory: nil)
+ if config.nil? && defined?(bolt_config)
+ config = bolt_config
+ end
+
+ if inventory.nil? && defined?(bolt_inventory)
+ inventory = bolt_inventory
+ end
+
result = BoltRunner.with_runner(config, inventory) do |runner|
runner.run_task(task_name, targets, params)
end
result = result.to_a
Bolt::Util.walk_keys(result, &:to_s)
end
def run_plan(plan_name, params, config: nil, inventory: nil)
+ if config.nil? && defined?(bolt_config)
+ config = bolt_config
+ end
+
+ if inventory.nil? && defined?(bolt_inventory)
+ inventory = bolt_inventory
+ end
+
# Users copying code from run_task may forget that targets is not a parameter for run plan
raise ArgumentError, "params must be a hash" unless params.is_a?(Hash)
result = BoltRunner.with_runner(config, inventory) do |runner|
runner.run_plan(plan_name, params)
@@ -30,26 +46,66 @@
{ "status" => result.status,
"value" => JSON.parse(result.value.to_json) }
end
def run_command(command, targets, options: {}, config: nil, inventory: nil)
+ if config.nil? && defined?(bolt_config)
+ config = bolt_config
+ end
+
+ if inventory.nil? && defined?(bolt_inventory)
+ inventory = bolt_inventory
+ end
+
result = BoltRunner.with_runner(config, inventory) do |runner|
runner.run_command(command, targets, options)
end
result = result.to_a
Bolt::Util.walk_keys(result, &:to_s)
end
def run_script(script, targets, arguments, options: {}, config: nil, inventory: nil)
+ if config.nil? && defined?(bolt_config)
+ config = bolt_config
+ end
+
+ if inventory.nil? && defined?(bolt_inventory)
+ inventory = bolt_inventory
+ end
+
result = BoltRunner.with_runner(config, inventory) do |runner|
runner.run_script(script, targets, arguments, options)
end
result = result.to_a
Bolt::Util.walk_keys(result, &:to_s)
end
+ def upload_file(source, dest, targets, options: {}, config: nil, inventory: nil)
+ if config.nil? && defined?(bolt_config)
+ config = bolt_config
+ end
+
+ if inventory.nil? && defined?(bolt_inventory)
+ inventory = bolt_inventory
+ end
+
+ result = BoltRunner.with_runner(config, inventory) do |runner|
+ runner.upload_file(source, dest, targets, options)
+ end
+ result = result.to_a
+ Bolt::Util.walk_keys(result, &:to_s)
+ end
+
def apply_manifest(manifest, targets, execute: false, noop: false, config: nil, inventory: nil)
+ if config.nil? && defined?(bolt_config)
+ config = bolt_config
+ end
+
+ if inventory.nil? && defined?(bolt_inventory)
+ inventory = bolt_inventory
+ end
+
# The execute parameter is equivalent to the --execute option
if execute
code = manifest
else
begin
@@ -123,9 +179,15 @@
def run_script(script, targets, arguments, options = {})
executor = Bolt::Executor.new(config.concurrency, @analytics)
targets = inventory.get_targets(targets)
executor.run_script(targets, script, arguments, options)
+ end
+
+ def upload_file(source, dest, targets, options = {})
+ executor = Bolt::Executor.new(config.concurrency, @analytics)
+ targets = inventory.get_targets(targets)
+ executor.upload_file(targets, source, dest, options)
end
def apply_manifest(code, targets, filename = nil, noop = false)
ast = pal.parse_manifest(code, filename)
executor = Bolt::Executor.new(config.concurrency, @analytics, noop)