You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by sa...@eucalyptus.com on 2011/05/13 02:54:29 UTC

bug fixes in mock/ec2 cucumber tests

The cucumber tests for ec2 and mock drivers had a few bugs as follows:
* 'api_steps.rb' doesn't check xml attributes for hardware_profiles and instances. In some situations, this hangs the cucumber process (bug in xpath library?). 
* some features attempt to check xml attributes (e.g., each 'image' should have 'architecture' attribute set to 'i386'), 
  but there is no such attributes (architecture) under the target element (image). So I added a new feature and the corresponding step definition which checks child elements instead of attributes.



[PATCH] bug fixes in mock/ec2 cucumber tests

Posted by sa...@eucalyptus.com.
From: Sang-Min Park <sp...@eucalyptus.com>

---
 tests/ec2/hardware_profiles.feature      |    2 +-
 tests/ec2/images.feature                 |    8 +++---
 tests/ec2/instances.feature              |    2 +-
 tests/ec2/step_definitions/api_steps.rb  |   39 +++++++++++++++++++++++++++++-
 tests/mock/hardware_profiles.feature     |    2 +-
 tests/mock/instances.feature             |    2 +-
 tests/mock/step_definitions/api_steps.rb |   37 ++++++++++++++++++++++++++++
 7 files changed, 83 insertions(+), 9 deletions(-)

diff --git a/tests/ec2/hardware_profiles.feature b/tests/ec2/hardware_profiles.feature
index 7339622..d42eba3 100644
--- a/tests/ec2/hardware_profiles.feature
+++ b/tests/ec2/hardware_profiles.feature
@@ -26,4 +26,4 @@ Feature: Accessing hardware profiles
     When client access this URI with parameters:
     | architecture | i386 |
     Then client should get some hardware_profiles
-    And each hardware_profile should have 'architecture' attribute set to 'i386'
+    And each hardware_profile should have 'architecture' property set to 'i386'
diff --git a/tests/ec2/images.feature b/tests/ec2/images.feature
index b4d0e63..9fdd721 100644
--- a/tests/ec2/images.feature
+++ b/tests/ec2/images.feature
@@ -40,7 +40,7 @@ Feature: Listing and showing images
     When client access this URI with parameters:
     | owner_id | 205605819716 |
     Then client should get some images
-    And each image should have 'owner_id' attribute set to '205605819716'
+    And each image should have 'owner_id' element set to '205605819716'
 
   Scenario: Filtering images by architecture
     Given URI /api/images exists
@@ -48,7 +48,7 @@ Feature: Listing and showing images
     When client access this URI with parameters:
     | architecture | i386 |
     Then client should get some images
-    And each image should have 'architecture' attribute set to 'i386'
+    And each image should have 'architecture' element set to 'i386'
 
   Scenario: Filtering images by architecture and owner_id
     Given URI /api/images exists
@@ -57,5 +57,5 @@ Feature: Listing and showing images
     | architecture | i386 |
     | owner_id | 205605819716 |
     Then client should get some images
-    And each image should have 'architecture' attribute set to 'i386'
-    And each image should have 'owner_id' attribute set to '205605819716'
+    And each image should have 'architecture' element set to 'i386'
+    And each image should have 'owner_id' element set to '205605819716'
diff --git a/tests/ec2/instances.feature b/tests/ec2/instances.feature
index d9b50d2..9cb1f21 100644
--- a/tests/ec2/instances.feature
+++ b/tests/ec2/instances.feature
@@ -68,7 +68,7 @@ Feature: Managing instances
     When client access this URI with parameters:
     | state | STOPPED |
     Then client should get some instances
-    And each instance should have 'state' attribute set to 'RUNNING'
+    And each instance should have 'state' element set to 'RUNNING'
 
   Scenario: Get details about first instance
     Given URI /api/instances exists
diff --git a/tests/ec2/step_definitions/api_steps.rb b/tests/ec2/step_definitions/api_steps.rb
index ba89f8f..c42af6f 100644
--- a/tests/ec2/step_definitions/api_steps.rb
+++ b/tests/ec2/step_definitions/api_steps.rb
@@ -79,6 +79,12 @@ Then /^each (\w+) should have '(.+)' attribute with valid (.+)$/ do |el, attr, t
       path = '/api/link'
     when 'image':
       path = '/images/image'
+    when 'instance':
+      path = '/instances/instance'
+    when 'key':
+      path = '/keys/key'
+    when 'realm':
+      path = '/realms/realm'
   end
   output_xml.xpath(path).each do |entry_point|
     @entry_points.include?(entry_point[attr]).should == true if t=='name'
@@ -92,13 +98,44 @@ end
 Then /^each ([\w\-]+) should have '(.+)' attribute set to '(.+)'$/ do |el, attr, v|
   case el
     when 'image':
-      path = "/image/images"
+      path = "/images/image"
+    when 'hardware_profile':
+      path = "/hardware_profiles/hardware_profile"
+    when 'instance':
+      path = "/instances/instance"
   end
   output_xml.xpath(path).each do |element|
     element[attr].should == v
   end
 end
 
