summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/how-to-use/APITests.rst4
-rw-r--r--snaps/domain/project.py4
-rw-r--r--snaps/domain/test/project_tests.py18
-rw-r--r--snaps/openstack/tests/create_project_tests.py38
-rw-r--r--snaps/openstack/utils/keystone_utils.py12
5 files changed, 70 insertions, 6 deletions
diff --git a/docs/how-to-use/APITests.rst b/docs/how-to-use/APITests.rst
index 68a1a07..ff0ab45 100644
--- a/docs/how-to-use/APITests.rst
+++ b/docs/how-to-use/APITests.rst
@@ -91,6 +91,10 @@ create_project_tests.py - CreateProjectSuccessTests
+----------------------------------+---------------+-----------------------------------------------------------+
| Test Name | Keystone API | Description |
+==================================+===============+===========================================================+
+| test_create_project_bad_domain | 3 | Ensures that keystone v3 clients using the domain ID |
+| | | project setting project creation will fail with an invalid|
+| | | domain id/name |
++----------------------------------+---------------+-----------------------------------------------------------+
| test_create_project | 2 & 3 | Tests the creation of a project via the OpenStackProject |
| | | class |
+----------------------------------+---------------+-----------------------------------------------------------+
diff --git a/snaps/domain/project.py b/snaps/domain/project.py
index 818645b..73357c7 100644
--- a/snaps/domain/project.py
+++ b/snaps/domain/project.py
@@ -19,14 +19,16 @@ class Project:
SNAPS domain object for Projects. Should contain attributes that
are shared amongst cloud providers
"""
- def __init__(self, name, project_id):
+ def __init__(self, name, project_id, domain_id=None):
"""
Constructor
:param name: the project's name
:param project_id: the project's id
+ :param domain_id: the project's domain id
"""
self.name = name
self.id = project_id
+ self.domain_id = domain_id
def __eq__(self, other):
return self.name == other.name and self.id == other.id
diff --git a/snaps/domain/test/project_tests.py b/snaps/domain/test/project_tests.py
index 4056bba..73939f0 100644
--- a/snaps/domain/test/project_tests.py
+++ b/snaps/domain/test/project_tests.py
@@ -22,12 +22,26 @@ class ProjectDomainObjectTests(unittest.TestCase):
Tests the construction of the snaps.domain.test.Project class
"""
- def test_construction_positional(self):
+ def test_construction_positional_minimal(self):
project = Project('foo', '123-456')
self.assertEqual('foo', project.name)
self.assertEqual('123-456', project.id)
+ self.assertIsNone(project.domain_id)
- def test_construction_named(self):
+ def test_construction_positional_all(self):
+ project = Project('foo', '123-456', 'hello')
+ self.assertEqual('foo', project.name)
+ self.assertEqual('123-456', project.id)
+ self.assertEqual('hello', project.domain_id)
+
+ def test_construction_named_minimal(self):
project = Project(project_id='123-456', name='foo')
self.assertEqual('foo', project.name)
self.assertEqual('123-456', project.id)
+ self.assertIsNone(project.domain_id)
+
+ def test_construction_named_all(self):
+ project = Project(domain_id='hello', project_id='123-456', name='foo')
+ self.assertEqual('foo', project.name)
+ self.assertEqual('123-456', project.id)
+ self.assertEqual('hello', project.domain_id)
diff --git a/snaps/openstack/tests/create_project_tests.py b/snaps/openstack/tests/create_project_tests.py
index f2af0d9..f388ba5 100644
--- a/snaps/openstack/tests/create_project_tests.py
+++ b/snaps/openstack/tests/create_project_tests.py
@@ -15,6 +15,8 @@
import unittest
import uuid
+from keystoneclient.exceptions import BadRequest
+
from snaps.openstack.create_project import (
OpenStackProject, ProjectSettings, ProjectSettingsError)
from snaps.openstack.create_security_group import OpenStackSecurityGroup
@@ -98,6 +100,19 @@ class CreateProjectSuccessTests(OSComponentTestCase):
if self.project_creator:
self.project_creator.clean()
+ def test_create_project_bad_domain(self):
+ """
+ Tests the creation of an OpenStack project with an invalid domain
+ value. This test will not do anything with a keystone v2.0 client.
+ """
+ if self.keystone.version != keystone_utils.V2_VERSION_STR:
+ self.project_settings.domain = 'foo'
+ self.project_creator = OpenStackProject(self.os_creds,
+ self.project_settings)
+
+ with self.assertRaises(BadRequest):
+ self.project_creator.create()
+
def test_create_project(self):
"""
Tests the creation of an OpenStack project.
@@ -111,6 +126,8 @@ class CreateProjectSuccessTests(OSComponentTestCase):
keystone=self.keystone, project_name=self.project_settings.name)
self.assertIsNotNone(retrieved_project)
self.assertEqual(created_project, retrieved_project)
+ self.assertTrue(validate_project(self.keystone, self.project_settings,
+ created_project))
def test_create_project_2x(self):
"""
@@ -130,6 +147,8 @@ class CreateProjectSuccessTests(OSComponentTestCase):
project2 = OpenStackProject(self.os_creds,
self.project_settings).create()
self.assertEqual(retrieved_project, project2)
+ self.assertTrue(validate_project(self.keystone, self.project_settings,
+ created_project))
def test_create_delete_project(self):
"""
@@ -147,7 +166,8 @@ class CreateProjectSuccessTests(OSComponentTestCase):
self.assertIsNone(self.project_creator.get_project())
- # TODO - Expand tests
+ self.assertTrue(validate_project(self.keystone, self.project_settings,
+ created_project))
class CreateProjectUserTests(OSComponentTestCase):
@@ -254,3 +274,19 @@ class CreateProjectUserTests(OSComponentTestCase):
self.assertEqual(self.project_creator.get_project().id,
sec_grp.project_id)
+
+
+def validate_project(keystone, project_settings, project):
+ """
+ Validates that the project_settings used to create the project have been
+ properly set
+ :param keystone: the keystone client for version checking
+ :param project_settings: the settings used to create the project
+ :param project: the SNAPS-OO Project domain object
+ :return: T/F
+ """
+ if keystone.version == keystone_utils.V2_VERSION_STR:
+ return project_settings.name == project.name
+ else:
+ return (project_settings.name == project.name and
+ project_settings.domain == project.domain_id)
diff --git a/snaps/openstack/utils/keystone_utils.py b/snaps/openstack/utils/keystone_utils.py
index 8446df0..e070a49 100644
--- a/snaps/openstack/utils/keystone_utils.py
+++ b/snaps/openstack/utils/keystone_utils.py
@@ -127,8 +127,12 @@ def get_project(keystone=None, os_creds=None, project_name=None):
projects = keystone.projects.list(**{'name': project_name})
for project in projects:
+ domain_id = None
+ if keystone.version != V2_VERSION_STR:
+ domain_id = project.domain_id
if project.name == project_name:
- return Project(name=project.name, project_id=project.id)
+ return Project(name=project.name, project_id=project.id,
+ domain_id=domain_id)
return None
@@ -140,6 +144,8 @@ def create_project(keystone, project_settings):
:param project_settings: the project configuration
:return: SNAPS-OO Project domain object
"""
+ domain_id = None
+
if keystone.version == V2_VERSION_STR:
os_project = keystone.tenants.create(
project_settings.name, project_settings.description,
@@ -149,8 +155,10 @@ def create_project(keystone, project_settings):
project_settings.name, project_settings.domain,
description=project_settings.description,
enabled=project_settings.enabled)
+ domain_id = os_project.domain_id
- return Project(name=os_project.name, project_id=os_project.id)
+ return Project(
+ name=os_project.name, project_id=os_project.id, domain_id=domain_id)
def delete_project(keystone, project):