X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fkeystone%2Fspec%2Funit%2Fprovider%2Fkeystone_spec.rb;h=44d265f52a2e82335dc1febc21ac625ba3e17601;hb=b0c5fa1bf27e28d72c80d56c0c84f7d301aaaac6;hp=4981f1e5ce2ba6ad2cb7a589c7d6d9d921418581;hpb=71a236efd9f45828d875a0a5fd025108bb1dcada;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb b/3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb index 4981f1e5c..44d265f52 100644 --- a/3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb +++ b/3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb @@ -6,13 +6,16 @@ require 'tempfile' klass = Puppet::Provider::Keystone class Puppet::Provider::Keystone - @credentials = Puppet::Provider::Openstack::CredentialsV2_0.new + @credentials = Puppet::Provider::Openstack::CredentialsV3.new def self.reset @admin_endpoint = nil @tenant_hash = nil @admin_token = nil @keystone_file = nil + @domain_id_to_name = nil + @default_domain_id = nil + @domain_hash = nil end end @@ -57,7 +60,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('http://192.168.56.210:35357/v2.0/') + expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v3/') end it 'should use localhost in the admin endpoint if bind_host is 0.0.0.0' do @@ -65,7 +68,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('http://127.0.0.1:35357/v2.0/') + expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v3/') end it 'should use [::1] in the admin endpoint if bind_host is ::0' do @@ -73,7 +76,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('http://[::1]:35357/v2.0/') + expect(klass.get_admin_endpoint).to eq('http://[::1]:35357/v3/') end it 'should use localhost in the admin endpoint if bind_host is unspecified' do @@ -81,7 +84,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('http://127.0.0.1:35357/v2.0/') + expect(klass.get_admin_endpoint).to eq('http://127.0.0.1:35357/v3/') end it 'should use https if ssl is enabled' do @@ -89,7 +92,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('https://192.168.56.210:35357/v2.0/') + expect(klass.get_admin_endpoint).to eq('https://192.168.56.210:35357/v3/') end it 'should use http if ssl is disabled' do @@ -97,7 +100,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('http://192.168.56.210:35357/v2.0/') + expect(klass.get_admin_endpoint).to eq('http://192.168.56.210:35357/v3/') end it 'should use the defined admin_endpoint if available' do @@ -105,7 +108,7 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('https://keystone.example.com/v2.0/') + expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v3/') end it 'should handle an admin_endpoint with a trailing slash' do @@ -113,9 +116,58 @@ describe Puppet::Provider::Keystone do 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_endpoint).to eq('https://keystone.example.com/v2.0/') + expect(klass.get_admin_endpoint).to eq('https://keystone.example.com/v3/') end end + describe 'when using domains' do + it 'name_and_domain should return the resource domain' do + expect(klass.name_and_domain('foo::in_name', 'from_resource', 'default')).to eq(['foo', 'from_resource']) + end + it 'name_and_domain should return the default domain' do + expect(klass.name_and_domain('foo', nil, 'default')).to eq(['foo', 'default']) + end + it 'name_and_domain should return the domain part of the name' do + expect(klass.name_and_domain('foo::in_name', nil, 'default')).to eq(['foo', 'in_name']) + end + it 'should return the default domain name using the default_domain_id from keystone.conf' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v3' + mock = { + 'DEFAULT' => { + 'admin_endpoint' => 'http://127.0.0.1:35357', + 'admin_token' => 'admin_token' + }, + 'identity' => {'default_domain_id' => 'somename'} + } + 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.expects(:openstack) + .with('domain', 'list', '--quiet', '--format', 'csv', []) + .returns('"ID","Name","Enabled","Description" +"somename","SomeName",True,"default domain" +') + expect(klass.name_and_domain('foo')).to eq(['foo', 'SomeName']) + end + it 'should return Default if default_domain_id is not configured' do + ENV['OS_USERNAME'] = 'test' + ENV['OS_PASSWORD'] = 'abc123' + ENV['OS_PROJECT_NAME'] = 'test' + ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v3' + mock = {} + Puppet::Util::IniConfig::File.expects(:new).returns(mock) + File.expects(:exists?).with('/etc/keystone/keystone.conf').returns(true) + mock.expects(:read).with('/etc/keystone/keystone.conf') + klass.expects(:openstack) + .with('domain', 'list', '--quiet', '--format', 'csv', []) + .returns('"ID","Name","Enabled","Description" +"default","Default",True,"default domain" +') + expect(klass.name_and_domain('foo')).to eq(['foo', 'Default']) + end + end end