]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb
add stackforge/keystone to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_spec.rb
diff --git a/3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb b/3rdparty/modules/keystone/spec/unit/provider/keystone_spec.rb
new file mode 100644 (file)
index 0000000..de9ceb0
--- /dev/null
@@ -0,0 +1,115 @@
+require 'puppet'
+require 'spec_helper'
+require 'puppet/provider/keystone'
+require 'tempfile'
+
+
+klass = Puppet::Provider::Keystone
+
+class Puppet::Provider::Keystone
+  def self.reset
+    @admin_endpoint = nil
+    @tenant_hash    = nil
+    @admin_token    = nil
+    @keystone_file  = nil
+  end
+end
+
+describe Puppet::Provider::Keystone do
+
+  after :each do
+    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)
+      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 = {}
+      Puppet::Util::IniConfig::File.expects(:new).returns(mock)
+      mock.expects(:read).with('/etc/keystone/keystone.conf')
+      expect(klass.get_admin_token).to be_nil
+    end
+
+    it 'should fail if the keystone config file does not contain an admin token' do
+      mock = {'DEFAULT' => {'not_a_token' => 'foo'}}
+      Puppet::Util::IniConfig::File.expects(:new).returns(mock)
+      mock.expects(:read).with('/etc/keystone/keystone.conf')
+      expect(klass.get_admin_token).to be_nil
+    end
+
+    it 'should parse the admin token if it is in the config file' do
+      mock = {'DEFAULT' => {'admin_token' => 'foo'}}
+      Puppet::Util::IniConfig::File.expects(:new).returns(mock)
+      mock.expects(:read).with('/etc/keystone/keystone.conf')
+      klass.get_admin_token.should == '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' }}
+      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/'
+    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' }}
+      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/'
+    end
+
+    it 'should use [::1] in the admin endpoint if bind_host is ::0' do
+      mock = {'DEFAULT' => { 'admin_bind_host' => '::0', 'admin_port' => '35357' }}
+      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/'
+    end
+
+    it 'should use localhost in the admin endpoint if bind_host is unspecified' do
+      mock = {'DEFAULT' => { 'admin_port' => '35357' }}
+      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/'
+    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'}}
+      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/'
+    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'}}
+      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/'
+    end
+
+    it 'should use the defined admin_endpoint if available' do
+      mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com' }, 'ssl' => {'enable' => 'False'}}
+      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/'
+    end
+
+    it 'should handle an admin_endpoint with a trailing slash' do
+      mock = {'DEFAULT' => {'admin_endpoint' => 'https://keystone.example.com/' }, 'ssl' => {'enable' => 'False'}}
+      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/'
+    end
+
+  end
+
+end