From dfc72835df16de12244072068a42c42b4a6fe15e Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Tue, 29 Oct 2013 11:03:44 -0500 Subject: [PATCH 1/2] [rackspace|monitoring] updating BadRequest exceptions to include validation errors --- lib/fog/rackspace.rb | 5 ++++- lib/fog/rackspace/monitoring.rb | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 541e5ae49..15a8211bb 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -64,9 +64,12 @@ module Fog class ServiceUnavailable < ServiceError; end class MethodNotAllowed < ServiceError; end class BadRequest < ServiceError - #TODO - Need to find a better way to print out these validation errors when they are thrown attr_reader :validation_errors + def to_s + "#{super} - #{validation_errors}" + end + def self.slurp(error, service=nil) new_error = super(error) unless new_error.response_data.nil? or new_error.response_data['badRequest'].nil? diff --git a/lib/fog/rackspace/monitoring.rb b/lib/fog/rackspace/monitoring.rb index 33d22d030..0f1a762dc 100644 --- a/lib/fog/rackspace/monitoring.rb +++ b/lib/fog/rackspace/monitoring.rb @@ -13,10 +13,26 @@ module Fog class IdentifierTaken < Fog::Errors::Error; end class ServiceError < Fog::Rackspace::Errors::ServiceError; end class InternalServerError < Fog::Rackspace::Errors::InternalServerError; end - class BadRequest < Fog::Rackspace::Errors::BadRequest; end class Conflict < Fog::Rackspace::Errors::Conflict; end class ServiceUnavailable < Fog::Rackspace::Errors::ServiceUnavailable; end + + class BadRequest < Fog::Rackspace::Errors::BadRequest + attr_reader :validation_errors + + def self.slurp(error, service=nil) + new_error = super(error) + if new_error.response_data && new_error.response_data['details'] + new_error.instance_variable_set(:@validation_errors, new_error.response_data['details']) + end + + status_code = error.response ? error.response.status : nil + new_error.instance_variable_set(:@status_code, status_code) + new_error.set_transaction_id(error, service) + new_error + end + end + requires :rackspace_api_key, :rackspace_username recognizes :rackspace_auth_url recognizes :persistent From 90ae91183a29faaffe4f652bbe27574d0b3511dc Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Tue, 29 Oct 2013 11:03:54 -0500 Subject: [PATCH 2/2] [rackspace] fixing broken tests --- tests/rackspace/requests/monitoring/list_tests.rb | 4 ++-- .../requests/storage/large_object_tests.rb | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/rackspace/requests/monitoring/list_tests.rb b/tests/rackspace/requests/monitoring/list_tests.rb index 0470f3902..208557718 100644 --- a/tests/rackspace/requests/monitoring/list_tests.rb +++ b/tests/rackspace/requests/monitoring/list_tests.rb @@ -39,8 +39,8 @@ Shindo.tests('Fog::Rackspace::Monitoring | list_tests', ['rackspace','rackspace_ tests('#get list of data points').formats(LIST_HEADERS_FORMAT) do options = { :points => 1, - :from => now, - :to => now+SLEEP_TIME + :from => now * 1000, + :to => (now+SLEEP_TIME) * 1000 } account.list_data_points(entity_id,check_id,metric_name,options).data[:headers] end diff --git a/tests/rackspace/requests/storage/large_object_tests.rb b/tests/rackspace/requests/storage/large_object_tests.rb index e8de08b6f..aa122b049 100644 --- a/tests/rackspace/requests/storage/large_object_tests.rb +++ b/tests/rackspace/requests/storage/large_object_tests.rb @@ -306,18 +306,20 @@ Shindo.tests('Fog::Storage[:rackspace] | large object requests', ['rackspace']) tests('#delete_static_large_object with missing container') do response = Fog::Storage[:rackspace].delete_static_large_object('fognoncontainer', 'fog_large_object') + returns(200) { response.status } - returns(0) { response.body["Number Not Found"] } - returns("400 Bad Request") { response.body["Response Status"]} - returns("Invalid bulk delete.") { response.body["Response Body"]} + returns(1) { response.body["Number Not Found"] } + returns("200 OK") { response.body["Response Status"]} + returns("") { response.body["Response Body"]} end tests('#delete_static_large_object with missing manifest') do response = Fog::Storage[:rackspace].delete_static_large_object(@directory.identity, 'fog_non_object') + returns(200) { response.status } - returns(0) { response.body["Number Not Found"] } - returns("400 Bad Request") { response.body["Response Status"]} - returns("Invalid bulk delete.") { response.body["Response Body"]} + returns(1) { response.body["Number Not Found"] } + returns("200 OK") { response.body["Response Status"]} + returns("") { response.body["Response Body"]} end tests('#delete_static_large_object with missing segment') do