Skip to content

Commit

Permalink
Support a timed sleep for SSH edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Oct 26, 2014
1 parent 5d7cf4c commit aee673f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
@@ -1,7 +1,8 @@
# ?.?.? / ????-??-??
# 1.7.0 / 2014-10-25

### New Features

* PR [#66][] - Allow setting a timed sleep for SSH check edge cases
* PR [#63][] - Add support for a static server name prefix; via [@ftclausen][]
* PR [#62][] - Add availability zone support; via [@fortable1999][]

Expand Down Expand Up @@ -133,6 +134,7 @@ certain specified NICs; via [@monsterzz][]

* Initial release! Woo!

[#66]: https://github.com/test-kitchen/kitchen-openstack/pull/66
[#63]: https://github.com/test-kitchen/kitchen-openstack/pull/63
[#62]: https://github.com/test-kitchen/kitchen-openstack/pull/62
[#60]: https://github.com/test-kitchen/kitchen-openstack/pull/60
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -63,6 +63,8 @@ behavior can be overridden with additional options:
network_ref:
- [OPENSTACK NETWORK NAMES OR...]
- [...ID TO CREATE INSTANCE WITH]
no_ssh_tcp_check: [DEFAULTS TO false, SKIPS TCP CHECK WHEN true]
no_ssh_tcp_check_sleep: [NUM OF SECONDS TO SLEEP IF no_ssh_tcp_check IS SET]

If a `server_name_prefix` is specified then this prefix will be used when
generating random names of the form `<NAME PREFIX>-<RANDOM STRING>` e.g.
Expand Down
18 changes: 16 additions & 2 deletions lib/kitchen/driver/openstack.rb
Expand Up @@ -56,6 +56,8 @@ class Openstack < Kitchen::Driver::SSHBase
default_config :availability_zone, nil
default_config :security_groups, nil
default_config :network_ref, nil
default_config :no_ssh_tcp_check, false
default_config :no_ssh_tcp_check_sleep, 120

def create(state)
unless config[:server_name]
Expand Down Expand Up @@ -302,8 +304,7 @@ def add_ohai_hint(state)
end

def setup_ssh(server, state)
wait_for_sshd(state[:hostname], config[:username], port: config[:port])
info '(ssh ready)'
tcp_check(state)
if config[:key_name]
info "Using OpenStack keypair <#{config[:key_name]}>"
end
Expand All @@ -326,6 +327,19 @@ def do_ssh_setup(state, config, server)
])
end

def tcp_check(state)
# allow driver config to bypass SSH tcp check -- because
# it doesn't respect ssh_config values that might be required
if config[:no_ssh_tcp_check]
sleep(config[:no_ssh_tcp_check_sleep])
else
wait_for_sshd(state[:hostname],
config[:username],
port: config[:port])
end
info '(ssh ready)'
end

def disable_ssl_validation
require 'excon'
Excon.defaults[:ssl_verify_peer] = false
Expand Down
45 changes: 45 additions & 0 deletions spec/kitchen/driver/openstack_spec.rb
Expand Up @@ -53,6 +53,14 @@

describe '#initialize'do
context 'default options' do
it 'uses the normal SSH status check' do
expect(driver[:no_ssh_tcp_check]).to eq(false)
end

it 'sets a default TCP check wait time' do
expect(driver[:no_ssh_tcp_check_sleep]).to eq(120)
end

context 'both DSA and RSA SSH keys available for the user' do
it 'prefers the local user\'s RSA private key' do
expect(driver[:private_key_path]).to eq(rsa)
Expand Down Expand Up @@ -1065,6 +1073,43 @@
end
end

describe '#setup_ssh' do
let(:server) { double }
before(:each) do
[:tcp_check, :do_ssh_setup].each do |m|
allow_any_instance_of(described_class).to receive(m)
end
end

it 'calls the TCP check' do
expect_any_instance_of(described_class).to receive(:tcp_check).with(state)
driver.send(:setup_ssh, server, state)
end
end

describe '#tcp_check' do
let(:state) { { hostname: 'hostname' } }

context 'standard SSH check' do
it 'calls the normal Kitchen SSH wait' do
expect_any_instance_of(described_class).not_to receive(:sleep)
expect_any_instance_of(described_class).to receive(:wait_for_sshd)
.with('hostname', 'root', port: '22')
driver.send(:tcp_check, state)
end
end

context 'override SSH wait' do
let(:config) { { no_ssh_tcp_check: true } }

it 'sleeps instead of monitoring the SSH port' do
expect_any_instance_of(described_class).not_to receive(:wait_for_sshd)
expect_any_instance_of(described_class).to receive(:sleep).with(120)
driver.send(:tcp_check, state)
end
end
end

describe '#disable_ssl_validation' do
it 'turns off Excon SSL cert validation' do
expect(driver.send(:disable_ssl_validation)).to eq(false)
Expand Down

0 comments on commit aee673f

Please sign in to comment.