Use tempest.common.identity.identity_utils for project management

This uses identity_utils from tempest.common.identity for
project creation/deletion in non-identity tests:

    A client that abstracts v2 and v3 identity operations.

    This can be used for creating and tearing down projects in tests.
    It should not be used for testing identity features.

This is a common pattern in Tempest and should be used in Patrole, too.

Change-Id: Id87294bd19c7abd92d202b5ba6b49e4aac6c7e42
This commit is contained in:
Felipe Monteiro 2018-08-31 13:56:08 -04:00
parent 842845eaef
commit 1daa06a5b8
2 changed files with 20 additions and 9 deletions

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import identity
from tempest.common import tempest_fixtures as fixtures
from tempest.common import utils
from tempest.lib.common.utils import data_utils
@ -24,6 +25,8 @@ from patrole_tempest_plugin.tests.api.compute import rbac_base
class QuotaClassesRbacTest(rbac_base.BaseV2ComputeRbacTest):
credentials = ['primary', 'admin']
def setUp(self):
# All test cases in this class need to externally lock on doing
# anything with default quota values.
@ -48,11 +51,14 @@ class QuotaClassesRbacTest(rbac_base.BaseV2ComputeRbacTest):
def resource_setup(cls):
super(QuotaClassesRbacTest, cls).resource_setup()
# Create a project with its own quota.
project_name = data_utils.rand_name(cls.__name__ + '-Project')
cls.project_id = cls.identity_projects_client.create_project(
project_name)['project']['id']
project_name = data_utils.rand_name(cls.__name__ + '-project')
project_desc = project_name + '-desc'
project = identity.identity_utils(cls.os_admin).create_project(
name=project_name, description=project_desc)
cls.project_id = project['id']
cls.addClassResourceCleanup(
cls.identity_projects_client.delete_project, cls.project_id)
identity.identity_utils(cls.os_admin).delete_project,
cls.project_id)
@decorators.idempotent_id('c10198ed-9df2-440e-a49b-367dadc6de94')
@rbac_rule_validation.action(

View File

@ -13,9 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import identity
from tempest.common import utils
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
from patrole_tempest_plugin import rbac_rule_validation
@ -24,6 +24,8 @@ from patrole_tempest_plugin.tests.api.compute import rbac_base
class QuotaSetsRbacTest(rbac_base.BaseV2ComputeRbacTest):
credentials = ['primary', 'admin']
@classmethod
def setup_clients(cls):
super(QuotaSetsRbacTest, cls).setup_clients()
@ -89,10 +91,13 @@ class QuotaSetsRbacTest(rbac_base.BaseV2ComputeRbacTest):
def test_delete_quota_set(self):
project_name = data_utils.rand_name(
self.__class__.__name__ + '-project')
project = self.projects_client.create_project(name=project_name)
project_id = project['project']['id']
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.projects_client.delete_project, project_id)
project_desc = project_name + '-desc'
project = identity.identity_utils(self.os_admin).create_project(
name=project_name, description=project_desc)
project_id = project['id']
self.addCleanup(
identity.identity_utils(self.os_admin).delete_project,
project_id)
with self.rbac_utils.override_role(self):
self.quotas_client.delete_quota_set(project_id)