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:
commit
bc42058c9b
2 changed files with 42 additions and 9 deletions
|
@ -522,13 +522,18 @@ module Fog
|
||||||
# @see Servers#bootstrap
|
# @see Servers#bootstrap
|
||||||
def setup(credentials = {})
|
def setup(credentials = {})
|
||||||
requires :public_ip_address, :identity, :public_key, :username
|
requires :public_ip_address, :identity, :public_key, :username
|
||||||
|
|
||||||
commands = [
|
commands = [
|
||||||
%{mkdir .ssh},
|
%{mkdir .ssh},
|
||||||
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
|
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
|
||||||
password_lock,
|
password_lock,
|
||||||
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
|
%{echo "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json},
|
||||||
%{echo "#{Fog::JSON.encode(metadata)}" >> ~/metadata.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)
|
Fog::SSH.new(public_ip_address, username, credentials).run(commands)
|
||||||
rescue Errno::ECONNREFUSED
|
rescue Errno::ECONNREFUSED
|
||||||
sleep(1)
|
sleep(1)
|
||||||
|
|
|
@ -198,30 +198,58 @@ Shindo.tests('Fog::Compute::RackspaceV2 | server', ['rackspace']) do
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#setup') do
|
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
|
Fog::SSH::Mock.data.clear
|
||||||
|
|
||||||
server = Fog::Compute::RackspaceV2::Server.new(attributes)
|
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.identity = "bar"
|
||||||
server.public_key = "baz"
|
server.public_key = "baz"
|
||||||
|
|
||||||
server.setup
|
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
|
test("leaves user unlocked only when requested") do
|
||||||
perform_setup.call(:service => service, :no_passwd_lock => true)
|
create_server.call(ATTRIBUTES.merge(:no_passwd_lock => true))
|
||||||
.none? { |c| c =~ /passwd\s+-l\s+root/ }
|
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
|
end
|
||||||
|
|
||||||
test("locks user by default") do
|
test("locks user by default") do
|
||||||
perform_setup.call(:service => service)
|
create_server.call(ATTRIBUTES)
|
||||||
.one? { |c| c =~ /passwd\s+-l\s+root/ }
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue