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 2011/12/13 15:24:35 UTC

[PATCH 1/3] Adds storage_volume create/delete to mock driver

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


Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/deltacloud/drivers/mock/mock_driver.rb |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 9a79671..5d07eed 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -245,6 +245,25 @@ module Deltacloud::Drivers::Mock
       volumes
     end
 
+    def create_storage_volume(credentials, opts=nil)
+      check_credentials(credentials)
+      opts ||= {}
+      opts[:capacity] ||= "1"
+      volume = {
+            :id => "Volume#{Time.now.to_i}",
+            :created => Time.now.to_s,
+            :state => "AVAILABLE",
+            :capacity => opts[:capacity],
+      }
+      @client.store(:storage_volumes, volume)
+      StorageVolume.new(volume)
+    end
+
+    def destroy_storage_volume(credentials, opts=nil)
+      check_credentials(credentials)
+      @client.destroy(:storage_volumes, opts[:id])
+    end
+
     #
     # Storage Snapshots
     #
-- 
1.7.6.4


[PATCH 2/3] Deal with volume not found for CIMI::Volume

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


Signed-off-by: marios <ma...@redhat.com>
---
 server/lib/cimi/server.rb |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 77a8d04..2d62c44 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -331,9 +331,13 @@ global_collection :volumes do
     param :id, :string, :required
     control do
       volume = Volume.find(params[:id], self)
-      respond_to do |format|
-        format.xml  { volume.to_xml  }
-        format.json { volume.to_json }
+      if volume
+        respond_to do |format|
+          format.xml  { volume.to_xml  }
+          format.json { volume.to_json }
+        end
+      else
+        report_error(404)
       end
     end
   end
-- 
1.7.6.4


Re: [PATCH 1/3] Adds storage_volume create/delete to mock driver

Posted by Michal Fojtik <mf...@redhat.com>.
On Dec 13, 2011, at 3:24 PM, marios@redhat.com wrote:

ACK to whole series

 -- Michal

> From: marios <ma...@redhat.com>
> 
> 
> Signed-off-by: marios <ma...@redhat.com>
> ---
> server/lib/deltacloud/drivers/mock/mock_driver.rb |   19 +++++++++++++++++++
> 1 files changed, 19 insertions(+), 0 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> index 9a79671..5d07eed 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> @@ -245,6 +245,25 @@ module Deltacloud::Drivers::Mock
>       volumes
>     end
> 
> +    def create_storage_volume(credentials, opts=nil)
> +      check_credentials(credentials)
> +      opts ||= {}
> +      opts[:capacity] ||= "1"
> +      volume = {
> +            :id => "Volume#{Time.now.to_i}",
> +            :created => Time.now.to_s,
> +            :state => "AVAILABLE",
> +            :capacity => opts[:capacity],
> +      }
> +      @client.store(:storage_volumes, volume)
> +      StorageVolume.new(volume)
> +    end
> +
> +    def destroy_storage_volume(credentials, opts=nil)
> +      check_credentials(credentials)
> +      @client.destroy(:storage_volumes, opts[:id])
> +    end
> +
>     #
>     # Storage Snapshots
>     #
> -- 
> 1.7.6.4
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


[PATCH 3/3] Adds cucumber scenario and steps for CIMI::Volumes

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


Signed-off-by: marios <ma...@redhat.com>
---
 server/Rakefile                                    |    4 +
 .../features/step_definitions/volumes_steps.rb     |   77 ++++++++++++++++++++
 server/tests/cimi/features/volumes.feature         |   32 ++++++++
 3 files changed, 113 insertions(+), 0 deletions(-)
 create mode 100644 server/tests/cimi/features/step_definitions/volumes_steps.rb
 create mode 100644 server/tests/cimi/features/volumes.feature

diff --git a/server/Rakefile b/server/Rakefile
index 50ea60a..5eacf16 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -63,6 +63,10 @@ begin
       t.cucumber_opts = "tests/cimi/features/machine_images.feature --format pretty"
       t.rcov = false
     end
+    Cucumber::Rake::Task.new(:volumes) do |t|
+      t.cucumber_opts = "tests/cimi/features/volumes.feature --format pretty"
+      t.rcov = false
+   end
   end
 rescue LoadError
 end
