deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [31/50] [abbrv] git commit: Core: Added initial RHEV-M unit tests
Date Mon, 30 Jul 2012 14:29:17 GMT
Core: Added initial RHEV-M unit tests


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/02bb895d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/02bb895d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/02bb895d

Branch: refs/heads/master
Commit: 02bb895de61d05a3a9630119f9bd79da727e473b
Parents: 43e4c23
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Jul 25 15:20:16 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Thu Jul 26 13:25:27 2012 +0200

----------------------------------------------------------------------
 server/tests/drivers/rhevm/common.rb               |   79 +
 ...001_must_throw_error_when_wrong_credentials.yml |   56 +
 .../test_0002_must_return_list_of_images.yml       |  972 ++
 .../test_0002_must_return_list_of_instances.yml    | 1151 ++
 .../test_0002_must_return_list_of_realms.yml       |  301 +
 ...must_support_listing_of_available_providers.yml |  288 +
 .../test_0003_must_allow_to_filter_images.yml      |  656 ++
 .../test_0003_must_allow_to_filter_instances.yml   | 4595 ++++++++
 .../test_0003_must_allow_to_filter_realms.yml      |  748 ++
 ...s_when_switching_between_different_clusters.yml |  415 +
 ...st_0004_must_allow_to_retrieve_single_image.yml |  388 +
 ...0004_must_allow_to_retrieve_single_instance.yml | 2873 +++++
 ...st_0004_must_allow_to_retrieve_single_realm.yml |  450 +
 ..._to_create_a_new_instance_and_destroy_it-10.yml |  659 ++
 ...w_to_create_a_new_instance_and_destroy_it-9.yml |  659 ++
 ...te_a_new_instance_and_destroy_it-destroy-10.yml |  659 ++
 ...ate_a_new_instance_and_destroy_it-destroy-9.yml |  577 +
 ...low_to_create_a_new_instance_and_destroy_it.yml | 6823 ++++++++++++
 ...proper_exception_when_destroying_used_image.yml |  195 +
 ...reate_a_new_instance_and_make_it_running-10.yml |  659 ++
 ...create_a_new_instance_and_make_it_running-9.yml |  659 ++
 ...new_instance_and_make_it_running-destroy-10.yml |  661 ++
 ..._new_instance_and_make_it_running-destroy-9.yml |  577 +
 ...a_new_instance_and_make_it_running-start-10.yml |  660 ++
 ..._a_new_instance_and_make_it_running-start-4.yml |  662 ++
 ..._a_new_instance_and_make_it_running-start-5.yml |  662 ++
 ..._a_new_instance_and_make_it_running-start-6.yml |  662 ++
 ..._a_new_instance_and_make_it_running-start-7.yml |  662 ++
 ..._a_new_instance_and_make_it_running-start-8.yml |  662 ++
 ..._a_new_instance_and_make_it_running-start-9.yml |  662 ++
 ..._a_new_instance_and_make_it_running-stop-10.yml |  662 ++
 ...e_a_new_instance_and_make_it_running-stop-9.yml |  661 ++
 ...o_create_a_new_instance_and_make_it_running.yml | 8250 +++++++++++++++
 .../test_0006_must_support_destroying_images.yml   |  246 +
 server/tests/drivers/rhevm/images_test.rb          |   66 +
 server/tests/drivers/rhevm/instance_test.rb        |  104 +
 server/tests/drivers/rhevm/provider_test.rb        |   48 +
 server/tests/drivers/rhevm/realms_test.rb          |   43 +
 38 files changed, 39812 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/02bb895d/server/tests/drivers/rhevm/common.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/rhevm/common.rb b/server/tests/drivers/rhevm/common.rb
