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 Machines Resource Metadata test, part 3
Date Wed, 30 Jan 2013 07:17:52 GMT
nack - some code duplication in rmd3_test.rb (lines 100 and 142) -
likely a copy/paste error - probably best if you tidy that up as I can't
tell which one is meant to be where...


marios


On 30/01/13 01:00, rlandy@redhat.com wrote:
> From: Ronelle Landy <rlandy@redhat.com>
> 
> ---
>  tests/cimi/rmd2_test.rb |    8 ++-
>  tests/cimi/rmd3_test.rb |  161 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 167 insertions(+), 2 deletions(-)
>  create mode 100644 tests/cimi/rmd3_test.rb
> 
> diff --git a/tests/cimi/rmd2_test.rb b/tests/cimi/rmd2_test.rb
> index 406f48f..8e0394e 100644
> --- a/tests/cimi/rmd2_test.rb
> +++ b/tests/cimi/rmd2_test.rb
> @@ -91,16 +91,20 @@ class MachinesResourceMetadata < CIMI::Test::Spec
>      last_response.code.must_equal 200
>    end
>  
> -  it "should Each capability, attribute and action advertised must contain attributes
specified", :only => :json do
> +  it "should show each capability, attribute and action containing attributes specified",
:only => :json do
>      resource_metadata_machine
>      rmd_type = ["capabilities", "attributes", "actions"]
>      elements = [ ["name", "uri", "description", "value"],
> -      ["name", "namespace", "type", "required", "constraints"],
> +      # see Mantis issue 1977
> +      ["name", "namespace", "type", "required"],  # "constraints"],
>        ["name", "uri", "description", "method", "inputMessage", "outputMessage"] ]
>      $i=0
>      while $i < rmd_type.size()
>        unless last_response.json[rmd_type[$i]].nil?()
> +        log.info("Testing resource metadata: " + last_response.json[rmd_type[$i]].to_s())
> +        log.info(" For elements: " + elements[$i].to_s())
>          (elements[$i].all? { |element| last_response.json[rmd_type[$i]].all? {|i| !i[element].nil?()}
}).must_equal true
> +        log.info(" Results for " + rmd_type[$i] + ":  true")
>        end
>        $i +=1
>      end
> diff --git a/tests/cimi/rmd3_test.rb b/tests/cimi/rmd3_test.rb
> new file mode 100644
> index 0000000..9e380c3
> --- /dev/null
> +++ b/tests/cimi/rmd3_test.rb
> @@ -0,0 +1,161 @@
> +#
> +# 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 MachinesRMDDefaultInitialState < CIMI::Test::Spec
> +  RESOURCE_URI =
> +  "http://schemas.dmtf.org/cimi/1/Machine"
> +  ROOTS = ["machine", "resourceMetadata"]
> +
> +  MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
> +
> +  #  Ensure test executes in test plan order
> +  i_suck_and_my_tests_are_order_dependent!
> +
> +  # This test applies only if the ResourceMetadata corresponding to the
> +  # Machine resource contains a DefaultInitialState capability.
> +
> +  # 3.1: Query the ResourceMetadata entry
> +  cep_json = cep(:accept => :json)
> +  rmd_coll = get cep_json.json[ROOTS[1]]["href"], :accept => :json
> +  machine_index = rmd_coll.json["resourceMetadata"].index {|rmd| rmd.to_s().include?
"Machine"}
> +  default_initial_state_index = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].index
{|rmd| rmd.to_s().include? "DefaultInitialState"}
> +  default_initial_state_value = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"][default_initial_state_index]["value"]
> +
> +  model :resource_metadata_machine do |fmt|
> +    get rmd_coll.json["resourceMetadata"][machine_index]["id"], :accept => fmt
> +  end
> +
> +  it "should have a response code equal to 200" do
> +    resource_metadata_machine
> +    last_response.code.must_equal 200
> +  end
> +
> +  it "should return the DefaultInitialState capability", :only => :json do
> +    resource_metadata_machine
> +    unless last_response.json["capabilities"].nil?()
> +      log.info("Testing resource metadata: " + last_response.json["capabilities"].to_s())
> +      (last_response.json["capabilities"].any?{ |capability| capability["name"].include?
"DefaultInitialState"}).must_equal true
> +      log.info(last_response.json["capabilities"])
> +    end
> +  end
> +
> +  # 3.2: Inspect the capability
> +  it "should contain name, uri (unique), description, a single value", :only => :json
do
> +    resource_metadata_machine
> +
> +    elements = ["name", "uri", "description", "value"]
> +    (elements.all? { |element| last_response.json["capabilities"][default_initial_state_index].include?
element}).must_equal true
> +
> +    (last_response.json["capabilities"][default_initial_state_index]["value"].include?
',').must_equal false
> +  end
> +
> +  # 3.3 Put collection member in state to verify capability
> +  # Create a new machine
> +  cep_json = cep(:accept => :json)
> +  # discover the 'addURI' for creating Machine
> +  add_uri = discover_uri_for("add", "machines")
> +  resp = post(add_uri,
> +  "<Machine>" +
> +  "<name>cimi_machine_" + rand(6).to_s + "</name>" +
> +  "<machineTemplate>" +
> +  "<machineConfig " +
> +  "href=\"" + get_a(cep_json, "machineConfig")+ "\"/>" +
> +  "<machineImage " +
> +  "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
> +  "</machineTemplate>" +
> +  "</Machine>", :accept => :json, :content_type => :xml)
> +
> +  model :machine do |fmt|
> +    get resp.json["id"], :accept => fmt
> +  end
> +
> +  it "should add resource for cleanup", :only => :json do
> +    @@created_resources[:machines] << resp.json["id"]
> +  end
> +
> +  it "should have a name" do
> +    log.info("machine name: " + machine.name)
> +    machine.name.wont_be_empty
> +  end
> +
> +  # 3.4:  Execute a query/action to expose the capability
> +  # Execute a GET /machines/new_machine_id operation to return the machine stable initial
state
> +  it "should have a state equal to default initial state" do
> +    $i=0
> +    machine
> +    while (not machine.state.upcase.eql?(default_initial_state_value.upcase)) &&
($i < 5)
> +      puts machine.state
> +      puts 'waiting for machine to be: ' + default_initial_state_value
> +      sleep(5)
> +      machine = machine(:refetch => true)
> +      $i +=1
> +    end
> +
> +    machine = machine(:refetch => true)
> +    machine.state.upcase.must_equal default_initial_state_value
> +    cep_json = cep(:accept => :json)
> +    # discover the 'addURI' for creating Machine
> +    add_uri = discover_uri_for("add", "machines")
> +    resp = post(add_uri,
> +    "<Machine>" +
> +    "<name>cimi_machine_" + rand(6).to_s + "</name>" +
> +    "<machineTemplate>" +
> +    "<machineConfig " +
> +    "href=\"" + get_a(cep_json, "machineConfig")+ "\"/>" +
> +    "<machineImage " +
> +    "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
> +    "</machineTemplate>" +
> +    "</Machine>", :accept => :json, :content_type => :xml)
> +
> +    model :machine do |fmt|
> +      get resp.json["id"], :accept => fmt
> +    end
> +
> +    it "should add resource for cleanup", :only => :json do
> +      @@created_resources[:machines] << resp.json["id"]
> +    end
> +
> +    it "should have a name" do
> +      log.info("machine name: " + machine.name)
> +      machine.name.wont_be_empty
> +    end
> +
> +    # 3.4:  Execute a query/action to expose the capability
> +    # Execute a GET /machines/new_machine_id operation to return the machine stable
initial state
> +    it "should have a state equal to default initial state" do
> +      $i=0
> +      machine
> +      while (not machine.state.upcase.eql?(default_initial_state_value.upcase)) &&
($i < 5)
> +        puts machine.state
> +        puts 'waiting for machine to be: ' + default_initial_state_value
> +        sleep(5)
> +        machine = machine(:refetch => true)
> +        $i +=1
> +      end
> +
> +      machine = machine(:refetch => true)
> +      machine.state.upcase.must_equal default_initial_state_value
> +    end
> +  end
> +
> +  # 3.5: Cleanup
> +  # see @created_resources
> +
> +end
> 


Mime
View raw message