You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2012/12/12 00:57:00 UTC

[PATCH 1/2] CIMI tests: some fixes for part4

From: David Lutterkort <lu...@redhat.com>

  * restore getting the volume after creating it, since not all servers
    return a body from the create request (see fe30257e)
  * add XML namespace to inline XML
  * accept 201 and 202 as response from create request
---
 tests/cimi/part4_test.rb |   27 +++++++++++----------------
 1 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
index 02a8e91..07e780e 100644
--- a/tests/cimi/part4_test.rb
+++ b/tests/cimi/part4_test.rb
@@ -78,12 +78,15 @@ class AddVolumeToMachine < CIMI::Test::Spec
         "</volumeTemplate>" +
       "</VolumeCreate>",
          :accept => fmt, :content_type => :xml)
+    resp.code.must_be_one_of [201, 202]
+    resp.location.must_be_uri
+    get resp.location
   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>" +
+      "<VolumeCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
         "<name>cimi_volume_by_value_xml</name>" +
         "<description>volume for testing</description>" +
         "<volumeTemplate>" +
@@ -94,7 +97,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
         "</volumeTemplate>" +
       "</VolumeCreate>",
          :accept => :json, :content_type => :xml)
-    res.code.must_equal 201
+    res.code.must_be_one_of [201, 202]
     #cleanup
     delete_uri = discover_uri_for("delete", "volumes", res.json["operations"])
     res= delete(delete_uri)
@@ -109,7 +112,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
             '{"volumeConfig": '+
               '{"type":"http://schemas.dmtf.org/cimi/1/mapped", "capacity": 1024 }}}',
        :accept => :json, :content_type => :json)
-    res.code.must_equal 201
+    res.code.must_be_one_of [201, 202]
     #cleanup
     delete_uri = discover_uri_for("delete", "volumes", res.json["operations"])
     res= delete(delete_uri)
@@ -132,12 +135,6 @@ class AddVolumeToMachine < CIMI::Test::Spec
     log.info("volume name: " + volume.name)
   end
 
-  it "should produce a valid create response" do
-    volume
-    last_response.code.must_be_one_of [201, 202]
-    last_response.headers[:location].must_be_uri
-  end
-
   it "should have the correct resourceURI", :only => :json do
     volume.wont_be_nil
     last_response.json["resourceURI"].must_equal RESOURCE_URI.gsub("Create", "")
@@ -159,18 +156,16 @@ class AddVolumeToMachine < CIMI::Test::Spec
   log.info(volume.location + " is the volume id")
   # 4.4: Attach the new Volume to a Machine
   model :machineWithVolume, :only => :xml do
