]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb
Update to Kilo
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_spec.rb
index 4981f1e5ce2ba6ad2cb7a589c7d6d9d921418581..44d265f52a2e82335dc1febc21ac625ba3e17601 100644 (file)
@@ -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