From c5446107911f8164673a87b4f56f41bc75f1e216 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Sun, 9 Dec 2012 16:51:07 -0500 Subject: [PATCH] OpenStack custom exception cleanup. Fixes an exception class name error for the custom OpenStack ServiceUnavailable exception. Previously the wrong class name was being used. Also cleans up and simplifies some other exceptions in the OpenStack implementation. (We can simply use NotFound from Fog::Errors instead) --- lib/fog/openstack.rb | 9 +++------ lib/fog/openstack/compute.rb | 3 ++- tests/openstack/authenticate_tests.rb | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/fog/openstack.rb b/lib/fog/openstack.rb index fe183789b..0cf9b1a97 100644 --- a/lib/fog/openstack.rb +++ b/lib/fog/openstack.rb @@ -26,9 +26,6 @@ module Fog end end - class InternalServerError < ServiceError; end - class Conflict < ServiceError; end - class NotFound < ServiceError; end class ServiceUnavailable < ServiceError; end class BadRequest < ServiceError @@ -103,7 +100,7 @@ module Fog body = Fog::JSON.decode(response.body) if body['tenants'].empty? - raise Errors::NotFound.new('No Tenant Found') + raise Fog::Errors::NotFound.new('No Tenant Found') else options[:openstack_tenant] = body['tenants'].first['name'] end @@ -127,12 +124,12 @@ module Fog message = "Could not find service #{missing}. Have #{available}" - raise Errors::NotFound, message + raise Fog::Errors::NotFound, message end if service['endpoints'].count > 1 regions = service["endpoints"].map{ |e| e['region'] }.uniq.join(',') - raise Errors::NotFound.new("Multiple regions available choose one of these '#{regions}'") + raise Fog::Errors::NotFound.new("Multiple regions available choose one of these '#{regions}'") end identity_service = body['access']['serviceCatalog']. diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index 9539cbb54..1efc9bbc1 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -372,6 +372,7 @@ module Fog } if @openstack_auth_uri.path =~ /\/v2.0\// + credentials = Fog::OpenStack.authenticate_v2(options, @connection_options) else credentials = Fog::OpenStack.authenticate_v1(options, @connection_options) @@ -393,7 +394,7 @@ module Fog @path.sub!(/\/$/, '') unless @path.match(/1\.1|v2/) - raise Fog::Compute::OpenStack::ServiceUnavailable.new( + raise Fog::OpenStack::Errors::ServiceUnavailable.new( "OpenStack binding only supports version 2 (a.k.a. 1.1)") end diff --git a/tests/openstack/authenticate_tests.rb b/tests/openstack/authenticate_tests.rb index 55490f599..38dd519a0 100644 --- a/tests/openstack/authenticate_tests.rb +++ b/tests/openstack/authenticate_tests.rb @@ -93,7 +93,7 @@ Shindo.tests('OpenStack | authenticate', ['openstack']) do Excon.stub({ :method => 'POST', :path => "/v2.0/tokens" }, { :status => 200, :body => Fog::JSON.encode(body) }) - raises(Fog::OpenStack::Errors::NotFound, + raises(Fog::Errors::NotFound, 'Could not find service network. Have compute, image') do Fog::OpenStack.authenticate_v2( :openstack_auth_uri => URI('http://example/v2.0/tokens'),