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 Pass options to alter execution through ‘opts`: * `:environment`: default: `{}`; these will be treated as extra environment variables that should be set before running the command.
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[:user].shellescape} #{file_path_escaped}" if opts[:user] commands << "chgrp #{opts[:group].shellescape} #{file_path_escaped}" if opts[:group] if commands.empty? success_result else use_local_shell(commands.join(' && '), opts) 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 |
# 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.delete("\n").shellescape} --detailed-exitcodes --modulepath spec/fixtures/modules --libdir lib"] cmd << "--debug" if opts[:debug] cmd << "--noop" if opts[:noop] cmd << "--trace" if opts[:trace] res = use_local_shell(cmd.join(' '), opts) 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 48 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 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
67 68 69 70 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 67 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 Pass options to alter execution through ‘opts`:
-
‘:environment`: default: `{}`; these will be treated as extra environment variables that should be set before running the command
75 76 77 |
# File 'lib/beaker/testmode_switcher/local_runner.rb', line 75 def shell_ex(cmd, opts = {}) use_local_shell(cmd, opts) end |