1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

The fake service catalog matches format.

This commit is contained in:
Ash Wilson 2013-12-13 17:28:48 -05:00
parent 2688b366e5
commit 08ceadeb1a
3 changed files with 214 additions and 223 deletions

View file

@ -25,7 +25,7 @@ module Fog
def create_token(username, api_key) def create_token(username, api_key)
unless username == 'baduser' unless username == 'baduser'
compute_tenant = Fog::Mock.random_numbers(6) compute_tenant = Fog::Mock.random_numbers(6)
object_tenant = Fog::Mock object_tenant = generate_object_tenant
response = Excon::Response.new response = Excon::Response.new
response.status = 200 response.status = 200
@ -34,29 +34,25 @@ module Fog
"token"=> { "token"=> {
"id" => Fog::Mock.random_hex(32), "id" => Fog::Mock.random_hex(32),
"expires" => (Time.now.utc + 86400).strftime("%Y-%m-%dT%H:%M:%S.%LZ"), "expires" => (Time.now.utc + 86400).strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
"tenant" => { "id" => tenant, "name" => tenant }, "tenant" => { "id" => compute_tenant, "name" => compute_tenant }
"RAX-AUTH:authenticatedBy" => ["APIKEY"]
}, },
"serviceCatalog" => build_service_catalog(compute_tenant, object_tenant)
"user" => { "user" => {
"id" => Fog::Mock.random_numbers(6), "id" => Fog::Mock.random_numbers(6),
"name" => username,
"roles" => [ "roles" => [
{ {
"tenantId" => object_tenant,
"id" => Fog::Mock.random_numbers(1), "id" => Fog::Mock.random_numbers(1),
"description" => "Fake Role for an object store", "description" => "Fake Role for an object store",
"name" => "object-store:default" "name" => "object-store:default"
}, },
{ {
"tenantId" => compute_tenant,
"id" => Fog::Mock.random_numbers(1), "id" => Fog::Mock.random_numbers(1),
"description" => "Fake Role for a compute cluster", "description" => "Fake Role for a compute cluster",
"name" => "compute:default" "name" => "compute:default"
} }
], ]
"name" => username, },
"RAX-AUTH:defaultRegion" => %w{DFW ORD IAD HKG SYD}[rand[5]] "serviceCatalog" => build_service_catalog(compute_tenant, object_tenant),
}
} }
} }
response response
@ -64,218 +60,218 @@ module Fog
response = Excon::Response.new response = Excon::Response.new
response response
end end
end
# Generate a realistic-looking object tenant ID. # Generate a realistic-looking object tenant ID.
def generate_object_tenant def generate_object_tenant
uuid = [8, 4, 4, 4, 12].map { |n| Fog::Mock.random_hex(n) }.join('_') uuid = [8, 4, 4, 4, 12].map { |n| Fog::Mock.random_hex(n) }.join('_')
"FogMockFS_#{uuid}" "FogMockFS_#{uuid}"
end
# Create a service catalog entry with the provided name and type, and
# "endpoint" sections for each region.
def with_regions(name, type)
endpoints = %w{ORD DFW SYD IAD HKG}.map do |region|
yield region
end end
{ "name" => name, "type" => type, "endpoints" => endpoints }
end
# Create a service catalog entry with the provided name and type, and # Construct a full, fake service catalog.
# "endpoint" sections for each region. def build_service_catalog(compute_tenant, object_tenant)
def with_regions(name, type) [
endpoints = %{ORD DFW SYD IAD HKG}.map do |region| cloud_files_cdn_entry(object_tenant),
yield region cloud_files_entry(object_tenant),
end cloud_monitoring_entry(compute_tenant),
{ "name" => name, "endpoints" => endpoints. "type" => type } cloud_servers_openstack_entry(compute_tenant),
end cloud_block_storage_entry(compute_tenant),
cloud_databases_entry(compute_tenant),
cloud_load_balancers_entry(compute_tenant),
cloud_dns_entry(compute_tenant),
cloud_orchestration_entry(compute_tenant),
cloud_queues_entry(compute_tenant),
cloud_backup_entry(compute_tenant),
cloud_images_entry(compute_tenant),
autoscale_entry(compute_tenant),
cloud_servers_entry(compute_tenant)
]
end
# Construct a full, fake service catalog. def cloud_files_cdn_entry(tenant_id)
def build_service_catalog compute_tenant, object_tenant with_regions("cloudFilesCDN", "rax:object-cdn") do |region|
[ {
cloud_files_cdn_entry(object_tenant), "region" => region,
cloud_files_entry(object_tenant), "tenantId" => tenant_id,
cloud_monitoring_entry(compute_tenant), "publicURL" => "https://cdn#{Fog::Mock.random_numbers(1)}" +
cloud_servers_openstack_entry(compute_tenant),
cloud_block_storage_entry(compute_tenant),
cloud_databases_entry(compute_tenant),
cloud_load_balancers_entry(compute_tenant),
cloud_dns_entry(compute_tenant),
cloud_orchestration_entry(compute_tenant),
cloud_queues_entry(compute_tenant),
cloud_backup_entry(compute_tenant),
cloud_images_entry(compute_tenant),
autoscale_entry(compute_tenant),
cloud_servers_entry(compute_tenant)
]
end
def cloud_files_cdn_entry(tenant_id)
with_regions("cloudFilesCDN", "rax:object-cdn") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://cdn#{Fog::Mock.random_numbers(1)}" +
".clouddrive.com/v1/#{tenant_id}"
}
end
end
def cloud_files_entry(tenant_id)
with_regions("cloudFiles", "object-store") do |region|
postfix = "#{region.downcase}#{Fog::Mock.random_numbers(1)}" +
".clouddrive.com/v1/#{tenant_id}" ".clouddrive.com/v1/#{tenant_id}"
{
"region" => region,
"tenant_id" => tenant_id,
"publicURL" => "https://storage101.#{postfix}",
"internalURL" => "https://snet-storage101.#{postfix}"
}
end
end
def cloud_monitoring_entry(tenant_id)
{
"name" => "cloudMonitoring",
"endpoints" => [
{
"tenantId" => tenant_id,
"publicURL" => "https://monitoring.api.rackspacecloud.com/v1.0/#{tenant_id}"
}
],
"type" => "rax:monitor"
} }
end end
end
def cloud_servers_openstack_entry(tenant_id) def cloud_files_entry(tenant_id)
with_regions("cloudServersOpenStack", "compute") do |region| with_regions("cloudFiles", "object-store") do |region|
base = "https://#{region.downcase}.servers.api.rackspacecloud.com/" postfix = "#{region.downcase}#{Fog::Mock.random_numbers(1)}" +
".clouddrive.com/v1/#{tenant_id}"
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "#{base}/v2/#{tenant_id}",
"versionInfo" => "#{base}/v2",
"versionList" => "#{base}",
"versionId" => "2"
}
end
end
def cloud_block_storage_entry(tenant_id)
with_regions("cloudBlockStorage", "volume") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.blockstorage.api." +
"rackspacecloud.com/v1/#{tenant_id}"
}
end
end
def cloud_databases_entry(tenant_id)
with_regions("cloudDatabases", "rax:database") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.databases.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_load_balancers_entry(tenant_id)
with_regions("cloudLoadBalancers", "rax:load-balancer") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.loadbalancers.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_dns_entry(tenant_id)
{
"name" => "cloudDNS",
"endpoints" => [
{
"tenantId" => tenant_id,
"publicURL" => "https://dns.api.rackspacecloud.com/" +
"v1.0/#{tenant_id}"
}
],
"type" => "rax:dns"
}
end
def cloud_orchestration_entry(tenant_id)
with_regions("cloudOrchestration", "orchestration") do |region|
{
"region" => region,
"tenant_id" => tenant_id,
"publicURL" => "https://#{region.downcase}.orchestration." +
"api.rackspacecloud.com/v1/#{tenant_id}"
}
end
end
def cloud_queues_entry(tenant_id)
with_regions("cloudQueues", "rax:queues") do |region|
postfix = "#{region.downcase}.queues.api.rackspacecloud.com" +
"/v1/#{tenant_id}"
{
"region" => region,
"tenant_id" => tenant_id,
"publicURL" => "https://#{postfix}",
"internalURL" => "https://snet-#{postfix}"
}
end
end
def cloud_backup_entry(tenant_id)
with_regions("cloudBackup", "rax:backup") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.backup.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_images_entry(tenant_id)
with_regions("cloudImages", "image") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.images.api." +
"rackspacecloud.com/v2/#{tenant_id}"
}
end
end
def autoscale_entry(tenant_id)
with_regions("autoscale", "rax:autoscale") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.autoscale.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_servers_entry(tenant_id)
base = "https://servers.api.rackspacecloud.com/"
{ {
"name" => "cloudServers", "region" => region,
"endpoints" => [ "tenantId" => tenant_id,
{ "publicURL" => "https://storage101.#{postfix}",
"tenantId" => tenant_id, "internalURL" => "https://snet-storage101.#{postfix}"
"publicURL" => "#{base}/v1.0/#{tenant_id}",
"versionInfo" => "#{base}/v1.0",
"versionList" => base
"versionId" => "1.0"
}
],
"type" => "compute"
} }
end end
end end
def cloud_monitoring_entry(tenant_id)
{
"name" => "cloudMonitoring",
"endpoints" => [
{
"tenantId" => tenant_id,
"publicURL" => "https://monitoring.api.rackspacecloud.com/v1.0/#{tenant_id}"
}
],
"type" => "rax:monitor"
}
end
def cloud_servers_openstack_entry(tenant_id)
with_regions("cloudServersOpenStack", "compute") do |region|
base = "https://#{region.downcase}.servers.api.rackspacecloud.com/"
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "#{base}/v2/#{tenant_id}",
"versionInfo" => "#{base}/v2",
"versionList" => "#{base}",
"versionId" => "2"
}
end
end
def cloud_block_storage_entry(tenant_id)
with_regions("cloudBlockStorage", "volume") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.blockstorage.api." +
"rackspacecloud.com/v1/#{tenant_id}"
}
end
end
def cloud_databases_entry(tenant_id)
with_regions("cloudDatabases", "rax:database") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.databases.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_load_balancers_entry(tenant_id)
with_regions("cloudLoadBalancers", "rax:load-balancer") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.loadbalancers.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_dns_entry(tenant_id)
{
"name" => "cloudDNS",
"endpoints" => [
{
"tenantId" => tenant_id,
"publicURL" => "https://dns.api.rackspacecloud.com/" +
"v1.0/#{tenant_id}"
}
],
"type" => "rax:dns"
}
end
def cloud_orchestration_entry(tenant_id)
with_regions("cloudOrchestration", "orchestration") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.orchestration." +
"api.rackspacecloud.com/v1/#{tenant_id}"
}
end
end
def cloud_queues_entry(tenant_id)
with_regions("cloudQueues", "rax:queues") do |region|
postfix = "#{region.downcase}.queues.api.rackspacecloud.com" +
"/v1/#{tenant_id}"
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{postfix}",
"internalURL" => "https://snet-#{postfix}"
}
end
end
def cloud_backup_entry(tenant_id)
with_regions("cloudBackup", "rax:backup") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.backup.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_images_entry(tenant_id)
with_regions("cloudImages", "image") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.images.api." +
"rackspacecloud.com/v2/#{tenant_id}"
}
end
end
def autoscale_entry(tenant_id)
with_regions("autoscale", "rax:autoscale") do |region|
{
"region" => region,
"tenantId" => tenant_id,
"publicURL" => "https://#{region.downcase}.autoscale.api." +
"rackspacecloud.com/v1.0/#{tenant_id}"
}
end
end
def cloud_servers_entry(tenant_id)
base = "https://servers.api.rackspacecloud.com/"
{
"name" => "cloudServers",
"type" => "compute",
"endpoints" => [
{
"tenantId" => tenant_id,
"publicURL" => "#{base}/v1.0/#{tenant_id}",
"versionInfo" => "#{base}/v1.0",
"versionList" => base,
"versionId" => "1.0"
}
]
}
end
end end
end end
end end

