You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2012/12/14 12:56:38 UTC
[PATCH 2/2] CIMI - tests skip if capability ! supported - DTACLOUD-400
From: marios <ma...@redhat.com>
https://issues.apache.org/jira/browse/DTACLOUD-400
Signed-off-by: marios <ma...@redhat.com>
---
tests/cimi/part4_test.rb | 59 ++++++++++++++++++++++++++---------------------
tests/cimi/test_helper.rb | 15 +++++++++---
2 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
index 07e780e..a58d5de 100644
--- a/tests/cimi/part4_test.rb
+++ b/tests/cimi/part4_test.rb
@@ -23,6 +23,8 @@ class AddVolumeToMachine < CIMI::Test::Spec
ROOTS = [ "machines" , "volumes" , "volumeConfigurations"]
+ need_capability("add", "volumes")
+
# Cleanup for resources created for the test
MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
@@ -53,17 +55,21 @@ class AddVolumeToMachine < CIMI::Test::Spec
# Create a machine to attach the volume
cep_json = cep(:accept => :json)
machine_add_uri = discover_uri_for("add", "machines")
- machine = post(machine_add_uri,
- "<MachineCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
- "<name>cimi_machine</name>" +
- "<machineTemplate>" +
- "<machineConfig " +
- "href=\"" + get_a(cep_json, "machineConfig") + "\"/>" +
- "<machineImage " +
- "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
- "</machineTemplate>" +
- "</MachineCreate>",
- {:accept => :json, :content_type => :xml})
+#no point creating machine if we can't run these tests:
+ begin
+ discover_uri_for("add", "volumes") # this will raise the RuntimeError
+ machine = post(machine_add_uri,
+ "<MachineCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
+ "<name>cimi_machine</name>" +
+ "<machineTemplate>" +
+ "<machineConfig " +
+ "href=\"" + get_a(cep_json, "machineConfig") + "\"/>" +
+ "<machineImage " +
+ "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
+ "</machineTemplate>" +
+ "</MachineCreate>", {:accept => :json, :content_type => :xml})
+ rescue RuntimeError =>e
+ end
# 4.3: Create a new Volume
model :volume, :cache => true do |fmt|
@@ -129,7 +135,6 @@ class AddVolumeToMachine < CIMI::Test::Spec
# it "should add resource for cleanup" do
# @@created_resources[:volumes] << volume.id
# end
-
it "should have a name" do
volume.name.wont_be_empty
log.info("volume name: " + volume.name)
@@ -140,20 +145,22 @@ class AddVolumeToMachine < CIMI::Test::Spec
last_response.json["resourceURI"].must_equal RESOURCE_URI.gsub("Create", "")
end
- log.info("#{machine.location} is the machine id")
- volume_add_uri = discover_uri_for("add", "volumes")
- volume = post(volume_add_uri,
- "<VolumeCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
- "<name>cimi_volume_for_attach</name>" +
- "<description>volume for attach testing</description>" +
- "<volumeTemplate>" +
- "<volumeConfig href=\"" + get_a(cep_json, "volumeConfig") + "\">" +
- "</volumeConfig>" +
- "</volumeTemplate>" +
- "</VolumeCreate>",
- :accept => :json, :content_type => :xml)
-
- log.info(volume.location + " is the volume id")
+ if machine # machine not created if we can't create volumes here
+ log.info("#{machine.location} is the machine id")
+ volume_add_uri = discover_uri_for("add", "volumes")
+ volume = post(volume_add_uri,
+ "<VolumeCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
+ "<name>cimi_volume_for_attach</name>" +
+ "<description>volume for attach testing</description>" +
+ "<volumeTemplate>" +
+ "<volumeConfig href=\"" + get_a(cep_json, "volumeConfig") + "\">" +
+ "</volumeConfig>" +
+ "</volumeTemplate>" +
+ "</VolumeCreate>",
+ :accept => :json, :content_type => :xml)
+ log.info(volume.location + " is the volume id")
+ end
+
# 4.4: Attach the new Volume to a Machine
model :machineWithVolume, :only => :xml do
attach_uri = discover_uri_for_subcollection("add", machine.location, "volumes")
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 6be43c1..1720dd7 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -108,7 +108,6 @@ module CIMI::Test::Methods
def cep(params = {})
get(api.cep_url, params)
end
-
def discover_uri_for(op, collection, operations = nil)
unless operations
cep_json = cep(:accept => :json)
@@ -116,8 +115,8 @@ module CIMI::Test::Methods
operations = get(cep_json.json["#{collection}"]["href"], {:accept=> :json}).json["operations"]
end
op_regex = Regexp.new(op, Regexp::IGNORECASE) # "add" == /add/i
- op_uri = operations.inject(""){|res,current| res = current["href"] if current["rel"] =~ op_regex; res}
- raise "Couldn't discover the #{collection} Collection #{op} URI" if op_uri.empty?
+ op_uri = operations.inject(""){|res,current| res = current["href"] if current["rel"] =~ op_regex; res} unless operations.nil?
+ raise "Couldn't discover the #{collection} Collection #{op} URI" if op_uri.nil? || op_uri.empty?
op_uri
end
@@ -273,6 +272,16 @@ module CIMI::Test::Methods
end
end
+ def need_capability(op, collection)
+ before :each do
+ begin
+ discover_uri_for(op, collection)
+ rescue RuntimeError => e
+ skip "Server at #{api.cep_url} doesn't support #{op} for #{collection} collection. #{e.message}"
+ end
+ end
+ end
+
# Perform basic collection checks; +model_name+ is the name of the
# method returning the collection model
def check_collection(model_name)
--
1.7.11.7