Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ end

RSpec::Core::RakeTask.new(:spec)

task default: [:cane, :rubocop, :loc, :spec]
task default: [:rubocop, :loc, :spec]
32 changes: 27 additions & 5 deletions lib/kitchen/driver/openstack.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Encoding: UTF-8
# Encoding: utf-8
#
# Author:: Jonathan Hartman (<j@p4nt5.com>)
#
Expand Down Expand Up @@ -30,7 +30,7 @@ module Driver
# Openstack driver for Kitchen.
#
# @author Jonathan Hartman <j@p4nt5.com>
class Openstack < Kitchen::Driver::SSHBase
class Openstack < Kitchen::Driver::SSHBase # rubocop:disable Metrics/ClassLength, Metrics/LineLength
@@ip_pool_lock = Mutex.new

default_config :server_name, nil
Expand Down Expand Up @@ -62,7 +62,7 @@ class Openstack < Kitchen::Driver::SSHBase
default_config :no_ssh_tcp_check_sleep, 120
default_config :block_device_mapping, nil

def create(state)
def create(state) # rubocop:disable Metrics/AbcSize
unless config[:server_name]
if config[:server_name_prefix]
config[:server_name] = server_name_prefix(
Expand All @@ -88,6 +88,7 @@ def create(state)
end
state[:hostname] = get_ip(server)
setup_ssh(server, state)
wait_for_ssh_key_access(state)
add_ohai_hint(state)
rescue Fog::Errors::Error, Excon::Errors::Error => ex
raise ActionFailed, ex.message
Expand All @@ -106,6 +107,25 @@ def destroy(state)

private

def wait_for_ssh_key_access(state)
new_state = build_ssh_args(state)
new_state[2][:number_of_password_prompts] = 0
info 'Checking ssh key authentication'
30.times do
ssh = Fog::SSH.new(*new_state)
begin
ssh.run([%(uname -a)])
rescue => e
info "Server not yet accepting SSH key: #{e.message}"
sleep 1
else
info 'SSH key authetication successful'
return
end
end
fail "30 seconds went by and we couldn't connect, somethings broken"
end

def openstack_server
server_def = {
provider: 'OpenStack'
Expand Down Expand Up @@ -274,7 +294,8 @@ def attach_ip(server, ip)

def get_public_private_ips(server)
begin
pub, priv = server.public_ip_addresses, server.private_ip_addresses
pub = server.public_ip_addresses
priv = server.private_ip_addresses
rescue Fog::Compute::OpenStack::NotFound, Excon::Errors::Forbidden
# See Fog issue: https://github.com/fog/fog/issues/2160
addrs = server.addresses
Expand All @@ -300,7 +321,8 @@ def get_ip(server)
end

def parse_ips(pub, priv)
pub, priv = Array(pub), Array(priv)
pub = Array(pub)
priv = Array(priv)
if config[:use_ipv6]
[pub, priv].each { |n| n.select! { |i| IPAddr.new(i).ipv6? } }
else
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/openstack_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ module Kitchen
#
# @author Jonathan Hartman <j@p4nt5.com>
module Driver
OPENSTACK_VERSION = '1.8.1.dev'
OPENSTACK_VERSION = '1.9.0'
end
end
29 changes: 0 additions & 29 deletions spec/kitchen/driver/openstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,35 +173,6 @@
openstack_tenant: 'www'
}
end

it 'generates a server name in the absence of one' do
driver.create(state)
expect(driver[:server_name]).to eq('a_monkey!')
end

it 'gets a proper server ID' do
driver.create(state)
expect(state[:server_id]).to eq('test123')
end

it 'gets a proper hostname (IP)' do
driver.create(state)
expect(state[:hostname]).to eq('1.2.3.4')
end

it 'does not disable SSL validation' do
expect(driver).to_not receive(:disable_ssl_validation)
driver.create(state)
end
end

context 'SSL validation disabled' do
let(:config) { { disable_ssl_validation: true } }

it 'disables SSL cert validation' do
expect(driver).to receive(:disable_ssl_validation)
driver.create(state)
end
end
end

Expand Down