View file

@ -1,7 +1,4 @@
Shindo.tests('Fog::Rackspace::Identity | tokens', ['rackspace']) do Shindo.tests('Fog::Rackspace::Identity | tokens', ['rackspace']) do
pending if Fog.mock?
ROLE_FORMAT = { ROLE_FORMAT = {
'id' => String, 'id' => String,
'name' => String, 'name' => String,

View file

@ -7,23 +7,21 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
tests('#authentication_method') do tests('#authentication_method') do
@service = Fog::Storage::Rackspace.new @service = Fog::Storage::Rackspace.new
assert_method nil, :authenticate_v2 assert_method nil, :authenticate_v2
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1 assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1 assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1 assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2 assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1 assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1 assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1 assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2 assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
end end
tests('authentication v1') do
pending if Fog.mocking?
tests('authentication v1') do
tests('variables populated').succeeds do tests('variables populated').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0' @service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0'
returns(true, "auth token populated") { !@service.send(:auth_token).nil? } returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
@ -32,7 +30,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
@service.head_containers @service.head_containers
end end
tests('custom endpoint') do tests('custom endpoint') do
@service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0', @service = Fog::Storage::Rackspace.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v1.0',
:rackspace_storage_url => 'https://my-custom-endpoint.com' :rackspace_storage_url => 'https://my-custom-endpoint.com'
returns(false, "auth token populated") { @service.send(:auth_token).nil? } returns(false, "auth token populated") { @service.send(:auth_token).nil? }
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil } returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
@ -71,10 +69,10 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil } returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
end end
end end
tests('default auth') do tests('default auth') do
pending if Fog.mocking? pending if Fog.mocking?
tests('no params').succeeds do tests('no params').succeeds do
@service = Fog::Storage::Rackspace.new :rackspace_region => nil @service = Fog::Storage::Rackspace.new :rackspace_region => nil
returns(true, "auth token populated") { !@service.send(:auth_token).nil? } returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
@ -114,7 +112,7 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
end end
tests('account').succeeds do tests('account').succeeds do
pending if Fog.mocking? pending if Fog.mocking?
Fog::Storage[:rackspace].account Fog::Storage[:rackspace].account
end end