Fallback to default rcfile
For missing HOME env variable set rcfile to /root/openrc by default. Change-Id: Icd13f7ce46a999f3def18131042a83de574ffed8
This commit is contained in:
parent
69a408d084
commit
086c8806c0
|
@ -12,8 +12,9 @@ module Puppet::Provider::Openstack::Auth
|
|||
|
||||
def get_os_vars_from_rcfile(filename)
|
||||
env = {}
|
||||
if File.exists?(filename)
|
||||
File.open(filename).readlines.delete_if{|l| l=~ /^#|^$/ }.each do |line|
|
||||
rcfile = [filename, '/root/openrc'].detect { |f| File.exists? f }
|
||||
unless rcfile.nil?
|
||||
File.open(rcfile).readlines.delete_if{|l| l=~ /^#|^$/ }.each do |line|
|
||||
key, value = line.split('=')
|
||||
key = key.split(' ').last
|
||||
value = value.chomp.gsub(/'/, '')
|
||||
|
|
|
@ -112,6 +112,25 @@ describe Puppet::Provider::Openstack::Auth do
|
|||
expect(response).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a nonexistent file' do
|
||||
it 'should get default rcfile when no environment or openrc file' do
|
||||
ENV.clear
|
||||
mock = "export OS_USERNAME='user'\nexport OS_PASSWORD='secret'\nexport OS_PROJECT_NAME='project'\nexport OS_AUTH_URL='http://127.0.0.1:5000'"
|
||||
filename = '/root/openrc'
|
||||
|
||||
File.expects(:exists?).with("#{ENV['HOME']}/openrc").returns(false)
|
||||
File.expects(:exists?).with(filename).returns(true)
|
||||
File.expects(:open).with(filename).returns(StringIO.new(mock))
|
||||
|
||||
expect(klass.get_os_vars_from_rcfile("#{ENV['HOME']}/openrc")).to eq({
|
||||
'OS_USERNAME' => 'user',
|
||||
'OS_PASSWORD' => 'secret',
|
||||
'OS_PROJECT_NAME' => 'project',
|
||||
'OS_AUTH_URL' => 'http://127.0.0.1:5000'
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
|
|
Loading…
Reference in New Issue