Module: Beaker::DSL::Roles
- Included in:
- Beaker::DSL
- Defined in:
- lib/beaker/dsl/roles.rb
Overview
Identifying hosts.
This aids in reaching common subsets of hosts in a testing matrix.
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.
Also the constant Outcomes::FailTest needs to be defined it will be raised in error conditions
Instance Method Summary collapse
-
#agents ⇒ Array<Host>
The hosts for which [‘roles’] include ‘agent’.
-
#any_hosts_as?(role) ⇒ Boolean
Determine if there is a host or hosts with the given role defined if any_hosts_as?(:master) puts “master is defined” end.
-
#dashboard ⇒ Array<Host>
The host for which [‘roles’] include ‘dashboard’.
-
#database ⇒ Array<Host>
The host for which [‘roles’] include ‘database’.
-
#default ⇒ Array<Host>
The default host - if only one host defined, then that host OR - host with ‘default’ as a role OR - host with ‘master’ as a role.
-
#find_only_one(role) ⇒ Host
Returns the host, if one and only one is found.
-
#hosts_as(desired_role = nil) ⇒ Array<Host>
Select hosts that include a desired role from #hosts.
-
#master ⇒ Array<Host>
The host for which [‘roles’] include ‘master’.
Instance Method Details
#agents ⇒ Array<Host>
The hosts for which [‘roles’] include ‘agent’
28 29 30 |
# File 'lib/beaker/dsl/roles.rb', line 28 def agents hosts_as 'agent' end |
#any_hosts_as?(role) ⇒ Boolean
Determine if there is a host or hosts with the given role defined if any_hosts_as?(:master)
puts "master is defined"
end
105 106 107 |
# File 'lib/beaker/dsl/roles.rb', line 105 def any_hosts_as?(role) hosts_as(role).length > 0 end |
#dashboard ⇒ Array<Host>
The host for which [‘roles’] include ‘dashboard’
67 68 69 |
# File 'lib/beaker/dsl/roles.rb', line 67 def dashboard find_only_one :dashboard end |
#database ⇒ Array<Host>
The host for which [‘roles’] include ‘database’
54 55 56 |
# File 'lib/beaker/dsl/roles.rb', line 54 def database find_only_one :database end |
#default ⇒ Array<Host>
The default host
- if only one host defined, then that host
OR
- host with 'default' as a role
OR
- host with 'master' as a role
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/beaker/dsl/roles.rb', line 84 def default if hosts.length == 1 return hosts[0] elsif any_hosts_as? :default return find_only_one :default elsif any_hosts_as? :master return find_only_one :master else raise DSL::Outcomes::FailTest, "no default host specified" end end |
#find_only_one(role) ⇒ Host
Returns the host, if one and only one is found
130 131 132 133 134 |
# File 'lib/beaker/dsl/roles.rb', line 130 def find_only_one role only_host_with_role(hosts, role) rescue ArgumentError => e raise DSL::Outcomes::FailTest, e.to_s end |
#hosts_as(desired_role = nil) ⇒ Array<Host>
Select hosts that include a desired role from #hosts
122 123 124 |
# File 'lib/beaker/dsl/roles.rb', line 122 def hosts_as(desired_role = nil) hosts_with_role(hosts, desired_role) end |
#master ⇒ Array<Host>
The host for which [‘roles’] include ‘master’
41 42 43 |
# File 'lib/beaker/dsl/roles.rb', line 41 def master find_only_one :master end |