try again, with puppetforge modules, correctly included now
[mirror/dsa-puppet.git] / 3rdparty / modules / glance / spec / unit / provider / glance_spec.rb
1 require 'puppet'
2 require 'spec_helper'
3 require 'puppet/provider/glance'
4 require 'tempfile'
5
6
7 klass = Puppet::Provider::Glance
8
9 describe Puppet::Provider::Glance do
10
11   after :each do
12     klass.reset
13   end
14
15   describe 'when retrieving the auth credentials' do
16
17     it 'should fail if the glance config file does not have the expected contents' do
18       mock = {}
19       Puppet::Util::IniConfig::File.expects(:new).returns(mock)
20       mock.expects(:read).with('/etc/glance/glance-api.conf')
21       expect do
22         klass.glance_credentials
23       end.to raise_error(Puppet::Error, /does not contain all required sections/)
24     end
25
26   describe 'when testing glance connection retries' do
27
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' =>
31             {
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'
38             },
39                 'DEFAULT' =>
40             {
41                 'os_region_name' => 'SomeRegion',
42             }
43           }
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(
48             '--os-tenant-name',
49             'foo',
50             '--os-username',
51             'user',
52             '--os-password',
53             'pass',
54             '--os-region-name',
55             'SomeRegion',
56             '--os-auth-url',
57             'http://127.0.0.1:35357/v2.0/',
58             ['test_retries']
59           ).raises(Exception, valid_message).then.returns('')
60           klass.auth_glance('test_retries')
61         end
62       end
63     end
64   end
65 end