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/05 14:28:14 UTC

[PATCH 2/2] CIMI - tests add creation of volume with config by value

From: marios <ma...@redhat.com>


Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/cimi/models/volume.rb |  3 +--
 tests/cimi/part4_test.rb         | 39 +++++++++++++++++++++++++++++++++++++++
 tests/cimi/test_helper.rb        |  7 +++++++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/server/lib/cimi/models/volume.rb b/server/lib/cimi/models/volume.rb
index a2904ce..afef16f 100644
--- a/server/lib/cimi/models/volume.rb
+++ b/server/lib/cimi/models/volume.rb
@@ -69,10 +69,9 @@ class CIMI::Model::Volume < CIMI::Model::Base
     end
   end
 
-
   def self.delete!(id, context)
     context.driver.destroy_storage_volume(context.credentials, {:id=>id} )
-    delete_attributes_for(Volume.new(:id => id))
+    context.delete_attributes_for(StorageVolume.new(:id => id))
   end
 
   def self.find_to_attach_from_json(json_in, context)
diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
index 72f22af..9591337 100644
--- a/tests/cimi/part4_test.rb
+++ b/tests/cimi/part4_test.rb
@@ -80,6 +80,45 @@ class AddVolumeToMachine < CIMI::Test::Spec
          :accept => fmt, :content_type => :xml)
   end
 
+  it "should allow creation of Volume with Config by value in XML" do
+    volume_add_uri = discover_uri_for("add", "volumes")
+    res = post(volume_add_uri,
+      "<VolumeCreate>" +
+        "<name>cimi_volume_by_value_xml</name>" +
+        "<description>volume for testing</description>" +
+        "<volumeTemplate>" +
+          "<volumeConfig>" +
+            "<type>http://schemas.dmtf.org/cimi/1/mapped</type>"+
+            "<capacity> 1024 </capacity>" +
+          "</volumeConfig>" +
+        "</volumeTemplate>" +
+      "</VolumeCreate>",
+         :accept => :json, :content_type => :xml)
+    res.code.must_equal 201
+    #cleanup
+    delete_uri = discover_uri_for("delete", "volumes", res.json["operations"])
+    res= delete(delete_uri)
+    res.code.must_equal 200
+  end
+
+  it "should allow creation of Volume with Config by value in JSON" do
+    volume_add_uri = discover_uri_for("add", "volumes")
+    res = post(volume_add_uri,
+      '{"name": "marios_new_volume_json", "description": "a new volume",' +
+        ' "volumeTemplate":'+
+            '{"volumeConfig": '+
+              '{"type":"http://schemas.dmtf.org/cimi/1/mapped", "capacity": 1024 }}}',
+       :accept => :json, :content_type => :json)
+    res.code.must_equal 201
+    #cleanup
+    delete_uri = discover_uri_for("delete", "volumes", res.json["operations"])
+    res= delete(delete_uri)
+    res.code.must_equal 200
+  end
+
+
+  #this test is not strictly part of the cimi plugfest scenario
+  #added for DTACLOUD-385
   it "should add resource machine resource for cleanup", :only => :json do
     @@created_resources[:machines] << machine.json["id"]
   end
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 0d318bf..811eaaf 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -148,6 +148,13 @@ module CIMI::Test::Methods
       resp
     end
 
+    def delete(path, params={})
+      log_request(:delete, path, :params=>params)
+      resp  = RestClient.delete absolute_url(path), headers(params)
+      log_response(:delete, path, resp)
+      resp
+    end
+
     # Find the model class that can process the body of the HTTP response
     # +resp+
     def model_class(resp)
-- 
1.7.11.7