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

@ -22,8 +22,6 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do
end end
tests('authentication v1') do tests('authentication v1') do
pending if Fog.mocking?
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? }