Improve error handling when keystone is not configured
Previously, the error message for the keystone native types when the environment was not correctly configured was a stacktrace. This commit updates the code to throw useful error messages when this occurrs.
This commit is contained in:
parent
1cac5d0001
commit
81260a3bde
@ -7,7 +7,11 @@ class Puppet::Provider::Keystone < Puppet::Provider
|
||||
end
|
||||
|
||||
def self.get_admin_token
|
||||
"#{keystone_file['DEFAULT']['admin_token'].strip}"
|
||||
if keystone_file and keystone_file['DEFAULT'] and keystone_file['DEFAULT']['admin_token']
|
||||
return "#{keystone_file['DEFAULT']['admin_token'].strip}"
|
||||
else
|
||||
raise(Puppet::Error, "File: /etc/keystone/keystone.conf does not contain a section DEFAULT with the admin_token specified. Keystone types will not work if keystone is not correctly configured")
|
||||
end
|
||||
end
|
||||
|
||||
def self.admin_endpoint
|
||||
|
@ -1,6 +1,7 @@
|
||||
require 'puppet'
|
||||
require 'rubygems'
|
||||
require 'rspec-puppet'
|
||||
require 'mocha'
|
||||
|
||||
def param_value(subject, type, title, param)
|
||||
subject.resource(type, title).send(:parameters)[param.to_sym]
|
||||
@ -12,6 +13,7 @@ def verify_contents(subject, title, expected_lines)
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
c.mock_with :mocha
|
||||
c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures/manifests'))
|
||||
c.module_path = File.join(File.dirname(__FILE__), '../../')
|
||||
end
|
||||
|
53
spec/unit/provider/keystone_spec.rb
Normal file
53
spec/unit/provider/keystone_spec.rb
Normal file
@ -0,0 +1,53 @@
|
||||
require 'puppet'
|
||||
require 'spec_helper'
|
||||
require 'puppet/provider/keystone'
|
||||
|
||||
|
||||
klass = Puppet::Provider::Keystone
|
||||
|
||||
describe Puppet::Provider::Keystone do
|
||||
|
||||
describe 'when retrieving the security token' do
|
||||
|
||||
after :each do
|
||||
klass.instance_variable_set(:@keystone_file, nil)
|
||||
end
|
||||
|
||||
it 'should fail if there is no keystone config file' do
|
||||
mock = nil
|
||||
Puppet::Util::IniConfig::File.expects(:new).returns(mock)
|
||||
mock.expects(:read).with('/etc/keystone/keystone.conf')
|
||||
expect do
|
||||
klass.get_admin_token
|
||||
end.to raise_error(Puppet::Error, /Keystone types will not work/)
|
||||
end
|
||||
|
||||
it 'should fail 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 do
|
||||
|
||||
klass.get_admin_token
|
||||
end.to raise_error(Puppet::Error, /Keystone types will not work/)
|
||||
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 do
|
||||
klass.get_admin_token
|
||||
end.to raise_error(Puppet::Error, /Keystone types will not work/)
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user