mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2247 from rackspace/uuid_queues
[rackspace] Adding Default UUID Queue Name
This commit is contained in:
commit
5ca4055eaa
17 changed files with 69 additions and 21 deletions
|
@ -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'
|
||||
|
|
|
@ -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:
|
||||
|
|
23
lib/fog/core/uuid.rb
Normal file
23
lib/fog/core/uuid.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'securerandom'
|
||||
|
||||
module Fog
|
||||
class UUID
|
||||
class << self
|
||||
|
||||
def uuid
|
||||
if supported?
|
||||
SecureRandom.uuid
|
||||
else
|
||||
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
|
|
@ -10,11 +10,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 +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]
|
||||
@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] || {}
|
||||
|
|
10
tests/core/uuid_tests.rb
Normal file
10
tests/core/uuid_tests.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
Shindo.tests('Fog::UUID', 'core') do
|
||||
|
||||
tests('supported?').succeeds do
|
||||
Fog::UUID.supported? == SecureRandom.respond_to?(: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
|
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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}",
|
||||
})
|
||||
|
|
|
@ -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}",
|
||||
})
|
||||
|
|
|
@ -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}",
|
||||
})
|
||||
|
|
|
@ -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}",
|
||||
})
|
||||
|
|
|
@ -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}",
|
||||
}
|
||||
|
|
|
@ -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}",
|
||||
}
|
||||
|
|
|
@ -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,22 @@ 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
|
||||
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
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue