# Pastebin 6OEyeLlH # -*- coding: utf-8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from __future__ import absolute_import import uuid import fixtures class ScopedAuth(fixtures.Fixture): def __init__(self, test_instance, project_name=None, reuse_project=False): self.project_name = project_name or uuid.uuid4().hex self.reuse_project = False self.test_instance = test_instance self.project = None def setUp(self): params = { 'name': self.project_name, 'description': 'Scoped Project Via Fixture' } if self.test_instance.identity_version == '3': params['domain_id'] = \ self.test_instance.operator_cloud.get_domain('default')['id'] self.project = self.test_instance.operator_cloud.create_project( **params) self.test_instance.assertIsNotNone(self.project) # TODO(morgan): Override scope for demo AND operator cloud auth self.addCleanup(self._cleanup_project()) def _cleanup_project(self): if not self.reuse_project: # Cleanup the Project only if we aren't re-using the project params = {'name': self.project_name} if self.test_instance.identity_version == '3': params['domain_id'] = \ self.test_instance.operator_cloud.get_domain( 'default')['id'] self.test_instance.assertTrue( self.test_instance.operator_cloud.delete_project( self.project['id']))