diff options
-rw-r--r-- | snaps/openstack/create_project.py | 2 | ||||
-rw-r--r-- | snaps/openstack/tests/create_project_tests.py | 4 | ||||
-rw-r--r-- | snaps/openstack/utils/keystone_utils.py | 34 | ||||
-rw-r--r-- | snaps/openstack/utils/tests/keystone_utils_tests.py | 2 |
4 files changed, 26 insertions, 16 deletions
diff --git a/snaps/openstack/create_project.py b/snaps/openstack/create_project.py index a20033e..1fbaef6 100644 --- a/snaps/openstack/create_project.py +++ b/snaps/openstack/create_project.py @@ -48,7 +48,7 @@ class OpenStackProject: """ self.__keystone = keystone_utils.keystone_client(self.__os_creds) self.__project = keystone_utils.get_project( - keystone=self.__keystone, project_name=self.project_settings.name) + keystone=self.__keystone, project_settings=self.project_settings) if self.__project: logger.info( 'Found project with name - ' + self.project_settings.name) diff --git a/snaps/openstack/tests/create_project_tests.py b/snaps/openstack/tests/create_project_tests.py index f388ba5..96d71f2 100644 --- a/snaps/openstack/tests/create_project_tests.py +++ b/snaps/openstack/tests/create_project_tests.py @@ -123,7 +123,7 @@ class CreateProjectSuccessTests(OSComponentTestCase): self.assertIsNotNone(created_project) retrieved_project = keystone_utils.get_project( - keystone=self.keystone, project_name=self.project_settings.name) + keystone=self.keystone, project_settings=self.project_settings) self.assertIsNotNone(retrieved_project) self.assertEqual(created_project, retrieved_project) self.assertTrue(validate_project(self.keystone, self.project_settings, @@ -140,7 +140,7 @@ class CreateProjectSuccessTests(OSComponentTestCase): self.assertIsNotNone(created_project) retrieved_project = keystone_utils.get_project( - keystone=self.keystone, project_name=self.project_settings.name) + keystone=self.keystone, project_settings=self.project_settings) self.assertIsNotNone(retrieved_project) self.assertEqual(created_project, retrieved_project) diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py index 3fff469..99779ee 100644 --- a/snaps/openstack/utils/keystone_utils.py +++ b/snaps/openstack/utils/keystone_utils.py @@ -104,18 +104,17 @@ def get_endpoint(os_creds, service_type, interface='public'): auth=auth, service_type=service_type, interface=interface) -def get_project(keystone=None, os_creds=None, project_name=None): +def get_project(keystone=None, os_creds=None, project_settings=None, + project_name=None): """ Returns the first project object or None if not found :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 ProjectSettings object :param project_name: the name to query :return: the SNAPS-OO Project domain object or None """ - if not project_name: - return None - if not keystone: if os_creds: keystone = keystone_client(os_creds) @@ -123,21 +122,30 @@ def get_project(keystone=None, os_creds=None, project_name=None): raise KeystoneException( 'Cannot lookup project without the proper credentials') + proj_filter = dict() + + if project_name: + proj_filter['name'] = project_name + elif project_settings: + proj_filter['name'] = project_settings.name + proj_filter['description'] = project_settings.description + proj_filter['domain'] = project_settings.domain + proj_filter['enabled'] = project_settings.enabled + if keystone.version == V2_VERSION_STR: projects = keystone.tenants.list() else: - projects = keystone.projects.list(**{'name': project_name}) + projects = keystone.projects.list(**proj_filter) for project in projects: - domain_id = None - if keystone.version != V2_VERSION_STR: - domain_id = project.domain_id - if project.name == project_name: + if project.name == proj_filter['name']: + domain_id = None + if keystone.version != V2_VERSION_STR: + domain_id = project.domain_id + return Project(name=project.name, project_id=project.id, domain_id=domain_id) - return None - def create_project(keystone, project_settings): """ @@ -193,7 +201,9 @@ def get_user(keystone, username, project_name=None): :param project_name: the associated project (optional) :return: a SNAPS-OO User domain object or None """ - project = get_project(keystone=keystone, project_name=project_name) + project = None + if project_name: + project = get_project(keystone=keystone, project_name=project_name) if project: users = keystone.users.list(tenant_id=project.id) diff --git a/snaps/openstack/utils/tests/keystone_utils_tests.py b/snaps/openstack/utils/tests/keystone_utils_tests.py index fad9041..3aa275d 100644 --- a/snaps/openstack/utils/tests/keystone_utils_tests.py +++ b/snaps/openstack/utils/tests/keystone_utils_tests.py @@ -104,7 +104,7 @@ class KeystoneUtilsTests(OSComponentTestCase): self.assertEqual(self.project_name, self.project.name) project = keystone_utils.get_project( - keystone=self.keystone, project_name=project_settings.name) + keystone=self.keystone, project_settings=project_settings) self.assertIsNotNone(project) self.assertEqual(self.project_name, self.project.name) |