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 add machineTemplates test and selection if no preferred option
Date Mon, 03 Dec 2012 15:09:33 GMT
CIMI - tests add machineTemplates test and selection if no preferred option


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

Branch: refs/heads/master
Commit: eed21c65fdea048d744d8f7374a500baa68076c8
Parents: ca39bca
Author: Ronelle Landy <rlandy@redhat.com>
Authored: Sun Dec 2 00:47:42 2012 -0500
Committer: marios <marios@redhat.com>
Committed: Mon Dec 3 16:02:47 2012 +0200

----------------------------------------------------------------------
 tests/cimi/part2_test.rb  |    4 +-
 tests/cimi/part3_test.rb  |   77 +++++++++++++++++++++++++++++++++++++++-
 tests/cimi/part4_test.rb  |   18 +++------
 tests/cimi/part5_test.rb  |    6 ++--
 tests/cimi/test_helper.rb |   30 ++++++++++------
 tests/config.yaml         |    6 ++--
 6 files changed, 109 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/eed21c65/tests/cimi/part2_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/part2_test.rb b/tests/cimi/part2_test.rb
index d04e026..ae26710 100644
--- a/tests/cimi/part2_test.rb
+++ b/tests/cimi/part2_test.rb
@@ -58,9 +58,9 @@ end
         "<name>cimi_machine_" + fmt.to_s() + "</name>" +
         "<machineTemplate>" +
           "<machineConfig " +
-            "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" + api.provider_perferred_config
+ "\"/>" +
+            "href=\"" + get_a(cep_json, "machineConfig")+ "\"/>" +
           "<machineImage " +
-            "href=\"" + cep_json.json["machineImages"]["href"] + "/" + api.provider_perferred_image
+ "\"/>" +
+            "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
         "</machineTemplate>" +
       "</Machine>",
       {'Authorization' => api.basic_auth, :accept => fmt})

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/eed21c65/tests/cimi/part3_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/part3_test.rb b/tests/cimi/part3_test.rb
index 10bc2d5..190fb61 100644
--- a/tests/cimi/part3_test.rb
+++ b/tests/cimi/part3_test.rb
@@ -19,5 +19,80 @@ $:.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.")
+  RESOURCE_URI =
+    "http://schemas.dmtf.org/cimi/1/CloudEntryPoint"
+  ROOTS = ["machines", "machineImages", "machineConfigurations"]
+
+  MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
+
+  # 3.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.
+  # CEP.machines, CEP.machineConfigs and CEP.machineImages must be set
+  query_the_cep(ROOTS)
+
+  # 3.2 Querying MachineTemplates
+  # At least one MachineTemplate resource must appear in the collection
+  it "should contain one MachineTemplates resource" do
+    r = "machineTemplates".underscore.to_sym
+    model = fetch(subject.send(r).href)
+    log.info(model.attribute_values[r][0])
+    assert_equal model.attribute_values[r][0].nil?(), false
+  end
+
+  # A represenation of a MachineTemplatesCollection resource is returned.
+  cep_json = cep(:accept => :json)
+  model :machineTemplate do |fmt|
+    get(cep_json.json["machineTemplates"]["href"], {:accept=> :json}).json["machineTemplates"][0]
+  end
+
+  it "should have a name" do
+    machineTemplate["name"].wont_be_empty
+  end
+
+  it "should have a response code equal to 200" do
+    machineTemplate
+    last_response.code.must_equal 200
+  end
+
+  it "should have a machineConfig" do
+    machineTemplate["machineConfig"].wont_be_empty
+  end
+
+  it "should have a machineImage" do
+    machineTemplate["machineImage"].wont_be_empty
+  end
+
+  # 3.3 Creating a new machine
+  model :machine do |fmt|
+    cep_json = cep(:accept => :json)
+    #discover the 'addURI' for creating Machine
+    add_uri = discover_uri_for("add", "machines")
+    RestClient.post(add_uri,
+      "<Machine>" +
+        "<name>cimi_machine_from_template" + fmt.to_s() + "</name>" +
+        "<description> Created machine from template" + fmt.to_s() + "</description>"
+
+        "<machineTemplate" +
+          "href=\"" + get_a(cep_json, "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

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/eed21c65/tests/cimi/part4_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
index 8e27c9c..056aeff 100644
--- a/tests/cimi/part4_test.rb
+++ b/tests/cimi/part4_test.rb
@@ -31,7 +31,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
     cep(:accept => fmt)
   end
 
-  # 2.2, 2.3: CEP.machines, CEP.volumes and CEP.volumeConfigs must be set
+  # 4.2, 4.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
@@ -55,9 +55,9 @@ class AddVolumeToMachine < CIMI::Test::Spec
        "<name>cimi_machine</name>" +
        "<machineTemplate>" +
          "<machineConfig " +
-           "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" + api.provider_perferred_config
+ "\"/>" +
+           "href=\"" + get_a(cep_json, "machineConfig") + "\"/>" +
          "<machineImage " +
-           "href=\"" + cep_json.json["machineImages"]["href"] + "/" + api.provider_perferred_image
+ "\"/>" +
+           "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
        "</machineTemplate>" +
      "</Machine>",
      {'Authorization' => api.basic_auth, :accept => :json})
@@ -70,8 +70,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
         "<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 href=\"" + get_a(cep_json, "volumeConfig") + "\">" +
           "</volumeConfig>" +
         "</volumeTemplate>" +
       "</Volume>",
@@ -108,8 +107,7 @@ class AddVolumeToMachine < CIMI::Test::Spec
     "<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 href=\"" + get_a(cep_json, "volumeConfig") + "\">" +
       "</volumeConfig>" +
     "</volumeTemplate>" +
   "</Volume>",
@@ -132,15 +130,11 @@ class AddVolumeToMachine < CIMI::Test::Spec
     last_response.code.must_equal 201
   end
 
-  it "should have delete and edit operations", :only => :xml do
-    # no edit
+  it "should have a delete operation", :only => :xml do
     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
     detach_uri = discover_uri_for("delete", "", machineWithVolume.operations)
     response = RestClient.delete(detach_uri,
     {'Authorization' => api.basic_auth, :accept => :xml})

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/eed21c65/tests/cimi/part5_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/part5_test.rb b/tests/cimi/part5_test.rb
index a5a58a9..d451a7b 100644
--- a/tests/cimi/part5_test.rb
+++ b/tests/cimi/part5_test.rb
@@ -36,9 +36,9 @@ class ManipulateAMachine < CIMI::Test::Spec
       "<name>cimi_machine_part5</name>" +
       "<machineTemplate>" +
         "<machineConfig " +
-          "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" + api.provider_perferred_config
+ "\"/>" +
+          "href=\"" + get_a(cep_json, "machineConfig") + "\"/>" +
         "<machineImage " +
-          "href=\"" + cep_json.json["machineImages"]["href"] + "/" + api.provider_perferred_image
+ "\"/>" +
+          "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
       "</machineTemplate>" +
     "</Machine>",
     {'Authorization' => api.basic_auth, :accept => :json})
