summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/utils/keystone_utils.py
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2018-02-22 11:42:52 -0700
committerspisarski <s.pisarski@cablelabs.com>2018-02-22 11:42:52 -0700
commitc711acf8ae3e4ad6f746500747857bcc9fd6f7be (patch)
tree4eeba467b4f42b37e935ccfff6b547bd11c65778 /snaps/openstack/utils/keystone_utils.py
parentf3553913925b8ee5869c8e06047d6e4161a968c7 (diff)
Changed pattern on how objects lookup themselves by name and project.
The pattern being replaced has unwittingly added the requirement that all creator credentials must be of type 'admin' as when looking up the associated project ID required a call to keystone.projects.list(). As the SNAPS integration tests were always creating users with an 'admin' role, this issue was not caught. As part of this patch, integration test users will no longer be admin. JIRA: SNAPS-274 Change-Id: I02957f69e31a9d4dfa63362d371f061687e59fbf Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/openstack/utils/keystone_utils.py')
-rw-r--r--snaps/openstack/utils/keystone_utils.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py
index 6262d06..263f823 100644
--- a/snaps/openstack/utils/keystone_utils.py
+++ b/snaps/openstack/utils/keystone_utils.py
@@ -18,6 +18,7 @@ from keystoneclient.client import Client
from keystoneauth1.identity import v3, v2
from keystoneauth1 import session
import requests
+from keystoneclient.exceptions import NotFound
from snaps.domain.project import Project, Domain
from snaps.domain.role import Role
@@ -105,26 +106,16 @@ def get_endpoint(os_creds, service_type, interface='public'):
interface=interface)
-def get_project(keystone=None, os_creds=None, project_settings=None,
- project_name=None):
+def get_project(keystone=None, project_settings=None, project_name=None):
"""
Returns the first project where the project_settings is used for the query
if not None, else the project_name parameter is used for the query. If both
parameters are None, None is returned
:param keystone: the Keystone client
- :param os_creds: the OpenStack credentials used to obtain the Keystone
- client if the keystone parameter is None
:param project_settings: a ProjectConfig object
:param project_name: the name to query
:return: the SNAPS-OO Project domain object or None
"""
- if not keystone:
- if os_creds:
- keystone = keystone_client(os_creds)
- else:
- raise KeystoneException(
- 'Cannot lookup project without the proper credentials')
-
proj_filter = dict()
if project_name:
@@ -152,6 +143,26 @@ def get_project(keystone=None, os_creds=None, project_settings=None,
domain_id=domain_id)
+def get_project_by_id(keystone, proj_id):
+ """
+ Returns the first project where the project_settings is used for the query
+ if not None, else the project_name parameter is used for the query. If both
+ parameters are None, None is returned
+ :param keystone: the Keystone client
+ :param proj_id: the project ID
+ """
+ if proj_id and len(proj_id) > 0:
+ try:
+ os_proj = keystone.projects.get(proj_id)
+ if os_proj:
+ return Project(name=os_proj.name, project_id=os_proj.id,
+ domain_id=os_proj)
+ except NotFound:
+ pass
+ except KeyError:
+ pass
+
+
def create_project(keystone, project_settings):
"""
Creates a project
@@ -237,8 +248,8 @@ def create_user(keystone, user_settings):
"""
project = None
if user_settings.project_name:
- project = get_project(keystone=keystone,
- project_name=user_settings.project_name)
+ project = get_project(
+ keystone=keystone, project_name=user_settings.project_name)
if keystone.version == V2_VERSION_STR:
project_id = None