Permalink
Browse files

Append a unique HTTP URL parameter to the list servers request to avo…

…id cached responses.

Added test case on the Connection.list_servers method.
  • Loading branch information...
1 parent 0c43b51 commit 5a8cddd680bc350fdf3e93930e1a35c4a4a9cf9a Dan Prince committed Sep 22, 2010
Showing with 18 additions and 5 deletions.
  1. +0 −4 TODO
  2. +2 −1 lib/cloudservers/connection.rb
  3. +16 −0 test/test_helper.rb
View
4 TODO
@@ -1,7 +1,3 @@
-* There are caching bugs in the API, so that accurate information is not always returned (ie. if you add a server and
- then list available servers, the new one will not show up.). That needs to be corrected on the API end before
- data will be accurate.
-
* Allow some sort of flag to get the stack trace when an exception is thrown.
* Shared IP group modification code.
View
3 lib/cloudservers/connection.rb
@@ -95,7 +95,8 @@ def get_server(id)
# => [{:name=>"demo-standingcloud-lts", :id=>168867},
# {:name=>"demo-aicache1", :id=>187853}]
def list_servers(options = {})
- path = CloudServers.paginate(options).empty? ? "#{svrmgmtpath}/servers" : "#{svrmgmtpath}/servers?#{CloudServers.paginate(options)}"
+ anti_cache_param="cacheid=#{Time.now.to_i}"
+ path = CloudServers.paginate(options).empty? ? "#{svrmgmtpath}/servers?#{anti_cache_param}" : "#{svrmgmtpath}/servers?#{CloudServers.paginate(options)}&#{anti_cache_param}"
response = csreq("GET",svrmgmthost,path,svrmgmtport,svrmgmtscheme)
CloudServers::Exception.raise_exception(response) unless response.code.match(/^20.$/)
CloudServers.symbolize_keys(JSON.parse(response.body)["servers"])
View
16 test/test_helper.rb
@@ -3,3 +3,19 @@
require 'cloudservers'
require 'rubygems'
require 'mocha'
+
+module TestConnection
+
+def get_test_connection
+
+ conn_response = {'x-server-management-url' => 'http://server-manage.example.com/path', 'x-auth-token' => 'dummy_token'}
+ conn_response.stubs(:code).returns('204')
+ server = mock(:use_ssl= => true, :verify_mode= => true, :start => true, :finish => true)
+ server.stubs(:get).returns(conn_response)
+ Net::HTTP.stubs(:new).returns(server)
+
+ CloudServers::Connection.new(:username => "test_account", :api_key => "AABBCCDD11")
+
+end
+
+end

0 comments on commit 5a8cddd

Please sign in to comment.