Method: Beaker::Shared::HostManager#find_at_most_one_host_with_role

Defined in:
lib/beaker/shared/host_manager.rb

#find_at_most_one_host_with_role(hosts, role) ⇒ Host

Find at most a single host with the role provided. Raise an error if more than one host is found to have the provided role.

Parameters:

  • hosts (Array<Host>)

    The hosts to examine

  • role (String)

    The host returned will have this role in its role list

Returns:

  • (Host)

    The single host with the desired role in its roles list or nil if no host is found

Raises:

  • (ArgumentError)

    Raised if more than one host has the given role defined



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/beaker/shared/host_manager.rb', line 57

def find_at_most_one_host_with_role(hosts, role)
  role_hosts = hosts_with_role(hosts, role)
  host_with_role = nil
  case role_hosts.length
  when 0
  when 1
    host_with_role = role_hosts[0]
  else
    host_string = ( role_hosts.map { |host| host.name } ).join( ', ')
    raise ArgumentError, "There should be only one host with #{role} defined, but I found #{role_hosts.length} (#{host_string})"
  end
  host_with_role
end