From 338ef025c76ae2d81e403f2dd9f0094a52f7ec7a Mon Sep 17 00:00:00 2001 From: Martin Packman Date: Wed, 18 Jul 2012 21:53:27 +0100 Subject: Tidy up handling of exceptions in floating_ip_dns Removes translation of NotAuthorized which is already handled at a higher level. Also makes delete methods more typical, switches http status code on success to 202 rather than 200, includes details when handling NotFound and adds test coverage. Change-Id: Id59e397891b80b45ea38e42654a6f7f9859379f8 --- .../openstack/compute/contrib/floating_ip_dns.py | 43 +++++++++------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/floating_ip_dns.py b/nova/api/openstack/compute/contrib/floating_ip_dns.py index 788d83b2d..2029ab2aa 100644 --- a/nova/api/openstack/compute/contrib/floating_ip_dns.py +++ b/nova/api/openstack/compute/contrib/floating_ip_dns.py @@ -162,28 +162,21 @@ class FloatingIPDNSDomainController(object): raise webob.exc.HTTPUnprocessableEntity() project = entry.get('project', None) av_zone = entry.get('availability_zone', None) - if (not scope or + if (scope not in ('private', 'public') or project and av_zone or scope == 'private' and project or scope == 'public' and av_zone): raise webob.exc.HTTPUnprocessableEntity() - try: - if scope == 'private': - self.network_api.create_private_dns_domain(context, - fqdomain, - av_zone) - return _translate_domain_entry_view({'domain': fqdomain, - 'scope': scope, - 'availability_zone': av_zone}) - else: - self.network_api.create_public_dns_domain(context, - fqdomain, - project) - return _translate_domain_entry_view({'domain': fqdomain, - 'scope': 'public', - 'project': project}) - except exception.NotAuthorized or exception.AdminRequired: - return webob.Response(status_int=403) + if scope == 'private': + create_dns_domain = self.network_api.create_private_dns_domain + area_name, area = 'availability_zone', av_zone + else: + create_dns_domain = self.network_api.create_public_dns_domain + area_name, area = 'project', project + create_dns_domain(context, fqdomain, area) + return _translate_domain_entry_view({'domain': fqdomain, + 'scope': scope, + area_name: area}) def delete(self, req, id): """Delete the domain identified by id. """ @@ -194,12 +187,10 @@ class FloatingIPDNSDomainController(object): # Delete the whole domain try: self.network_api.delete_dns_domain(context, domain) - except exception.NotAuthorized or exception.AdminRequired: - return webob.Response(status_int=403) - except exception.NotFound: - return webob.Response(status_int=404) + except exception.NotFound as e: + raise webob.exc.HTTPNotFound(explanation=unicode(e)) - return webob.Response(status_int=200) + return webob.Response(status_int=202) class FloatingIPDNSEntryController(object): @@ -280,10 +271,10 @@ class FloatingIPDNSEntryController(object): try: self.network_api.delete_dns_entry(context, name, domain) - except exception.NotFound: - return webob.Response(status_int=404) + except exception.NotFound as e: + raise webob.exc.HTTPNotFound(explanation=unicode(e)) - return webob.Response(status_int=200) + return webob.Response(status_int=202) class Floating_ip_dns(extensions.ExtensionDescriptor): -- cgit