Add possibility to create subprojects in cloud layer
Add previously missing support for managing sub-projects. Since this is not really working in v2 we depend on dropping v2 support from cloud layer. Change-Id: Ibcfe5d6233c4f1728229f5f1107aada459f7434a
This commit is contained in:
@@ -88,8 +88,9 @@ class IdentityCloudMixin(_normalize.Normalizer):
|
||||
return _utils._get_entity(self, 'project', name_or_id, filters,
|
||||
domain_id=domain_id)
|
||||
|
||||
def update_project(self, name_or_id, enabled=None, domain_id=None,
|
||||
**kwargs):
|
||||
def update_project(
|
||||
self, name_or_id, enabled=None, domain_id=None, **kwargs
|
||||
):
|
||||
|
||||
project = self.identity.find_project(
|
||||
name_or_id=name_or_id,
|
||||
@@ -104,7 +105,7 @@ class IdentityCloudMixin(_normalize.Normalizer):
|
||||
return project
|
||||
|
||||
def create_project(
|
||||
self, name, domain_id, description=None, enabled=True):
|
||||
self, name, domain_id, description=None, enabled=True, **kwargs):
|
||||
"""Create a project."""
|
||||
attrs = dict(
|
||||
name=name,
|
||||
@@ -112,6 +113,8 @@ class IdentityCloudMixin(_normalize.Normalizer):
|
||||
domain_id=domain_id,
|
||||
is_enabled=enabled
|
||||
)
|
||||
if kwargs:
|
||||
attrs.update(kwargs)
|
||||
return self.identity.create_project(**attrs)
|
||||
|
||||
def delete_project(self, name_or_id, domain_id=None):
|
||||
|
||||
@@ -37,7 +37,7 @@ from openstack.tests import fakes
|
||||
_ProjectData = collections.namedtuple(
|
||||
'ProjectData',
|
||||
'project_id, project_name, enabled, domain_id, description, '
|
||||
'json_response, json_request')
|
||||
'parent_id, json_response, json_request')
|
||||
|
||||
|
||||
_UserData = collections.namedtuple(
|
||||
@@ -247,9 +247,11 @@ class TestCase(base.TestCase):
|
||||
|
||||
def _get_project_data(self, project_name=None, enabled=None,
|
||||
domain_id=None, description=None, v3=True,
|
||||
project_id=None):
|
||||
project_id=None, parent_id=None):
|
||||
project_name = project_name or self.getUniqueString('projectName')
|
||||
project_id = uuid.UUID(project_id or uuid.uuid4().hex).hex
|
||||
if parent_id:
|
||||
parent_id = uuid.UUID(parent_id).hex
|
||||
response = {'id': project_id, 'name': project_name}
|
||||
request = {'name': project_name}
|
||||
domain_id = (domain_id or uuid.uuid4().hex) if v3 else None
|
||||
@@ -260,6 +262,9 @@ class TestCase(base.TestCase):
|
||||
enabled = bool(enabled)
|
||||
response['enabled'] = enabled
|
||||
request['enabled'] = enabled
|
||||
if parent_id:
|
||||
request['parent_id'] = parent_id
|
||||
response['parent_id'] = parent_id
|
||||
response.setdefault('enabled', True)
|
||||
request.setdefault('enabled', True)
|
||||
if description:
|
||||
@@ -267,8 +272,8 @@ class TestCase(base.TestCase):
|
||||
request['description'] = description
|
||||
request.setdefault('description', None)
|
||||
return _ProjectData(project_id, project_name, enabled, domain_id,
|
||||
description, {'project': response},
|
||||
{'project': request})
|
||||
description, parent_id,
|
||||
{'project': response}, {'project': request})
|
||||
|
||||
def _get_group_data(self, name=None, domain_id=None, description=None):
|
||||
group_id = uuid.uuid4().hex
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
import uuid
|
||||
|
||||
import openstack.cloud
|
||||
import openstack.cloud._utils
|
||||
@@ -36,7 +37,8 @@ class TestProject(base.TestCase):
|
||||
|
||||
def test_create_project_v3(self,):
|
||||
project_data = self._get_project_data(
|
||||
description=self.getUniqueString('projectDesc'))
|
||||
description=self.getUniqueString('projectDesc'),
|
||||
parent_id=uuid.uuid4().hex)
|
||||
reference_req = project_data.json_request.copy()
|
||||
reference_req['project']['enabled'] = True
|
||||
self.register_uris([
|
||||
@@ -49,7 +51,8 @@ class TestProject(base.TestCase):
|
||||
project = self.cloud.create_project(
|
||||
name=project_data.project_name,
|
||||
description=project_data.description,
|
||||
domain_id=project_data.domain_id)
|
||||
domain_id=project_data.domain_id,
|
||||
parent_id=project_data.parent_id)
|
||||
self.assertThat(project.id, matchers.Equals(project_data.project_id))
|
||||
self.assertThat(
|
||||
project.name, matchers.Equals(project_data.project_name))
|
||||
|
||||
Reference in New Issue
Block a user