deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH] CIMI - tests adding test points for CIMI Basics test plan
Date Thu, 29 Nov 2012 14:35:46 GMT
ACK - pushed

On 29/11/12 08:02, rlandy@redhat.com wrote:
> From: Ronelle Landy <rlandy@redhat.com>
> 
> ---
>  tests/cimi/cep_test.rb    |   40 ++++++++----
>  tests/cimi/part2_test.rb  |   83 +++++++++++++++++++++++++
>  tests/cimi/part3_test.rb  |   23 +++++++
>  tests/cimi/part4_test.rb  |  147 +++++++++++++++++++++++++++++++++++++++++++
>  tests/cimi/part5_test.rb  |  131 +++++++++++++++++++++++++++++++++++++++
>  tests/cimi/test_helper.rb |  151 +++++++++++++++++++++++++++++++++++++++++++++
>  tests/config.yaml         |    4 +
>  7 files changed, 566 insertions(+), 13 deletions(-)
>  create mode 100644 tests/cimi/part2_test.rb
>  create mode 100644 tests/cimi/part3_test.rb
>  create mode 100644 tests/cimi/part4_test.rb
>  create mode 100644 tests/cimi/part5_test.rb
> 
> diff --git a/tests/cimi/cep_test.rb b/tests/cimi/cep_test.rb
> index 42bb057..f764ea2 100644
> --- a/tests/cimi/cep_test.rb
> +++ b/tests/cimi/cep_test.rb
> @@ -50,23 +50,37 @@ class CloundEntryPointBehavior < CIMI::Test::Spec
>      subject.name.wont_be_empty
>    end
>  
> +  it "should have a response code equal to 200" do
> +    subject
> +    last_response.code.must_equal 200
> +  end
> +
>    it "should have the correct resourceURI", :only => :json do
>      subject.wont_be_nil     # Make sure we talk to the server
>      last_response.json["resourceURI"].must_equal RESOURCE_URI
>    end
>  
> -  it "should have root collections" do
> -    ROOTS.each do |root|
> -      r = root.underscore.to_sym
> -      if subject.respond_to?(r)
> -        coll = subject.send(r)
> -        coll.must_respond_to :href, "#{root} collection"
> -        unless coll.href.nil?
> -          coll.href.must_be_uri "#{root} collection"
> -          model = fetch(coll.href)
> -          last_response.code.must_equal 200
> -        end
> -      end
> -    end
> +  query_the_cep(ROOTS)
> +
> +  # Testing "*/*" Accept Headers returns json output
> +  response = RestClient.get(api.cep_url, "Accept" => "*/*")
> +  log.info( " */* accept headers return: " + response.json.to_s() )
> +
> +  it "should return json response", :only => "*/*" do
> +    response.wont_be_nil
> +    response.headers[:content_type].eql?("application/json")
> +  end
> +
> +  it "should have a response code equal to 200", :only => "*/*" do
> +    response.code.must_equal 200
>    end
> +
> +  it "should have an id equal to the CEP URL" , :only => "*/*" do
> +    response.json["id"].must_equal api.cep_url
> +  end
> +
> +  it "should have a baseURI" do
> +    response.json["baseURI"].must_be_uri
> +  end
> +
>  end
> diff --git a/tests/cimi/part2_test.rb b/tests/cimi/part2_test.rb
> new file mode 100644
> index 0000000..0742a90
> --- /dev/null
> +++ b/tests/cimi/part2_test.rb
> @@ -0,0 +1,83 @@
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.  The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +$:.unshift File.join(File.dirname(__FILE__))
> +
> +require "test_helper.rb"
> +
> +class CreateNewMachine < CIMI::Test::Spec
> +  RESOURCE_URI =
> +    "http://schemas.dmtf.org/cimi/1/CloudEntryPoint"
> +  ROOTS = ["machines", "machineImages", "machineConfigurations"]
> +
> +  MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
> +
> +  # 2.1: Query the CEP
> +  model :subject, :cache => true do |fmt|
> +    cep(:accept => fmt)
> +  end
> +
> +  # This test must adhere to one of the "Query the CEP" test in the previous section.
> +  query_the_cep(ROOTS)
> +
> +  # At least one MachineImage resource must appear in the collection
> +  # At least one MachineConfiguration resource must appear in the collection
> +  it "should contain one MachineImage resource and one MachineConfiguration resource"
do
> +  ROOTS.each do |root|
> +    r = root.underscore.to_sym
> +    unless r.eql?(:machines)
> +      model = fetch(subject.send(r).href)
> +      log.info(model.attribute_values[r][0])
> +      assert_equal model.attribute_values[r][0].nil?(), false
> +    end
> +  end
> +end
> +
> +  # 2.4:  Create a new CredentialResource
> +  log.info("Create a new CredentialResource: credential_resources is not a supported
collection.")
> +
> +  # 2.5: Create a new Machine
> +  model :machine do |fmt|
> +    cep_json = cep(:accept => :json)
> +
> +    RestClient.post(cep_json.json["machines"]["href"],
> +      "<Machine>" +
> +        "<name>cimi_machine_" + fmt.to_s() + "</name>" +
> +        "<machineTemplate>" +
> +          "<machineConfig " +
> +            "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" + api.provider_perferred_config
+ "\"/>" +
> +          "<machineImage " +
> +            "href=\"" + cep_json.json["machineImages"]["href"] + "/" + api.provider_perferred_image
+ "\"/>" +
> +        "</machineTemplate>" +
> +      "</Machine>",
> +      {'Authorization' => api.basic_auth, :accept => fmt})
> +  end
> +
> +  it "should add resource for cleanup" do
> +    @@created_resources[:machines] << machine.id
> +  end
> +
> +  it "should have a name" do
> +    machine.name.wont_be_empty
> +    log.info("machine name: " + machine.name)
> +  end
> +
> +  it "should have a response code equal to 201" do
> +    machine
> +    last_response.code.must_equal 201
> +  end
> +
> +end
> diff --git a/tests/cimi/part3_test.rb b/tests/cimi/part3_test.rb
> new file mode 100644
> index 0000000..10bc2d5
> --- /dev/null
> +++ b/tests/cimi/part3_test.rb
> @@ -0,0 +1,23 @@
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.  The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +$:.unshift File.join(File.dirname(__FILE__))
> +
> +require "test_helper.rb"
> +
> +class CreateNewMachineFromMachineTemplate < CIMI::Test::Spec
> + log.info("MachineTemplates are not yet a supported collection - Deltacloud CIMI interface.")
> +end
> diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
> new file mode 100644
> index 0000000..e5c1433
> --- /dev/null
> +++ b/tests/cimi/part4_test.rb
> @@ -0,0 +1,147 @@
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.  The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +$:.unshift File.join(File.dirname(__FILE__))
> +
> +require "test_helper.rb"
> +
> +class AddVolumeToMachine < CIMI::Test::Spec
> +  RESOURCE_URI = "http://schemas.dmtf.org/cimi/1/VolumeCreate"
> +
> +  ROOTS = [ "machines" , "volumes" , "volumeConfigurations"]
> +
> +  # Cleanup for resources created for the test
> +  MiniTest::Unit.after_tests {  teardown(@@created_resources, api.basic_auth) }
> +
> +  # 4.1: Query the CEP
> +  model :subject, :cache => true do |fmt|
> +    cep(:accept => fmt)
> +  end
> +
> +  # 2.2, 2.3: CEP.machines, CEP.volumes and CEP.volumeConfigs must be set
> +  query_the_cep(ROOTS)
> +
> +  # At least one VolumeConfiguration resource must appear in the collection
> +  it "should have at least one volumeConfiguration collection" do
> +    ROOTS.each do |root|
> +      r = root.underscore.to_sym
> +      if r.eql?(:volume_configurations)
> +        model = fetch(subject.send(r).href)
> +        log.info(model.attribute_values[r][0])
> +        assert_equal model.attribute_values[r][0].nil?(), false
> +        model.attribute_values[r][0].id.must_be_uri
> +      end
> +    end
> +  end
> +
> +# Create a machine to attach the volume
> +   cep_json = cep(:accept => :json)
> +   machine = RestClient.post(cep_json.json["machines"]["href"],
> +     "<Machine>" +
> +       "<name>cimi_machine</name>" +
> +       "<machineTemplate>" +
> +         "<machineConfig " +
> +           "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" + api.provider_perferred_config
+ "\"/>" +
> +         "<machineImage " +
> +           "href=\"" + cep_json.json["machineImages"]["href"] + "/" + api.provider_perferred_image
+ "\"/>" +
> +       "</machineTemplate>" +
> +     "</Machine>",
> +     {'Authorization' => api.basic_auth, :accept => :json})
> +
> +  # 4.3:  Create a new Volume
> +  model :volume do |fmt|
> +    RestClient.post(cep_json.json["volumes"]["href"],
> +      "<Volume>" +
> +        "<name>cimi_volume_" + fmt.to_s() +"</name>" +
> +        "<description>volume for testing</description>" +
> +        "<volumeTemplate>" +
> +          "<volumeConfig href=\"" + cep_json.json["volumeConfigs"]["href"]  +  "/"
+
> +            api.provider_perferred_volume_config + "\">" +
> +          "</volumeConfig>" +
> +        "</volumeTemplate>" +
> +      "</Volume>",
> +    {'Authorization' => api.basic_auth, :accept => fmt})
> +  end
> +
> +  it "should add resource machine resource for cleanup", :only => :json do
> +    @@created_resources[:machines] << machine.json["id"]
> +  end
> +
> +#  it "should add resource for cleanup" do
> +#    @@created_resources[:volumes] << volume.id
> +#  end
> +
> +  it "should have a name" do
> +    volume.name.wont_be_empty
> +    log.info("volume name: " + volume.name)
> +  end
> +
> +  it "should have a response code equal to 201 for creating a volume" do
> +    volume
> +    last_response.code.must_equal 201
> +  end
> +
> +  it "should have the correct resourceURI", :only => :json do
> +    volume.wont_be_nil
> +    last_response.json["resourceURI"].must_equal RESOURCE_URI.gsub("Create", "")
> +  end
> +
> +  # 4.4: Attach the new Volume to a Machine
> +  log.info(machine.json["id"].to_s() + " is the machine id")
> +  volume = RestClient.post(cep_json.json["volumes"]["href"],
> +  "<Volume>" +
> +    "<name>cimi_volume_for_attach</name>" +
> +    "<description>volume for attach testing</description>" +
> +    "<volumeTemplate>" +
> +      "<volumeConfig href=\"" + cep_json.json["volumeConfigs"]["href"] +  "/" +
> +        api.provider_perferred_volume_config + "\">" +
> +      "</volumeConfig>" +
> +    "</volumeTemplate>" +
> +  "</Volume>",
> +{'Authorization' => api.basic_auth, :accept => :json})
> +
> +  log.info(volume.json["id"].to_s() + " is the volume id")
> +
> +  model :machineWithVolume, :only => :xml do
> +    RestClient.put(machine.json["id"] + "/volume_attach",
> +    "<MachineVolume xmlns=\"http://schemas.dmtf.org/cimi/1/MachineVolume\">" +
> +    "<initialLocation>/dev/sdf</initialLocation>" +
> +    "<volume href=\"" + volume.json["id"] + "\"/>" +
> +    "</MachineVolume>",
> +    {'Authorization' => api.basic_auth, :accept => :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
> +  end
> +
> +  it "should have delete and edit operations", :only => :xml do
> +    # no edit
> +    machineWithVolume[:operations][0][0].must_include "delete"
> +  end
> +
> +  it "should be able to detach from the instance", :only => :xml do
> +    log.info( machine.json["id"] +
> +    "/volumes/" + volume.json["id"].split("/volumes/")[1])
> +     sleep 5
> +    response = RestClient.delete(machine.json["id"] +
> +      "/volumes/" + volume.json["id"].split("/volumes/")[1],
> +    {'Authorization' => api.basic_auth, :accept => :xml})
> +      response.code.must_equal 200
> +  end
> +
> +end
> diff --git a/tests/cimi/part5_test.rb b/tests/cimi/part5_test.rb
> new file mode 100644
> index 0000000..52f8b58
> --- /dev/null
> +++ b/tests/cimi/part5_test.rb
> @@ -0,0 +1,131 @@
> +#
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.  The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +$:.unshift File.join(File.dirname(__FILE__))
> +
> +require "test_helper.rb"
> +require "set"
> +require "time"
> +
> +class ManipulateAMachine < CIMI::Test::Spec
> +  RESOURCE_URI =
> +    "http://schemas.dmtf.org/cimi/1/Machine"
> +
> +  MiniTest::Unit.after_tests {  teardown(@@created_resources, api.basic_auth) }
> +
> +  # 2.1: Query the Machine
> +  # For some providers - need to create a machine before querying it.
> +  cep_json = cep(:accept => :json)
> +  machine_created = RestClient.post(cep_json.json["machines"]["href"],
> +    "<Machine>" +
> +      "<name>cimi_machine_part5</name>" +
> +      "<machineTemplate>" +
> +        "<machineConfig " +
> +          "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" + api.provider_perferred_config
+ "\"/>" +
> +        "<machineImage " +
> +          "href=\"" + cep_json.json["machineImages"]["href"] + "/" + api.provider_perferred_image
+ "\"/>" +
> +      "</machineTemplate>" +
> +    "</Machine>",
> +    {'Authorization' => api.basic_auth, :accept => :json})
> +
> +  model :machine do |fmt|
> +    get machine_created.json["id"], :accept => fmt
> +  end
> +
> +  it "should add resource for cleanup", :only => :json do
> +    @@created_resources[:machines] << machine_created.json["id"]
> +  end
> +
> +  it "should have a name" do
> +    log.info("machine name: " + machine.name)
> +    machine.name.wont_be_empty
> +  end
> +
> +  it "should have have a description" do
> +    machine.description.wont_be_empty
> +  end
> +
> +  it "should have an id including the cep url" do
> +   log.info("machine id: " + machine.id)
> +   machine.id.must_include api.cep_url.gsub("cloudEntryPoint", "machines/")
> +  end
> +
> +  it "should have a valid creation time" do
> +    Time.parse(machine.created.to_s()) < Time.now
> +  end
> +
> +  it "should have numerical values for memory and cpu" do
> +    machine.cpu.to_s.must_match /^[0-9]+$/
> +    machine.memory.to_s.must_match /^[0-9]+$/
> +  end
> +
> +  it "should have a valid state" do
> +    s = Set.new ["RUNNING", "NEW", "PAUSED", "STOPPED", "STARTED"]
> +    log.info("machine state: " + machine.state.upcase)
> +    s.must_include machine.state.upcase
> +  end
> +
> +  it "should have disks and columes collections" do
> +    machine.disks.must_respond_to :href, "disks collection"
> +    machine.volumes.must_respond_to :href, "volumes collection"
> +  end
> +
> +  it "should have a response code equal to 200" do
> +    machine
> +    last_response.code.must_equal 200
> +  end
> +
> +  it "should return correct content type" do
> +    machine
> +    last_response.wont_be_nil
> +    last_response.headers[:content_type].eql?(:fmt)
> +  end
> +
> +  it "should return possible operations to be executed on a machine" do
> +    if (machine.state.upcase.eql?("RUNNING") ||
> +      machine.state.upcase.eql?("STARTED"))
> +      log.info(RESOURCE_URI.gsub("Machine", "action/restart"))
> +        # This relies on odering and needs to be improved
> +      machine[:operations][0][0].must_include RESOURCE_URI.gsub( "Machine", "action/restart")
> +      machine[:operations][1][0].must_include RESOURCE_URI.gsub( "Machine", "action/stop")
> +      machine[:operations][2][0].must_include RESOURCE_URI.gsub( "Machine", "action/capture")
> +    elsif machine.state.upcase.eql?("STOPPED")
> +      machine[:operations][0][0].must_include RESOURCE_URI.gsub( "Machine", "action/start")
> +      machine[:operations][1][0].must_include RESOURCE_URI.gsub( "Machine", "action/destroy")
> +      machine[:operations][2][0].must_include RESOURCE_URI.gsub( "Machine", "action/capture")
> +    else
> +      log.info("machine is in an intermediate state: " +  machine.state)
> +    end
> +  end
> +
> +  # 52., 5.3: Start, stop the machine
> +  it "should be able to start and stop machines" do
> +    if (machine.state.upcase.eql?("RUNNING") ||
> +      machine.state.upcase.eql?("STARTED"))
> +       machine_stop_start(machine, "stop", "STOPPED")
> +        machine_stop_start(machine, "start", "STARTED")
> +    elsif machine.state.upcase.eql?("STOPPED")
> +      machine_stop_start(machine, "start", "STARTED")
> +      machine_stop_start(machine, "stop", "STOPPED")
> +    else
> +      log.info("machine is in an intermediate state: " +  machine.state)
> +    end
> +  end
> +
> +  # 5.4: Modify a Machine attribute
> +  log.info("Modifying machine attributes is not supported - Deltacloud CIMI interface.")
> +
> +end
> diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
> index 29a8d71..ace38bd 100644
> --- a/tests/cimi/test_helper.rb
> +++ b/tests/cimi/test_helper.rb
> @@ -19,6 +19,7 @@ require 'require_relative'
>  require_relative '../helpers/common.rb'
>  require 'singleton'
>  require_relative "../../server/lib/cimi/models"
> +require 'logger'
>  
>  # Add CIMI specific config stuff
>  module CIMI
> @@ -33,6 +34,7 @@ module CIMI
>        def initialize
>          @hash = Deltacloud::Test::yaml_config
>          @cimi = @hash["cimi"]
> +        @preferred = @cimi["preferred"]
>        end
>  
>        def cep_url
> @@ -49,6 +51,18 @@ module CIMI
>          "Basic #{Base64.encode64("#{u}:#{p}")}"
>        end
>  
> +      def provider_perferred_image
> +        @preferred["machine_image"]
> +      end
> +
> +      def provider_perferred_config
> +        @preferred["machine_config"]
> +      end
> +
> +      def provider_perferred_volume_config
> +        @preferred["volume_config"]
> +      end
> +
>        def collections
>          xml.xpath("/c:CloudEntryPoint/c:*[@href]", ns).map { |c| c.name.to_sym }
>        end
> @@ -61,6 +75,7 @@ module CIMI
>          { "c" => CIMI_NAMESPACE }
>        end
>  
> +
>        private
>        def xml
>          unless @xml
> @@ -79,6 +94,7 @@ end
>  module CIMI::Test::Methods
>  
>    module Global
> +
>      def api
>        CIMI::Test::config
>      end
> @@ -134,6 +150,40 @@ module CIMI::Test::Methods
>        end
>        headers
>      end
> +
> +    # Adding logging capability
> +    def log
> +      unless @log
> +        @log = Logger.new(STDOUT)
> +        if ENV['LOG_LEVEL'].nil?
> +          @log.level = Logger::WARN
> +        else
> +          @log.level = Logger.const_get ENV['LOG_LEVEL']
> +        end
> +      end
> +      @log
> +    end
> +
> +    def poll_state(machine, state)
> +      while not machine.state.upcase.eql?(state)
> +        puts state
> +        puts 'waiting for machine to be: ' + state.to_s()
> +        sleep(10)
> +        machine = machine(:refetch => true)
> +      end
> +    end
> +
> +    def machine_stop_start(machine, action, state)
> +      response = RestClient.post( machine.id + "/" + action,
> +            "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
> +              "<action> http://http://schemas.dmtf.org/cimi/1/action/" + action
+ "</action>" +
> +            "</Action>",
> +            {'Authorization' => api.basic_auth, :accept => :xml })
> +      response.code.must_equal 202
> +      poll_state(machine(:refetch => true), state)
> +      machine(:refetch => true).state.upcase.must_equal state
> +    end
> +
>    end
>  
>    module ClassMethods
> @@ -164,6 +214,98 @@ module CIMI::Test::Methods
>          end
>        end
>      end
> +
> +    # Cleanup: stop/destroy the resources created for the tests
> +    def teardown(created_resources, api_basic_auth)
> +      @@created_resources = created_resources
> +      puts "CLEANING UP... resources for deletion: #{@@created_resources.inspect}"
> +
> +      # 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",
> +            "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
> +            "<action> http://http://schemas.dmtf.org/cimi/1/action/stop</action>"
+
> +            "</Action>",
> +            {'Authorization' => api.basic_auth, :accept => :xml } )
> +
> +            if stop_res.code == 202
> +
> +              model_state = RestClient.get( @@created_resources[:machines][i],
> +              {'Authorization' => api_basic_auth, :accept => :json} ).json["state"]
> +
> +              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)
> +          end
> +        end
> +
> +        @@created_resources[:machines].compact!
> +        @@created_resources.delete(:machines) if @@created_resources[:machines].empty?
> +      end
> +
> +      # machine_image, machine_volumes, other collections
> +      if (not @@created_resources[:machine_images].nil?) &&
> +      (not @@created_resources[:volumes].nil?)
> +        [:machine_images, :volumes].each do |col|
> +          @@created_resources[col].each do |k|
> +            attempts = 0
> +            begin
> +              puts "#{k}"
> +              res = RestClient.delete( "#{k}",
> +              {'Authorization' => api_basic_auth, :accept => :json} )
> +              @@created_resources[col].delete(k) if res.code == 200
> +            rescue Exception => e
> +              sleep(10)
> +              attempts += 1
> +              retry if (attempts <= 5)
> +            end
> +          end
> +          @@created_resources.delete(col) if @@created_resources[col].empty?
> +        end
> +      end
> +
> +      puts "CLEANUP attempt finished... resources looks like: #{@@created_resources.inspect}"
> +      raise Exception.new("Unable to delete all created resources - please check: #{@@created_resources.inspect}")
unless @@created_resources.empty?
> +    end
> +
> +    def query_the_cep(collections = [])
> +      it "should have root collections" do
> +        cep = self.send(:subject)
> +        collections.each do |root|
> +          r = root.underscore.to_sym
> +          if cep.respond_to?(r)
> +            log.info( "Testing collection: " + root )
> +            coll = cep.send(r)
> +            coll.must_respond_to :href, "#{root} collection"
> +            unless coll.href.nil?
> +              coll.href.must_be_uri "#{root} collection"
> +              model = fetch(coll.href)
> +              last_response.code.must_equal 200
> +              if last_response.headers[:content_type].eql?("application/json")
> +                last_response.json["resourceURI"].wont_be_nil
> +              end
> +            else
> +              log.info( root + " is not supported by this provider." )
> +            end
> +          end
> +        end
> +      end
> +
> +    end
>    end
>  
>    def self.included(base)
> @@ -220,6 +362,7 @@ class CIMI::Test::Spec < MiniTest::Spec
>            @@_cache.delete(k)
>          end
>        end
> +
>        resp = @_memoized.fetch("#{name}_#{@format}") do |k|
>          if opts[:cache]
>            @_memoized[k] = @@_cache.fetch(k) do |k|
> @@ -241,6 +384,14 @@ class CIMI::Test::Spec < MiniTest::Spec
>      @@_cache[:last_response][@format]
>    end
>  
> +  def setup
> +   unless defined? @@created_resources
> +     # Keep track of what collections were created for deletion after tests:
> +     @@created_resources = {:machines=>[], :machine_images=>[], :volumes=>[]}
> +   end
> +   @@created_resources
> + end
> +
>    private
>  
>    def parse(response)
> diff --git a/tests/config.yaml b/tests/config.yaml
> index 67892f0..a8cd727 100644
> --- a/tests/config.yaml
> +++ b/tests/config.yaml
> @@ -35,3 +35,7 @@ cimi:
>    cep: "http://localhost:3001/cimi/cloudEntryPoint"
>    user: "mockuser"
>    password: "mockpassword"
> +  preferred:
> +    machine_image: "img2"
> +    machine_config: "m1-small"
> +    volume_config: "2"
> 


Mime
View raw message