deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rla...@redhat.com
Subject [PATCH] CIMI Tests - adding Resource Metadata test, part 4
Date Wed, 30 Jan 2013 20:13:43 GMT
From: Ronelle Landy <rlandy@redhat.com>

---
 tests/cimi/rmd4_test.rb |  149 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 insertions(+), 0 deletions(-)
 create mode 100644 tests/cimi/rmd4_test.rb

diff --git a/tests/cimi/rmd4_test.rb b/tests/cimi/rmd4_test.rb
new file mode 100644
index 0000000..bf1ef5a
--- /dev/null
+++ b/tests/cimi/rmd4_test.rb
@@ -0,0 +1,149 @@
+#
+# 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 MachinesRMDInitialStates < 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 the InitialStates capability.
+
+  # 4.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"}
+  initial_states_index = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].index
{|rmd| rmd.to_s().include? "InitialStates"}
+  initial_states_value = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"][initial_states_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 InitialStates 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?
"InitialStates"}).must_equal true
+      log.info(last_response.json["capabilities"])
+    end
+  end
+
+  # 4.2: Inspect the capability
+  it "should contain name, uri (unique), description, value(s)", :only => :json do
+    resource_metadata_machine
+
+    elements = ["name", "uri", "description", "value"]
+    (elements.all? { |element| last_response.json["capabilities"][initial_states_index].include?
element}).must_equal true
+
+  end
+
+  # 4.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")
+
+  # Specify a desired initial state which is different from
+  # the default value (see DefaultInitalState capability)
+  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"]
+
+  default_within_initial_state_index = initial_states_value.split(',').index {|rmd| rmd.to_s().include?
default_initial_state_value}
+# chosen_initial_state = initial_states_value.split(',')[default_within_initial_state_index]
+# unless initial_states_value.split(',').size().eql? 1
+    $i=0
+    while $i < initial_states_value.split(',').size()
+      chosen_initial_state = initial_states_value.split(',')[$i]
+      if !chosen_initial_state.eql? default_initial_state_value
+        puts "Testing initial state value: " + chosen_initial_state
+      else
+        puts "Testing initial state value - " +
+          " equal to the default initial state: " + chosen_initial_state
+      end
+
+  resp = post(add_uri,
+  "<Machine>" +
+  "<name>cimi_machine_" + $i.to_s + "</name>" +
+  "<machineTemplate>" +
+  "<initialState>" + chosen_initial_state + "</initialState>" +
+  "<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 201 (or 202) created response code" do
+    resp.code.must_be_one_of [201, 202]
+  end
+
+  it "should have a name" do
+    log.info("machine name: " + machine.name)
+    machine.name.wont_be_empty
+  end
+
+  # 4.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 the specified initial state" do
+    $j=0
+    machine
+    while (not machine.state.upcase.eql?(chosen_initial_state.upcase)) && ($j <
5)
+      puts machine.state
+      puts 'waiting for machine to be: ' + chosen_initial_state
+      sleep(5)
+      machine = machine(:refetch => true)
+      $j +=1
+    end
+
+    machine = machine(:refetch => true)
+    machine.state.upcase.must_equal chosen_initial_state
+   end
+
+  # 4.5: Cleanup
+  # see @created_resources
+
+  # 4.6: Repeat the test for initial states advertised
+  # (if there are more states to test)
+   $i +=1
+ end
+
+end
-- 
1.7.7.6


Mime
View raw message