blob: 709ca6f40b533daa096cd6cc350ce696286d72fd [file] [log] [blame]
David Kranz8d1a0dc2015-03-13 11:43:37 -04001# Copyright 2015 Red Hat, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
Doug Hellmannd5205022015-05-06 19:59:05 +000015from oslo_config import cfg
David Kranz8d1a0dc2015-03-13 11:43:37 -040016from oslotest import mockpatch
17
18from tempest.common import credentials
19from tempest import config
20from tempest.tests import base
21from tempest.tests import fake_config
22
23
24class TestAdminAvailable(base.TestCase):
25
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010026 identity_version = 'v2'
27
David Kranz8d1a0dc2015-03-13 11:43:37 -040028 def setUp(self):
29 super(TestAdminAvailable, self).setUp()
30 self.useFixture(fake_config.ConfigFixture())
31 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
32
33 def run_test(self, tenant_isolation, use_accounts_file, admin_creds):
34
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070035 cfg.CONF.set_default('use_dynamic_credentials',
David Kranz8d1a0dc2015-03-13 11:43:37 -040036 tenant_isolation, group='auth')
37 if use_accounts_file:
38 accounts = [{'username': 'u1',
39 'tenant_name': 't1',
40 'password': 'p'},
41 {'username': 'u2',
42 'tenant_name': 't2',
43 'password': 'p'}]
44 if admin_creds == 'role':
45 accounts.append({'username': 'admin',
46 'tenant_name': 'admin',
47 'password': 'p',
48 'roles': ['admin']})
49 elif admin_creds == 'type':
50 accounts.append({'username': 'admin',
51 'tenant_name': 'admin',
52 'password': 'p',
53 'types': ['admin']})
54 self.useFixture(mockpatch.Patch(
Andrea Frittoli (andreaf)f9e01262015-05-22 10:24:12 -070055 'tempest.common.preprov_creds.read_accounts_yaml',
David Kranz8d1a0dc2015-03-13 11:43:37 -040056 return_value=accounts))
Aaron Rosen48070042015-03-30 16:17:11 -070057 cfg.CONF.set_default('test_accounts_file',
58 use_accounts_file, group='auth')
David Kranz8d1a0dc2015-03-13 11:43:37 -040059 self.useFixture(mockpatch.Patch('os.path.isfile',
60 return_value=True))
61 else:
62 self.useFixture(mockpatch.Patch('os.path.isfile',
63 return_value=False))
64 if admin_creds:
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010065 (u, t, p, d) = ('u', 't', 'p', 'd')
David Kranz8d1a0dc2015-03-13 11:43:37 -040066 else:
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010067 (u, t, p, d) = (None, None, None, None)
David Kranz8d1a0dc2015-03-13 11:43:37 -040068
Matthew Treinish16cf1e52015-08-11 10:39:23 -040069 cfg.CONF.set_default('admin_username', u, group='auth')
70 cfg.CONF.set_default('admin_tenant_name', t, group='auth')
71 cfg.CONF.set_default('admin_password', p, group='auth')
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010072 cfg.CONF.set_default('admin_domain_name', d, group='auth')
David Kranz8d1a0dc2015-03-13 11:43:37 -040073
74 expected = admin_creds is not None or tenant_isolation
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010075 observed = credentials.is_admin_available(
76 identity_version=self.identity_version)
David Kranz8d1a0dc2015-03-13 11:43:37 -040077 self.assertEqual(expected, observed)
78
79 # Tenant isolation implies admin so only one test case for True
80 def test__tenant_isolation__accounts_file__no_admin(self):
81 self.run_test(tenant_isolation=True,
82 use_accounts_file=True,
83 admin_creds=None)
84
85 def test__no_tenant_isolation__accounts_file__no_admin(self):
86 self.run_test(tenant_isolation=False,
87 use_accounts_file=True,
88 admin_creds=None)
89
90 def test__no_tenant_isolation__accounts_file__admin_role(self):
91 self.run_test(tenant_isolation=False,
92 use_accounts_file=True,
93 admin_creds='role')
94
95 def test__no_tenant_isolation__accounts_file__admin_type(self):
96 self.run_test(tenant_isolation=False,
97 use_accounts_file=True,
98 admin_creds='type')
99
100 def test__no_tenant_isolation__no_accounts_file__no_admin(self):
101 self.run_test(tenant_isolation=False,
102 use_accounts_file=False,
103 admin_creds=None)
104
105 def test__no_tenant_isolation__no_accounts_file__admin(self):
106 self.run_test(tenant_isolation=False,
107 use_accounts_file=False,
108 admin_creds='role')
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +0100109
110
111class TestAdminAvailableV3(TestAdminAvailable):
112
113 identity_version = 'v3'