2013-02-19 15:43:06 -05:00
|
|
|
require 'fog/rackspace/models/identity/service_catalog'
|
|
|
|
|
|
|
|
Shindo.tests('Fog::Rackspace::ServiceCatalog | users', ['rackspace']) do
|
|
|
|
|
2013-08-07 15:23:01 -04:00
|
|
|
tests('successful') do
|
|
|
|
before_hash = {"access"=>{"token"=>{"expires"=>"2013-02-20T10:31:00.000-06:00", "tenant"=>{"name"=>"777", "id"=>"777"}, "id"=>"6ca10877-7c50-4a5c-b58f-004d835c39c3"},
|
|
|
|
"serviceCatalog"=>[{"type"=>"volume", "endpoints"=>[{"region"=>"DFW", "tenantId"=>"777", "publicURL"=>"https://dfw.blockstorage.api.rackspacecloud.com/v1/777"},
|
|
|
|
{"region"=>"ORD", "tenantId"=>"777", "publicURL"=>"https://ord.blockstorage.api.rackspacecloud.com/v1/777"}], "name"=>"cloudBlockStorage"},
|
|
|
|
{"type"=>"rax:load-balancer", "endpoints"=>[{"region"=>"ORD", "tenantId"=>"777", "publicURL"=>"https://ord.loadbalancers.api.rackspacecloud.com/v1.0/777"},
|
|
|
|
{"region"=>"DFW", "tenantId"=>"777", "publicURL"=>"https://dfw.loadbalancers.api.rackspacecloud.com/v1.0/777"}], "name"=>"cloudLoadBalancers"},
|
|
|
|
{"type"=>"object-store", "endpoints"=>[{"internalURL"=>"https://snet-storage101.dfw1.clouddrive.com/v1/Mosso777", "region"=>"DFW",
|
|
|
|
"tenantId"=>"Mosso777",
|
|
|
|
"publicURL"=>"https://storage101.dfw1.clouddrive.com/v1/Mosso777"},
|
|
|
|
{"internalURL"=>"https://snet-storage101.ord1.clouddrive.com/v1/Mosso777", "region"=>"ORD",
|
|
|
|
"tenantId"=>"Mosso777",
|
|
|
|
"publicURL"=>"https://storage101.ord1.clouddrive.com/v1/Mosso777"}], "name"=>"cloudFiles"}, {"type"=>"rax:database",
|
|
|
|
"endpoints"=>[{"region"=>"DFW", "tenantId"=>"777", "publicURL"=>"https://dfw.databases.api.rackspacecloud.com/v1.0/777"}, {"region"=>"ORD", "tenantId"=>"777",
|
|
|
|
"publicURL"=>"https://ord.databases.api.rackspacecloud.com/v1.0/777"}], "name"=>"cloudDatabases"}, {"type"=>"rax:dns", "endpoints"=>[{"tenantId"=>"777",
|
|
|
|
"publicURL"=>"https://dns.api.rackspacecloud.com/v1.0/777"}], "name"=>"cloudDNS"}, {"type"=>"compute", "endpoints"=>[{"versionId"=>"1.0", "tenantId"=>"777",
|
|
|
|
"versionList"=>"https://servers.api.rackspacecloud.com/", "versionInfo"=>"https://servers.api.rackspacecloud.com/v1.0",
|
|
|
|
"publicURL"=>"https://servers.api.rackspacecloud.com/v1.0/777"}], "name"=>"cloudServers"}, {"type"=>"compute", "endpoints"=>[{"region"=>"DFW", "versionId"=>"2",
|
|
|
|
"tenantId"=>"777", "versionList"=>"https://dfw.servers.api.rackspacecloud.com/", "versionInfo"=>"https://dfw.servers.api.rackspacecloud.com/v2",
|
|
|
|
"publicURL"=>"https://dfw.servers.api.rackspacecloud.com/v2/777"}, {"region"=>"ORD", "versionId"=>"2", "tenantId"=>"777",
|
|
|
|
"versionList"=>"https://ord.servers.api.rackspacecloud.com/", "versionInfo"=>"https://ord.servers.api.rackspacecloud.com/v2",
|
2013-10-25 10:29:28 -04:00
|
|
|
"publicURL"=>"https://ord.servers.api.rackspacecloud.com/v2/777"}, {"versionId"=>"2", "tenantId"=>"777", "versionList"=>"https://servers.api.rackspacecloud.com/", "versionInfo"=>"https://servers.api.rackspacecloud.com/v2", "publicURL"=>"https://servers.api.rackspacecloud.com/v2/777"}], "name"=>"cloudServersOpenStack"}, {"type"=>"rax:monitor", "endpoints"=>[{"tenantId"=>"777",
|
2013-08-07 15:23:01 -04:00
|
|
|
"publicURL"=>"https://monitoring.api.rackspacecloud.com/v1.0/777"}], "name"=>"cloudMonitoring"}, {"type"=>"rax:object-cdn", "endpoints"=>[{"region"=>"DFW",
|
|
|
|
"tenantId"=>"Mosso777", "publicURL"=>"https://cdn1.clouddrive.com/v1/Mosso777"},
|
|
|
|
{"region"=>"ORD", "tenantId"=>"Mosso777",
|
2013-10-25 10:29:28 -04:00
|
|
|
"publicURL"=>"https://cdn2.clouddrive.com/v1/Mosso777"}], "name"=>"cloudFilesCDN"},
|
|
|
|
|
|
|
|
{"type"=>"not_here", "name" => "not_here", "endpoints"=>[{"tenantId"=>"777", "region" => "LON",
|
|
|
|
"publicURL"=>"https://monitoring.api.rackspacecloud.com/v1.0/777"}]}
|
|
|
|
],
|
|
|
|
|
|
|
|
"user"=>{"roles"=>[{"description"=>"User Admin
|
2013-08-07 15:23:01 -04:00
|
|
|
Role.", "name"=>"identity:user-admin", "id"=>"3"}], "name"=>"joe-racker", "RAX-AUTH:defaultRegion"=>"", "id"=>"TK421"}}}
|
|
|
|
|
|
|
|
@service_catalog = Fog::Rackspace::Identity::ServiceCatalog.from_response(nil, before_hash)
|
|
|
|
end
|
2013-02-19 15:43:06 -05:00
|
|
|
|
2013-10-25 10:29:28 -04:00
|
|
|
tests('services') do
|
|
|
|
services = ["cloudBlockStorage", "cloudDNS", "cloudDatabases", "cloudFiles", "cloudFilesCDN", "cloudLoadBalancers", "cloudMonitoring", "cloudServers", "cloudServersOpenStack", "not_here"]
|
|
|
|
|
|
|
|
returns(services) { @service_catalog.services.collect {|s| s.to_s }.sort }
|
|
|
|
end
|
2013-02-19 15:43:06 -05:00
|
|
|
|
|
|
|
tests('get_endpoints') do
|
2013-10-25 10:29:28 -04:00
|
|
|
endpoints = [{"region"=>"DFW", "versionId"=>"2", "tenantId"=>"777", "versionList"=>"https://dfw.servers.api.rackspacecloud.com/", "versionInfo"=>"https://dfw.servers.api.rackspacecloud.com/v2", "publicURL"=>"https://dfw.servers.api.rackspacecloud.com/v2/777"}, {"region"=>"ORD", "versionId"=>"2", "tenantId"=>"777", "versionList"=>"https://ord.servers.api.rackspacecloud.com/", "versionInfo"=>"https://ord.servers.api.rackspacecloud.com/v2", "publicURL"=>"https://ord.servers.api.rackspacecloud.com/v2/777"}, {"versionId"=>"2", "tenantId"=>"777", "versionList"=>"https://servers.api.rackspacecloud.com/", "versionInfo"=>"https://servers.api.rackspacecloud.com/v2", "publicURL"=>"https://servers.api.rackspacecloud.com/v2/777"}]
|
2013-02-19 15:43:06 -05:00
|
|
|
returns(endpoints) { @service_catalog.get_endpoints(:cloudServersOpenStack) }
|
|
|
|
returns(endpoints) { @service_catalog.get_endpoints('cloudServersOpenStack') }
|
2013-10-25 10:29:28 -04:00
|
|
|
returns({}) { @service_catalog.get_endpoints('non-existent') }
|
2013-02-19 15:43:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('get_endpoint') do
|
|
|
|
tests('service with mulitple endpoints') do
|
|
|
|
returns("https://dfw.servers.api.rackspacecloud.com/v2/777") { @service_catalog.get_endpoint(:cloudServersOpenStack, :dfw) }
|
2013-10-25 10:29:28 -04:00
|
|
|
returns("https://ord.servers.api.rackspacecloud.com/v2/777") { @service_catalog.get_endpoint(:cloudServersOpenStack, :ord) }
|
2013-02-19 15:43:06 -05:00
|
|
|
returns("https://dfw.servers.api.rackspacecloud.com/v2/777") { @service_catalog.get_endpoint(:cloudServersOpenStack, 'dfw') }
|
|
|
|
returns("https://dfw.servers.api.rackspacecloud.com/v2/777") { @service_catalog.get_endpoint('cloudServersOpenStack', 'dfw') }
|
2013-10-25 10:29:28 -04:00
|
|
|
returns("https://servers.api.rackspacecloud.com/v2/777") { @service_catalog.get_endpoint('cloudServersOpenStack', :global) }
|
2013-02-19 15:43:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('with one endpoint') do
|
2013-10-25 10:29:28 -04:00
|
|
|
tests('no region specified').returns("https://blockstorage.api.rackspacecloud.com/v1/777") do
|
|
|
|
list = [{"type"=>"volume", "endpoints"=>[{"tenantId"=>"777", "publicURL"=>"https://blockstorage.api.rackspacecloud.com/v1/777"}], "name"=>"cloudBlockStorage"}]
|
|
|
|
service_catalog = Fog::Rackspace::Identity::ServiceCatalog.new(:service => nil, :catalog => list)
|
|
|
|
service_catalog.get_endpoint(:cloudBlockStorage)
|
|
|
|
end
|
|
|
|
tests('specify region as :global').returns("https://blockstorage.api.rackspacecloud.com/v1/777") do
|
|
|
|
list = [{"type"=>"volume", "endpoints"=>[{"tenantId"=>"777", "publicURL"=>"https://blockstorage.api.rackspacecloud.com/v1/777"}], "name"=>"cloudBlockStorage"}]
|
|
|
|
service_catalog = Fog::Rackspace::Identity::ServiceCatalog.new(:service => nil, :catalog => list)
|
|
|
|
service_catalog.get_endpoint(:cloudBlockStorage, :global)
|
|
|
|
end
|
|
|
|
tests('wrong region') do
|
|
|
|
list = [{"type"=>"volume", "endpoints"=>[{"region" => "ORD", "tenantId"=>"777", "publicURL"=>"https://ord.blockstorage.api.rackspacecloud.com/v1/777"}], "name"=>"cloudBlockStorage"}]
|
|
|
|
service_catalog = Fog::Rackspace::Identity::ServiceCatalog.new(:service => nil, :catalog => list)
|
|
|
|
raises(RuntimeError) { service_catalog.get_endpoint(:cloudBlockStorage, :dfw) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('endpoint type') do
|
|
|
|
returns("https://storage101.ord1.clouddrive.com/v1/Mosso777") { @service_catalog.get_endpoint(:cloudFiles, :ord) }
|
|
|
|
returns("https://snet-storage101.ord1.clouddrive.com/v1/Mosso777") { @service_catalog.get_endpoint(:cloudFiles, :ord, true) }
|
|
|
|
returns("https://storage101.ord1.clouddrive.com/v1/Mosso777") { @service_catalog.get_endpoint(:cloudFiles, :ord, false) }
|
2013-02-19 15:43:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('error conditions') do
|
|
|
|
raises(RuntimeError) { @service_catalog.get_endpoint(:cloudServersOpenStack) }
|
2013-02-20 16:48:19 -05:00
|
|
|
raises(RuntimeError) { @service_catalog.get_endpoint(:cloudServersOpenStack, :sat) }
|
2013-10-25 10:29:28 -04:00
|
|
|
raises(RuntimeError) { @service_catalog.get_endpoint(:cloudServersOpenStack, :sat, true) }
|
|
|
|
raises(RuntimeError) { @service_catalog.get_endpoint(:not_here, :dfw) }
|
2013-02-19 15:43:06 -05:00
|
|
|
raises(RuntimeError) { @service_catalog.get_endpoint('non-existent') }
|
2013-10-25 10:29:28 -04:00
|
|
|
raises(RuntimeError) { @service_catalog.get_endpoint(:cloudServersOpenStack, :ord, true) }
|
2013-02-19 15:43:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests('reload').succeeds do
|
|
|
|
pending if Fog.mocking?
|
|
|
|
|
2013-02-21 14:07:29 -05:00
|
|
|
service = Fog::Identity[:rackspace]
|
|
|
|
service_catalog = service.service_catalog
|
2013-10-25 10:29:28 -04:00
|
|
|
service_catalog.catalog << {"name"=>"fakeService", "endpoints"=>[{ "publicURL"=>"http:///fake-endpoint.com"}]}
|
2013-02-21 14:07:29 -05:00
|
|
|
returns("http:///fake-endpoint.com") { service_catalog.get_endpoint :fakeService }
|
|
|
|
returns("http:///fake-endpoint.com") { service.service_catalog.get_endpoint :fakeService }
|
|
|
|
service_catalog.reload
|
|
|
|
raises(RuntimeError) { service_catalog.get_endpoint :fakeService }
|
2013-08-07 15:23:01 -04:00
|
|
|
raises(RuntimeError) { service.service_catalog.get_endpoint :fakeService }
|
2013-10-25 10:29:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
tests('display_service_regions') do
|
|
|
|
returns(":dfw, :ord, :global") { @service_catalog.display_service_regions(:cloudServersOpenStack) }
|
|
|
|
end
|
2013-02-19 15:43:06 -05:00
|
|
|
end
|