3 require 'puppet/provider/keystone_tenant/openstack'
5 provider_class = Puppet::Type.type(:keystone_tenant).provider(:openstack)
7 class Puppet::Provider::Keystone
13 @domain_id_to_name = nil
14 @default_domain_id = nil
19 describe provider_class do
28 :description => 'foo',
35 Puppet::Type::Keystone_tenant.new(tenant_attrs)
39 provider_class.new(resource)
42 def before_hook(domainlist)
44 provider.class.expects(:openstack).once
45 .with('domain', 'list', '--quiet', '--format', 'csv', [])
46 .returns('"ID","Name","Enabled","Description"
47 "foo_domain_id","foo_domain",True,"foo domain"
48 "bar_domain_id","bar_domain",True,"bar domain"
49 "another_domain_id","another_domain",True,"another domain"
50 "disabled_domain_id","disabled_domain",False,"disabled domain"
51 "default","Default",True,"the default domain"
56 before :each, :domainlist => true do
60 before :each, :domainlist => false do
64 shared_examples 'authenticated with environment variables' do
65 ENV['OS_USERNAME'] = 'test'
66 ENV['OS_PASSWORD'] = 'abc123'
67 ENV['OS_PROJECT_NAME'] = 'test'
68 ENV['OS_AUTH_URL'] = 'http://127.0.0.1:35357/v3'
71 describe 'when managing a tenant' do
73 it_behaves_like 'authenticated with environment variables' do
74 describe '#create', :domainlist => true do
75 it 'creates a tenant' do
76 provider.class.expects(:openstack)
77 .with('project', 'create', '--format', 'shell', ['foo', '--enable', '--description', 'foo', '--domain', 'Default'])
78 .returns('description="foo"
82 domain_id="foo_domain_id"
85 expect(provider.exists?).to be_truthy
89 describe '#destroy', :domainlist => false do
90 it 'destroys a tenant' do
91 provider.instance_variable_get('@property_hash')[:id] = 'my-project-id'
92 provider.class.expects(:openstack)
93 .with('project', 'delete', 'my-project-id')
95 expect(provider.exists?).to be_falsey
99 context 'when tenant does not exist', :domainlist => false do
100 subject(:response) do
101 response = provider.exists?
104 it { expect(response).to be_falsey }
107 describe '#instances', :domainlist => true do
108 it 'finds every tenant' do
109 provider.class.expects(:openstack)
110 .with('project', 'list', '--quiet', '--format', 'csv', '--long')
111 .returns('"ID","Name","Domain ID","Description","Enabled"
112 "1cb05cfed7c24279be884ba4f6520262","foo","foo_domain_id","foo",True
113 "2cb05cfed7c24279be884ba4f6520262","foo","bar_domain_id","foo",True
115 instances = provider.class.instances
116 expect(instances[0].name).to eq('foo')
117 expect(instances[0].domain).to eq('bar_domain')
118 expect(instances[1].name).to eq('foo::foo_domain')
123 describe 'v3 domains with no domain in resource', :domainlist => true do
125 let(:tenant_attrs) do
128 :description => 'foo',
129 :ensure => 'present',
134 it 'adds default domain to commands' do
136 'identity' => {'default_domain_id' => 'foo_domain_id'}
138 Puppet::Util::IniConfig::File.expects(:new).returns(mock)
139 File.expects(:exists?).with('/etc/keystone/keystone.conf').returns(true)
140 mock.expects(:read).with('/etc/keystone/keystone.conf')
141 provider.class.expects(:openstack)
142 .with('project', 'create', '--format', 'shell', ['foo', '--enable', '--description', 'foo', '--domain', 'foo_domain'])
143 .returns('description="foo"
147 domain_id="foo_domain_id"
150 expect(provider.exists?).to be_truthy
151 expect(provider.id).to eq("project-id")
156 describe 'v3 domains with domain in resource', :domainlist => false do
158 let(:tenant_attrs) do
161 :description => 'foo',
162 :ensure => 'present',
164 :domain => 'foo_domain'
168 it 'uses given domain in commands' do
169 provider.class.expects(:openstack)
170 .with('project', 'create', '--format', 'shell', ['foo', '--enable', '--description', 'foo', '--domain', 'foo_domain'])
171 .returns('description="foo"
175 domain_id="foo_domain_id"
178 expect(provider.exists?).to be_truthy
179 expect(provider.id).to eq("project-id")
183 describe 'v3 domains with domain in name/title', :domainlist => false do
185 let(:tenant_attrs) do
187 :name => 'foo::foo_domain',
188 :description => 'foo',
189 :ensure => 'present',
194 it 'uses given domain in commands' do
195 provider.class.expects(:openstack)
196 .with('project', 'create', '--format', 'shell', ['foo', '--enable', '--description', 'foo', '--domain', 'foo_domain'])
197 .returns('description="foo"
201 domain_id="foo_domain_id"
204 expect(provider.exists?).to be_truthy
205 expect(provider.id).to eq("project-id")
209 describe 'v3 domains with domain in name/title and in resource', :domainlist => false do
211 let(:tenant_attrs) do
213 :name => 'foo::bar_domain',
214 :description => 'foo',
215 :ensure => 'present',
217 :domain => 'foo_domain'
221 it 'uses given domain in commands' do
222 provider.class.expects(:openstack)
223 .with('project', 'create', '--format', 'shell', ['foo', '--enable', '--description', 'foo', '--domain', 'foo_domain'])
224 .returns('description="foo"
228 domain_id="foo_domain_id"
231 expect(provider.exists?).to be_truthy
232 expect(provider.id).to eq("project-id")