Skip to content

Commit

Permalink
Revert "(BKR-1155) Allow configurable ssh connection preference"
Browse files Browse the repository at this point in the history
This reverts commit 4df3501.
  • Loading branch information
kevpl committed Jul 26, 2017
1 parent 5cf6b96 commit 0e9e499
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/beaker/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def connection
# create new connection object if necessary
@connection ||= SshConnection.connect( { :ip => self['ip'], :vmhostname => self['vmhostname'], :hostname => @name },
self['user'],
self['ssh'], { :logger => @logger, :ssh_connection_preference => self[:ssh_connection_preference] } )
self['ssh'], { :logger => @logger } )
# update connection information
if self['ip'] && (@connection.ip != self['ip'])
@connection.ip = self['ip']
Expand Down
25 changes: 1 addition & 24 deletions lib/beaker/hypervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.create(type, hosts_to_provision, options)

hypervisor = hyper_class.new(hosts_to_provision, options)
hypervisor.provision if options[:provision]
self.set_ssh_connection_preference(hosts_to_provision, hypervisor)

hypervisor
end

Expand All @@ -65,29 +65,6 @@ def cleanup
nil
end

DEFAULT_CONNECTION_PREFERENCE = ['ip', 'vmhostname', 'hostname']
#SSH connection method preference. Can be overwritten by hypervisor to change the order
def connection_preference
DEFAULT_CONNECTION_PREFERENCE
end

#Check if overriding method returns correct array with ip, vmhostname hostname as elements
def self.set_ssh_connection_preference(hosts_to_provision, hypervisor)
if hypervisor.connection_preference.sort == DEFAULT_CONNECTION_PREFERENCE.sort
hosts_to_provision.each{ |h| h[:ssh_connection_preference] = hypervisor.connection_preference}
else
raise ArgumentError, <<-HEREDOC
Hypervisor's overriding connection_pereference method is not matching the API.
Make sure your hypervisor's connection_preference returns an array
containing the following elements in any order you prefer:
"ip", "hostname", "vmhostname"
Please check hypervisor.rb file's "self.connection_preference" method for an example
HEREDOC
end
end

#Proxy package managers on tests hosts created by this hypervisor, runs before validation and configuration.
def proxy_package_manager
if @options[:package_proxy]
Expand Down
23 changes: 15 additions & 8 deletions lib/beaker/ssh_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Beaker
class SshConnection

attr_accessor :logger
attr_accessor :ip, :vmhostname, :hostname, :ssh_connection_preference
attr_accessor :ip, :vmhostname, :hostname

RETRYABLE_EXCEPTIONS = [
SocketError,
Expand All @@ -33,7 +33,6 @@ def initialize name_hash, user = nil, ssh_opts = {}, options = {}
@ssh_opts = ssh_opts
@logger = options[:logger]
@options = options
@ssh_connection_preference = @options[:ssh_connection_preference]
end

def self.connect name_hash, user = 'root', ssh_opts = {}, options = {}
Expand Down Expand Up @@ -67,13 +66,21 @@ def connect_block host, user, ssh_opts
# connect to the host
def connect
#try three ways to connect to host (vmhostname, ip, hostname)
# Try each method in turn until we succeed
methods = @ssh_connection_preference.dup
while (not @ssh) && (not methods.empty?) do
@ssh = connect_block(instance_variable_get("@#{methods.shift}"), @user, @ssh_opts)
methods = []
if @vmhostname
@ssh ||= connect_block(@vmhostname, @user, @ssh_opts)
methods << "vmhostname (#{@vmhostname})"
end
unless @ssh
@logger.error "Failed to connect to #{@hostname}, attempted #{@ssh_connection_preference.join(', ')}"
if @ip && !@ssh
@ssh ||= connect_block(@ip, @user, @ssh_opts)
methods << "ip (#{@ip})"
end
if @hostname && !@ssh
@ssh ||= connect_block(@hostname, @user, @ssh_opts)
methods << "hostname (#{@hostname})"
end
if not @ssh
@logger.error "Failed to connect to #{@hostname}, attempted #{methods.join(', ')}"
raise RuntimeError, "Cannot connect to #{@hostname}"
end
@ssh
Expand Down

0 comments on commit 0e9e499

Please sign in to comment.