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:37 UTC
[PATCH 1/2] CIMI - dont expose 'add' URI for collection if not supported DTACLOUD-400
From: marios <ma...@redhat.com>
https://issues.apache.org/jira/browse/DTACLOUD-400
Signed-off-by: marios <ma...@redhat.com>
---
server/lib/cimi/helpers/cimi_helper.rb | 12 ++++++++++++
server/lib/cimi/models/collection.rb | 8 +++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/server/lib/cimi/helpers/cimi_helper.rb b/server/lib/cimi/helpers/cimi_helper.rb
index 8fad786..b062af7 100644
--- a/server/lib/cimi/helpers/cimi_helper.rb
+++ b/server/lib/cimi/helpers/cimi_helper.rb
@@ -92,6 +92,18 @@ module CIMI
type = (xml)? :xml : :json
end
+ def deltacloud_create_method_for(cimi_entity)
+ case cimi_entity
+ when "machine" then "create_instance"
+ when "machine_configuration" then "create_hardware_profile"
+ when "machine_image" then "create_image"
+ when "volume" then "create_storage_volume"
+ when "volume_image" then "create_storage_snapshot"
+ else "create_#{cimi_entity}"
+ end
+
+ end
+
end
end
diff --git a/server/lib/cimi/models/collection.rb b/server/lib/cimi/models/collection.rb
index c7f3b21..0fc5eec 100644
--- a/server/lib/cimi/models/collection.rb
+++ b/server/lib/cimi/models/collection.rb
@@ -118,9 +118,11 @@ module CIMI::Model
desc = "#{self.name.split("::").last} Collection for the #{context.driver.name.capitalize} driver"
id = context.send("#{collection_class.entry_name}_url")
ops = []
- create = "create_#{collection_class.entry_name.to_s.singularize}_url"
- if context.respond_to?(create)
- url = context.send(create)
+ cimi_entity = collection_class.entry_name.to_s.singularize
+ cimi_create = "create_#{cimi_entity}_url"
+ dcloud_create = context.deltacloud_create_method_for(cimi_entity)
+ if context.respond_to?(cimi_create) && context.driver.respond_to?(dcloud_create)
+ url = context.send(cimi_create)
ops << { :rel => "add", :href => url }
end
collection_class.new(:id => id, :name => 'default',
--
1.7.11.7
[PATCH 2/2] CIMI - tests skip if capability ! supported - DTACLOUD-400
Posted by ma...@redhat.com.
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