@@ -80,7 +80,7 @@ class ManipulateAMachine < CIMI::Test::Spec
     s.must_include machine.state.upcase
   end
 
-  it "should have disks and columes collections" do
+  it "should have disks and volumes collections" do
     machine.disks.must_respond_to :href, "disks collection"
     machine.volumes.must_respond_to :href, "volumes collection"
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/eed21c65/tests/cimi/test_helper.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 3b9e4bf..1b235c7 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -34,7 +34,6 @@ module CIMI
       def initialize
         @hash = Deltacloud::Test::yaml_config
         @cimi = @hash["cimi"]
-        @preferred = @cimi["preferred"]
       end
 
       def cep_url
@@ -51,16 +50,8 @@ 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"]
+      def preferred
+        @cimi["preferred"] || {}
       end
 
       def collections
@@ -121,6 +112,23 @@ module CIMI::Test::Methods
       discover_uri_for(op, "", subcollection_ops)
     end
 
+    def get_a(cep, item)
+      if api.preferred[item]
+        item_id = cep.json[item.pluralize]["href"] + "/" + api.preferred[item]
+      else
+        item_id = get(cep.json[item.pluralize]["href"], {:accept=> :json}).json[full_name(item).pluralize][0]["id"]
+      end
+    end
+
+    def full_name(item)
+      if item.include?("Config")
+        full_name = item.gsub("Config", "Configuration")
+      else
+        full_name = item
+      end
+    end
+
+
     def get(path, params = {})
       RestClient.get absolute_url(path), headers(params)
     end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/eed21c65/tests/config.yaml
----------------------------------------------------------------------
diff --git a/tests/config.yaml b/tests/config.yaml
index a8cd727..9e21c9f 100644
--- a/tests/config.yaml
+++ b/tests/config.yaml
@@ -36,6 +36,6 @@ cimi:
   user: "mockuser"
   password: "mockpassword"
   preferred:
-    machine_image: "img2"
-    machine_config: "m1-small"
-    volume_config: "2"
+   machineImage: "img2"
+   machineConfig: "m1-small"
+   volumeConfig: "2"


Mime
View raw message