Class: Beaker::TestmodeSwitcher::LocalRunner
- Inherits:
-
RunnerBase
- Object
- RunnerBase
- Beaker::TestmodeSwitcher::LocalRunner
- Defined in:
- lib/beaker/testmode_switcher/local_runner.rb
Overview
All functionality specific to running in ‘local’ mode
Instance Method Summary collapse
-
#create_remote_file_ex(file_path, file_content, opts = {}) ⇒ Object
creates the file on the local machine and adjusts permissions the opts hash allows the following keys: :mode, :user, :group.
-
#execute_manifest(manifest, opts = {}) ⇒ Object
executes the supplied manifest using bundle and puppet apply the opts hash works like the opts of [apply_manifest_on](www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL/Helpers/PuppetHelpers#apply_manifest_on-instance_method) in the Beaker DSL.
-
#resource(type, name, opts = {}) ⇒ Object
build and execute complex puppet resource commands locally the type argument is the name of the resource type the name argument is the namevar of the resource the opts hash works like the opts of [apply_manifest_on](www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL/Helpers/PuppetHelpers#apply_manifest_on-instance_method) in the Beaker DSL.
-
#scp_to_ex(from, to) ⇒ Object
copies the file locally.
-
#shell_ex(cmd, opts = {}) ⇒ Object
run a command through a local shell.
Methods inherited from RunnerBase
#get_acceptable_puppet_run_exit_codes, #handle_puppet_run_returned_exit_code
Instance Method Details
#create_remote_file_ex(file_path, file_content, opts = {}) ⇒ Object
creates the file on the local machine and adjusts permissions the opts hash allows the following keys: :mode, :user, :group
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 11 def create_remote_file_ex(file_path, file_content, opts = {}) File.open(file_path, 'w') { |file| file.write(file_content) } file_path_escaped = file_path.shellescape commands = [] commands << "chmod #{opts[:mode].shellescape} #{file_path_escaped}" if opts[:mode] commands << "chown #{opts[:owner].shellescape} #{file_path_escaped}" if opts[:owner] commands << "chgrp #{opts[:group].shellescape} #{file_path_escaped}" if opts[:group] if commands.empty? success_result else use_local_shell(commands.join(' && '), {}) end end |
#execute_manifest(manifest, opts = {}) ⇒ Object
executes the supplied manifest using bundle and puppet apply the opts hash works like the opts of [apply_manifest_on](www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL/Helpers/PuppetHelpers#apply_manifest_on-instance_method) in the Beaker DSL. it accepts the following keys: :dry_run, :environment, :trace, :noop, and :debug
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 29 def execute_manifest(manifest, opts = {}) puts "Applied manifest [#{manifest}]" if ENV['DEBUG_MANIFEST'] cmd = ["bundle exec puppet apply -e #{manifest.shellescape} --detailed-exitcodes --modulepath spec/fixtures/modules --libdir lib"] cmd << "--debug" if opts[:debug] cmd << "--noop" if opts[:noop] cmd << "--trace" if opts[:trace] raise ArgumentError, 'Can\'t handle environment key' if opts.key? :environment res = use_local_shell(cmd.join(' ')) handle_puppet_run_returned_exit_code(get_acceptable_puppet_run_exit_codes(opts), res.exit_code) res end |
#resource(type, name, opts = {}) ⇒ Object
build and execute complex puppet resource commands locally the type argument is the name of the resource type the name argument is the namevar of the resource the opts hash works like the opts of [apply_manifest_on](www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL/Helpers/PuppetHelpers#apply_manifest_on-instance_method) in the Beaker DSL. it accepts the following keys: :dry_run, :environment, :trace, :noop, and :debug additionally opts can be set to a hash of resource values to pass on the command line
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 50 def resource(type, name, opts = {}) cmd = ["bundle exec puppet resource --modulepath spec/fixtures/modules --libdir lib"] cmd << "--debug" if opts[:debug] cmd << "--noop" if opts[:noop] cmd << "--trace" if opts[:trace] cmd << type.shellescape cmd << name.shellescape opts.delete(:debug) opts.delete(:noop) opts.delete(:trace) if opts[:values] opts[:values].each do |k, v| cmd << "#{k.shellescape}=#{v.shellescape}" end end # apply the command use_local_shell(cmd.join(' '), opts) end |
#scp_to_ex(from, to) ⇒ Object
copies the file locally
73 74 75 76 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 73 def scp_to_ex(from, to) FileUtils.cp(from, to) success_result end |
#shell_ex(cmd, opts = {}) ⇒ Object
run a command through a local shell
79 80 81 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 79 def shell_ex(cmd, opts = {}) use_local_shell(cmd, opts) end |