3 require 'puppet/provider/keystone_endpoint/openstack'
5 provider_class = Puppet::Type.type(:keystone_endpoint).provider(:openstack)
7 describe provider_class do
9 describe 'when updating an endpoint' do
11 let(:endpoint_attrs) do
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',
20 'password' => 'abc123',
21 'tenant_name' => 'foo',
22 'auth_url' => 'http://127.0.0.1:5000/v2.0',
28 Puppet::Type::Keystone_endpoint.new(endpoint_attrs)
32 provider_class.new(resource)
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"
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"
49 service_id="8137d72980fd462192f276585a002426"
54 expect(provider.exists?).to be_truthy
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"
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
73 context 'when endpoint exists' 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"
81 response = provider.exists?
84 it { is_expected.to be_truthy }
87 context 'when tenant does not exist' 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?
96 it { is_expected.to be_falsey }
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"
107 instances = provider.instances
108 expect(instances.count).to eq(1)