]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb
a0ac7523ec9c3e26531b7157855eba4597ddaa09
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_endpoint / openstack_spec.rb
1 require 'puppet'
2 require 'spec_helper'
3 require 'puppet/provider/keystone_endpoint/openstack'
4
5 provider_class = Puppet::Type.type(:keystone_endpoint).provider(:openstack)
6
7 describe provider_class do
8
9   describe 'when updating an endpoint' do
10
11     let(:endpoint_attrs) do
12       {
13         :name         => 'foo/bar',
14         :ensure       => 'present',
15         :public_url   => 'http://127.0.0.1:5000/v2.0',
16         :internal_url => 'http://127.0.0.1:5001/v2.0',
17         :admin_url    => 'http://127.0.0.1:5002/v2.0',
18         :auth         => {
19           'username'    => 'test',
20           'password'    => 'abc123',
21           'tenant_name' => 'foo',
22           'auth_url'    => 'http://127.0.0.1:5000/v2.0',
23         }
24       }
25     end
26
27     let(:resource) do
28       Puppet::Type::Keystone_endpoint.new(endpoint_attrs)
29     end
30
31     let(:provider) do
32       provider_class.new(resource)
33     end
34
35     describe '#create' do
36       it 'creates an endpoint' do
37         provider.class.stubs(:openstack)
38                       .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
39                       .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
40 "1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
41 ')
42         provider.class.stubs(:openstack)
43                       .with('endpoint', 'create', '--format', 'shell', [['bar', '--region', 'foo', '--publicurl', 'http://127.0.0.1:5000/v2.0', '--internalurl', 'http://127.0.0.1:5001/v2.0', '--adminurl', 'http://127.0.0.1:5002/v2.0', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
44                       .returns('adminurl="http://127.0.0.1:5002/v2.0"
45 id="3a5c4378981e4112a0d44902a43e16ef"
46 internalurl="http://127.0.0.1:5001/v2.0"
47 publicurl="http://127.0.0.1:5000/v2.0"
48 region="foo"
49 service_id="8137d72980fd462192f276585a002426"
50 service_name="bar"
51 service_type="test"
52 ')
53         provider.create
54         expect(provider.exists?).to be_truthy
55       end
56     end
57
58     describe '#destroy' do
59       it 'destroys an endpoint' do
60         provider.class.stubs(:openstack)
61                       .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
62                       .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
63 "1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
64 ')
65         provider.class.stubs(:openstack)
66                       .with('endpoint', 'delete', [['1cb05cfed7c24279be884ba4f6520262', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
67         expect(provider.destroy).to be_nil # We don't really care that it's nil, only that it runs successfully
68       end
69
70     end
71
72     describe '#exists' do
73       context 'when endpoint exists' do
74
75         subject(:response) do
76           provider.class.stubs(:openstack)
77                         .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
78                         .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
79 "1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
80 ')
81           response = provider.exists?
82         end
83
84         it { is_expected.to be_truthy }
85       end
86
87       context 'when tenant does not exist' do
88
89         subject(:response) do
90           provider.class.stubs(:openstack)
91                         .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
92                         .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"')
93           response = provider.exists?
94         end
95
96         it { is_expected.to be_falsey }
97       end
98     end
99
100     describe '#instances' do
101       it 'finds every tenant' do
102         provider.class.stubs(:openstack)
103                       .with('endpoint', 'list', '--quiet', '--format', 'csv', [['--long', '--os-username', 'test', '--os-password', 'abc123', '--os-tenant-name', 'foo', '--os-auth-url', 'http://127.0.0.1:5000/v2.0']])
104                       .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
105 "1cb05cfed7c24279be884ba4f6520262","foo","bar","","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
106 ')
107         instances = provider.instances
108         expect(instances.count).to eq(1)
109       end
110     end
111
112   end
113 end