incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1090287 [1/21] - in /incubator/deltacloud/trunk/server: ./ lib/deltacloud/drivers/rhevm/ tests/ tests/drivers/rhevm/ tests/drivers/rhevm/fixtures/
Date Fri, 08 Apr 2011 15:04:28 GMT
Author: mfojtik
Date: Fri Apr  8 15:04:27 2011
New Revision: 1090287

URL: http://svn.apache.org/viewvc?rev=1090287&view=rev
Log:
Added RHEV-M unit tests

Added:
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/api_test.rb
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/delete-47029714ecef17a0de559cfb7a4ee13e281fa75a.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/delete-79f01130866a0046140ada9d82b43f67173664e3.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-07591e87170082376368945386fe89e7df3a4f7e.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-0f50173e8cba941468c17039c11d63e940e351f7.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-163a76f09d41670494c54dcd2eab373a5588683d.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-2e0a6ff922e6b22884bdbc6d2320181fb5df2c08.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-31b55347b5adb27c83cd59e66ba8d39716736db0.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-5f04d9148e4e16d1f5c75536f58189cfa1c24d6f.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-61306a27a37ce8ff87e6e5501f71f0b37b8c89ac.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-620965396fa389179e1f43d6a4e553d9a8ad9523.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-68b0108a904ff68196f211620bc43aa0346ba651.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-6c91ab81e916b9caefd5571489e3d3d4069467b8.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-84898e68d65b04b154bb0af07b4c227c9fb78ced.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-dd7d02910e76e86ce94d113c1175f2ddb2ec711d.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-ebe038d5a1a303f6f636b5b9677d9f3f539253ef.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-f1d6fe5300bb627fd7d85a415b2e1a6ffe3194af.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/get-f3ae8b88ce387807e428e844a0863ad60b7b3f08.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/post-2f12ca06cbcda70b8067386a4a8550070b1c0101.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/post-2f79c1a608a5baca7fe2df4dd9b9bc480f23b5ab.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/post-62450ce8956a66b347580c422b780152504f64a2.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/post-870e41a661d593ec659e51fd4230a3c6629c6763.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/post-8df81dde5740cfcc811f8cc6a144ac381f417a77.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/fixtures/post-e6ef0d15fa869bf38d040855c89472533ae30df8.yml
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/hardware_profiles_test.rb
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/images_test.rb
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/instances_test.rb
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/realms_test.rb
    incubator/deltacloud/trunk/server/tests/drivers/rhevm/setup.rb
Modified:
    incubator/deltacloud/trunk/server/Rakefile
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
    incubator/deltacloud/trunk/server/tests/common.rb

Modified: incubator/deltacloud/trunk/server/Rakefile
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/Rakefile?rev=1090287&r1=1090286&r2=1090287&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/Rakefile (original)
+++ incubator/deltacloud/trunk/server/Rakefile Fri Apr  8 15:04:27 2011
@@ -46,6 +46,14 @@ namespace :test do
     t.warning = false
   }
 
+  desc "Run rackspace unit tests"
+  Rake::TestTask.new("rhevm") { |t|
+    t.test_files = [ 'tests/common.rb', 'tests/drivers/rhevm/setup.rb' ] + FileList.new('tests/drivers/rhevm/*_test.rb')
+    t.options = "-v -v"
+    t.verbose = true
+    t.warning = false
+  }
+
 
 end
 

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb?rev=1090287&r1=1090286&r2=1090287&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb Fri Apr
 8 15:04:27 2011
@@ -111,14 +111,10 @@ module RHEVM
         :authorization => "Basic " + Base64.encode64("#{@username}:#{@password}"),
         :accept => 'application/xml',
       }
-      if ENV['RACK_ENV'] == 'test'
-        response = mock_request(:get, uri, {}, headers)
-      else
-        begin
-          response = RestClient.get(uri, headers).to_s
-        rescue Exception => e
-          raise ConnectionError::new(500, "GET #{uri}", "#{e.message} (GET #{uri})", e.backtrace)
-        end
+      begin
+        response = RestClient.get(uri, headers).to_s
+      rescue Exception => e
+        raise ConnectionError::new(500, "GET #{uri}", "#{e.message} (GET #{uri})", e.backtrace)
       end
       response
     end
@@ -130,12 +126,7 @@ module RHEVM
         :content_type => 'application/xml'
       }
       params = "<action/>" if params.size==0
-      if ENV['RACK_ENV'] == 'test'
-        response = mock_request(:post, uri, params, headers)
-      else
-        response = RestClient.post(uri, params, headers).to_s
-      end
-      response
+      RestClient.post(uri, params, headers).to_s
     end
 
     def discover_entry_points()
@@ -160,33 +151,6 @@ module RHEVM
       end
     end
 
-    def mock_request(*args)
-      http_method, request_uri, params, headers = args[0].to_sym, args[1], args[2], args[3]
-      params ||= {}
-      fixture_filename = "#{Digest::MD5.hexdigest("#{http_method}#{request_uri}#{params.inspect}#{headers}")}.fixture"
-      begin
-        read_fake_url(fixture_filename)[2]["body"]
-      rescue FixtureNotFound
-        if http_method.eql?(:get)
-          r = RestClient.send(http_method, request_uri, headers)
-        elsif http_method.eql?(:post)
-          r = RestClient.send(http_method, request_uri, params, headers)
-        else
-          r = RestClient.send(http_method, request_uri, headers)
-        end
-        response = {
-          :body => r.to_s,
-          :status => r.code,
-          :content_type => r.headers[:content_type]
-        }
-        fixtures_dir = "../tests/rhevm/support/fixtures/"
-        FileUtils.mkdir_p(fixtures_dir)
-        File.open(File::join(fixtures_dir, fixture_filename), 'w') do |f|
-          f.puts [request_uri, http_method, response].to_json
-        end and retry
-      end
-    end
-
     def singularize(str)
       str.gsub(/s$/, '')
     end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb?rev=1090287&r1=1090286&r2=1090287&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb Fri Apr
 8 15:04:27 2011
