blob: 1b450ab9f538c86f6d69ed1188a026c6f7482507 [file] [log] [blame]
Andrea Frittoli8283b4e2014-07-17 13:28:58 +01001# Copyright (c) 2014 Deutsche Telekom AG
2# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
Marc Kodererd2690fe2014-07-16 14:17:47 +02003# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain 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,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import abc
Matthew Treinish96e9e882014-06-09 18:37:19 -040016
Marc Kodererd2690fe2014-07-16 14:17:47 +020017import six
18
Andrea Frittoli (andreaf)db9672e2016-02-23 14:07:24 -050019from tempest.lib import auth
Andrea Frittoli (andreaf)af4f7cf2016-06-13 15:12:26 +010020from tempest.lib import exceptions
Marc Kodererd2690fe2014-07-16 14:17:47 +020021
Andrea Frittoli878d5ab2015-01-30 13:22:50 +000022
Marc Kodererd2690fe2014-07-16 14:17:47 +020023@six.add_metaclass(abc.ABCMeta)
24class CredentialProvider(object):
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010025 def __init__(self, identity_version, name=None, network_resources=None,
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010026 credentials_domain=None, admin_role=None):
Andrea Frittolic3280152015-02-26 12:42:34 +000027 """A CredentialProvider supplies credentials to test classes.
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000028
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010029 :param identity_version: Identity version of the credentials provided
Ken'ichi Ohmichi592eb132015-07-01 04:08:30 +000030 :param name: Name of the calling test. Included in provisioned
31 credentials when credentials are provisioned on the fly
32 :param network_resources: Network resources required for the
33 credentials
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010034 :param credentials_domain: Domain credentials belong to
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010035 :param admin_role: Name of the role of the admin account
Andrea Frittolic3280152015-02-26 12:42:34 +000036 """
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010037 self.identity_version = identity_version
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010038 self.name = name or "test_creds"
39 self.network_resources = network_resources
40 self.credentials_domain = credentials_domain or 'Default'
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010041 self.admin_role = admin_role
Andrea Frittolic3280152015-02-26 12:42:34 +000042 if not auth.is_identity_version_supported(self.identity_version):
43 raise exceptions.InvalidIdentityVersion(
44 identity_version=self.identity_version)
Marc Kodererd2690fe2014-07-16 14:17:47 +020045
46 @abc.abstractmethod
47 def get_primary_creds(self):
48 return
49
50 @abc.abstractmethod
51 def get_admin_creds(self):
52 return
53
54 @abc.abstractmethod
55 def get_alt_creds(self):
56 return
57
58 @abc.abstractmethod
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070059 def clear_creds(self):
Marc Kodererd2690fe2014-07-16 14:17:47 +020060 return
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010061
62 @abc.abstractmethod
63 def is_multi_user(self):
64 return
Yair Fried76488d72014-10-21 10:13:19 +030065
66 @abc.abstractmethod
67 def is_multi_tenant(self):
68 return
Matthew Treinish976e8df2014-12-19 14:21:54 -050069
70 @abc.abstractmethod
71 def get_creds_by_roles(self, roles, force_new=False):
72 return
Matthew Treinish4a596932015-03-06 20:37:01 -050073
74 @abc.abstractmethod
75 def is_role_available(self, role):
76 return
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040077
78
79class TestResources(object):
80 """Readonly Credentials, with network resources added."""
81
82 def __init__(self, credentials):
83 self._credentials = credentials
84 self.network = None
85 self.subnet = None
86 self.router = None
87
88 def __getattr__(self, item):
89 return getattr(self._credentials, item)
90
Andrea Frittoli (andreaf)a1edb2d2016-05-10 16:09:59 +010091 def __str__(self):
92 _format = "Credentials: %s, Network: %s, Subnet: %s, Router: %s"
93 return _format % (self._credentials, self.network, self.subnet,
94 self.router)
95
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040096 def set_resources(self, **kwargs):
Joe H. Rahmea72f2c62016-07-11 16:28:19 +020097 for key in kwargs:
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040098 if hasattr(self, key):
99 setattr(self, key, kwargs[key])
100
101 @property
102 def credentials(self):
103 return self._credentials