blob: 5c69c5e44d8a923883ba7b726402a6c5769a05f3 [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
26 def setUp(self):
27 super(TestAdminAvailable, self).setUp()
28 self.useFixture(fake_config.ConfigFixture())
29 self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate)
30
31 def run_test(self, tenant_isolation, use_accounts_file, admin_creds):
32
33 cfg.CONF.set_default('allow_tenant_isolation',
34 tenant_isolation, group='auth')
35 if use_accounts_file:
36 accounts = [{'username': 'u1',
37 'tenant_name': 't1',
38 'password': 'p'},
39 {'username': 'u2',
40 'tenant_name': 't2',
41 'password': 'p'}]
42 if admin_creds == 'role':
43 accounts.append({'username': 'admin',
44 'tenant_name': 'admin',
45 'password': 'p',
46 'roles': ['admin']})
47 elif admin_creds == 'type':
48 accounts.append({'username': 'admin',
49 'tenant_name': 'admin',
50 'password': 'p',
51 'types': ['admin']})
52 self.useFixture(mockpatch.Patch(
53 'tempest.common.accounts.read_accounts_yaml',
54 return_value=accounts))
Aaron Rosen48070042015-03-30 16:17:11 -070055 cfg.CONF.set_default('test_accounts_file',
56 use_accounts_file, group='auth')
David Kranz8d1a0dc2015-03-13 11:43:37 -040057 self.useFixture(mockpatch.Patch('os.path.isfile',
58 return_value=True))
59 else:
60 self.useFixture(mockpatch.Patch('os.path.isfile',
61 return_value=False))
62 if admin_creds:
63 (u, t, p) = ('u', 't', 'p')
64 else:
65 (u, t, p) = (None, None, None)
66
67 cfg.CONF.set_default('admin_username', u, group='identity')
68 cfg.CONF.set_default('admin_tenant_name', t, group='identity')
69 cfg.CONF.set_default('admin_password', p, group='identity')
70
71 expected = admin_creds is not None or tenant_isolation
72 observed = credentials.is_admin_available()
73 self.assertEqual(expected, observed)
74
75 # Tenant isolation implies admin so only one test case for True
76 def test__tenant_isolation__accounts_file__no_admin(self):
77 self.run_test(tenant_isolation=True,
78 use_accounts_file=True,
79 admin_creds=None)
80
81 def test__no_tenant_isolation__accounts_file__no_admin(self):
82 self.run_test(tenant_isolation=False,
83 use_accounts_file=True,
84 admin_creds=None)
85
86 def test__no_tenant_isolation__accounts_file__admin_role(self):
87 self.run_test(tenant_isolation=False,
88 use_accounts_file=True,
89 admin_creds='role')
90
91 def test__no_tenant_isolation__accounts_file__admin_type(self):
92 self.run_test(tenant_isolation=False,
93 use_accounts_file=True,
94 admin_creds='type')
95
96 def test__no_tenant_isolation__no_accounts_file__no_admin(self):
97 self.run_test(tenant_isolation=False,
98 use_accounts_file=False,
99 admin_creds=None)
100
101 def test__no_tenant_isolation__no_accounts_file__admin(self):
102 self.run_test(tenant_isolation=False,
103 use_accounts_file=False,
104 admin_creds='role')