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
112 113 114 |
# File 'lib/beaker/dsl/roles.rb', line 112 def any_hosts_as?(role) hosts_as(role).length > 0 end |
#dashboard ⇒ Array<Host>
The host for which [‘roles’] include ‘dashboard’
74 75 76 |
# File 'lib/beaker/dsl/roles.rb', line 74 def dashboard find_only_one :dashboard end |
#database ⇒ Array<Host>
The host for which [‘roles’] include ‘database’
61 62 63 |
# File 'lib/beaker/dsl/roles.rb', line 61 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
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/beaker/dsl/roles.rb', line 91 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
137 138 139 140 141 |
# File 'lib/beaker/dsl/roles.rb', line 137 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
129 130 131 |
# File 'lib/beaker/dsl/roles.rb', line 129 def hosts_as(desired_role = nil) hosts_with_role(hosts, desired_role) end |
#master ⇒ Array<Host>
The host for which [‘roles’] include ‘master’. If no host has the ‘master’ role, then use the host defined as ‘default’. If no host is defined as a ‘master’ and there is no ‘default’ host defined then raise an error.
44 45 46 47 48 49 50 |
# File 'lib/beaker/dsl/roles.rb', line 44 def master begin find_only_one :master rescue DSL::Outcomes::FailTest => e default end end |