You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2010/11/29 14:16:57 UTC

[PATCH core 5/6] Added storage_volume Cucumber features

From: Michal Fojtik <mf...@redhat.com>

---
 .../ec2/step_definitions/storage_volumes_steps.rb  |   89 ++++++++++++++++++++
 tests/ec2/storage_volumes.feature                  |   52 ++++++++++++
 2 files changed, 141 insertions(+), 0 deletions(-)
 create mode 100644 tests/ec2/step_definitions/storage_volumes_steps.rb
 create mode 100644 tests/ec2/storage_volumes.feature

diff --git a/tests/ec2/step_definitions/storage_volumes_steps.rb b/tests/ec2/step_definitions/storage_volumes_steps.rb
new file mode 100644
index 0000000..62b84f4
--- /dev/null
+++ b/tests/ec2/step_definitions/storage_volumes_steps.rb
@@ -0,0 +1,89 @@
+When /^client want create a new ([\w_]+)$/ do |object|
+end
+
+When /^client want to list all storage_volumes$/ do
+end
+
+When /^client want to attach storage volume to RUNNING instance$/ do
+  get "/api/instances", { :state => "RUNNING" }
+  @instance_id = (output_xml/"/instances/instance").first[:id]
+  get "/api/storage_volumes"
+  @storage_volume_id = (output_xml/"/storage_volumes/storage_volume").first[:id]
+end
+
+Then /^client should POST on ([\w_\/\$]+) using$/ do |uri, table|
+  params = {}
+  uri.gsub!(/\$storage_volume_id/, @storage_volume_id) if @storage_volume_id
+  table.raw.each do |key, value|
+    if value =~ /\$(.*)/
+      value = case $1.strip
+                when 'instance_id' then @instance_id 
+              end
+    end
+    params[key.to_sym] = value.strip
+  end
+  post uri, params
+end
+
+Then /^client should do a POST on ([\w_\/\$]+)$/ do |uri|
+  get "/api/storage_volumes"
+  @storage_volume_id = (output_xml/"/storage_volumes/storage_volume").first[:id]
+  uri.gsub!(/\$storage_volume_id/, @storage_volume_id) if @storage_volume_id
+end
+
+Then /^client should GET on ([\w_\/]+)$/ do |uri|
+  get uri
+end
+
+Then /^a new storage_volume should be created$/ do
+  last_response.status.should == 200
+end
+
+Then /^a list of ([\w_]+) should be returned$/ do |collection|
+  last_response.status.should == 200
+  (output_xml/"/#{collection}").size.should_not == 0
+end
+
+Then /^this storage_volume should have (\w+) set to '(\w+)'$/ do |key, val|
+  (output_xml/"/storage_volume/#{key}").text.should == val
+end
+
+Then /^this storage_volume should have (\w+) with valid date$/ do |key|
+  (output_xml/"/storage_volume/#{key}").text.class.should_not == nil
+end
+
+Then /^each (\w+) should have (\w+) with valid date$/ do |object, key|
+  (output_xml/"/#{object}s/#{object}").each do |item|
+    (item/"#{key}").should_not == nil
+  end
+end
+
+Then /^this storage_volume should have actions:$/ do |table|
+  table.raw.each do |key|
+    (output_xml/"/storage_volume/actions/link[@rel = '#{key}']").should_not == nil
+  end
+end
+
+Then /^each (\w+) should have (\w+)$/ do |object, key|
+  (output_xml/"/#{object}s/#{object}").each do |item|
+    (item/"#{key}").should_not == nil
+  end
+end
+
+Then /^storage_volume should be attached to this instance$/ do
+  get "/api/storage_volumes/#{@storage_volume_id}"
+  (output_xml/"/storage_volume/mount/instance").first['id'].should == @instance_id
+end
+
+Then /^this storage_volume should have mounted instance with:$/ do |table|
+  table.raw.each do |key|
+    (output_xml/"/storage_volume/mount/#{key}").should_not == nil
+  end
+end
+
+When /^client want to detach created storage volume$/ do
+end
+
+Then /^storage_volume should be detached from$/ do
+  last_response.status.should == 200
+end
diff --git a/tests/ec2/storage_volumes.feature b/tests/ec2/storage_volumes.feature
new file mode 100644
index 0000000..e5d0585
--- /dev/null
+++ b/tests/ec2/storage_volumes.feature
@@ -0,0 +1,52 @@
+Feature: Managing storage volumes
+
+  @prefix-create
+  Scenario: Create a new storage volume
+    Given URI /api/storage_volumes exists
+    And authentification is required for this URI
+    When client want create a new storage_volume
+    Then client should POST on /api/storage_volumes using
+      | capacity | 1 |
+      | realm_id | us-east-1a |
+    And a new storage_volume should be created
+    And this storage_volume should have capacity set to '1'
+    And this storage_volume should have created_at with valid date
+    And this storage_volume should have state set to 'CREATING'
+    And this storage_volume should have actions:
+      | attach |
+      | detach |
+      | destroy |
+
+  @prefix-list
+  Scenario: Getting a list of all storage volumes
+    Given URI /api/storage_volumes exists
+    And authentification is required for this URI
+    When client want to list all storage_volumes
+    Then client should GET on /api/storage_volumes
+    And a list of storage_volumes should be returned
+    And each storage_volume should have id
+    And each storage_volume should have created_at with valid date
+    And each storage_volume should have state
+    And each storage_volume should have capacity
+    And each storage_volume should have actions
+
+  @prefix-attach
+  Scenario: Attach storage volume to instance
+    Given URI /api/storage_volumes exists
+    And authentification is required for this URI
+    When client want to attach storage volume to RUNNING instance
+    Then client should POST on /api/storage_volumes/$storage_volume_id/attach using
+      | device | /dev/sdc |
+      | instance_id | $instance_id |
+    And storage_volume should be attached to this instance
+    And this storage_volume should have mounted instance with:
+      | instance |
+      | device |
+
+  @prefix-detach
+  Scenario: Detach storage volume to instance
+    Given URI /api/storage_volumes exists
+    And authentification is required for this URI
+    When client want to detach created storage volume
+    Then client should do a POST on /api/storage_volumes/$storage_volume_id/detach
+    And storage_volume should be detached from
-- 
1.7.3.2