deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [2/2] git commit: CIMI Tests: Adding Resource Metadata test part 4, InitialStates
Date Fri, 08 Feb 2013 17:36:05 GMT
Updated Branches:
  refs/heads/master e56db6144 -> 91c891a5e


CIMI Tests: Adding Resource Metadata test part 4, InitialStates

TrackedAt: http://tracker.deltacloud.org/patch/d7174327854a3ad6fe13a891f7fdd22c980dbc9e


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/dea3046e
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/dea3046e
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/dea3046e

Branch: refs/heads/master
Commit: dea3046e3fbc805729c0d52d5f82733fe27f1907
Parents: e56db61
Author: Ronelle Landy <rlandy@redhat.com>
Authored: Tue Feb 5 15:29:47 2013 -0500
Committer: marios <marios@redhat.com>
Committed: Fri Feb 8 19:35:30 2013 +0200

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


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/dea3046e/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..9d18c54
--- /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
+  @@created_resources ||= {}
+  RESOURCE_URI =
+  "http://schemas.dmtf.org/cimi/1/Machine"
+  ROOTS = ["machine", "resourceMetadata"]
+  INITIAL_STATES_CAPABILITY_URI = "http://schemas.dmtf.org/cimi/1/capability/Machine/InitialStates"
+  DEFAULT_INITIAL_STATE_CAPABILITY_URI = "http://schemas.dmtf.org/cimi/1/capability/Machine/DefaultInitialState"
+
+  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["typeUri"] ==  RESOURCE_URI}
+  initial_states_index = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].index
{|rmd| rmd["uri"] == INITIAL_STATES_CAPABILITY_URI}
+  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_value = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].inject([]){|res,
cur| res = cur["value"] if cur["uri"] == DEFAULT_INITIAL_STATE_CAPABILITY_URI; res}
+
+# chosen_initial_state = initial_states_value.split(',')[default_within_initial_state_index]
+# unless initial_states_value.split(',').size().eql? 1
+  @@rmd4_created_machines = {}
+  (0..(initial_states_value.split(",").size() - 1)).each do |i|
+    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)
+
+  @@rmd4_created_machines.merge!(chosen_initial_state => resp.json["id"])
+
+  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
+    machine = get(@@rmd4_created_machines[chosen_initial_state], :accept=>:json)
+    5.times do |j|
+      machine = get(@@rmd4_created_machines[chosen_initial_state], :accept=>:json)
+      break if machine.json["state"].upcase.eql?(chosen_initial_state.upcase)
+      puts machine.json["state"]
+      puts 'waiting for machine to be: ' + chosen_initial_state
+      sleep(5)
+    end unless machine.json["state"].upcase.eql?(chosen_initial_state.upcase)
+
+    machine.json["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)
+ end
+
+end


Mime
View raw message