diff --git a/server/tests/cimi/features/step_definitions/volumes_steps.rb b/server/tests/cimi/features/step_definitions/volumes_steps.rb
new file mode 100644
index 0000000..922cb04
--- /dev/null
+++ b/server/tests/cimi/features/step_definitions/volumes_steps.rb
@@ -0,0 +1,77 @@
+When /^client specifies a Volume Configuration$/ do |volume_config|
+  header 'Accept', 'application/xml'
+  authorize 'mockuser', 'mockpassword'
+  get volume_config.raw[0][1]
+  last_response.status.should==200
+  @volume_config = CIMI::Model::VolumeConfiguration.from_xml(last_response.body)
+  @volume_config.class.should == CIMI::Model::VolumeConfiguration
+  @volume_config.attribute_values[:capacity].quantity.should == "2"
+  @volume_config.uri.should == volume_config.raw[0][1]
+end
+
+When /^client specifies a new Volume using$/ do |volume|
+  @volume_config.should_not be_nil
+  volume_name = volume.raw[0][1]
+  volume_description = volume.raw[1][1]
+  @builder = Nokogiri::XML::Builder.new do |xml|
+    xml.Volume(:xmlns => CMWG_NAMESPACE) {
+      xml.name volume_name
+      xml.description volume_description
+      xml.volumeTemplate {
+        xml.volumeConfig( :href => @volume_config.uri )
+      }
+    }
+  end
+end
+
+Then /^client should be able to create this Volume$/ do
+  authorize 'mockuser', 'mockpassword'
+  header 'Content-Type', 'application/xml'
+  post '/cimi/volumes', @builder.to_xml
+  last_response.status.should == 200
+  @@created_volume = CIMI::Model::Volume.from_xml(last_response.body)
+end
+
+When /^client GET the Volumes Collection$/ do
+  authorize 'mockuser', 'mockpassword'
+  header 'Content-Type', 'application/xml'
+  get "/cimi/volumes"
+  last_response.status.should == 200
+  @@volume_collection = VolumeCollection.from_xml(last_response.body)
+end
+
+Then /^client should get a list of volumes$/ do
+  @@volume_collection.uri.end_with?("/cimi/volumes").should == true
+  @@volume_collection.attribute_values.has_key?(:volumes).should == true
+end
+
+Then /^list of volumes should contain newly created volume$/ do
+  volumes = @@volume_collection.attribute_values[:volumes].map{|v| v.href.split("/").last}
+  volumes.include?(@@created_volume.name).should == true
+end
+
+When /^client GET the newly created Volume in json format$/ do
+  authorize 'mockuser', 'mockpassword'
+  get "/cimi/volumes/#{@@created_volume.name}?format=json"
+  last_response.status.should == 200
+  @@retrieved_volume = CIMI::Model::Volume.from_json(last_response.body)
+end
+
+Then /^client should verify that this Volume was created correctly$/ do |capacity|
+  @@retrieved_volume.name.should == @@created_volume.name
+  @@retrieved_volume.uri.should == @@created_volume.uri
+  @@retrieved_volume.capacity[:quantity].should == capacity.raw[0][1]
+end
+
+When /^client deletes the newly created Volume$/ do
+  authorize 'mockuser', 'mockpassword'
+  delete "/cimi/volumes/#{@@created_volume.name}"
+  last_response.status.should == 200
+end
+
+Then /^client should verify the volume was deleted$/ do
+  authorize 'mockuser', 'mockpassword'
+  get "/cimi/volumes/#{@@created_volume.name}"
+  last_response.status.should == 404
+end
+
diff --git a/server/tests/cimi/features/volumes.feature b/server/tests/cimi/features/volumes.feature
new file mode 100644
index 0000000..c8d5282
--- /dev/null
+++ b/server/tests/cimi/features/volumes.feature
@@ -0,0 +1,32 @@
+Feature: CIMI Volumes Collection
+  The URI of the Volumes collection is given in the Cloud Entry Point.
+
+Scenario: Create a new Volume entity
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client specifies a Volume Configuration
+    | volumeConfig | http://example.com/cimi/volume_configurations/2 |
+  And client specifies a new Volume using
+    | name | cucumber_volume |
+    | description | created in a cucumber scenario |
+  Then client should be able to create this Volume
+
+Scenario: Query the Volume collection
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client GET the Volumes Collection
+  Then client should get a list of volumes
+  And list of volumes should contain newly created volume
+
+Scenario: Query the newly created Volume
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client GET the newly created Volume in json format
+  Then client should verify that this Volume was created correctly
+    | capacity | 2 |
+
+Scenario: Delete the newly created Volume
+  Given Cloud Entry Point URL is provided
+  And client retrieve the Cloud Entry Point
+  When client deletes the newly created Volume
+  Then client should verify the volume was deleted
-- 
1.7.6.4