Module: Beaker::DSL::Patterns

Included in:
Beaker::DSL, Host, HostPrebuiltSteps
Defined in:
lib/beaker/dsl/patterns.rb

Overview

These are simple patterns that appear frequently in beaker test code, and are provided to simplify test construction.

It requires the class it is mixed into to provide the attribute ‘hosts` which contain the hosts to search, these should implement Host’s interface. They, at least, must have #[] and #to_s available and provide an array when #[](‘roles’) is called.

Instance Method Summary collapse

Instance Method Details

#block_on(hosts_or_filter, opts = {}, &block) ⇒ Array<Result>, ...

Execute a block selecting the hosts that match with the provided criteria

Parameters:

  • hosts_or_filter (Array<Host>, Host, String, Symbol)

    A host role as a String or Symbol that can be used to search for a set of Hosts, a host name as a String that can be used to search for a set of Hosts, or a Host or Array<Host> to run the block against

  • opts (Hash{Symbol=>String}) (defaults to: {})

    Options to alter execution.

  • block (Block)

    This method will yield to a block of code passed by the caller

Options Hash (opts):

  • :run_in_parallel (Boolean)

    Whether to run on each host in parallel.

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/beaker/dsl/patterns.rb', line 25

def block_on hosts_or_filter, opts = {}, &block
  block_hosts = nil
  if defined? hosts
    block_hosts = hosts
  end
  filter = nil
  if hosts_or_filter.is_a? String or hosts_or_filter.is_a? Symbol
    filter = hosts_or_filter
  else
    block_hosts = hosts_or_filter
  end
  run_block_on block_hosts, filter, opts, &block
end