deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [3/4] git commit: CIMI - Tests - cleanly skip CIMI Resource Metadata tests for unsupported capabilities DTACLOUD-471
Date Fri, 22 Feb 2013 16:15:26 GMT
CIMI - Tests - cleanly skip CIMI Resource Metadata tests for unsupported capabilities DTACLOUD-471

TrackedAt: http://tracker.deltacloud.org/patch/5ef613dcee21edad280a0ae935182ec29d54054c


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

Branch: refs/heads/master
Commit: d5c0ad7d3494c5b9614a3199f26f0f13a9064a66
Parents: 05ab34a
Author: Ronelle Landy <rlandy@redhat.com>
Authored: Tue Feb 19 17:46:58 2013 -0500
Committer: marios <marios@redhat.com>
Committed: Fri Feb 22 18:06:29 2013 +0200

----------------------------------------------------------------------
 tests/cimi/rmd3_test.rb   |   53 +++++++++------
 tests/cimi/rmd4_test.rb   |  147 +++++++++++++++++++++-------------------
 tests/cimi/test_helper.rb |   21 ++++++
 3 files changed, 130 insertions(+), 91 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d5c0ad7d/tests/cimi/rmd3_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/rmd3_test.rb b/tests/cimi/rmd3_test.rb
index 2587468..7efec39 100644
--- a/tests/cimi/rmd3_test.rb
+++ b/tests/cimi/rmd3_test.rb
@@ -22,6 +22,10 @@ class MachinesRMDDefaultInitialState < CIMI::Test::Spec
   RESOURCE_URI =
   "http://schemas.dmtf.org/cimi/1/Machine"
   ROOTS = ["machine", "resourceMetadata"]
+  DEFAULT_INITIAL_STATE_CAPABILITY_URI = "http://schemas.dmtf.org/cimi/1/capability/Machine/DefaultInitialState"
+
+  need_rmd(RESOURCE_URI, "capabilities", DEFAULT_INITIAL_STATE_CAPABILITY_URI)
+
 
   MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
 
@@ -34,12 +38,17 @@ class MachinesRMDDefaultInitialState < CIMI::Test::Spec
   # 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"]
+  machine_index = rmd_coll.json["resourceMetadata"].index {|rmd| rmd["typeUri"] ==  RESOURCE_URI}
+
+  unless  machine_index.nil?() || rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].nil?()
+    default_initial_state_index = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].index
{|rmd| rmd["uri"] == DEFAULT_INITIAL_STATE_CAPABILITY_URI}
+    unless default_initial_state_index.nil?()
+      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
+      model :resource_metadata_machine do |fmt|
+        get rmd_coll.json["resourceMetadata"][machine_index]["id"], :accept => fmt
+      end
+    end
   end
 
   it "should have a response code equal to 200" do
@@ -68,22 +77,24 @@ class MachinesRMDDefaultInitialState < CIMI::Test::Spec
 
   # 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
+  unless default_initial_state_index.nil?()
+    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
   end
 
   it "should add resource for cleanup", :only => :json do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d5c0ad7d/tests/cimi/rmd4_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/rmd4_test.rb b/tests/cimi/rmd4_test.rb
index b0d6c8c..9375661 100644
--- a/tests/cimi/rmd4_test.rb
+++ b/tests/cimi/rmd4_test.rb
@@ -27,6 +27,8 @@ class MachinesRMDInitialStates < CIMI::Test::Spec
   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"
 
+  need_rmd(RESOURCE_URI, "capabilities", INITIAL_STATES_CAPABILITY_URI)
+
   MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
 
   #  Ensure test executes in test plan order
@@ -38,11 +40,15 @@ class MachinesRMDInitialStates < CIMI::Test::Spec
   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
+  unless  machine_index.nil?() || rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].nil?()
+    initial_states_index = rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].index
{|rmd| rmd["uri"] == INITIAL_STATES_CAPABILITY_URI}
+    unless initial_states_index.nil?()
+      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
+    end
   end
 
   it "should have a response code equal to 200" do
@@ -75,76 +81,77 @@ class MachinesRMDInitialStates < CIMI::Test::Spec
 
   # 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
+  unless rmd_coll.json["resourceMetadata"][machine_index]["capabilities"].nil?()
+    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}
   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
+  unless initial_states_value.nil?() || default_initial_state_value.nil?()
+    @@rmd4_created_machines = {}
+    (0..(initial_states_value.split(",").size() - 1)).each do |i|
+      chosen_initial_state = initial_states_value.split(',')[i]
 
-  it "should have a name" do
-    log.info("machine name: " + machine.name)
-    machine.name.wont_be_empty
+      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
-
-  # 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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d5c0ad7d/tests/cimi/test_helper.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 96e94f6..37f0166 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -129,6 +129,17 @@ module CIMI::Test::Methods
       discover_uri_for(op, "", subcollection_ops)
     end
 
+    def discover_uri_for_rmd(resource_uri, rmd_type, rmd_uri)
+      cep_json = cep(:accept => :json)
+      rmd_coll = get cep_json.json["resourceMetadata"]["href"], :accept => :json
+      #get the collection index:
+      collection_index = rmd_coll.json["resourceMetadata"].index {|rmd| rmd["typeUri"] ==
 resource_uri}
+      unless rmd_coll.json["resourceMetadata"][collection_index][rmd_type].nil?()
+        rmd_index = rmd_coll.json["resourceMetadata"][collection_index][rmd_type].index {|rmd|
rmd["uri"] == rmd_uri}
+      end
+      raise "Couldn't discover the #{rmd_uri} URI" if rmd_index.nil?() || rmd_index.empty?()
+    end
+
     def get_a(cep, item)
       if api.preferred[item]
         item_id = cep.json[item.pluralize]["href"] + "/" + api.preferred[item]
@@ -285,6 +296,16 @@ module CIMI::Test::Methods
       end
     end
 
+    def need_rmd(resource_uri, rmd_type, rmd_uri)
+      before :each do
+        begin
+          discover_uri_for_rmd(resource_uri, rmd_type, rmd_uri)
+        rescue RuntimeError => e
+          skip "Server at #{api.cep_url} doesn't support #{rmd_uri}. #{e.message}"
+        end
+      end
+    end
+
     # Perform basic collection checks; +model_name+ is the name of the
     # method returning the collection model
     def check_collection(model_name)


Mime
View raw message