+Then /^each ([\w\-]+) should have '(.+)' element set to '(.+)'$/ do |el, child, v|
+  case el
+    when 'image':
+      path = "/images/image"
+    when 'hardware_profile':
+      path = "/hardware_profiles/hardware_profile"
+    when 'instance':
+      path = "/instances/instance"
+  end
+  output_xml.xpath(path).each do |element|
+     element.xpath(child).should_not be_nil
+     element.xpath(child).first.content.should == v
+  end
+end
+
+Then /^each ([\w\-]+) should have '(.+)' property set to '(.+)'$/ do |el, property, v|
+  case el
+    when 'hardware_profile':
+      path = "/hardware_profiles/hardware_profile"
+  end
+  output_xml.xpath(path).each do |element|
+    property_elm=element.xpath("property[@name=\"#{property}\"]")
+    property_elm.should_not be_nil 
+    property_elm.first["value"].should == v
+  end
+end
+
 When /^client follow this attribute$/ do
   output_xml.xpath('/api/link').each do |entry_point|
     get entry_point[@last_attribute], {}
diff --git a/tests/mock/hardware_profiles.feature b/tests/mock/hardware_profiles.feature
index bb43076..5ac7da7 100644
--- a/tests/mock/hardware_profiles.feature
+++ b/tests/mock/hardware_profiles.feature
@@ -26,4 +26,4 @@ Feature: Accessing hardware profiles
     When client access this URI with parameters:
     | architecture | i386 |
     Then client should get some hardware_profiles
-    And each hardware_profile should have 'architecture' attribute set to 'i386'
+    And each hardware_profile should have 'architecture' property set to 'i386'
diff --git a/tests/mock/instances.feature b/tests/mock/instances.feature
index 9e92938..83a5017 100644
--- a/tests/mock/instances.feature
+++ b/tests/mock/instances.feature
@@ -25,7 +25,7 @@ Feature: Managing instances
     When client access this URI with parameters:
     | state | RUNNING |
     Then client should get some instances
-    And each instance should have 'state' attribute set to 'RUNNING'
+    And each instance should have 'state' element set to 'RUNNING'
 
   Scenario: Get details about first instance
     Given URI /api/instances exists
diff --git a/tests/mock/step_definitions/api_steps.rb b/tests/mock/step_definitions/api_steps.rb
index e55a4eb..4ef8d44 100644
--- a/tests/mock/step_definitions/api_steps.rb
+++ b/tests/mock/step_definitions/api_steps.rb
@@ -72,6 +72,12 @@ Then /^each (\w+) should have '(.+)' attribute with valid (.+)$/ do |el, attr, t
       path = '/api/link'
     when 'image':
       path = '/images/image'
+    when 'instance':
+      path = '/instances/instance'
+    when 'key':
+      path = '/keys/key'
+    when 'realm':
+      path = '/realms/realm'
   end
   output_xml.xpath(path).each do |entry_point|
     @entry_points.include?(entry_point[attr]).should == true if t=='name'
@@ -86,12 +92,43 @@ Then /^each ([\w\-]+) should have '(.+)' attribute set to '(.+)'$/ do |el, attr,
   case el
     when 'image':
       path = "/image/images"
+    when 'hardware_profile':
+      path = "/hardware_profiles/hardware_profile"
+    when 'instance':
+      path = "/instances/instance"
   end
   output_xml.xpath(path).each do |element|
     element[attr].should == v
   end
 end
 
+Then /^each ([\w\-]+) should have '(.+)' element set to '(.+)'$/ do |el, child, v|
+  case el
+    when 'image':
+      path = "/images/image"
+    when 'hardware_profile':
+      path = "/hardware_profiles/hardware_profile"
+    when 'instance':
+      path = "/instances/instance"
+  end
+  output_xml.xpath(path).each do |element|
+     element.xpath(child).should_not be_nil
+     element.xpath(child).first.content.should == v
+  end
+end
+
+Then /^each ([\w\-]+) should have '(.+)' property set to '(.+)'$/ do |el, property, v|
+  case el
+    when 'hardware_profile':
+      path = "/hardware_profiles/hardware_profile"
+  end
+  output_xml.xpath(path).each do |element|
+    property_elm=element.xpath("property[@name=\"#{property}\"]")
+    property_elm.should_not be_nil
+    property_elm.first["value"].should == v
+  end
+end
+
 When /^client follow this attribute$/ do
   output_xml.xpath('/api/link').each do |entry_point|
     get entry_point[@last_attribute], {}
-- 
1.7.4.1


Re: bug fixes in mock/ec2 cucumber tests

Posted by Michal Fojtik <mf...@redhat.com>.
On May 13, 2011, at 2:54 AM, sang-min.park@eucalyptus.com wrote:

Hi,

> The cucumber tests for ec2 and mock drivers had a few bugs as follows:
> * 'api_steps.rb' doesn't check xml attributes for hardware_profiles and instances. In some situations, this hangs the cucumber process (bug in xpath library?). 
> * some features attempt to check xml attributes (e.g., each 'image' should have 'architecture' attribute set to 'i386'), 
>  but there is no such attributes (architecture) under the target element (image). So I added a new feature and the corresponding step definition which checks child elements instead of attributes.

A big thanks for this one Sang! I was scratching my head on this issue for several days.
This fix works perfectly. ACK!.

I will push it to SVN and then fix failing features for EC2.

  -- Michal

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