Skip to content

Commit

Permalink
Respect a configured password when setting up SSH
Browse files Browse the repository at this point in the history
  • Loading branch information
hartmantis committed Jan 8, 2015
1 parent a15bf09 commit 86f21cb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
8 changes: 5 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
CyclomaticComplexity:
Enabled: false
Max: 8
MethodLength:
Enabled: false
Max: 30
ClassLength:
Enabled: false
Max: 300
ClassVars:
Enabled: false
PerceivedComplexity:
Max: 10
AbcSize:
Max: 41
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ?.?.? / ????-??-??

* PR [#70][] - Use configured password for SSH access, if provided

# 1.7.0 / 2014-10-25

### New Features
Expand Down Expand Up @@ -136,6 +138,7 @@ certain specified NICs; via [@monsterzz][]

* Initial release! Woo!

[#70]: https://github.com/test-kitchen/kitchen-openstack/pull/70
[#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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ behavior can be overridden with additional options:
private_key_path: [PATH TO YOUR PRIVATE SSH KEY]
public_key_path: [PATH TO YOUR SSH PUBLIC KEY]
username: [SSH USER]
password: [SSH PASSWORD]
port: [SSH PORT]
key_name: [SSH KEY NAME]
openstack_tenant: [YOUR OPENSTACK TENANT ID]
Expand Down
3 changes: 2 additions & 1 deletion lib/kitchen/driver/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Openstack < Kitchen::Driver::SSHBase
driver[:private_key_path] + '.pub'
end
default_config :username, 'root'
default_config :password, nil
default_config :port, '22'
default_config :use_ipv6, false
default_config :openstack_tenant, nil
Expand Down Expand Up @@ -318,7 +319,7 @@ def do_ssh_setup(state, config, server)
info "Setting up SSH access for key <#{config[:public_key_path]}>"
ssh = Fog::SSH.new(state[:hostname],
config[:username],
password: server.password)
password: config[:password] || server.password)
pub_key = open(config[:public_key_path]).read
ssh.run([
%(mkdir .ssh),
Expand Down
33 changes: 21 additions & 12 deletions spec/kitchen/driver/openstack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1033,24 +1033,33 @@
let(:server) { double(password: 'aloha') }
let(:state) { { hostname: 'host' } }
let(:read) { double(read: 'a_key') }
let(:ssh) do
s = double('ssh')
allow(s).to receive(:run) { |args| args }
s
let(:ssh) { double(run: true) }

before(:each) do
allow(driver).to receive(:open).with(config[:public_key_path])
.and_return(read)
end

it 'opens an SSH session to the server' do
allow(Fog::SSH).to receive(:new).with('host', 'root', password: 'aloha')
.and_return(ssh)
allow(driver).to receive(:open).with('/pub_key').and_return(read)
allow(read).to receive(:read).and_return('a_key')
res = driver.send(:do_ssh_setup, state, config, server)
expected = [
expect(Fog::SSH).to receive(:new).with(state[:hostname],
'root',
password: 'aloha').and_return(ssh)
expect(ssh).to receive(:run).with([
'mkdir .ssh',
'echo "a_key" >> ~/.ssh/authorized_keys',
'passwd -l root'
]
expect(res).to eq(expected)
])
driver.send(:do_ssh_setup, state, config, server)
end

context 'a configured SSH password' do
let(:config) { super().merge(password: '12345') }

it 'uses the configured password' do
expect(Fog::SSH).to receive(:new)
.with(state[:hostname], 'root', password: '12345').and_return(ssh)
driver.send(:do_ssh_setup, state, config, server)
end
end
end

Expand Down

0 comments on commit 86f21cb

Please sign in to comment.