> From: [email protected]
> To: [email protected]
> Sent: Tuesday, December 11, 2012 6:57:01 PM
> Subject: [PATCH 2/2] CIMI tests: make cleanup of machines work
> 
> From: David Lutterkort <[email protected]>
> 
> ---
>  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
> 
> 

Reply via email to