1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #2497 from elight/optional_root_lock

[Rackspace | Compute] 1.8.7 fix plus better passwd -l handling
This commit is contained in:
Kyle Rames 2013-12-20 08:40:17 -08:00
commit bc42058c9b
2 changed files with 42 additions and 9 deletions

View file

@ -522,13 +522,18 @@ module Fog
# @see Servers#bootstrap
def setup(credentials = {})
requires :public_ip_address, :identity, :public_key, :username
commands = [
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
password_lock,
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
%{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.json}
].compact
]
commands.compact
@password = nil if password_lock
Fog::SSH.new(public_ip_address, username, credentials).run(commands)
rescue Errno::ECONNREFUSED
sleep(1)

View file

@ -198,30 +198,58 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
end
tests('#setup') do
perform_setup = lambda { |attributes|
ATTRIBUTES = {
:name => "foo",
:image_id => 42,
:flavor_id => 42
}
create_server = lambda { |attributes|
service = Fog::Compute::RackspaceV2.new
attributes.merge!(:service => service)
Fog::SSH::Mock.data.clear
server = Fog::Compute::RackspaceV2::Server.new(attributes)
server.save(attributes)
address = 123
@address = 123
server.ipv4_address = address
server.ipv4_address = @address
server.identity = "bar"
server.public_key = "baz"
server.setup
Fog::SSH::Mock.data[address].first[:commands]
server
}
commands = lambda {
Fog::SSH::Mock.data[@address].first[:commands]
}
test("leaves user unlocked only when requested") do
perform_setup.call(:service => service, :no_passwd_lock => true)
.none? { |c| c =~ /passwd\s+-l\s+root/ }
create_server.call(ATTRIBUTES.merge(:no_passwd_lock => true))
commands.call.none? { |c| c =~ /passwd\s+-l\s+root/ }
end
test("provide a password when the passed isn't locked") do
pwd = create_server.call(
ATTRIBUTES.merge(:no_passwd_lock => true)
).password
# shindo expects a boolean not truthyness :-(
!!pwd
end
test("locks user by default") do
perform_setup.call(:service => service)
.one? { |c| c =~ /passwd\s+-l\s+root/ }
create_server.call(ATTRIBUTES)
commands.call.one? { |c| c =~ /passwd\s+-l\s+root/ }
end
test("nils password when password is locked") do
pwd = create_server.call(ATTRIBUTES).password
pwd.nil?
end
end