require 'puppet/provider/keystone'
require 'tempfile'
-
klass = Puppet::Provider::Keystone
class Puppet::Provider::Keystone
+ @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new
+
def self.reset
@admin_endpoint = nil
@tenant_hash = nil
klass.reset
end
-
describe 'when retrieving the security token' do
-
it 'should return nothing if there is no keystone config file' do
- ini_file = Puppet::Util::IniConfig::File.new
- t = Tempfile.new('foo')
- path = t.path
- t.unlink
- ini_file.read(path)
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(false)
expect(klass.get_admin_token).to be_nil
end
it 'should return nothing if the keystone config file does not have a DEFAULT section' do
mock = {}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
expect(klass.get_admin_token).to be_nil
it 'should fail if the keystone config file does not contain an admin token' do
mock = {'DEFAULT' => {'not_a_token' => 'foo'}}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
expect(klass.get_admin_token).to be_nil
it 'should parse the admin token if it is in the config file' do
mock = {'DEFAULT' => {'admin_token' => 'foo'}}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_token.should == 'foo'
+ expect(klass.get_admin_token).to eq('foo')
end
it 'should use the specified bind_host in the admin endpoint' do
mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'http://192.168.56.210:35357/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/')
end
it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do
mock = {'DEFAULT' => { 'admin_bind_host' => '0.0.0.0', 'admin_port' => '35357' }}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'http://127.0.0.1:35357/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/')
end
it 'should use [::1] in the admin endpoint if bind_host is ::0' do
mock = {'DEFAULT' => { 'admin_bind_host' => '::0', 'admin_port' => '35357' }}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'http://[::1]:35357/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('http://[::1]:35357/v2.0/')
end
it 'should use localhost in the admin endpoint if bind_host is unspecified' do
mock = {'DEFAULT' => { 'admin_port' => '35357' }}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'http://127.0.0.1:35357/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v2.0/')
end
it 'should use https if ssl is enabled' do
mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'True'}}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'https://192.168.56.210:35357/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('https://192.168.56.210:35357/v2.0/')
end
it 'should use http if ssl is disabled' do
mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'False'}}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'http://192.168.56.210:35357/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v2.0/')
end
it 'should use the defined admin_endpoint if available' do
mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'https://keystone.example.com/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/')
end
it 'should handle an admin_endpoint with a trailing slash' do
mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}}
+ File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
mock.expects(:read).with('/etc/keystone/keystone.conf')
- klass.get_admin_endpoint.should == 'https://keystone.example.com/v2.0/'
+ expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v2.0/')
end
end