@@ -134,13 +134,6 @@ class RHEVMDriver < Deltacloud::BaseDriv
     filter_on( inst_arr, :state, opts )
   end
 
-  def reboot_instance(credentials, id)
-    client = new_client(credentials)
-    safely do
-      client.vm_action(:reboot, id)
-    end
-  end
-
   def start_instance(credentials, id)
     client = new_client(credentials)
     safely do
@@ -151,7 +144,7 @@ class RHEVMDriver < Deltacloud::BaseDriv
   def stop_instance(credentials, id)
     client = new_client(credentials)
     safely do
-      client.vm_action(:suspend, id)
+      client.vm_action(:shutdown, id)
     end
   end
 
@@ -181,14 +174,13 @@ class RHEVMDriver < Deltacloud::BaseDriv
       # FIXME: Condor is using GlobalJobId here as a name, which is malformed
       #        and contains >50 characters
       #
-      # FIXME: Memory calculation is wrong in Conductor, they are sending
-      #        value/1024. Original line is here.
+      # FIXME: Memory calculation is wrong in Conductor, they are sending value/1024
+      #
       vm_name = opts[:name] ? "<name>#{opts[:name].split("#").last}</name>" :
"<name>#{Time.now.to_i}</name>"
       vm_template = "<template id='#{image_id}'/>"
       vm_cluster = opts[:realm_id] ? "<cluster id='#{opts[:realm_id]}'/>" : "<cluster
id='0'/>"
       vm_type = opts[:hwp_id] ? "<type>#{opts[:hwp_id].upcase}</type>" : "<type>DESKTOP</type>"
-      #vm_memory = opts[:hwp_memory] ? "<memory>#{opts[:hwp_memory].to_i*1024*1024}</memory>"
 : ''
-      vm_memory = opts[:hwp_memory] ? "<memory>#{opts[:hwp_memory].to_i*1024}</memory>"
 : '' # Conductor workaround
+      vm_memory = opts[:hwp_memory] ? "<memory>#{opts[:hwp_memory].to_i*1024*1024}</memory>"
 : ''
       vm_cpus = opts[:hwp_cpu] ? "<cpu><topology cores='#{opts[:hwp_cpu]}' sockets='1'/></cpu>"
 : ''
       xml = "<vm>"+
         vm_name +
@@ -217,9 +209,9 @@ class RHEVMDriver < Deltacloud::BaseDriv
 
   def new_client(credentials)
     url = (Thread.current[:provider] || ENV['API_PROVIDER'] || provider_uri)
-    #safely do
+    safely do
       ::RHEVM::Client.new(credentials.user, credentials.password, url)
-    #end
+    end
   end
 
   def convert_instance(client, inst)
@@ -317,8 +309,8 @@ class RHEVMDriver < Deltacloud::BaseDriv
   # how to pass those message to our exception handling tool)
   def catched_exceptions_list
     {
-      :auth => RestClient::Unauthorized,
-      :error => RestClient::InternalServerError,
+      :auth => [RestClient::Unauthorized],
+      :error => [RestClient::InternalServerError],
       :glob => [ /(RestClient|RHEVM)::(\w+)/ ]
     }
   end

Modified: incubator/deltacloud/trunk/server/tests/common.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/common.rb?rev=1090287&r1=1090286&r2=1090287&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/tests/common.rb (original)
+++ incubator/deltacloud/trunk/server/tests/common.rb Fri Apr  8 15:04:27 2011
@@ -101,7 +101,7 @@ module DeltacloudTestCommon
         get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
       end
     else
-        get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
+      get(uri, params || {}, opts[:auth] ? authenticate(opts) : {})
     end
     last_response.status.should_not == 401
   end

Added: incubator/deltacloud/trunk/server/tests/drivers/rhevm/api_test.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/tests/drivers/rhevm/api_test.rb?rev=1090287&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/tests/drivers/rhevm/api_test.rb (added)
+++ incubator/deltacloud/trunk/server/tests/drivers/rhevm/api_test.rb Fri Apr  8 15:04:27
2011
@@ -0,0 +1,39 @@
+$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
+require 'tests/common'
+
+module RHEVMTest
+
+  class ApiTest < Test::Unit::TestCase
+    include Rack::Test::Methods
+
+    def app
+      Sinatra::Application
+    end
+
+    def test_01_it_returns_entry_points
+      get_auth_url '/api;driver=rhevm?force_auth=1'
+      (last_xml_response/'/api').first[:driver].should == 'rhevm'
+      (last_xml_response/'/api/link').length.should > 0
+    end
+
+    def test_02_it_has_rhevm_features
+      get_url '/api;driver=rhevm'
+      features = (last_xml_response/'/api/link[@rel="instances"]/feature').collect { |f|
f[:name] }
+      features.include?('user_name').should == true
+      features.include?('hardware_profiles').should == true
+      features.length.should == 2
+    end
+
+    def test_03_it_has_rhevm_collections
+      get_url '/api;driver=rhevm'
+      collections = (last_xml_response/'/api/link').collect { |f| f[:rel] }
+      collections.include?('instance_states').should == true
+      collections.include?('instances').should == true
+      collections.include?('images').should == true
+      collections.include?('realms').should == true
+      collections.include?('hardware_profiles').should == true
+      collections.length.should == 8
+    end
+
+  end
+end



Mime
View raw message