From: Ronelle Landy <[email protected]>
---
tests/cimi/cep_test.rb | 35 +++++++++++-
tests/cimi/part2_test.rb | 88 ++++++++++++++++++++++++++++
tests/cimi/part3_test.rb | 23 +++++++
tests/cimi/part4_test.rb | 81 ++++++++++++++++++++++++++
tests/cimi/part5_test.rb | 141 +++++++++++++++++++++++++++++++++++++++++++++
tests/cimi/test_helper.rb | 21 +++++++
tests/config.yaml | 3 +
7 files changed, 391 insertions(+), 1 deletions(-)
create mode 100644 tests/cimi/part2_test.rb
create mode 100644 tests/cimi/part3_test.rb
create mode 100644 tests/cimi/part4_test.rb
create mode 100644 tests/cimi/part5_test.rb
diff --git a/tests/cimi/cep_test.rb b/tests/cimi/cep_test.rb
index 42bb057..39dbbdf 100644
--- a/tests/cimi/cep_test.rb
+++ b/tests/cimi/cep_test.rb
@@ -49,6 +49,11 @@ class CloundEntryPointBehavior < CIMI::Test::Spec
it "should have a name" do
subject.name.wont_be_empty
end
+
+ it "should have a response code equal to 200" do
+ subject
+ last_response.code.must_equal 200
+ end
it "should have the correct resourceURI", :only => :json do
subject.wont_be_nil # Make sure we talk to the server
@@ -59,14 +64,42 @@ class CloundEntryPointBehavior < CIMI::Test::Spec
ROOTS.each do |root|
r = root.underscore.to_sym
if subject.respond_to?(r)
+ log.info( "Testing collection: " + root )
coll = subject.send(r)
coll.must_respond_to :href, "#{root} collection"
unless coll.href.nil?
coll.href.must_be_uri "#{root} collection"
model = fetch(coll.href)
last_response.code.must_equal 200
- end
+ if last_response.headers[:content_type].eql?("application/json")
+ last_response.json["resourceURI"].wont_be_nil
+ end
+ else
+ log.info( root + " is not supported by this provider." )
+ end
end
end
end
+
+ # Testing "*/*" Accept Headers returns json output
+ response = RestClient.get(api.cep_url, "Accept" => "*/*")
+ log.info( " */* accept headers return: " + response.json.to_s() )
+
+ it "should return json response", :only => "*/*" do
+ response.wont_be_nil
+ response.headers[:content_type].eql?("application/json")
+ end
+
+ it "should have a response code equal to 200", :only => "*/*" do
+ response.code.must_equal 200
+ end
+
+ it "should have an id equal to the CEP URL" , :only => "*/*" do
+ response.json["id"].must_equal api.cep_url
+ end
+
+ it "should have a baseURI" do
+ response.json["baseURI"].must_be_uri
+ end
+
end
diff --git a/tests/cimi/part2_test.rb b/tests/cimi/part2_test.rb
new file mode 100644
index 0000000..facd221
--- /dev/null
+++ b/tests/cimi/part2_test.rb
@@ -0,0 +1,88 @@
+#
+# 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 CreateNewMachine < CIMI::Test::Spec
+ RESOURCE_URI =
+ "http://schemas.dmtf.org/cimi/1/CloudEntryPoint"
+
+ # CEP.machines, CEP.machineConfigs and CEP.machineImages must be set
+ ROOTS = [ "machines" , "machineImages" , "machineConfigurations"]
+
+ # 2.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.
+ # Does this mean we need to repeat the checks performed in cep_test?
+ # If we run tests in order so that the cep test always runs first, this
should not be needed.
+
+ # 2.2, 2.3: Querying the MachineImages and MachineConfigurations
+ it "should have root collections" do
+ ROOTS.each do |root|
+ r = root.underscore.to_sym
+ log.info( "Testing collection: " + root )
+ coll = subject.send(r)
+ coll.must_respond_to :href, "#{root} collection"
+ coll.href.must_be_uri "#{root} collection"
+ model = fetch(coll.href)
+ last_response.code.must_equal 200
+ unless r.eql?(:machines)
+ # At least one resource must appear in the collection
+ log.info(model.attribute_values[r][0])
+ assert_equal model.attribute_values[r][0].nil?(), false
+ end
+ end
+ end
+
+ # 2.4: Create a new CredentialResource
+ log.info("Create a new CredentialResource: credential_resources is not a
supported collection.")
+
+ # 2.5: Create a new Machine
+ model :machine, :cache => true do |fmt|
+ cep_json = cep(:accept => :json)
+
+ RestClient.post(cep_json.json["machines"]["href"],
+ "<Machine>" +
+ "<name>cimi_machine_" + fmt.to_s() + "</name>" +
+ "<machineTemplate>" +
+ "<machineConfig " +
+ "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" +
api.provider_perferred_config + "\"/>" +
+ "<machineImage " +
+ "href=\"" + cep_json.json["machineImages"]["href"] + "/" +
api.provider_perferred_image + "\"/>" +
+ "</machineTemplate>" +
+ "</Machine>",
+ {'Authorization' => api.basic_auth, :accept => fmt})
+ 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
+
+# Should clean up the machine we created ...
+
+
+end
diff --git a/tests/cimi/part3_test.rb b/tests/cimi/part3_test.rb
new file mode 100644
index 0000000..10bc2d5
--- /dev/null
+++ b/tests/cimi/part3_test.rb
@@ -0,0 +1,23 @@
+#
+# 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 CreateNewMachineFromMachineTemplate < CIMI::Test::Spec
+ log.info("MachineTemplates are not yet a supported collection - Deltacloud
CIMI interface.")
+end
diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb
new file mode 100644
index 0000000..b56af34
--- /dev/null
+++ b/tests/cimi/part4_test.rb
@@ -0,0 +1,81 @@
+#
+# 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 AddVolumeToMachine < CIMI::Test::Spec
+ RESOURCE_URI = "http://schemas.dmtf.org/cimi/1/CoundEntryPoint"
+
+ # CEP.machines, CEP.volumes and CEP.volumeConfigs must be set
+ ROOTS = [ "machines" , "volumes" , "volumeConfigurations"]
+
+ # 4.1: Query the CEP
+ model :subject, :cache => true do |fmt|
+ cep(:accept => fmt)
+ end
+
+ # 2.2, 2.3: Querying the volumeConfigurations
+ it "should have root collections" do
+ ROOTS.each do |root|
+ r = root.underscore.to_sym
+ log.info( "Testing collection: " + root )
+ coll = subject.send(r)
+ coll.must_respond_to :href, "#{root} collection"
+ coll.href.must_be_uri "#{root} collection"
+ model = fetch(coll.href)
+ last_response.code.must_equal 200
+ if r.eql?(:volume_configurations)
+ # At least one VolumeConfiguration resource must appear in the
collection
+ log.info(model.attribute_values[r][0])
+ assert_equal model.attribute_values[r][0].nil?(), false
+ model.attribute_values[r][0].id.must_be_uri
+ end
+ end
+ end
+
+# Create a machine to attach the volume
+ cep_json = cep(:accept => :json)
+ MACHINE = RestClient.post(cep_json.json["machines"]["href"],
+ "<Machine>" +
+ "<name>cimi_machine</name>" +
+ "<machineTemplate>" +
+ "<machineConfig " +
+ "href=\"" + cep_json.json["machineConfigs"]["href"] + "/" +
api.provider_perferred_config + "\"/>" +
+ "<machineImage " +
+ "href=\"" + cep_json.json["machineImages"]["href"] + "/" +
api.provider_perferred_image + "\"/>" +
+ "</machineTemplate>" +
+ "</Machine>",
+ {'Authorization' => api.basic_auth, :accept => :json})
+
+ # 4.3: Create a new Volume and
+ # 4.4: Attach the new Volume to a Machine
+ model :volume, :cache => true do |fmt|
+
+ # See https://issues.apache.org/jira/browse/DTACLOUD-375 ... awaiting
fix/instructions
+ # on how to create a volume from a volumeTemplate
+
+
+
+ end
+
+
+
+# Should clean up the machine, volume we created ...
+
+
+end
diff --git a/tests/cimi/part5_test.rb b/tests/cimi/part5_test.rb
new file mode 100644
index 0000000..5394322
--- /dev/null
+++ b/tests/cimi/part5_test.rb
@@ -0,0 +1,141 @@
+#
+# 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"
+require "set"
+require "time"
+
+class ManipulateAMachine < CIMI::Test::Spec
+ RESOURCE_URI =
+ "http://schemas.dmtf.org/cimi/1/Machine"
+
+ # 2.1: Query the Machine
+ # We may want to create a machine before we query it.
+ # For the mock provider, querying a machine w/o creating will work
+ model :machine do |fmt|
+ mcoll_uri = cep(:accept => :json).json["machines"]["href"]
+ mcoll = get(mcoll_uri, :accept => :json).json
+ m_url = mcoll["machines"][0]["id"]
+ get m_url, :accept => fmt
+ end
+
+ it "should have a name" do
+ log.info("machine name: " + machine.name)
+ machine.name.wont_be_empty
+ end
+
+ it "should have have a description" do
+ machine.description.wont_be_empty
+ end
+
+ it "should have an id including the cep url" do
+ log.info("machine id: " + machine.id)
+ machine.id.must_include api.cep_url.gsub("cloudEntryPoint", "machines/")
+ end
+
+ it "should have a valid creation time" do
+ Time.parse(machine.created.to_s()) < Time.now
+ end
+
+ it "should have numerical values for memory and cpu" do
+ machine.cpu.to_s.must_match /^[0-9]+$/
+ machine.memory.to_s.must_match /^[0-9]+$/
+ end
+
+ it "should have a valid state" do
+ s = Set.new ["RUNNING", "NEW", "PAUSED", "STOPPED", "STARTED"]
+ log.info("machine state: " + machine.state.upcase)
+ s.must_include machine.state.upcase
+ end
+
+ it "should have disks and columes collections" do
+ machine.disks.must_respond_to :href, "disks collection"
+ machine.volumes.must_respond_to :href, "volumes collection"
+ end
+
+ it "should have a response code equal to 200" do
+ machine
+ last_response.code.must_equal 200
+ end
+
+ it "should return correct content type" do
+ machine
+ last_response.wont_be_nil
+ last_response.headers[:content_type].eql?(:fmt)
+ end
+
+ it "should return possible operations to be executed on a machine" do
+ if (machine.state.upcase.eql?("RUNNING") ||
+ machine.state.upcase.eql?("STARTED"))
+ log.info(RESOURCE_URI.gsub("Machine", "action/restart"))
+ # This relies on odering and needs to be improved
+ machine[:operations][0][0].must_include RESOURCE_URI.gsub( "Machine",
"action/restart")
+ machine[:operations][1][0].must_include RESOURCE_URI.gsub( "Machine",
"action/stop")
+ machine[:operations][2][0].must_include RESOURCE_URI.gsub( "Machine",
"action/capture")
+ elsif machine.state.upcase.eql?("STOPPED")
+ machine[:operations][0][0].must_include RESOURCE_URI.gsub( "Machine",
"action/start")
+ machine[:operations][1][0].must_include RESOURCE_URI.gsub( "Machine",
"action/capture")
+ else
+ log.info("machine is in an intermediate state: " + machine.state)
+ end
+ end
+
+ # 52., 5.3: Start, stop the machine
+ it "should be able to start and stop machines" do
+ if (machine.state.upcase.eql?("RUNNING") ||
+ machine.state.upcase.eql?("STARTED"))
+
+ response = RestClient.post( machine.id + "/stop",
+
"<Action><action>http://www.dmtf.org/cimi/action/stop></action></Action>",
+ {'Authorization' => api.basic_auth, :accept => :json} )
+ # For providers other than mock, need to poll for state change here
+ machine.state.upcase.must_equal "STOPPED"
+ response.code.must_equal 200
+
+ response = RestClient.post( machine.id + "/start",
+
"<Action><action>http://www.dmtf.org/cimi/action/start></action></Action>",
+ {'Authorization' => api.basic_auth, :accept => :xml} )
+ # For providers other than mock, need to poll for state change here
+ machine.state.upcase.must_equal "STARTED"
+ response.code.must_equal 200
+
+ elsif machine.state.upcase.eql?("STOPPED")
+
+ response = RestClient.post( machine.id + "/start",
+
"<Action><action>http://www.dmtf.org/cimi/action/start></action></Action>",
+ {'Authorization' => api.basic_auth, :accept => :xml} )
+ # For providers other than mock, need to poll for state change here
+ machine.state.upcase.must_equal "STARTED"
+ response.code.must_equal 200
+
+ response = RestClient.post( machine.id + "/stop",
+
"<Action><action>http://www.dmtf.org/cimi/action/stop></action></Action>",
+ {'Authorization' => api.basic_auth, :accept => :json} )
+ # For providers other than mock, need to poll for state change here
+ machine.state.upcase.must_equal "STOPPED"
+ response.code.must_equal 200
+ else
+ log.info("machine is in an intermediate state: " + machine.state)
+ end
+ end
+
+ # 5.4: Modify a Machine attribute
+ # Not sure that this is supported?
+
+
+end
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index c6d9c0c..8bbbbce 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -19,6 +19,7 @@ require 'require_relative'
require_relative '../helpers/common.rb'
require 'singleton'
require_relative "../../server/lib/cimi/models"
+require 'logger'
# Add CIMI specific config stuff
module CIMI
@@ -33,6 +34,7 @@ module CIMI
def initialize
@hash = Deltacloud::Test::yaml_config
@cimi = @hash["cimi"]
+ @preferred = @cimi["preferred"]
end
def cep_url
@@ -48,6 +50,15 @@ module CIMI
p ||= @cimi["password"]
"Basic #{Base64.encode64("#{u}:#{p}")}"
end
+
+ def provider_perferred_image
+ @preferred["machine_image"]
+ end
+
+ def provider_perferred_config
+ @preferred["machine_config"]
+ end
+
def collections
xml.xpath("/c:CloudEntryPoint/c:*[@href]", ns).map { |c| c.name.to_sym
}
@@ -79,6 +90,16 @@ end
module CIMI::Test::Methods
module Global
+
+ # Adding logging capability
+ def log
+ unless @log
+ @log = Logger.new(STDOUT)
+ @log.level = Logger::INFO
+ end
+ @log
+ end
+
def api
CIMI::Test::config
end
diff --git a/tests/config.yaml b/tests/config.yaml
index 67892f0..e6f51c2 100644
--- a/tests/config.yaml
+++ b/tests/config.yaml
@@ -35,3 +35,6 @@ cimi:
cep: "http://localhost:3001/cimi/cloudEntryPoint"
user: "mockuser"
password: "mockpassword"
+ preferred:
+ machine_image: "img2"
+ machine_config: "m1-small"
--
1.7.7.6