You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2013/03/07 23:57:38 UTC
Parametrize RHEV-M unit tests
These patches change things so that the RHEV-M tests do not depend on any
hardcoded values. Rather, everything is now read from
~/.deltacloud/config. The new entries for rhevm in that file should be:
rhevm:
user: USERNAME
password: PASSWORD
provider: https://rhevm.example.com/api
preferred:
datacenter: UUID of a datacenter/realm
vm: UUID of an existing instance
template: UUID of an existing template
It's now also possible to rerecord tests by setting the env var
VCR_RECORD=all
Patch 6/6 is too large to send out; I have recorded the series as
http://tracker.deltacloud.org/set/380 The last patch is available as
http://tracker.deltacloud.org/patch/1a3d36c3
Joe: can you update the site docs about rerecording to reflect these
changes ?
David
[PATCH 1/6] RHEVM tests: have VCR match only on path and query, not full URI
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/tests/drivers/rhevm/common.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/server/tests/drivers/rhevm/common.rb b/server/tests/drivers/rhevm/common.rb
index 14a51f9..b3d3a63 100644
--- a/server/tests/drivers/rhevm/common.rb
+++ b/server/tests/drivers/rhevm/common.rb
@@ -22,5 +22,5 @@ VCR.configure do |c|
# be sure to clear fixtures/*.yml files which can be done with "git checkout".
# e.g.:
# c.default_cassette_options = { :record => :all }
- c.default_cassette_options = { :record => :none }
+ c.default_cassette_options = { :record => :none, :match_requests_on => [ :method, :path, :query ] }
end
--
1.8.1.4
[PATCH 3/6] * server/tests/test_helper.rb: simplify defaulting of user/passeword/provider
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/tests/test_helper.rb | 39 ++++++++++++++++++++-------------------
1 file changed, 20 insertions(+), 19 deletions(-)
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 61ee26d..55d2ff5 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -72,10 +72,21 @@ module Deltacloud
def initialize
fname = ENV["CONFIG"] || File::expand_path("~/.deltacloud/config")
+ @hash = Hash.new do |hash, driver|
+ if hash[driver.to_s]
+ hash[driver] = hash[driver.to_s]
+ else
+ hash[driver] = {
+ "user" => "fakeuser",
+ "password" => "fakepassword",
+ "provider" => "fakeprovider"
+ }
+ end
+ end
begin
- @hash = YAML.load(File::open(fname))
+ @hash.merge!(YAML.load(File::open(fname)))
rescue Errno::ENOENT
- @hash = {}
+ # Ignore
end
end
@@ -92,26 +103,16 @@ module Deltacloud
# provider: compute
def credentials(driver)
driver = driver.to_s
- if @hash.has_key?(driver)
- user = @hash[driver]["user"]
- password = @hash[driver]["password"]
- else
- user = "fakeuser"
- password = "fakepassword"
- end
+ user = @hash[driver]["user"]
+ password = @hash[driver]["password"]
{ :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
+ def driver(driver)
+ user = @hash[driver.to_s]["user"]
+ password = @hash[driver.to_s]["password"]
+ provider = @hash[driver.to_s]["provider"]
+ params = {:user => user, :password => password, :provider => provider}
Deltacloud::new(driver, params)
end
--
1.8.1.4
[PATCH 5/6] * server/tests/test_helper.rb: allow accessing preferred items from config
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/tests/test_helper.rb | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 9d37ccf..8bcb374 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -124,6 +124,13 @@ module Deltacloud
Deltacloud::new(driver, params)
end
+ def preferences(driver)
+ @hash[driver.to_s]["preferred"]
+ end
+
+ def set_preferences(driver, prefs)
+ @hash[driver.to_s]["preferred"] = prefs
+ end
end
def self.config
--
1.8.1.4
[PATCH 2/6] RHEVM tests: do not record username/password/hostname with VCR
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
---
server/tests/drivers/rhevm/common.rb | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/server/tests/drivers/rhevm/common.rb b/server/tests/drivers/rhevm/common.rb
index b3d3a63..88d7d36 100644
--- a/server/tests/drivers/rhevm/common.rb
+++ b/server/tests/drivers/rhevm/common.rb
@@ -18,6 +18,14 @@ 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
+ # Rewrite sensitive information before recording
+ c.before_record do |i|
+ u = URI::parse(i.request.uri)
+ u.host = "rhevm.example.com"
+ u.user = "admin"
+ u.password = "secret"
+ i.request.uri = u.to_s
+ end
# Set :record to :all, when re-recording and between re-record attemps
# be sure to clear fixtures/*.yml files which can be done with "git checkout".
# e.g.:
--
1.8.1.4
Re: Parametrize RHEV-M unit tests
Posted by Joseph VLcek <jv...@redhat.com>.
Looks great! All tests ran fine. Thanks.
Ack
On Mar 11, 2013, at 3:34 PM, David Lutterkort wrote:
> Hi Joe,
>
> On Fri, 2013-03-08 at 10:03 -0500, jvlcek wrote:
>> nack and 2 nits
>>
>> nack because the ec2 gogrid and rhevm driver tests fail with this patch
>> applied.
>>
>> See attached file: failing_tests
>
> I fixed up the patch series, and rerecorded it as
> http://tracker.deltacloud.org/set/382
>
> The new series addresses this and your two nits below:
>
>> 1 - using admin:secret for the creds might match live creds.
>> Would it be safer to use something far less likely to possibly match
>> e.g.: fakeuser:fakepassword
>
> Changed.
>
>> 2 - Patch 5/6 defines 2 new methods but I don't see where they are being
>> used.
>> Am I missing something?
>
> The preferences method is used in the actual rhev-m tests in 6/6 to get
> at a fixed VM etc. I removed set_preferences since that is not used any
> longer.
>
> David
>
>
Re: Parametrize RHEV-M unit tests
Posted by David Lutterkort <lu...@redhat.com>.
Hi Joe,
On Fri, 2013-03-08 at 10:03 -0500, jvlcek wrote:
> nack and 2 nits
>
> nack because the ec2 gogrid and rhevm driver tests fail with this patch
> applied.
>
> See attached file: failing_tests
I fixed up the patch series, and rerecorded it as
http://tracker.deltacloud.org/set/382
The new series addresses this and your two nits below:
> 1 - using admin:secret for the creds might match live creds.
> Would it be safer to use something far less likely to possibly match
> e.g.: fakeuser:fakepassword
Changed.
> 2 - Patch 5/6 defines 2 new methods but I don't see where they are being
> used.
> Am I missing something?
The preferences method is used in the actual rhev-m tests in 6/6 to get
at a fixed VM etc. I removed set_preferences since that is not used any
longer.
David
Re: Parametrize RHEV-M unit tests
Posted by jvlcek <jv...@redhat.com>.
On 03/07/2013 05:57 PM, lutter@redhat.com wrote:
> These patches change things so that the RHEV-M tests do not depend on any
> hardcoded values. Rather, everything is now read from
> ~/.deltacloud/config. The new entries for rhevm in that file should be:
>
> rhevm:
> user: USERNAME
> password: PASSWORD
> provider: https://rhevm.example.com/api
> preferred:
> datacenter: UUID of a datacenter/realm
> vm: UUID of an existing instance
> template: UUID of an existing template
>
> It's now also possible to rerecord tests by setting the env var
> VCR_RECORD=all
>
> Patch 6/6 is too large to send out; I have recorded the series as
> http://tracker.deltacloud.org/set/380 The last patch is available as
> http://tracker.deltacloud.org/patch/1a3d36c3
>
> Joe: can you update the site docs about rerecording to reflect these
> changes ?
>
> David
nack and 2 nits
nack because the ec2 gogrid and rhevm driver tests fail with this patch
applied.
See attached file: failing_tests
The 2 nits.
1 - using admin:secret for the creds might match live creds.
Would it be safer to use something far less likely to possibly match
e.g.: fakeuser:fakepassword
2 - Patch 5/6 defines 2 new methods but I don't see where they are being
used.
Am I missing something?
I'm totally OK with you pushing this with these 2 nits but the test
failure are an issue..
Joe
Re: Parametrize RHEV-M unit tests
Posted by jvlcek <jv...@redhat.com>.
On 03/07/2013 05:57 PM, lutter@redhat.com wrote:
> These patches change things so that the RHEV-M tests do not depend on any
> hardcoded values. Rather, everything is now read from
> ~/.deltacloud/config. The new entries for rhevm in that file should be:
>
> rhevm:
> user: USERNAME
> password: PASSWORD
> provider: https://rhevm.example.com/api
> preferred:
> datacenter: UUID of a datacenter/realm
> vm: UUID of an existing instance
> template: UUID of an existing template
>
> It's now also possible to rerecord tests by setting the env var
> VCR_RECORD=all
>
> Patch 6/6 is too large to send out; I have recorded the series as
> http://tracker.deltacloud.org/set/380 The last patch is available as
> http://tracker.deltacloud.org/patch/1a3d36c3
>
> Joe: can you update the site docs about rerecording to reflect these
> changes ?
Will do.
Joe
> David
[PATCH 4/6] RHEVM unit tests: allow triggering of rerecording with env var VCR_RECORD
Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>
Setting VCR_RECORD=all will rerecord the fixtures
---
server/tests/drivers/rhevm/common.rb | 9 ++++-----
server/tests/test_helper.rb | 8 ++++++++
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/server/tests/drivers/rhevm/common.rb b/server/tests/drivers/rhevm/common.rb
index 88d7d36..0ddd6ea 100644
--- a/server/tests/drivers/rhevm/common.rb
+++ b/server/tests/drivers/rhevm/common.rb
@@ -26,9 +26,8 @@ VCR.configure do |c|
u.password = "secret"
i.request.uri = u.to_s
end
- # Set :record to :all, when re-recording and between re-record attemps
- # be sure to clear fixtures/*.yml files which can be done with "git checkout".
- # e.g.:
- # c.default_cassette_options = { :record => :all }
- c.default_cassette_options = { :record => :none, :match_requests_on => [ :method, :path, :query ] }
+ c.default_cassette_options = {
+ :record => vcr_record_mode,
+ :match_requests_on => [ :method, :path, :query ]
+ }
end
diff --git a/server/tests/test_helper.rb b/server/tests/test_helper.rb
index 55d2ff5..9d37ccf 100644
--- a/server/tests/test_helper.rb
+++ b/server/tests/test_helper.rb
@@ -45,6 +45,14 @@ def record_retries(name='', opts = {})
opts
end
+def vcr_record_mode
+ (ENV['VCR_RECORD'] || :none).to_sym
+end
+
+def vcr_recording?
+ vcr_record_mode != :none
+end
+
include Rack::Test::Methods
def run_frontend(frontend=:deltacloud)
--
1.8.1.4