blob: 42ed41b395a8912003ac94e79aea4d93cd0e05e8 [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 Frittolidcd91002017-07-18 11:34:13 +010025 def __init__(self, identity_version, name=None,
26 network_resources=None, credentials_domain=None,
27 admin_role=None, identity_uri=None):
Andrea Frittolic3280152015-02-26 12:42:34 +000028 """A CredentialProvider supplies credentials to test classes.
Ken'ichi Ohmichicb67d2d2015-11-19 08:23:22 +000029
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010030 :param identity_version: Identity version of the credentials provided
Ken'ichi Ohmichi592eb132015-07-01 04:08:30 +000031 :param name: Name of the calling test. Included in provisioned
32 credentials when credentials are provisioned on the fly
33 :param network_resources: Network resources required for the
34 credentials
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010035 :param credentials_domain: Domain credentials belong to
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010036 :param admin_role: Name of the role of the admin account
Andrea Frittolidcd91002017-07-18 11:34:13 +010037 :param identity_uri: Identity URI of the target cloud. This *must* be
38 specified for anything to work.
Andrea Frittolic3280152015-02-26 12:42:34 +000039 """
Andrea Frittoli (andreaf)32d0de12015-10-09 14:43:53 +010040 self.identity_version = identity_version
Andrea Frittolidcd91002017-07-18 11:34:13 +010041 self.identity_uri = identity_uri
Andrea Frittoli (andreaf)1eb04962015-10-09 14:48:06 +010042 self.name = name or "test_creds"
43 self.network_resources = network_resources
44 self.credentials_domain = credentials_domain or 'Default'
Andrea Frittoli (andreaf)29491a72015-10-13 11:24:17 +010045 self.admin_role = admin_role
Andrea Frittolic3280152015-02-26 12:42:34 +000046 if not auth.is_identity_version_supported(self.identity_version):
47 raise exceptions.InvalidIdentityVersion(
48 identity_version=self.identity_version)
Marc Kodererd2690fe2014-07-16 14:17:47 +020049
50 @abc.abstractmethod
51 def get_primary_creds(self):
52 return
53
54 @abc.abstractmethod
55 def get_admin_creds(self):
56 return
57
58 @abc.abstractmethod
59 def get_alt_creds(self):
60 return
61
62 @abc.abstractmethod
Andrea Frittoli (andreaf)17209bb2015-05-22 10:16:57 -070063 def clear_creds(self):
Marc Kodererd2690fe2014-07-16 14:17:47 +020064 return
Andrea Frittoli8283b4e2014-07-17 13:28:58 +010065
66 @abc.abstractmethod
67 def is_multi_user(self):
68 return
Yair Fried76488d72014-10-21 10:13:19 +030069
70 @abc.abstractmethod
71 def is_multi_tenant(self):
72 return
Matthew Treinish976e8df2014-12-19 14:21:54 -050073
74 @abc.abstractmethod
75 def get_creds_by_roles(self, roles, force_new=False):
76 return
Matthew Treinish4a596932015-03-06 20:37:01 -050077
78 @abc.abstractmethod
79 def is_role_available(self, role):
80 return
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -040081
82
83class TestResources(object):
84 """Readonly Credentials, with network resources added."""
85
86 def __init__(self, credentials):
87 self._credentials = credentials
88 self.network = None
89 self.subnet = None
90 self.router = None
91
92 def __getattr__(self, item):
93 return getattr(self._credentials, item)
94
Andrea Frittoli (andreaf)a1edb2d2016-05-10 16:09:59 +010095 def __str__(self):
96 _format = "Credentials: %s, Network: %s, Subnet: %s, Router: %s"
97 return _format % (self._credentials, self.network, self.subnet,
98 self.router)
99
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400100 def set_resources(self, **kwargs):
Joe H. Rahmea72f2c62016-07-11 16:28:19 +0200101 for key in kwargs:
Andrea Frittoli (andreaf)9540dfd2015-03-25 17:06:50 -0400102 if hasattr(self, key):
103 setattr(self, key, kwargs[key])
104
105 @property
106 def credentials(self):
107 return self._credentials