From 0e9e499b1bf6af7c4861ab2b00969021098deca7 Mon Sep 17 00:00:00 2001 From: kevpl Date: Wed, 26 Jul 2017 16:17:23 -0700 Subject: [PATCH] Revert "(BKR-1155) Allow configurable ssh connection preference" This reverts commit 4df3501a80434a71ae83c009894c39ee85534302. --- lib/beaker/host.rb | 2 +- lib/beaker/hypervisor.rb | 25 +------------------------ lib/beaker/ssh_connection.rb | 23 +++++++++++++++-------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/lib/beaker/host.rb b/lib/beaker/host.rb index cbb5963561..19e1a57c03 100644 --- a/lib/beaker/host.rb +++ b/lib/beaker/host.rb @@ -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'] diff --git a/lib/beaker/hypervisor.rb b/lib/beaker/hypervisor.rb index c0e81790a8..fd0f0b1c72 100644 --- a/lib/beaker/hypervisor.rb +++ b/lib/beaker/hypervisor.rb @@ -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 @@ -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] diff --git a/lib/beaker/ssh_connection.rb b/lib/beaker/ssh_connection.rb index c73288590c..36924b2ad7 100644 --- a/lib/beaker/ssh_connection.rb +++ b/lib/beaker/ssh_connection.rb @@ -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, @@ -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 = {} @@ -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