diff options
| author | Martin Packman <martin.packman@canonical.com> | 2012-07-18 21:53:27 +0100 |
|---|---|---|
| committer | Martin Packman <martin.packman@canonical.com> | 2012-07-18 23:21:02 +0100 |
| commit | 338ef025c76ae2d81e403f2dd9f0094a52f7ec7a (patch) | |
| tree | b80d96f4a35194fe15c09be3ea93f5a5142b26c8 /nova/api | |
| parent | 758356c512df7f23d112b6ffa6e921991bbae6f6 (diff) | |
| download | nova-338ef025c76ae2d81e403f2dd9f0094a52f7ec7a.tar.gz nova-338ef025c76ae2d81e403f2dd9f0094a52f7ec7a.tar.xz nova-338ef025c76ae2d81e403f2dd9f0094a52f7ec7a.zip | |
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
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/floating_ip_dns.py | 43 |
1 files changed, 17 insertions, 26 deletions
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): |
