diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 7d5f9de91..cf52432f1 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -130,7 +130,10 @@ module Fog # CGI.escape, but without special treatment on spaces def self.escape(str,extra_exclude_chars = '') - str.gsub(/([^a-zA-Z0-9_.-#{extra_exclude_chars}]+)/) do + # '-' is a special character inside a regex class so it must be first or last. + # Add extra excludes before the final '-' so it always remains trailing, otherwise + # an unwanted range is created by mistake. + str.gsub(/([^a-zA-Z0-9_.#{extra_exclude_chars}-]+)/) do '%' + $1.unpack('H2' * $1.bytesize).join('%').upcase end end diff --git a/lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb b/lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb new file mode 100644 index 000000000..96c4885ec --- /dev/null +++ b/lib/fog/rackspace/examples/compute_v2/bootstrap_server.rb @@ -0,0 +1,98 @@ +#!/usr/bin/env ruby + +# This example demonstrates creating a server with the Rackpace Open Cloud + +require 'rubygems' #required for Ruby 1.8.x +require 'fog' +require 'base64' #required to encode files for personality functionality +require 'sshkey' #required to generate ssh keys. 'gem install sshkey' + +def get_user_input(prompt) + print "#{prompt}: " + gets.chomp +end + +# Use username defined in ~/.fog file, if absent prompt for username. +# For more details on ~/.fog refer to http://fog.io/about/getting_started.html +def rackspace_username + Fog.credentials[:rackspace_username] || get_user_input("Enter Rackspace Username") +end + +# Use api key defined in ~/.fog file, if absent prompt for api key +# For more details on ~/.fog refer to http://fog.io/about/getting_started.html +def rackspace_api_key + Fog.credentials[:rackspace_api_key] || get_user_input("Enter Rackspace API key") +end + +# Generates a ssh key using the SSHKey library. The private key is avaialble via +# the '.private_key' and the public key is avaialble via '.ssh_public_key' +def generate_ssh_key + SSHKey.generate +end + +# create Next Generation Cloud Server service +service = Fog::Compute.new({ + :provider => 'rackspace', + :rackspace_username => rackspace_username, + :rackspace_api_key => rackspace_api_key, + :version => :v2, # Use Next Gen Cloud Servers + :rackspace_region => :ord #Use Chicago Region +}) + +# pick the first flavor +flavor = service.flavors.first + +# pick the first Ubuntu image we can find +image = service.images.find {|image| image.name =~ /Ubuntu/} + +# prompt for server name +server_name = get_user_input "\nEnter Server Name" + +# generate the ssh key +ssh_key = generate_ssh_key + +# reload flavor in order to retrieve all of its attributes +flavor.reload + +puts "\nNow creating server '#{server_name}' the following with specifications:\n" +puts "\t* #{flavor.ram} MB RAM" +puts "\t* #{flavor.disk} GB" +puts "\t* #{flavor.vcpus} CPU(s)" +puts "\t* #{image.name}" +puts "\n" + +begin + # bootstrap server + server = service.servers.bootstrap :name => server_name, + :flavor_id => flavor.id, + :image_id => image.id, + :private_key => ssh_key.private_key, + :public_key => ssh_key.ssh_public_key + + if server.ready? + puts "[DONE]\n\n" + + puts "The server has been successfully created.\n" + puts "Write the following ssh keys to you ~/.ssh directory in order to log in\n\n" + puts "+++++++++++PRIVATE_KEY (~/.ssh/fog_key)++++++++++++" + puts ssh_key.private_key + puts "++++++++++PUBLIC_KEY (~/.ssh/fog_key.pub)++++++++++" + puts ssh_key.ssh_public_key + puts "+++++++++++++++++++++++++++++++++++++++++++++++++++i\n\n" + + puts "You can then log into the server using the following command\n" + puts "ssh #{server.username}@#{server.public_ip_address}\n\n" + else + puts "An error occured, please try again" + end + +rescue Fog::Errors::TimeoutError + puts "[TIMEOUT]\n\n" + + puts "This server is currently #{server.progress}% into the build process and is taking longer to complete than expected." + puts "You can continute to monitor the build process through the web console at https://mycloud.rackspace.com/\n\n" +end + +puts "To delete the server please execute the delete_server.rb script\n\n" + + diff --git a/lib/fog/rackspace/load_balancers.rb b/lib/fog/rackspace/load_balancers.rb index d14f20a56..fe8adb96d 100644 --- a/lib/fog/rackspace/load_balancers.rb +++ b/lib/fog/rackspace/load_balancers.rb @@ -73,6 +73,7 @@ module Fog request :get_error_page request :set_error_page request :remove_error_page + request :get_stats module Shared diff --git a/lib/fog/rackspace/models/compute_v2/images.rb b/lib/fog/rackspace/models/compute_v2/images.rb index 566a54781..a8ac32dcf 100644 --- a/lib/fog/rackspace/models/compute_v2/images.rb +++ b/lib/fog/rackspace/models/compute_v2/images.rb @@ -5,6 +5,30 @@ module Fog module Compute class RackspaceV2 class Images < Fog::Collection + + # @!attribute [rw] name + # @return [String] Given a string value x, filters the list of images by image name. + attribute :name + + # @!attribute [rw] status + # @return [String] Given a string value x, filters the list of images by status. + # @note Possible values are ACTIVE, DELETED, ERROR, SAVING, and UNKNOWN. + attribute :status + + # @!attribute [rw] marker + # @return [String] Given a string value x, return object names greater in value than the specified marker. + # @see http://docs.rackspace.com/files/api/v1/cf-devguide/content/List_Large_Number_of_Objects-d1e1521.html + attribute :marker + + # @!attribute [rw] limit + # @return [Integer] For an integer value n, limits the number of results to at most n values. + # @see http://docs.rackspace.com/files/api/v1/cf-devguide/content/List_Large_Number_of_Objects-d1e1521.html + attribute :limit + + # @!attribute [rw] type + # @return [String] Given a string value x, filters the list of images by type. + # @note Valid values are BASE and SNAPSHOT + attribute :type model Fog::Compute::RackspaceV2::Image @@ -17,8 +41,17 @@ module Fog # @note Fog's current implementation only returns 1000 images. # @note Fog does not retrieve all image details. Please use get to retrieve all details for a specific image. # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html - def all - data = service.list_images.body['images'] + def all(options = {}) + options = { + 'name' => name, + 'status' => status, + 'marker' => marker, + 'limit' => limit, + 'type' => type + }.merge!(options) + merge_attributes(options) + + data = service.list_images(options).body['images'] load(data) end diff --git a/lib/fog/rackspace/models/load_balancers/load_balancer.rb b/lib/fog/rackspace/models/load_balancers/load_balancer.rb index 4891f9375..cca2b6ac2 100644 --- a/lib/fog/rackspace/models/load_balancers/load_balancer.rb +++ b/lib/fog/rackspace/models/load_balancers/load_balancer.rb @@ -196,6 +196,11 @@ module Fog service.get_load_balancer_usage(identity, options).body end + def stats + requires :identity + service.get_stats(identity).body + end + def error_page requires :identity service.get_error_page(identity).body['errorpage']['content'] diff --git a/lib/fog/rackspace/requests/compute_v2/list_images.rb b/lib/fog/rackspace/requests/compute_v2/list_images.rb index 08e10fdda..687b605c9 100644 --- a/lib/fog/rackspace/requests/compute_v2/list_images.rb +++ b/lib/fog/rackspace/requests/compute_v2/list_images.rb @@ -4,29 +4,39 @@ module Fog class Real # Retrieves a list of images + # ==== Parameters + # * options<~String>: + # * 'name'<~String> - Filters the list of images by image name + # * 'limit'<~String> - Maximum number of objects to return + # * 'marker'<~String> - Only return objects whose name is greater than marker + # * 'status'<~String> - Filters the list of images by status + # * 'type'<~String> - Filters base Rackspace images or anyn custom server images that have been created + # # @return [Excon::Response] response: # * body [Hash]: # * images [Array]: # * [Hash]: - # * id [String] - flavor id + # * id [String] - image id # * links [Array] - image links # * name [String] - image name # @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 # @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 # @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 # @raise [Fog::Compute::RackspaceV2::ServiceError] - # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Flavors-d1e4188.html - def list_images + # @see http://docs.rackspace.com/servers/api/v2/cs-devguide/content/List_Images-d1e4435.html + def list_images(options = {}) + options = options.reject {|key, value| value.nil?} request( :expects => [200, 203], :method => 'GET', - :path => 'images' + :path => 'images', + :query => {'format' => 'json'}.merge!(options) ) end end class Mock - def list_images + def list_images(options = {}) images = self.data[:images].values response(:body => {"images" => images}) end diff --git a/lib/fog/rackspace/requests/identity/create_token.rb b/lib/fog/rackspace/requests/identity/create_token.rb index 964e25894..8a1111724 100644 --- a/lib/fog/rackspace/requests/identity/create_token.rb +++ b/lib/fog/rackspace/requests/identity/create_token.rb @@ -12,7 +12,7 @@ module Fog } } - request( + request_without_retry( :body => Fog::JSON.encode(data), :expects => [200, 203], :method => 'POST', diff --git a/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb b/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb index 304b09aa3..5f36f5bc1 100644 --- a/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb +++ b/lib/fog/rackspace/requests/load_balancers/create_load_balancer.rb @@ -24,6 +24,18 @@ module Fog ) end end + + class Mock + def create_load_balancer(name, protocol, port, virtual_ips, nodes, options = {}) + data = {"loadBalancer"=>{"name"=>name, "id"=>uniq_id, "protocol"=>protocol, "port"=>port, "algorithm"=>"RANDOM", "status"=>"BUILD", + "cluster"=>{"name"=>"ztm-n13.dfw1.lbaas.rackspace.net"}, "timeout"=>30, "created"=>{"time"=>"2013-08-20T20:52:44Z"}, + "updated"=>{"time"=>"2013-08-20T20:52:44Z"}, "halfClosed"=>false, "connectionLogging"=>{"enabled"=>false}, "contentCaching"=>{"enabled"=>false}}} + data["virtual_ips"] = virtual_ips.collect {|n| {"virtualIps"=>[{"address"=>"192.237.192.152", "id"=>uniq_id, "type"=>n[:type], "ipVersion"=>"IPV4"}, {"address"=>"2001:4800:7901:0000:ba81:a6a5:0000:0002", "id"=>9153169, "type"=>"PUBLIC", "ipVersion"=>"IPV6"}], "sourceAddresses"=>{"ipv6Public"=>"2001:4800:7901::13/64", "ipv4Servicenet"=>"10.189.254.5", "ipv4Public"=>"166.78.44.5"}} + data["nodes"] = nodes.collect {|n| {"address"=>n[:address], "id"=>uniq_id, "type"=>"PRIMARY", "port"=>n[:port], "status"=>"ONLINE", "condition"=>"ENABLED", "weight"=>1}} + data = Excon::Response.new(:body => data, :status => 202) + } + end + end end end end diff --git a/lib/fog/rackspace/requests/load_balancers/get_stats.rb b/lib/fog/rackspace/requests/load_balancers/get_stats.rb new file mode 100644 index 000000000..ddb4aeefa --- /dev/null +++ b/lib/fog/rackspace/requests/load_balancers/get_stats.rb @@ -0,0 +1,31 @@ +module Fog + module Rackspace + class LoadBalancers + class Real + def get_stats(load_balancer_id) + + request( + :expects => 200, + :path => "loadbalancers/#{load_balancer_id}/stats", + :method => 'GET' + ) + end + end + + class Mock + def get_stats(load_balancer_id) + mock_data = { + 'connectTimeOut' => 0, + 'connectError' => 1, + 'connectFailure' => 2, + 'dataTimedOut' => 3, + 'keepAliveTimedOut' => 4, + 'maxConn' => 5 + } + + Excon::Response.new(:body => mock_data, :status => 200) + end + end + end + end +end \ No newline at end of file diff --git a/lib/fog/rackspace/service.rb b/lib/fog/rackspace/service.rb index 8649cf273..8683e2a00 100644 --- a/lib/fog/rackspace/service.rb +++ b/lib/fog/rackspace/service.rb @@ -30,6 +30,13 @@ module Fog self.send authentication_method, options end + def request_without_retry(params, parse_json = true, &block) + response = @connection.request(request_params(params), &block) + + process_response(response) if parse_json + response + end + def request(params, parse_json = true, &block) first_attempt = true begin diff --git a/lib/fog/rackspace/storage.rb b/lib/fog/rackspace/storage.rb index 7496b5ac4..dec87ef05 100644 --- a/lib/fog/rackspace/storage.rb +++ b/lib/fog/rackspace/storage.rb @@ -77,6 +77,7 @@ module Fog require 'mime/types' @rackspace_api_key = options[:rackspace_api_key] @rackspace_username = options[:rackspace_username] + @rackspace_cdn_ssl = options[:rackspace_cdn_ssl] end def data @@ -95,6 +96,10 @@ module Fog @rackspace_region end + def ssl? + !!@rackspace_cdn_ssl + end + end class Real < Fog::Rackspace::Service @@ -134,7 +139,7 @@ module Fog # @return [Boolean] return true if service is returning SSL-Secured URLs in public_url methods # @see Directory#public_url def ssl? - !rackspace_cdn_ssl.nil? + !!rackspace_cdn_ssl end # Resets presistent service connections diff --git a/tests/rackspace/block_storage_tests.rb b/tests/rackspace/block_storage_tests.rb index f9e17c697..5a16d649e 100644 --- a/tests/rackspace/block_storage_tests.rb +++ b/tests/rackspace/block_storage_tests.rb @@ -105,10 +105,15 @@ Shindo.tests('Fog::Rackspace::BlockStorage', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Rackspace::BlockStorage.new :rackspace_region => :ord - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad-token") - returns(200) { @service.list_volumes.status } + tests('should reauth with valid credentials') do + @service = Fog::Rackspace::BlockStorage.new :rackspace_region => :ord + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad-token") + returns(200) { @service.list_volumes.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) {Fog::Rackspace::BlockStorage.new :rackspace_api_key => 'bad_key' } + end end end \ No newline at end of file diff --git a/tests/rackspace/cdn_tests.rb b/tests/rackspace/cdn_tests.rb index cda51d850..c369a49fc 100644 --- a/tests/rackspace/cdn_tests.rb +++ b/tests/rackspace/cdn_tests.rb @@ -99,10 +99,15 @@ Shindo.tests('Fog::CDN::Rackspace', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::CDN::Rackspace.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad-token") - returns(true) { [200, 204].include? @service.get_containers.status } + tests('should reauth with valid credentials') do + @service = Fog::CDN::Rackspace.new :rackspace_region => :ord + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad-token") + returns(true) { [200, 204].include? @service.get_containers.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::CDN::Rackspace.new :rackspace_api_key => 'bad_key' } + end end pending if Fog.mocking? diff --git a/tests/rackspace/compute_tests.rb b/tests/rackspace/compute_tests.rb index 638ed5776..f64e8a6c3 100644 --- a/tests/rackspace/compute_tests.rb +++ b/tests/rackspace/compute_tests.rb @@ -91,9 +91,15 @@ Shindo.tests('Rackspace | Compute', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Compute::Rackspace.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad-token") - returns(true) { [200, 203].include?(@service.list_flavors.status) } + tests('should reauth with valid credentials') do + @service = Fog::Compute::Rackspace.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad-token") + returns(true) { [200, 203].include?(@service.list_flavors.status) } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Compute::Rackspace.new :rackspace_api_key => 'bad_key' } + end + end end diff --git a/tests/rackspace/compute_v2_tests.rb b/tests/rackspace/compute_v2_tests.rb index 3d0d9e63f..494f53707 100644 --- a/tests/rackspace/compute_v2_tests.rb +++ b/tests/rackspace/compute_v2_tests.rb @@ -104,10 +104,15 @@ Shindo.tests('Fog::Compute::RackspaceV2', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Compute::RackspaceV2.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad_token") - returns(true) { [200, 203].include? @service.list_flavors.status } + tests('should reauth with valid credentials') do + @service = Fog::Compute::RackspaceV2.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad_token") + returns(true) { [200, 203].include? @service.list_flavors.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Compute::RackspaceV2.new :rackspace_api_key => 'bad_key' } + end end end diff --git a/tests/rackspace/databases_tests.rb b/tests/rackspace/databases_tests.rb index e80302c05..caaf044a6 100644 --- a/tests/rackspace/databases_tests.rb +++ b/tests/rackspace/databases_tests.rb @@ -105,10 +105,15 @@ Shindo.tests('Fog::Rackspace::Databases', ['rackspace']) do |variable| tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Rackspace::Databases.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad_token") - returns(200) { @service.list_flavors.status } + tests('should reauth with valid credentials') do + @service = Fog::Rackspace::Databases.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad_token") + returns(200) { @service.list_flavors.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Rackspace::Databases.new :rackspace_api_key => 'bad_key' } + end end @service = Fog::Rackspace::Databases.new diff --git a/tests/rackspace/dns_tests.rb b/tests/rackspace/dns_tests.rb index 243886c48..1d5cb9ab7 100644 --- a/tests/rackspace/dns_tests.rb +++ b/tests/rackspace/dns_tests.rb @@ -85,10 +85,15 @@ Shindo.tests('Fog::DNS::Rackspace', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service =Fog::DNS::Rackspace.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad_token") - returns(200) { @service.list_domains.status } + tests('should reauth with valid credentials') do + @service = Fog::DNS::Rackspace.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad_token") + returns(200) { @service.list_domains.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::DNS::Rackspace.new :rackspace_api_key => 'bad_key' } + end end tests('array_to_query_string') do diff --git a/tests/rackspace/identity_tests.rb b/tests/rackspace/identity_tests.rb index ca3ad478a..28171825b 100644 --- a/tests/rackspace/identity_tests.rb +++ b/tests/rackspace/identity_tests.rb @@ -16,10 +16,15 @@ Shindo.tests('Fog::Rackspace::Identity', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Rackspace::Identity.new :rackspace_region => :ord - returns(true, "auth token populated") { !@service.auth_token.nil? } - @service.instance_variable_set("@auth_token", "bad-token") - returns(true) { [200, 203].include? @service.list_tenants.status } + tests('should reauth with valid credentials') do + @service = Fog::Rackspace::Identity.new :rackspace_region => :ord + returns(true, "auth token populated") { !@service.auth_token.nil? } + @service.instance_variable_set("@auth_token", "bad-token") + returns(true) { [200, 203].include? @service.list_tenants.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Rackspace::Identity.new :rackspace_api_key => 'bad_key' } + end end end \ No newline at end of file diff --git a/tests/rackspace/load_balancer_tests.rb b/tests/rackspace/load_balancer_tests.rb index 2f4dab179..0dfb67eb5 100644 --- a/tests/rackspace/load_balancer_tests.rb +++ b/tests/rackspace/load_balancer_tests.rb @@ -105,10 +105,14 @@ Shindo.tests('Fog::Rackspace::LoadBalancers', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Rackspace::LoadBalancers.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad-token") - returns(200) { @service.list_load_balancers.status } + tests('should reauth with valid credentials') do + @service = Fog::Rackspace::LoadBalancers.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad-token") + returns(200) { @service.list_load_balancers.status } end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Rackspace::LoadBalancers.new:rackspace_api_key => 'bad_key' } + end end pending if Fog.mocking? diff --git a/tests/rackspace/models/load_balancers/load_balancer_tests.rb b/tests/rackspace/models/load_balancers/load_balancer_tests.rb index 1397324ec..bea275406 100644 --- a/tests/rackspace/models/load_balancers/load_balancer_tests.rb +++ b/tests/rackspace/models/load_balancers/load_balancer_tests.rb @@ -20,6 +20,11 @@ Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer', ['rackspace']) do end @instance.wait_for { ready? } + + tests('#stats').succeeds do + @instance.stats + end + tests('#enable_connection_logging').succeeds do @instance.enable_connection_logging returns(true) { @instance.connection_logging } diff --git a/tests/rackspace/monitoring_tests.rb b/tests/rackspace/monitoring_tests.rb index 5ab8dafb6..95a69cbef 100644 --- a/tests/rackspace/monitoring_tests.rb +++ b/tests/rackspace/monitoring_tests.rb @@ -63,10 +63,15 @@ Shindo.tests('Fog::Rackspace::Monitoring', ['rackspace','rackspace_monitoring']) tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Rackspace::Monitoring.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad_token") - returns(true) { [200, 203].include? @service.list_entities.status } + tests('should reauth with valid credentials') do + @service = Fog::Rackspace::Monitoring.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad_token") + returns(true) { [200, 203].include? @service.list_entities.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Rackspace::Monitoring.new :rackspace_api_key => 'bad_key' } + end end end \ No newline at end of file diff --git a/tests/rackspace/requests/load_balancers/get_stats_tests.rb b/tests/rackspace/requests/load_balancers/get_stats_tests.rb new file mode 100644 index 000000000..ebb8b344f --- /dev/null +++ b/tests/rackspace/requests/load_balancers/get_stats_tests.rb @@ -0,0 +1,13 @@ +Shindo.tests('Fog::Rackspace::LoadBalancers | load_balancer_get_stats', ['rackspace']) do + + given_a_load_balancer_service do + given_a_load_balancer do + tests('success') do + @lb.wait_for { ready? } + tests("#get_stats(#{@lb.id})").formats(LOAD_BALANCER_STATS_FORMAT) do + @service.get_stats(@lb.id).body + end + end + end + end +end \ No newline at end of file diff --git a/tests/rackspace/requests/load_balancers/helper.rb b/tests/rackspace/requests/load_balancers/helper.rb index 7f79f9250..407462b23 100644 --- a/tests/rackspace/requests/load_balancers/helper.rb +++ b/tests/rackspace/requests/load_balancers/helper.rb @@ -32,6 +32,15 @@ LOAD_BALANCER_USAGE_FORMAT = { ] } +LOAD_BALANCER_STATS_FORMAT = { + 'connectTimeOut' => Integer, + 'connectError' => Integer, + 'connectFailure' => Integer, + 'dataTimedOut' => Integer, + 'keepAliveTimedOut' => Integer, + 'maxConn' => Integer +} + SSL_TERMINATION_FORMAT = { 'sslTermination' => { 'certificate' => String, diff --git a/tests/rackspace/storage_tests.rb b/tests/rackspace/storage_tests.rb index fc3dc6b16..2985318c9 100644 --- a/tests/rackspace/storage_tests.rb +++ b/tests/rackspace/storage_tests.rb @@ -102,15 +102,34 @@ Shindo.tests('Rackspace | Storage', ['rackspace']) do tests('reauthentication') do pending if Fog.mocking? - @service = Fog::Storage::Rackspace.new - returns(true, "auth token populated") { !@service.send(:auth_token).nil? } - @service.instance_variable_set("@auth_token", "bad-token") - returns(204) { @service.head_containers.status } + tests('should reauth with valid credentials') do + @service = Fog::Storage::Rackspace.new + returns(true, "auth token populated") { !@service.send(:auth_token).nil? } + @service.instance_variable_set("@auth_token", "bad-token") + returns(204) { @service.head_containers.status } + end + tests('should terminate with incorrect credentials') do + raises(Excon::Errors::Unauthorized) { Fog::Storage::Rackspace.new :rackspace_api_key => 'bad_key' } + end end tests('account').succeeds do pending if Fog.mocking? Fog::Storage[:rackspace].account end + + tests('ssl') do + tests('ssl enabled') do + @service = Fog::Storage::Rackspace.new(:rackspace_cdn_ssl => true) + returns(true) { @service.ssl? } + end + tests('ssl disabled') do + @service = Fog::Storage::Rackspace.new(:rackspace_cdn_ssl => false) + returns(false) { @service.ssl? } + + @service = Fog::Storage::Rackspace.new(:rackspace_cdn_ssl => nil) + returns(false) { @service.ssl? } + end + end end diff --git a/tests/rackspace/url_encoding_tests.rb b/tests/rackspace/url_encoding_tests.rb index 6e5b92d80..6b5eebb18 100644 --- a/tests/rackspace/url_encoding_tests.rb +++ b/tests/rackspace/url_encoding_tests.rb @@ -1,3 +1,5 @@ Shindo.tests('Rackspace | url_encoding', ['rackspace']) do - returns( Fog::Rackspace.escape( "is this my file?.jpg" ) ) { "is%20this%20my%20file%3F.jpg" } + returns("is%20this%20my%20file%3F.jpg") { Fog::Rackspace.escape("is this my file?.jpg") } + returns("foo/bar") { Fog::Rackspace.escape("foo/bar", "/") } + returns("foo%2Fbar") { Fog::Rackspace.escape("foo/bar", "0") } end