-  attach_uri = discover_uri_for_subcollection("add", machine.location, "volumes")
-    post(attach_uri,
+    attach_uri = discover_uri_for_subcollection("add", machine.location, "volumes")
+    resp = post(attach_uri,
     "<MachineVolume xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
     "<initialLocation>/dev/sdf</initialLocation>" +
     "<volume href=\"" + volume.location + "\"/>" +
     "</MachineVolume>",
     :accept => :xml, :content_type => :xml)
-  end
-
-  it "should have a response code equal to 201 for attaching a volume", :only => :xml do
-    machineWithVolume
-    last_response.code.must_equal 201
+    resp.code.must_be_one_of [201, 202]
+    resp.location.must_be_uri
+    get resp.location
   end
 
   it "should have a delete operation", :only => :xml do
-- 
1.7.7.6


Re: [PATCH 2/2] CIMI tests: make cleanup of machines work

Posted by Ronelle Landy <rl...@redhat.com>.
> > From: lutter@redhat.com
> > To: dev@deltacloud.apache.org
> > Sent: Tuesday, December 11, 2012 6:57:01 PM
> > Subject: [PATCH 2/2] CIMI tests: make cleanup of machines work
> > 
> > From: David Lutterkort <lu...@redhat.com>
> > 
> > ---
> >  tests/cimi/test_helper.rb |   42
> >  ++++++++++++++++++++----------------------
> >  1 files changed, 20 insertions(+), 22 deletions(-)
> > 
> > diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
> > index 025a705..45ff6a3 100644
> > --- a/tests/cimi/test_helper.rb
> > +++ b/tests/cimi/test_helper.rb
> > @@ -169,6 +169,8 @@ module CIMI::Test::Methods
> >          else
> >            resource = resp.xml.root.name
> >          end
> > +      elsif resp.body.nil? || resp.body.size == 0
> > +        raise "Can not construct model from empty body"
> >        else
> >          raise "Unexpected content type #{resp.content_type}"
> >        end
> > @@ -292,33 +294,29 @@ module CIMI::Test::Methods
> >        # machines:
> >        if not @@created_resources[:machines].nil?
> >          @@created_resources[:machines].each_index do |i|
> > -          attempts = 0
> > -          begin
> > -            stop_res = RestClient.post(
> > @@created_resources[:machines][i] + "/stop",
> > +          machine = get(@@created_resources[:machines][i], :accept
> > => :json)
> 
> This line errors out for me :
> 
> ***********
> 
> /home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:182:in
> `absolute_url': undefined method `start_with?' for
> #<CIMI::Model::Machine:0x000000020f6840> (NoMethodError)
> 	from
> 	/home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:141:in
> 	`get'
> 	from
> 	/home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:297:in
> 	`block in teardown'
> 	from
> 	/home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:296:in
> 	`each_index'
> 	from
> 	/home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:296:in
> 	`teardown'
> 	from part2_test.rb:26:in `block in <class:CreateNewMachine>'
> 	from
> 	/usr/local/share/gems/gems/minitest-4.3.3/lib/minitest/unit.rb:778:in
> 	`call'
> 	from
> 	/usr/local/share/gems/gems/minitest-4.3.3/lib/minitest/unit.rb:778:in
> 	`reverse_each'
> 	from
> 	/usr/local/share/gems/gems/minitest-4.3.3/lib/minitest/unit.rb:778:in
> 	`block (2 levels) in autorun'
> 
> 
> ***********

So running these tests again, looks like the issue is that part4_test.rb and part5_test.rb were adding machine resources for deletion (@@created_resources[:machines] << machine_created.json["id"] or machine.location) differently than part2_test.rb and part3_test.rb (@@created_resources[:machines] << machine). 

> 
> > +          unless machine.json["state"].upcase.eql?("STOPPED")
> > +            stop_op = machine.json["operations"].find { |op|
> > op["rel"] =~ /stop$/ }
> > +            stop_res = post( stop_op["href"],
> >              "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
> > -            "<action>
> > http://http://schemas.dmtf.org/cimi/1/action/stop</action>" +
> > +
> >            "<action>http://schemas.dmtf.org/cimi/1/action/stop</action>"
> > +
> >              "</Action>",
> > -            {'Authorization' => api.basic_auth, :accept => :xml }
> > )
> > +            :accept => :xml, :content_type => :xml )
> >  
> > -            if stop_res.code == 202
> > +            machine = get(machine.json["id"], :accept => :json)
> > +          end
> >  
> > -              model_state = RestClient.get(
> > @@created_resources[:machines][i],
> > -              {'Authorization' => api_basic_auth, :accept =>
> > :json}
> > ).json["state"]
> > +          while not machine.json["state"].upcase.eql?("STOPPED")
> > +            puts 'waiting for machine to be STOPPED'
> > +            sleep(1)
> > +            machine = get(machine.json["id"], :accept => :json)
> > +          end
> >  
> > -              while not model_state.upcase.eql?("STOPPED")
> > -                puts 'waiting for machine to be STOPPED'
> > -                sleep(10)
> > -                model_state = RestClient.get(
> > @@created_resources[:machines][i],
> > -                {'Authorization' => api_basic_auth, :accept =>
> > :json} ).json["state"]
> > -              end
> > -            end
> > -            delete_res = RestClient.delete(
> > @@created_resources[:machines][i],
> > -            {'Authorization' => api_basic_auth, :accept => :json}
> > )
> > -            @@created_resources[:machines][i] = nil if
> > delete_res.code == 200
> > -          rescue Exception => e
> > -            sleep(10)
> > -            attempts += 1
> > -            retry if (attempts <= 5)
> > +          delete_op = machine.json["operations"].find { |op|
> > op["rel"] =~ /delete$/ }
> > +          if delete_op
> > +            delete_res = RestClient.delete( delete_op["href"],
> > +                {'Authorization' => api_basic_auth, :accept =>
> > :json} )
> > +            @@created_resources[:machines][i] = nil if
> > (200..207).include? delete_res.code
> >            end
> >          end
> >  
> > --
> > 1.7.7.6
> > 
> > 
> 

Re: [PATCH 2/2] CIMI tests: make cleanup of machines work

Posted by Ronelle Landy <rl...@redhat.com>.
> From: lutter@redhat.com
> To: dev@deltacloud.apache.org
> Sent: Tuesday, December 11, 2012 6:57:01 PM
> Subject: [PATCH 2/2] CIMI tests: make cleanup of machines work
> 
> From: David Lutterkort <lu...@redhat.com>
> 
> ---
>  tests/cimi/test_helper.rb |   42
>  ++++++++++++++++++++----------------------
>  1 files changed, 20 insertions(+), 22 deletions(-)
> 
> diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
> index 025a705..45ff6a3 100644
> --- a/tests/cimi/test_helper.rb
> +++ b/tests/cimi/test_helper.rb
> @@ -169,6 +169,8 @@ module CIMI::Test::Methods
>          else
>            resource = resp.xml.root.name
>          end
> +      elsif resp.body.nil? || resp.body.size == 0
> +        raise "Can not construct model from empty body"
>        else
>          raise "Unexpected content type #{resp.content_type}"
>        end
> @@ -292,33 +294,29 @@ module CIMI::Test::Methods
>        # machines:
>        if not @@created_resources[:machines].nil?
>          @@created_resources[:machines].each_index do |i|
> -          attempts = 0
> -          begin
> -            stop_res = RestClient.post(
> @@created_resources[:machines][i] + "/stop",
> +          machine = get(@@created_resources[:machines][i], :accept
> => :json)

This line errors out for me :

***********

/home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:182:in `absolute_url': undefined method `start_with?' for #<CIMI::Model::Machine:0x000000020f6840> (NoMethodError)
	from /home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:141:in `get'
	from /home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:297:in `block in teardown'
	from /home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:296:in `each_index'
	from /home/dcloud/workspace/deltacloud/tests/cimi/test_helper.rb:296:in `teardown'
	from part2_test.rb:26:in `block in <class:CreateNewMachine>'
	from /usr/local/share/gems/gems/minitest-4.3.3/lib/minitest/unit.rb:778:in `call'
	from /usr/local/share/gems/gems/minitest-4.3.3/lib/minitest/unit.rb:778:in `reverse_each'
	from /usr/local/share/gems/gems/minitest-4.3.3/lib/minitest/unit.rb:778:in `block (2 levels) in autorun'


***********

Adding "[:id]" as in "machine = get(@@created_resources[:machines][i][:id], :accept => :json)" worked  although there may be a better way to fix this.

> +          unless machine.json["state"].upcase.eql?("STOPPED")
> +            stop_op = machine.json["operations"].find { |op|
> op["rel"] =~ /stop$/ }
> +            stop_res = post( stop_op["href"],
>              "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
> -            "<action>
> http://http://schemas.dmtf.org/cimi/1/action/stop</action>" +
> +
>            "<action>http://schemas.dmtf.org/cimi/1/action/stop</action>"
> +
>              "</Action>",
> -            {'Authorization' => api.basic_auth, :accept => :xml } )
> +            :accept => :xml, :content_type => :xml )
>  
> -            if stop_res.code == 202
> +            machine = get(machine.json["id"], :accept => :json)
> +          end
>  
> -              model_state = RestClient.get(
> @@created_resources[:machines][i],
> -              {'Authorization' => api_basic_auth, :accept => :json}
> ).json["state"]
> +          while not machine.json["state"].upcase.eql?("STOPPED")
> +            puts 'waiting for machine to be STOPPED'
> +            sleep(1)
> +            machine = get(machine.json["id"], :accept => :json)
> +          end
>  
> -              while not model_state.upcase.eql?("STOPPED")
> -                puts 'waiting for machine to be STOPPED'
> -                sleep(10)
> -                model_state = RestClient.get(
> @@created_resources[:machines][i],
> -                {'Authorization' => api_basic_auth, :accept =>
> :json} ).json["state"]
> -              end
> -            end
> -            delete_res = RestClient.delete(
> @@created_resources[:machines][i],
> -            {'Authorization' => api_basic_auth, :accept => :json} )
> -            @@created_resources[:machines][i] = nil if
> delete_res.code == 200
> -          rescue Exception => e
> -            sleep(10)
> -            attempts += 1
> -            retry if (attempts <= 5)
> +          delete_op = machine.json["operations"].find { |op|
> op["rel"] =~ /delete$/ }
> +          if delete_op
> +            delete_res = RestClient.delete( delete_op["href"],
> +                {'Authorization' => api_basic_auth, :accept =>
> :json} )
> +            @@created_resources[:machines][i] = nil if
> (200..207).include? delete_res.code
>            end
>          end
>  
> --
> 1.7.7.6
> 
> 

[PATCH 2/2] CIMI tests: make cleanup of machines work

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

---
 tests/cimi/test_helper.rb |   42 ++++++++++++++++++++----------------------
 1 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 025a705..45ff6a3 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -169,6 +169,8 @@ module CIMI::Test::Methods
         else
           resource = resp.xml.root.name
         end
+      elsif resp.body.nil? || resp.body.size == 0
+        raise "Can not construct model from empty body"
       else
         raise "Unexpected content type #{resp.content_type}"
       end
@@ -292,33 +294,29 @@ module CIMI::Test::Methods
       # machines:
       if not @@created_resources[:machines].nil?
         @@created_resources[:machines].each_index do |i|
-          attempts = 0
-          begin
-            stop_res = RestClient.post( @@created_resources[:machines][i] + "/stop",
+          machine = get(@@created_resources[:machines][i], :accept => :json)
+          unless machine.json["state"].upcase.eql?("STOPPED")
+            stop_op = machine.json["operations"].find { |op| op["rel"] =~ /stop$/ }
+            stop_res = post( stop_op["href"],
             "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
-            "<action> http://http://schemas.dmtf.org/cimi/1/action/stop</action>" +
+            "<action>http://schemas.dmtf.org/cimi/1/action/stop</action>" +
             "</Action>",
-            {'Authorization' => api.basic_auth, :accept => :xml } )
+            :accept => :xml, :content_type => :xml )
 
-            if stop_res.code == 202
+            machine = get(machine.json["id"], :accept => :json)
+          end
 
-              model_state = RestClient.get( @@created_resources[:machines][i],
-              {'Authorization' => api_basic_auth, :accept => :json} ).json["state"]
+          while not machine.json["state"].upcase.eql?("STOPPED")
+            puts 'waiting for machine to be STOPPED'
+            sleep(1)
+            machine = get(machine.json["id"], :accept => :json)
+          end
 
-              while not model_state.upcase.eql?("STOPPED")
-                puts 'waiting for machine to be STOPPED'
-                sleep(10)
-                model_state = RestClient.get( @@created_resources[:machines][i],
-                {'Authorization' => api_basic_auth, :accept => :json} ).json["state"]
-              end
-            end
-            delete_res = RestClient.delete( @@created_resources[:machines][i],
-            {'Authorization' => api_basic_auth, :accept => :json} )
-            @@created_resources[:machines][i] = nil if delete_res.code == 200
-          rescue Exception => e
-            sleep(10)
-            attempts += 1
-            retry if (attempts <= 5)
+          delete_op = machine.json["operations"].find { |op| op["rel"] =~ /delete$/ }
+          if delete_op
+            delete_res = RestClient.delete( delete_op["href"],
+                {'Authorization' => api_basic_auth, :accept => :json} )
+            @@created_resources[:machines][i] = nil if (200..207).include? delete_res.code
           end
         end
 
-- 
1.7.7.6