]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/keystone/spec/unit/provider/keystone_endpoint/openstack_spec.rb
try with modules from master
[dsa-puppet.git] / 3rdparty / modules / keystone / spec / unit / provider / keystone_endpoint / openstack_spec.rb
index a0ac7523ec9c3e26531b7157855eba4597ddaa09..9ca5b436f3594557d011a30fc6b0f06027933ab8 100644 (file)
@@ -6,7 +6,14 @@ provider_class = Puppet::Type.type(:keystone_endpoint).provider(:openstack)
 
 describe provider_class do
 
-  describe 'when updating an endpoint' do
+  shared_examples 'authenticated with environment variables' do
+    ENV['OS_USERNAME']     = 'test'
+    ENV['OS_PASSWORD']     = 'abc123'
+    ENV['OS_PROJECT_NAME'] = 'test'
+    ENV['OS_AUTH_URL']     = 'http://127.0.0.1:35357/v2.0'
+  end
+
+  describe 'when managing an endpoint' do
 
     let(:endpoint_attrs) do
       {
@@ -15,12 +22,6 @@ describe provider_class do
         :public_url   => 'http://127.0.0.1:5000/v2.0',
         :internal_url => 'http://127.0.0.1:5001/v2.0',
         :admin_url    => 'http://127.0.0.1:5002/v2.0',
-        :auth         => {
-          'username'    => 'test',
-          'password'    => 'abc123',
-          'tenant_name' => 'foo',
-          'auth_url'    => 'http://127.0.0.1:5000/v2.0',
-        }
       }
     end
 
@@ -32,16 +33,17 @@ describe provider_class do
       provider_class.new(resource)
     end
 
-    describe '#create' do
-      it 'creates an endpoint' do
-        provider.class.stubs(:openstack)
-                      .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']])
-                      .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
+    it_behaves_like 'authenticated with environment variables' do
+      describe '#create' do
+        it 'creates an endpoint' do
+          provider.class.stubs(:openstack)
+                        .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long')
+                        .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
 "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"
 ')
-        provider.class.stubs(:openstack)
-                      .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']])
-                      .returns('adminurl="http://127.0.0.1:5002/v2.0"
+          provider.class.stubs(:openstack)
+                        .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'])
+                        .returns('adminurl="http://127.0.0.1:5002/v2.0"
 id="3a5c4378981e4112a0d44902a43e16ef"
 internalurl="http://127.0.0.1:5001/v2.0"
 publicurl="http://127.0.0.1:5000/v2.0"
@@ -50,64 +52,49 @@ service_id="8137d72980fd462192f276585a002426"
 service_name="bar"
 service_type="test"
 ')
-        provider.create
-        expect(provider.exists?).to be_truthy
-      end
-    end
-
-    describe '#destroy' do
-      it 'destroys an endpoint' do
-        provider.class.stubs(:openstack)
-                      .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']])
-                      .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
-"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"
-')
-        provider.class.stubs(:openstack)
-                      .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']])
-        expect(provider.destroy).to be_nil # We don't really care that it's nil, only that it runs successfully
+          provider.create
+          expect(provider.exists?).to be_truthy
+        end
       end
 
-    end
-
-    describe '#exists' do
-      context 'when endpoint exists' do
-
-        subject(:response) do
+      describe '#destroy' do
+        it 'destroys an endpoint' do
           provider.class.stubs(:openstack)
-                        .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']])
+                        .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long')
                         .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
-"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"
+"1cb05cfed7c24279be884ba4f6520262","foo","bar","test","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
 ')
-          response = provider.exists?
+          provider.class.stubs(:openstack)
+                        .with('endpoint', 'delete', [])
+          provider.destroy
+          expect(provider.exists?).to be_falsey
         end
-
-        it { is_expected.to be_truthy }
       end
 
-      context 'when tenant does not exist' do
+      describe '#exists' do
+        context 'when tenant does not exist' do
+          subject(:response) do
+            provider.class.stubs(:openstack)
+                          .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long')
+                          .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"')
+            response = provider.exists?
+          end
 
-        subject(:response) do
-          provider.class.stubs(:openstack)
-                        .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']])
-                        .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"')
-          response = provider.exists?
+          it { is_expected.to be_falsey }
         end
-
-        it { is_expected.to be_falsey }
       end
-    end
 
-    describe '#instances' do
-      it 'finds every tenant' do
-        provider.class.stubs(:openstack)
-                      .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']])
-                      .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
-"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"
+      describe '#instances' do
+        it 'finds every tenant' do
+          provider.class.stubs(:openstack)
+                        .with('endpoint', 'list', '--quiet', '--format', 'csv', '--long')
+                        .returns('"ID","Region","Service Name","Service Type","PublicURL","AdminURL","InternalURL"
+"3a5c4378981e4112a0d44902a43e16ef","foo","bar","test","http://127.0.0.1:5000/v2.0","http://127.0.0.1:5001/v2.0","http://127.0.0.1:5002/v2.0"
 ')
-        instances = provider.instances
-        expect(instances.count).to eq(1)
+          instances = Puppet::Type::Keystone_endpoint::ProviderOpenstack.instances
+          expect(instances.count).to eq(1)
+        end
       end
     end
-
   end
 end