3 require 'puppet/provider/keystone'
6 klass = Puppet::Provider::Keystone
8 class Puppet::Provider::Keystone
9 @credentials = Puppet::Provider::Openstack::CredentialsV3.new
16 @domain_id_to_name = nil
17 @default_domain_id = nil
22 describe Puppet::Provider::Keystone do
28 describe 'when retrieving the security token' do
29 it 'should return nothing if there is no keystone config file' do
30 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(false)
31 expect(klass.get_admin_token).to be_nil
34 it 'should return nothing if the keystone config file does not have a DEFAULT section' do
36 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
37 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
38 mock.expects(:read).with('/etc/keystone/keystone.conf')
39 expect(klass.get_admin_token).to be_nil
42 it 'should fail if the keystone config file does not contain an admin token' do
43 mock = {'DEFAULT' => {'not_a_token' => 'foo'}}
44 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
45 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
46 mock.expects(:read).with('/etc/keystone/keystone.conf')
47 expect(klass.get_admin_token).to be_nil
50 it 'should parse the admin token if it is in the config file' do
51 mock = {'DEFAULT' => {'admin_token' => 'foo'}}
52 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
53 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
54 mock.expects(:read).with('/etc/keystone/keystone.conf')
55 expect(klass.get_admin_token).to eq('foo')
58 it 'should use the specified bind_host in the admin endpoint' do
59 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }}
60 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
61 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
62 mock.expects(:read).with('/etc/keystone/keystone.conf')
63 expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v3/')
66 it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do
67 mock = {'DEFAULT' => { 'admin_bind_host' => '0.0.0.0', 'admin_port' => '35357' }}
68 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
69 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
70 mock.expects(:read).with('/etc/keystone/keystone.conf')
71 expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v3/')
74 it 'should use [::1] in the admin endpoint if bind_host is ::0' do
75 mock = {'DEFAULT' => { 'admin_bind_host' => '::0', 'admin_port' => '35357' }}
76 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
77 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
78 mock.expects(:read).with('/etc/keystone/keystone.conf')
79 expect(klass.get_admin_endpoint).to eq('http://[::1]:35357/v3/')
82 it 'should use localhost in the admin endpoint if bind_host is unspecified' do
83 mock = {'DEFAULT' => { 'admin_port' => '35357' }}
84 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
85 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
86 mock.expects(:read).with('/etc/keystone/keystone.conf')
87 expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v3/')
90 it 'should use https if ssl is enabled' do
91 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'True'}}
92 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
93 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
94 mock.expects(:read).with('/etc/keystone/keystone.conf')
95 expect(klass.get_admin_endpoint).to eq('https://192.168.56.210:35357/v3/')
98 it 'should use http if ssl is disabled' do
99 mock = {'DEFAULT' => {'admin_bind_host' => '192.168.56.210', 'admin_port' => '35357' }, 'ssl' => {'enable' => 'False'}}
100 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
101 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
102 mock.expects(:read).with('/etc/keystone/keystone.conf')
103 expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v3/')
106 it 'should use the defined admin_endpoint if available' do
107 mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}}
108 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
109 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
110 mock.expects(:read).with('/etc/keystone/keystone.conf')
111 expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v3/')
114 it 'should handle an admin_endpoint with a trailing slash' do
115 mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}}
116 File.expects(:exists?).with("/etc/keystone/keystone.conf").returns(true)
117 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
118 mock.expects(:read).with('/etc/keystone/keystone.conf')
119 expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v3/')
124 describe 'when using domains' do
125 it 'name_and_domain should return the resource domain' do
126 expect(klass.name_and_domain('foo::in_name', 'from_resource', 'default')).to eq(['foo', 'from_resource'])
128 it 'name_and_domain should return the default domain' do
129 expect(klass.name_and_domain('foo', nil, 'default')).to eq(['foo', 'default'])
131 it 'name_and_domain should return the domain part of the name' do
132 expect(klass.name_and_domain('foo::in_name', nil, 'default')).to eq(['foo', 'in_name'])
134 it 'should return the default domain name using the default_domain_id from keystone.conf' do
135 ENV['OS_USERNAME'] = 'test'
136 ENV['OS_PASSWORD'] = 'abc123'
137 ENV['OS_PROJECT_NAME'] = 'test'
138 ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v3'
141 'admin_endpoint' => 'http://127.0.0.1:35357',
142 'admin_token' => 'admin_token'
144 'identity' => {'default_domain_id' => 'somename'}
146 File.expects(:exists?).with('/etc/keystone/keystone.conf').returns(true)
147 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
148 mock.expects(:read).with('/etc/keystone/keystone.conf')
149 klass.expects(:openstack)
150 .with('domain', 'list', '--quiet', '--format', 'csv', [])
151 .returns('"ID","Name","Enabled","Description"
152 "somename","SomeName",True,"default domain"
154 expect(klass.name_and_domain('foo')).to eq(['foo', 'SomeName'])
156 it 'should return Default if default_domain_id is not configured' do
157 ENV['OS_USERNAME'] = 'test'
158 ENV['OS_PASSWORD'] = 'abc123'
159 ENV['OS_PROJECT_NAME'] = 'test'
160 ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v3'
162 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
163 File.expects(:exists?).with('/etc/keystone/keystone.conf').returns(true)
164 mock.expects(:read).with('/etc/keystone/keystone.conf')
165 klass.expects(:openstack)
166 .with('domain', 'list', '--quiet', '--format', 'csv', [])
167 .returns('"ID","Name","Enabled","Description"
168 "default","Default",True,"default domain"
170 expect(klass.name_and_domain('foo')).to eq(['foo', 'Default'])