3 require 'puppet/provider/glance'
7 klass = Puppet::Provider::Glance
9 describe Puppet::Provider::Glance do
15 describe 'when retrieving the auth credentials' do
17 it 'should fail if the glance config file does not have the expected contents' do
19 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
20 mock.expects(:read).with('/etc/glance/glance-api.conf')
22 klass.glance_credentials
23 end.to raise_error(Puppet::Error, /does not contain all required sections/)
26 describe 'when testing glance connection retries' do
28 ['[Errno 111] Connection refused', '(HTTP 400)', 'HTTP Unable to establish connection'].reverse.each do |valid_message|
29 it "should retry when glance is not ready with error #{valid_message}" do
30 mock = {'keystone_authtoken' =>
32 'auth_host' => '127.0.0.1',
33 'auth_port' => '35357',
34 'auth_protocol' => 'http',
35 'admin_tenant_name' => 'foo',
36 'admin_user' => 'user',
37 'admin_password' => 'pass'
41 'os_region_name' => 'SomeRegion',
44 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
45 mock.expects(:read).with('/etc/glance/glance-api.conf')
46 klass.expects(:sleep).with(10).returns(nil)
47 klass.expects(:glance).twice.with(
57 'http://127.0.0.1:35357/v2.0/',
59 ).raises(Exception, valid_message).then.returns('')
60 klass.auth_glance('test_retries')