deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/15] RHEV-M: avoid failure of GET instance details
Date Thu, 28 Feb 2013 14:17:14 GMT
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d96847ba/server/tests/drivers/rhevm/instance_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/rhevm/instance_test.rb b/server/tests/drivers/rhevm/instance_test.rb
index 867fb76..382cd4a 100644
--- a/server/tests/drivers/rhevm/instance_test.rb
+++ b/server/tests/drivers/rhevm/instance_test.rb
@@ -3,10 +3,16 @@ require 'require_relative' if RUBY_VERSION < '1.9'
 
 require_relative 'common.rb'
 
+TST_REALM    = 'b91b0346-4ba3-11e2-a3ac-0050568c6b2d'
+TST_INSTANCE = '28c7428b-834a-46b6-8d21-bf350e00e3d7'
+TST_IMAGE    = '3cd2891a-9a0f-44c8-8dec-6280efa278e3'
+
 describe 'RhevmDriver Instances' do
 
   before do
-    @driver = Deltacloud::new(:rhevm, credentials)
+    # Read credentials from ${HOME/.deltacloud/config
+    @driver = Deltacloud::Test::config.driver(:rhevm,
+      provider="https://10.16.120.71/api;b9bb11c2-f397-4f41-a57b-7ac15a894779")
     VCR.insert_cassette __name__
   end
 
@@ -26,34 +32,31 @@ describe 'RhevmDriver Instances' do
   end
 
   it 'must allow to filter instances' do
-    @driver.instances(:id =>'a949192d-55eb-465c-9ef1-d59581a562a3').wont_be_empty
-    @driver.instances(:id =>'a949192d-55eb-465c-9ef1-d59581a562a3').must_be_kind_of Array
-    @driver.instances(:id =>'a949192d-55eb-465c-9ef1-d59581a562a3').size.must_equal 1
-    @driver.instances(:id => 'a949192d-55eb-465c-9ef1-d59581a562a3').first.id.must_equal
'a949192d-55eb-465c-9ef1-d59581a562a3'
-    @driver.instances(:owner_id => 'admin@internal').wont_be_empty
-    @driver.instances(:owner_id => 'admin@internal').each do |inst|
-      inst.owner_id.must_equal 'admin@internal'
-    end
+    @driver.instances(:id =>TST_INSTANCE).wont_be_empty
+    @driver.instances(:id =>TST_INSTANCE).must_be_kind_of Array
+    @driver.instances(:id =>TST_INSTANCE).size.must_equal 1
+    @driver.instances(:id => TST_INSTANCE).first.id.must_equal TST_INSTANCE
     @driver.instances(:id => 'i-00000000').must_be_empty
     @driver.instances(:id => 'unknown').must_be_empty
   end
 
   it 'must allow to retrieve single instance' do
-    @driver.instance(:id => 'a949192d-55eb-465c-9ef1-d59581a562a3').wont_be_nil
-    @driver.instance(:id => 'a949192d-55eb-465c-9ef1-d59581a562a3').must_be_kind_of Instance
-    @driver.instance(:id => 'a949192d-55eb-465c-9ef1-d59581a562a3').id.must_equal 'a949192d-55eb-465c-9ef1-d59581a562a3'
+    @driver.instance(:id => TST_INSTANCE).wont_be_nil
+    @driver.instance(:id => TST_INSTANCE).wont_be_nil
+    @driver.instance(:id => TST_INSTANCE).must_be_kind_of Instance
+    @driver.instance(:id => TST_INSTANCE).id.must_equal TST_INSTANCE
     @driver.instance(:id => 'i-00000000').must_be_nil
     @driver.instance(:id => 'unknown').must_be_nil
   end
 
   it 'must allow to create a new instance and destroy it' do
