1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
from oslo_config import cfg
from tempest.common import credentials_factory as credentials
from tempest import config
from tempest.tests import base
from tempest.tests import fake_config
class TestAdminAvailable(base.TestCase):
identity_version = 'v2'
def setUp(self):
super(TestAdminAvailable, self).setUp()
self.useFixture(fake_config.ConfigFixture())
self.patchobject(config, 'TempestConfigPrivate',
fake_config.FakePrivate)
def run_test(self, dynamic_creds, use_accounts_file, admin_creds):
cfg.CONF.set_default('use_dynamic_credentials',
dynamic_creds, group='auth')
if use_accounts_file:
accounts = [{'username': 'u1',
'project_name': 't1',
'password': 'p'},
{'username': 'u2',
'project_name': 't2',
'password': 'p'}]
if admin_creds == 'role':
accounts.append({'username': 'admin',
'project_name': 'admin',
'password': 'p',
'roles': ['admin']})
elif admin_creds == 'type':
accounts.append({'username': 'admin',
'project_name': 'admin',
'password': 'p',
'types': ['admin']})
self.useFixture(fixtures.MockPatch(
'tempest.lib.common.preprov_creds.read_accounts_yaml',
return_value=accounts))
cfg.CONF.set_default('test_accounts_file',
use_accounts_file, group='auth')
self.useFixture(fixtures.MockPatch('os.path.isfile',
return_value=True))
else:
self.useFixture(fixtures.MockPatch('os.path.isfile',
return_value=False))
if admin_creds:
username = 'u'
project = 't'
password = 'p'
domain = 'd'
else:
username = None
project = None
password = None
domain = None
cfg.CONF.set_default('admin_username', username, group='auth')
cfg.CONF.set_default('admin_project_name', project, group='auth')
cfg.CONF.set_default('admin_password', password, group='auth')
cfg.CONF.set_default('admin_domain_name', domain, group='auth')
expected = admin_creds is not None or dynamic_creds
observed = credentials.is_admin_available(
identity_version=self.identity_version)
self.assertEqual(expected, observed)
# Dynamic credentials implies admin so only one test case for True
def test__dynamic_creds__accounts_file__no_admin(self):
self.run_test(dynamic_creds=True,
use_accounts_file=True,
admin_creds=None)
def test__no_dynamic_creds__accounts_file__no_admin(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
admin_creds=None)
def test__no_dynamic_creds__accounts_file__admin_role(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
admin_creds='role')
def test__no_dynamic_creds__accounts_file__admin_type(self):
self.run_test(dynamic_creds=False,
use_accounts_file=True,
admin_creds='type')
def test__no_dynamic_creds__no_accounts_file__no_admin(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
admin_creds=None)
def test__no_dynamic_creds__no_accounts_file__admin(self):
self.run_test(dynamic_creds=False,
use_accounts_file=False,
admin_creds='role')
class TestAdminAvailableV3(TestAdminAvailable):
identity_version = 'v3'
|