Class: Beaker::TestmodeSwitcher::BeakerRunnerBase
- Inherits:
-
RunnerBase
- Object
- RunnerBase
- Beaker::TestmodeSwitcher::BeakerRunnerBase
- Includes:
- DSL
- Defined in:
- lib/beaker/testmode_switcher/beaker_runners.rb
Overview
Re-used functionality for all beaker runners
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#create_remote_file_ex(file_path, file_content, options = {}) ⇒ Object
create a remote file (using puppet apply) on the default host.
-
#initialize(hosts, logger) ⇒ BeakerRunnerBase
constructor
A new instance of BeakerRunnerBase.
-
#resource(type, name, opts = {}) ⇒ Object
execute a puppet resource command on the default host.
-
#scp_to_ex(from, to) ⇒ Object
copy a file using beaker’s scp_to to all hosts.
-
#shell_ex(cmd) ⇒ Object
execute an arbitrary command on the default host.
Methods inherited from RunnerBase
#get_acceptable_puppet_run_exit_codes, #handle_puppet_run_returned_exit_code
Constructor Details
#initialize(hosts, logger) ⇒ BeakerRunnerBase
Returns a new instance of BeakerRunnerBase.
14 15 16 17 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 14 def initialize(hosts, logger) self.hosts = hosts self.logger = logger end |
Instance Attribute Details
#hosts ⇒ Object
Returns the value of attribute hosts.
12 13 14 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 12 def hosts @hosts end |
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 12 def logger @logger end |
Instance Method Details
#create_remote_file_ex(file_path, file_content, options = {}) ⇒ Object
create a remote file (using puppet apply) on the default host
20 21 22 23 24 25 26 27 28 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 20 def create_remote_file_ex(file_path, file_content, = {}) mode = [:mode] || '0644' user = [:user] || 'root' group = [:group] || 'root' file_content.tr!(/\\/, '\\') file_content.tr!(/'/, "\\'") file_content.tr!(/\n/, '\\n') apply_manifest_on default, "file { '#{file_path}': ensure => present, content => '#{file_content}', mode => '#{mode}', user => '#{user}', group => '#{group}' }", catch_failures: true end |
#resource(type, name, opts = {}) ⇒ Object
execute a puppet resource command on the default host
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 31 def resource(type, name, opts = {}) cmd = ["resource"] cmd << "--debug" if opts[:debug] cmd << "--noop" if opts[:noop] cmd << "--trace" if opts[:trace] cmd << type cmd << name if opts[:values] opts[:values].each do |k, v| cmd << "#{k}=#{v}" end end on(default, puppet(*cmd), dry_run: opts[:dry_run], environment: opts[:environment] || {}, acceptable_exit_codes: (0...256) ) end |
#scp_to_ex(from, to) ⇒ Object
copy a file using beaker’s scp_to to all hosts
54 55 56 57 58 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 54 def scp_to_ex(from, to) @hosts.each do |host| scp_to host, from, to end end |
#shell_ex(cmd) ⇒ Object
execute an arbitrary command on the default host
61 62 63 |
# File 'lib/beaker/testmode_switcher/beaker_runners.rb', line 61 def shell_ex(cmd) shell(cmd) end |