Return-Path: X-Original-To: apmail-deltacloud-commits-archive@www.apache.org Delivered-To: apmail-deltacloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6E4F9D422 for ; Mon, 30 Jul 2012 14:29:18 +0000 (UTC) Received: (qmail 1065 invoked by uid 500); 30 Jul 2012 14:29:18 -0000 Delivered-To: apmail-deltacloud-commits-archive@deltacloud.apache.org Received: (qmail 1012 invoked by uid 500); 30 Jul 2012 14:29:18 -0000 Mailing-List: contact commits-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list commits@deltacloud.apache.org Received: (qmail 808 invoked by uid 99); 30 Jul 2012 14:29:18 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jul 2012 14:29:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id BB8BA1A07A; Mon, 30 Jul 2012 14:29:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mfojtik@apache.org To: commits@deltacloud.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [31/50] [abbrv] git commit: Core: Added initial RHEV-M unit tests Message-Id: <20120730142917.BB8BA1A07A@tyr.zones.apache.org> Date: Mon, 30 Jul 2012 14:29:17 +0000 (UTC) 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 Authored: Wed Jul 25 15:20:16 2012 +0200 Committer: Michal fojtik 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: ! 'JBoss Web/2.1.11.GA - Error report

HTTP + Status 401 -


type Status report

message +

description This request requires HTTP authentication + ().


JBoss Web/2.1.11.GA

' + http_version: + recorded_at: Wed, 25 Jul 2012 11:48:13 GMT +recorded_with: VCR 2.1.1