-    instance = @driver.create_instance('5558c5b6-9dd6-41b7-87f9-7cbce4fd40c5',
-                                       :realm_id => '99408929-82cf-4dc7-a532-9d998063fa95',
+    instance = @driver.create_instance(TST_IMAGE,
+                                       :realm_id => TST_REALM,
                                        :hwp_id => 'SERVER',
                                        :hwp_memory => '1024',
                                        :user_data => 'test user data'
                                       )
-    instance = instance.wait_for!(@driver, record_retries) { |i| i.is_stopped? }
+    instance = instance.wait_for!(@driver, record_retries('', :timeout => 60)) { |i| i.is_stopped?
}
     instance.must_be_kind_of Instance
     instance.is_running?.must_equal false
     @driver.instance(:id => instance.id).wont_be_nil
@@ -61,23 +64,24 @@ describe 'RhevmDriver Instances' do
     @driver.instance(:id => instance.id).name.wont_be_nil
     @driver.instance(:id => instance.id).instance_profile.name.must_equal 'SERVER'
     @driver.instance(:id => instance.id).instance_profile.memory.must_equal 1024
-    @driver.instance(:id => instance.id).realm_id.must_equal '99408929-82cf-4dc7-a532-9d998063fa95'
-    @driver.instance(:id => instance.id).image_id.must_equal '5558c5b6-9dd6-41b7-87f9-7cbce4fd40c5'
-    @driver.instance(:id => instance.id).owner_id.must_equal 'admin@internal'
+    @driver.instance(:id => instance.id).realm_id.must_equal TST_REALM
+    @driver.instance(:id => instance.id).image_id.must_equal TST_IMAGE
     @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
     @driver.instance(:id => instance.id).actions.must_include :start
     @driver.destroy_instance(instance.id)
     instance.wait_for!(@driver, record_retries('destroy')) { |i| i.nil? }
   end
 
+
   it 'must allow to create a new instance and make it running' do
-    instance = @driver.create_instance('5558c5b6-9dd6-41b7-87f9-7cbce4fd40c5',
-                                       :realm_id => '99408929-82cf-4dc7-a532-9d998063fa95',
+    instance = @driver.create_instance(TST_IMAGE,
+                                       :realm_id => TST_REALM,
                                        :hwp_id => 'SERVER',
                                        :hwp_memory => '1024',
                                        :user_data => 'test user data'
                                       )
-    instance = instance.wait_for!(@driver, record_retries) { |i| i.is_stopped? }
+    instance = instance.wait_for!(@driver, record_retries('', :timeout => 60)) { |i| i.is_stopped?
}
+    skip "Skip this test due to RHEVm bug: https://bugzilla.redhat.com/show_bug.cgi?id=910741"
     instance.must_be_kind_of Instance
     instance.is_running?.must_equal false
     @driver.instance(:id => instance.id).wont_be_nil
@@ -85,20 +89,22 @@ describe 'RhevmDriver Instances' do
     @driver.instance(:id => instance.id).name.wont_be_nil
     @driver.instance(:id => instance.id).instance_profile.name.must_equal 'SERVER'
     @driver.instance(:id => instance.id).instance_profile.memory.must_equal 1024
-    @driver.instance(:id => instance.id).realm_id.must_equal '99408929-82cf-4dc7-a532-9d998063fa95'
-    @driver.instance(:id => instance.id).image_id.must_equal '5558c5b6-9dd6-41b7-87f9-7cbce4fd40c5'
-    @driver.instance(:id => instance.id).owner_id.must_equal 'admin@internal'
+    @driver.instance(:id => instance.id).realm_id.must_equal TST_REALM
+    @driver.instance(:id => instance.id).image_id.must_equal TST_IMAGE
     @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
     @driver.instance(:id => instance.id).actions.must_include :start
     @driver.start_instance(instance.id)
-    instance = instance.wait_for!(@driver, record_retries('start')) { |i| i.is_running? }
+    instance = instance.wait_for!(@driver, record_retries('start', :timeout => 60)) {
|i| i.is_running? }
     @driver.instance(:id => instance.id).state.must_equal 'RUNNING'
-    Proc.new { @driver.destroy_instance(instance.id) }.must_raise Deltacloud::Exceptions::BackendError,
'Cannot remove VM. VM is running.'
+    @driver.instance(:id => instance.id).actions.must_include :stop
+    Proc.new do
+      @driver.destroy_instance(instance.id)
+    end.must_raise Deltacloud::Exceptions::BackendError, 'Cannot remove VM. VM is running.'
     @driver.stop_instance(instance.id)
-    instance = instance.wait_for!(@driver, record_retries('stop')) { |i| i.is_stopped? }
+    instance = instance.wait_for!(@driver, record_retries('stop', :timeout => 60)) { |i|
i.is_stopped?  }
     @driver.instance(:id => instance.id).state.must_equal 'STOPPED'
     @driver.destroy_instance(instance.id)
-    instance.wait_for!(@driver, record_retries('destroy')) { |i| i.nil? }
+    instance.wait_for!(@driver, record_retries('destroy', :timeout => 60)) { |i| i.nil?
}
   end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d96847ba/server/tests/test_helper.rb
----------------------------------------------------------------------
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 8d8073f..4d5b1ef 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -79,6 +79,17 @@ module Deltacloud
         end
       end
 
+      # Read credentials from ${HOME/.deltacloud/config if found.
+      # e.g.:
+      # cat ${HOME/.deltacloud/config
+      # rhevm:
+      #   user:     'user@domain'
+      #   password: 'mypassword'
+      #   provider: 'https://16.0.0.7/api;b9bb11c2-f397-4f41-a57b-7ac15a894779'
+      # mock:
+      #   user: mockuser
+      #   password: mockpassword
+      #   provider: compute
       def credentials(driver)
         driver = driver.to_s
         if @hash.has_key?(driver)
@@ -90,6 +101,20 @@ module Deltacloud
         end
         { :user => user, :password => password }
       end
+
+      def driver(driver, provider = nil)
+        if @hash.has_key?(driver.to_s)
+          user = @hash[driver.to_s]["user"]
+          password = @hash[driver.to_s]["password"]
+          provider = @hash[driver.to_s]["provider"] unless provider
+          params = {:user => user, :password => password, :provider => provider}
+        else
+          provider = "fakeprovider" unless provider
+          params = { :user => "fakeuser", :password => "fakepassword", :provider =>
provider }
+        end
+        Deltacloud::new(driver, params)
+      end
+
     end
 
     def self.config


Mime
View raw message