From 9c176f586ebaca4cd8f87646804df96711d63976 Mon Sep 17 00:00:00 2001 From: Henry Nash Date: Tue, 1 Mar 2016 09:01:30 +0000 Subject: [PATCH] Deprecate domain driver interface methods Now that domains are represented as projects as domains, we can deprecate the domain driver methods by moving these to the V8 legacy driver interface. These methods are still supported so that older drivers can continue to function. Change-Id: Ic6d11f39cf069aa641ba2dfaf51ccacda72aec4c Partially-Implements: blueprint reseller --- keystone/resource/backends/sql.py | 69 ----------- keystone/resource/core.py | 154 ++++++++++++------------ keystone/tests/unit/test_backend_sql.py | 38 ------ 3 files changed, 77 insertions(+), 184 deletions(-) diff --git a/keystone/resource/backends/sql.py b/keystone/resource/backends/sql.py index b01161b144..39bb4f3b82 100644 --- a/keystone/resource/backends/sql.py +++ b/keystone/resource/backends/sql.py @@ -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' diff --git a/keystone/resource/core.py b/keystone/resource/core.py index d76243b88f..7c58e20a94 100644 --- a/keystone/resource/core.py +++ b/keystone/resource/core.py @@ -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. diff --git a/keystone/tests/unit/test_backend_sql.py b/keystone/tests/unit/test_backend_sql.py index 6aed35ac53..3e16e0aa9d 100644 --- a/keystone/tests/unit/test_backend_sql.py +++ b/keystone/tests/unit/test_backend_sql.py @@ -564,44 +564,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