new file mode 100644
index 0000000..79f0794
--- /dev/null
+++ b/server/tests/drivers/rhevm/common.rb
@@ -0,0 +1,79 @@
+# Make less noise to console
+ENV['RACK_ENV'] ||= 'test'
+
+require 'vcr'
+require 'pp'
+require 'time'
+
+# Credentials used to access RHEV-M server
+#
+# NOTE: If these are changed, the VCR fixtures need to be re-recorded
+#
+def credentials
+  {
+    :user => 'vdcadmin@rhev.lab.eng.brq.redhat.com',
+    :password => '123456',
+    :provider => 'https://rhev30-dc.lab.eng.brq.redhat.com:8443/api;645e425e-66fe-4ac9-8874-537bd10ef08d'
+  }
+end
+
+module TestPooler
+  # This method will pool the resource until condition is true
+  # Will raise 'Timeout' when it reach retry count
+  #
+  # default opts[:retries] => 10
+  # default opts[:time_between_retry] => 10 (seconds)
+  # default opts[:timeout] => 60 (seconds) -> single request timeout
+  #
+  # opts[:before] => Proc -> executed 'before' making each request
+  # opts[:after] => Proc -> executed 'after' making each request
+  #
+  def wait_for!(driver, opts={}, &block)
+    opts[:retries] ||= 10
+    opts[:time_between_retry] ||= 10
+    opts[:timeout] ||= 60
+    opts[:method] ||= self.class.name.downcase.to_sym
+    opts[:retries].downto(0) do |r|
+      result = begin
+        timeout(opts[:timeout]) do
+          if opts[:before]
+            new_instance = opts[:before].call(r) { driver.send(opts[:method], :id => self.id)
}
+          else
+            new_instance = driver.send(opts[:method], :id => self.id)
+          end
+          ((yield new_instance) == true) ? new_instance : false
+        end
+      rescue Timeout::Error
+        false
+      ensure
+        opts[:after].call(r) if opts[:after]
+      end
+      return result unless result == false
+      sleep(opts[:time_between_retry])
+    end
+    raise Timeout::Error
+  end
+end
+
+class Instance; include TestPooler; end
+class Image; include TestPooler; end
+
+VCR.configure do |c|
+  # NOTE: Empty this directory before re-recording
+  c.cassette_library_dir = File.join(File.dirname(__FILE__), 'fixtures')
+  c.hook_into :webmock
+  # Set this to :new_epizodes when you want to 're-record'
+  c.default_cassette_options = { :record => :none }
+end
+
+# Some test scenarios use .wait_for! method that do multiple retries
+# for requests. We need to deal with that passing a Proc that use
+# different cassette for each request
+
+def record_retries(name='')
+  {
+    :before => Proc.new { |r, &block|
+      VCR.use_cassette("#{__name__}-#{name.empty? ? '' : "#{name}-"}#{r}", &block)
+    }
+  }
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/02bb895d/server/tests/drivers/rhevm/fixtures/test_0001_must_throw_error_when_wrong_credentials.yml
----------------------------------------------------------------------
diff --git a/server/tests/drivers/rhevm/fixtures/test_0001_must_throw_error_when_wrong_credentials.yml
b/server/tests/drivers/rhevm/fixtures/test_0001_must_throw_error_when_wrong_credentials.yml
new file mode 100644
index 0000000..2d3fe8f
--- /dev/null
+++ b/server/tests/drivers/rhevm/fixtures/test_0001_must_throw_error_when_wrong_credentials.yml
@@ -0,0 +1,56 @@
+---
+http_interactions:
+- request:
+    method: get
+    uri: https://unknown:wrong@rhev30-dc.lab.eng.brq.redhat.com:8443/api/datacenters/645e425e-66fe-4ac9-8874-537bd10ef08d
+    body:
+      encoding: US-ASCII
+      string: ''
+    headers:
+      Accept:
+      - application/xml
+      Accept-Encoding:
+      - gzip, deflate
+      Content-Type:
+      - application/xml
+      User-Agent:
+      - Ruby
+  response:
+    status:
+      code: 401
+      message: Unauthorized
+    headers:
+      Server:
+      - Apache-Coyote/1.1
+      Pragma:
+      - No-cache
+      Cache-Control:
+      - no-cache
+      Expires:
+      - Thu, 01 Jan 1970 01:00:00 CET
+      X-Powered-By:
+      - Servlet 2.5; JBoss-5.0/JBossWeb-2.1
+      Www-Authenticate:
+      - Basic realm = "RHEVM"
+      Content-Type:
+      - text/html;charset=utf-8
+      Content-Length:
+      - '952'
+      Date:
+      - Wed, 25 Jul 2012 11:47:08 GMT
+    body:
+      encoding: US-ASCII
+      string: ! '<html><head><title>JBoss Web/2.1.11.GA - Error report</title><style><!--H1
+        {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
+        H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
+        H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
+        BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
+        B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}
+        P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A
+        {color : black;}A.name {color : black;}HR {color : #525D76;}--></style>
</head><body><h1>HTTP
+        Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b>
Status report</p><p><b>message</b>
+        <u></u></p><p><b>description</b> <u>This
request requires HTTP authentication
+        ().</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/2.1.11.GA</h3></body></html>'
+    http_version: 
+  recorded_at: Wed, 25 Jul 2012 11:48:13 GMT
+recorded_with: VCR 2.1.1


Mime
View raw message