From e0ff3cb304a370267b942969d54de71c1daf0252 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Thu, 10 Oct 2013 09:00:46 -0500 Subject: [PATCH 1/6] Revert "[rackspace] updated shindo helper to add :rackspace_queues_client_id to credentials if it does not already exist. Hopefully this will make it easier to run Rackspace tests" This reverts commit 6efc48d9ebe690a676e5fdeea9183a84f5e3495a. --- lib/fog/core/errors.rb | 3 ++- tests/helper.rb | 4 ---- tests/helpers/mock_helper.rb | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/fog/core/errors.rb b/lib/fog/core/errors.rb index f9d9b7188..7ff06d775 100644 --- a/lib/fog/core/errors.rb +++ b/lib/fog/core/errors.rb @@ -72,7 +72,8 @@ An alternate file may be used by placing its path in the FOG_RC environment vari :libvirt_uri: :rackspace_api_key: :rackspace_username: - :rackspace_queues_client_id: + :rackspace_servicenet: + :rackspace_cdn_ssl: :riakcs_access_key_id: :riakcs_secret_access_key: :stormondemand_username: diff --git a/tests/helper.rb b/tests/helper.rb index c7ba92e27..e9d183aeb 100644 --- a/tests/helper.rb +++ b/tests/helper.rb @@ -21,10 +21,6 @@ Excon.defaults.merge!(:debug_request => true, :debug_response => true) require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper')) -# Live tests will not run for the Rackspace provider without :rackspace_queues_client_id in the .fog file. -# I am anticipating this issue to occur frequently. I am hoping this line mitigates this issue. -Fog.credentials[:rackspace_queues_client_id] ||= 'test-fog-mock-queue' - def lorem_file File.open(File.dirname(__FILE__) + '/lorem.txt', 'r') end diff --git a/tests/helpers/mock_helper.rb b/tests/helpers/mock_helper.rb index e987eba3c..f7c397c17 100644 --- a/tests/helpers/mock_helper.rb +++ b/tests/helpers/mock_helper.rb @@ -75,7 +75,6 @@ if Fog.mock? :libvirt_uri => 'qemu://libvirt/system', :rackspace_api_key => 'rackspace_api_key', :rackspace_username => 'rackspace_username', - :rackspace_queues_client_id => 'test-fog-mock-queue', :riakcs_access_key_id => 'riakcs_access_key_id', :riakcs_secret_access_key => 'riakcs_secret_access_key', :storm_on_demand_username => 'storm_on_demand_username', From c0707cb41d895207bdf6609e03f800c6212b8071 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Thu, 10 Oct 2013 10:24:39 -0500 Subject: [PATCH 2/6] added uuidtools gem to dependencies --- fog.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/fog.gemspec b/fog.gemspec index c1b594885..587cf2593 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -51,6 +51,7 @@ Gem::Specification.new do |s| s.add_dependency('nokogiri', '~>1.5') s.add_dependency('ruby-hmac') s.add_dependency('unicode', "~> 0.4.4") + s.add_dependency('uuidtools', ">= 2.1.0") ## List your development dependencies here. Development dependencies are ## those that are only needed during development From aae2a4f7d9c21a7df4ab11857120f80b6b0f09c6 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Thu, 10 Oct 2013 10:25:35 -0500 Subject: [PATCH 3/6] [rackspace|queues] updated Fog::Rackspace::Queues to generate UUID for client id if it is not provided with one. --- lib/fog/rackspace/queues.rb | 6 ++++-- tests/rackspace/models/queues/claim_tests.rb | 2 +- tests/rackspace/models/queues/claims_tests.rb | 2 +- tests/rackspace/models/queues/message_tests.rb | 2 +- .../rackspace/models/queues/messages_tests.rb | 2 +- tests/rackspace/models/queues/queue_tests.rb | 2 +- tests/rackspace/models/queues/queues_tests.rb | 2 +- tests/rackspace/queues_tests.rb | 18 +++++++++++++++++- tests/rackspace/requests/queues/claim_tests.rb | 4 ++-- .../requests/queues/messages_tests.rb | 4 ++-- .../rackspace/requests/queues/queues_tests.rb | 3 +-- 11 files changed, 32 insertions(+), 15 deletions(-) diff --git a/lib/fog/rackspace/queues.rb b/lib/fog/rackspace/queues.rb index e5bf0e39a..cf3b29b7e 100644 --- a/lib/fog/rackspace/queues.rb +++ b/lib/fog/rackspace/queues.rb @@ -1,4 +1,5 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace')) +require 'uuidtools' module Fog module Rackspace @@ -10,11 +11,12 @@ module Fog class BadRequest < Fog::Rackspace::Errors::BadRequest; end class MethodNotAllowed < Fog::Rackspace::Errors::BadRequest; end - requires :rackspace_api_key, :rackspace_username, :rackspace_queues_client_id + requires :rackspace_api_key, :rackspace_username recognizes :rackspace_auth_url recognizes :rackspace_auth_token recognizes :rackspace_region recognizes :rackspace_queues_url + recognizes :rackspace_queues_client_id model_path 'fog/rackspace/models/queues' @@ -60,7 +62,7 @@ module Fog def initialize(options = {}) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] - @rackspace_queues_client_id = options[:rackspace_queues_client_id] + @rackspace_queues_client_id = options[:rackspace_queues_client_id] || UUIDTools::UUID.random_create.to_s @rackspace_auth_url = options[:rackspace_auth_url] @rackspace_must_reauthenticate = false @connection_options = options[:connection_options] || {} diff --git a/tests/rackspace/models/queues/claim_tests.rb b/tests/rackspace/models/queues/claim_tests.rb index 2203bc53d..f3669e31d 100644 --- a/tests/rackspace/models/queues/claim_tests.rb +++ b/tests/rackspace/models/queues/claim_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | claim', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new queue = service.queues.create({ :name => "fog_queue_#{Time.now.to_i.to_s}", }) diff --git a/tests/rackspace/models/queues/claims_tests.rb b/tests/rackspace/models/queues/claims_tests.rb index 05e6907ad..47ba9d5de 100644 --- a/tests/rackspace/models/queues/claims_tests.rb +++ b/tests/rackspace/models/queues/claims_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | claims', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new queue = service.queues.create({ :name => "fog_queue_#{Time.now.to_i.to_s}", }) diff --git a/tests/rackspace/models/queues/message_tests.rb b/tests/rackspace/models/queues/message_tests.rb index 23fdc952f..fca064839 100644 --- a/tests/rackspace/models/queues/message_tests.rb +++ b/tests/rackspace/models/queues/message_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | message', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new queue = service.queues.create({ :name => "fog_instance_#{Time.now.to_i.to_s}", }) diff --git a/tests/rackspace/models/queues/messages_tests.rb b/tests/rackspace/models/queues/messages_tests.rb index 95d4439fc..ab5bb8796 100644 --- a/tests/rackspace/models/queues/messages_tests.rb +++ b/tests/rackspace/models/queues/messages_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | messages', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new queue = service.queues.create({ :name => "fog_queue_#{Time.now.to_i.to_s}", }) diff --git a/tests/rackspace/models/queues/queue_tests.rb b/tests/rackspace/models/queues/queue_tests.rb index d5de67ae4..b51b72be1 100644 --- a/tests/rackspace/models/queues/queue_tests.rb +++ b/tests/rackspace/models/queues/queue_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | queue', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new options = { :name => "fog_instance_#{Time.now.to_i.to_s}", } diff --git a/tests/rackspace/models/queues/queues_tests.rb b/tests/rackspace/models/queues/queues_tests.rb index a90cfc857..15970aade 100644 --- a/tests/rackspace/models/queues/queues_tests.rb +++ b/tests/rackspace/models/queues/queues_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | queues', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new options = { :name => "fog_instance_#{Time.now.to_i.to_s}", } diff --git a/tests/rackspace/queues_tests.rb b/tests/rackspace/queues_tests.rb index 0f641f398..f7d5828bc 100644 --- a/tests/rackspace/queues_tests.rb +++ b/tests/rackspace/queues_tests.rb @@ -9,7 +9,7 @@ Shindo.tests('Fog::Rackspace::Queues', ['rackspace']) do end tests('#authentication_method') do - @service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + @service = Fog::Rackspace::Queues.new assert_method nil, :authenticate_v2 @@ -97,4 +97,20 @@ Shindo.tests('Fog::Rackspace::Queues', ['rackspace']) do data = @service.queues returns(true) { data.is_a? Array } end + + tests('client_id') do + pending if Fog.mocking? + + tests('should generate uuid if a client id is not provided').succeeds do + service = Fog::Rackspace::Queues.new + service.client_id =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ + end + tests('should use specified uuid').succeeds do + my_uuid = UUIDTools::UUID.random_create.to_s + service = Fog::Rackspace::Queues.new :rackspace_queues_client_id => my_uuid + service.client_id == my_uuid + end + + end + end diff --git a/tests/rackspace/requests/queues/claim_tests.rb b/tests/rackspace/requests/queues/claim_tests.rb index 2272a5ad2..3770d3a01 100644 --- a/tests/rackspace/requests/queues/claim_tests.rb +++ b/tests/rackspace/requests/queues/claim_tests.rb @@ -2,10 +2,10 @@ pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new queue_name = 'fog' + Time.now.to_i.to_s - client_id = 'fog-client-' + Time.now.to_i.to_s + client_id = service.client_id claim_id = nil service.create_queue(queue_name) diff --git a/tests/rackspace/requests/queues/messages_tests.rb b/tests/rackspace/requests/queues/messages_tests.rb index da1d7f8c9..28b30a6e3 100644 --- a/tests/rackspace/requests/queues/messages_tests.rb +++ b/tests/rackspace/requests/queues/messages_tests.rb @@ -2,10 +2,10 @@ Shindo.tests('Fog::Rackspace::Queues | messages_tests', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new queue_name = 'fog' + Time.now.to_i.to_s - client_id = 'fog-client-' + Time.now.to_i.to_s + client_id = service.client_id message_id = nil service.create_queue(queue_name) diff --git a/tests/rackspace/requests/queues/queues_tests.rb b/tests/rackspace/requests/queues/queues_tests.rb index 4ba25f7fb..c4947b5ea 100644 --- a/tests/rackspace/requests/queues/queues_tests.rb +++ b/tests/rackspace/requests/queues/queues_tests.rb @@ -2,7 +2,7 @@ Shindo.tests('Fog::Rackspace::Queues | queue_tests', ['rackspace']) do pending if Fog.mocking? - service = Fog::Rackspace::Queues.new(:rackspace_queues_client_id => 'test_client') + service = Fog::Rackspace::Queues.new tests('success') do @@ -14,7 +14,6 @@ Shindo.tests('Fog::Rackspace::Queues | queue_tests', ['rackspace']) do tests("#list_queues").formats(LIST_QUEUES_FORMAT) do response = service.list_queues - puts response.inspect response.body end From 773104e9dcb700a4873765a1219803cb28f71092 Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Thu, 10 Oct 2013 15:18:43 -0500 Subject: [PATCH 4/6] [core] removing uuidtools dependency; added Fog::UUID class --- fog.gemspec | 1 - lib/fog/core.rb | 1 + lib/fog/core/uuid.rb | 21 +++++++++++++++++++++ tests/core/uuid_tests.rb | 16 ++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 lib/fog/core/uuid.rb create mode 100644 tests/core/uuid_tests.rb diff --git a/fog.gemspec b/fog.gemspec index 587cf2593..c1b594885 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -51,7 +51,6 @@ Gem::Specification.new do |s| s.add_dependency('nokogiri', '~>1.5') s.add_dependency('ruby-hmac') s.add_dependency('unicode', "~> 0.4.4") - s.add_dependency('uuidtools', ">= 2.1.0") ## List your development dependencies here. Development dependencies are ## those that are only needed during development diff --git a/lib/fog/core.rb b/lib/fog/core.rb index b12e54e64..38d618ad6 100644 --- a/lib/fog/core.rb +++ b/lib/fog/core.rb @@ -31,6 +31,7 @@ require 'fog/core/time' require 'fog/core/timeout' require 'fog/core/wait_for' require 'fog/core/class_from_string' +require 'fog/core/uuid' # data exchange specific (to be extracted and used on a per provider basis) require 'fog/xml' diff --git a/lib/fog/core/uuid.rb b/lib/fog/core/uuid.rb new file mode 100644 index 000000000..77ec36de5 --- /dev/null +++ b/lib/fog/core/uuid.rb @@ -0,0 +1,21 @@ +require 'securerandom' + +module Fog + class UUID + class << self + + def uuid + if supported? + SecureRandom.uuid + else + raise "UUID generation is not supported by your ruby implementation. Please try upgrading to Ruby 1.9.x." + end + end + + def supported? + SecureRandom.respond_to?(:uuid) + end + + end + end +end \ No newline at end of file diff --git a/tests/core/uuid_tests.rb b/tests/core/uuid_tests.rb new file mode 100644 index 000000000..a96c03385 --- /dev/null +++ b/tests/core/uuid_tests.rb @@ -0,0 +1,16 @@ +Shindo.tests('Fog::UUID', 'core') do + + tests('supported?').succeeds do + Fog::UUID.supported? == SecureRandom.respond_to?(:uuid) + end + + if Fog::UUID.supported? + tests('success').succeeds do + Fog::UUID.uuid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ + end + else + tests('success').succeeds do + raises(RuntimeError) { Fog::UUID.uuid } + end + end +end \ No newline at end of file From 1a003b8537442eaa9228368c92d69e0cfd2e8f5d Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Thu, 10 Oct 2013 15:19:20 -0500 Subject: [PATCH 5/6] [rackspace|queues] updated to use FOG::UUID --- lib/fog/rackspace/queues.rb | 3 +-- tests/rackspace/queues_tests.rb | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/fog/rackspace/queues.rb b/lib/fog/rackspace/queues.rb index cf3b29b7e..7bd0a39eb 100644 --- a/lib/fog/rackspace/queues.rb +++ b/lib/fog/rackspace/queues.rb @@ -1,5 +1,4 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'rackspace')) -require 'uuidtools' module Fog module Rackspace @@ -62,7 +61,7 @@ module Fog def initialize(options = {}) @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] - @rackspace_queues_client_id = options[:rackspace_queues_client_id] || UUIDTools::UUID.random_create.to_s + @rackspace_queues_client_id = options[:rackspace_queues_client_id] || Fog::UUID.uuid @rackspace_auth_url = options[:rackspace_auth_url] @rackspace_must_reauthenticate = false @connection_options = options[:connection_options] || {} diff --git a/tests/rackspace/queues_tests.rb b/tests/rackspace/queues_tests.rb index f7d5828bc..eaf4e0edb 100644 --- a/tests/rackspace/queues_tests.rb +++ b/tests/rackspace/queues_tests.rb @@ -102,11 +102,13 @@ Shindo.tests('Fog::Rackspace::Queues', ['rackspace']) do pending if Fog.mocking? tests('should generate uuid if a client id is not provided').succeeds do + pending unless Fog::UUID.supported? service = Fog::Rackspace::Queues.new service.client_id =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ end tests('should use specified uuid').succeeds do - my_uuid = UUIDTools::UUID.random_create.to_s + pending unless Fog::UUID.supported? + my_uuid = Fog::UUID.uuid service = Fog::Rackspace::Queues.new :rackspace_queues_client_id => my_uuid service.client_id == my_uuid end From bda470486a25bc529a17a8c3624412dcf3e4552a Mon Sep 17 00:00:00 2001 From: Kyle Rames Date: Fri, 11 Oct 2013 07:51:23 -0500 Subject: [PATCH 6/6] [core] updated UUID to use it's own UUID implementation if one was not available from the ruby lib. --- lib/fog/core/uuid.rb | 6 ++++-- tests/core/uuid_tests.rb | 10 ++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/fog/core/uuid.rb b/lib/fog/core/uuid.rb index 77ec36de5..f4554f313 100644 --- a/lib/fog/core/uuid.rb +++ b/lib/fog/core/uuid.rb @@ -8,14 +8,16 @@ module Fog if supported? SecureRandom.uuid else - raise "UUID generation is not supported by your ruby implementation. Please try upgrading to Ruby 1.9.x." + ary = SecureRandom.random_bytes(16).unpack("NnnnnN") + ary[2] = (ary[2] & 0x0fff) | 0x4000 + ary[3] = (ary[3] & 0x3fff) | 0x8000 + "%08x-%04x-%04x-%04x-%04x%08x" % ary end end def supported? SecureRandom.respond_to?(:uuid) end - end end end \ No newline at end of file diff --git a/tests/core/uuid_tests.rb b/tests/core/uuid_tests.rb index a96c03385..d4dbe1a0a 100644 --- a/tests/core/uuid_tests.rb +++ b/tests/core/uuid_tests.rb @@ -4,13 +4,7 @@ Shindo.tests('Fog::UUID', 'core') do Fog::UUID.supported? == SecureRandom.respond_to?(:uuid) end - if Fog::UUID.supported? - tests('success').succeeds do - Fog::UUID.uuid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ - end - else - tests('success').succeeds do - raises(RuntimeError) { Fog::UUID.uuid } - end + tests('success').succeeds do + Fog::UUID.uuid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ end end \ No newline at end of file