Merge "Deprecate domain driver interface methods"

This commit is contained in:
Jenkins 2016-03-01 20:49:40 +00:00 committed by Gerrit Code Review
commit 19bd12b74c
3 changed files with 77 additions and 184 deletions

View File

@ -223,75 +223,6 @@ class Resource(keystone_resource.ResourceDriverV9):
'deleted.') % project_id)
query.delete(synchronize_session=False)
# domain crud
@sql.handle_conflicts(conflict_type='domain')
def create_domain(self, domain_id, domain):
with sql.session_for_write() as session:
ref = Domain.from_dict(domain)
session.add(ref)
return ref.to_dict()
@driver_hints.truncated
def list_domains(self, hints):
with sql.session_for_read() as session:
query = session.query(Domain)
refs = sql.filter_limit_query(Domain, query, hints)
return [ref.to_dict() for ref in refs
if not self._is_hidden_ref(ref)]
def list_domains_from_ids(self, ids):
if not ids:
return []
else:
with sql.session_for_read() as session:
query = session.query(Domain)
query = query.filter(Domain.id.in_(ids))
domain_refs = query.all()
return [domain_ref.to_dict() for domain_ref in domain_refs
if not self._is_hidden_ref(domain_ref)]
def _get_domain(self, session, domain_id):
ref = session.query(Domain).get(domain_id)
if ref is None or self._is_hidden_ref(ref):
raise exception.DomainNotFound(domain_id=domain_id)
return ref
def get_domain(self, domain_id):
with sql.session_for_read() as session:
return self._get_domain(session, domain_id).to_dict()
def get_domain_by_name(self, domain_name):
with sql.session_for_read() as session:
try:
ref = (session.query(Domain).
filter_by(name=domain_name).one())
except sql.NotFound:
raise exception.DomainNotFound(domain_id=domain_name)
if self._is_hidden_ref(ref):
raise exception.DomainNotFound(domain_id=domain_name)
return ref.to_dict()
@sql.handle_conflicts(conflict_type='domain')
def update_domain(self, domain_id, domain):
with sql.session_for_write() as session:
ref = self._get_domain(session, domain_id)
old_dict = ref.to_dict()
for k in domain:
old_dict[k] = domain[k]
new_domain = Domain.from_dict(old_dict)
for attr in Domain.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_domain, attr))
ref.extra = new_domain.extra
return ref.to_dict()
def delete_domain(self, domain_id):
with sql.session_for_write() as session:
ref = self._get_domain(session, domain_id)
session.delete(ref)
class Domain(sql.ModelBase, sql.DictBase):
__tablename__ = 'domain'

View File

@ -930,83 +930,6 @@ class ResourceDriverBase(object):
def _get_list_limit(self):
return CONF.resource.list_limit or CONF.list_limit
# domain crud
@abc.abstractmethod
def create_domain(self, domain_id, domain):
"""Creates a new domain.
:raises keystone.exception.Conflict: if the domain_id or domain name
already exists
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_domains(self, hints):
"""List domains in the system.
:param hints: filter hints which the driver should
implement if at all possible.
:returns: a list of domain_refs or an empty list.
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_domains_from_ids(self, domain_ids):
"""List domains for the provided list of ids.
:param domain_ids: list of ids
:returns: a list of domain_refs.
This method is used internally by the assignment manager to bulk read
a set of domains given their ids.
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def get_domain(self, domain_id):
"""Get a domain by ID.
:returns: domain_ref
:raises keystone.exception.DomainNotFound: if domain_id does not exist
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def get_domain_by_name(self, domain_name):
"""Get a domain by name.
:returns: domain_ref
:raises keystone.exception.DomainNotFound: if domain_name does not
exist
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def update_domain(self, domain_id, domain):
"""Updates an existing domain.
:raises keystone.exception.DomainNotFound: if domain_id does not exist
:raises keystone.exception.Conflict: if domain name already exists
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def delete_domain(self, domain_id):
"""Deletes an existing domain.
:raises keystone.exception.DomainNotFound: if domain_id does not exist
"""
raise exception.NotImplemented() # pragma: no cover
# project crud
@abc.abstractmethod
def create_project(self, project_id, project):
@ -1197,6 +1120,83 @@ class ResourceDriverV8(ResourceDriverBase):
else:
raise ValueError(_('Expected dict or list: %s') % type(ref))
# domain crud
@abc.abstractmethod
def create_domain(self, domain_id, domain):
"""Creates a new domain.
:raises keystone.exception.Conflict: if the domain_id or domain name
already exists
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_domains(self, hints):
"""List domains in the system.
:param hints: filter hints which the driver should
implement if at all possible.
:returns: a list of domain_refs or an empty list.
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_domains_from_ids(self, domain_ids):
"""List domains for the provided list of ids.
:param domain_ids: list of ids
:returns: a list of domain_refs.
This method is used internally by the assignment manager to bulk read
a set of domains given their ids.
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def get_domain(self, domain_id):
"""Get a domain by ID.
:returns: domain_ref
:raises keystone.exception.DomainNotFound: if domain_id does not exist
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def get_domain_by_name(self, domain_name):
"""Get a domain by name.
:returns: domain_ref
:raises keystone.exception.DomainNotFound: if domain_name does not
exist
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def update_domain(self, domain_id, domain):
"""Updates an existing domain.
:raises keystone.exception.DomainNotFound: if domain_id does not exist
:raises keystone.exception.Conflict: if domain name already exists
"""
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def delete_domain(self, domain_id):
"""Deletes an existing domain.
:raises keystone.exception.DomainNotFound: if domain_id does not exist
"""
raise exception.NotImplemented() # pragma: no cover
class ResourceDriverV9(ResourceDriverBase):
"""New or redefined methods from V8.

View File

@ -611,44 +611,6 @@ class SqlIdentity(SqlTests, test_backend.IdentityTests):
_exercise_project_api(uuid.uuid4().hex)
_exercise_project_api(resource.NULL_DOMAIN_ID)
def test_hidden_domain_root_is_really_hidden(self):
"""Ensure we cannot access the hidden root of all domains.
Calling any of the driver methods should result in the same as
would be returned if we passed a domain that does not exist. We don't
test create_domain, since we do not allow a caller of our API to
specify their own ID for a new entity.
"""
def _exercise_domain_api(ref_id):
driver = self.resource_api.driver
self.assertRaises(exception.DomainNotFound,
driver.get_domain,
ref_id)
self.assertRaises(exception.DomainNotFound,
driver.get_domain_by_name,
resource.NULL_DOMAIN_ID)
domain_ids = [x['id'] for x in
driver.list_domains(driver_hints.Hints())]
self.assertNotIn(ref_id, domain_ids)
domains = driver.list_domains_from_ids([ref_id])
self.assertThat(domains, matchers.HasLength(0))
self.assertRaises(exception.DomainNotFound,
driver.update_domain,
ref_id,
{})
self.assertRaises(exception.DomainNotFound,
driver.delete_domain,
ref_id)
_exercise_domain_api(uuid.uuid4().hex)
_exercise_domain_api(resource.NULL_DOMAIN_ID)
class SqlTrust(SqlTests, test_backend.TrustTests):
pass