You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2013/04/22 18:35:15 UTC
[7/7] git commit: CIMI: CIMI (white box) Tests - fixes for
start/stop/delete system (+machines)
CIMI: CIMI (white box) Tests - fixes for start/stop/delete system (+machines)
Adds rake task for pf2 (rake test:cimiplan_pf2) and skips if no systems
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/f6f2599d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/f6f2599d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/f6f2599d
Branch: refs/heads/master
Commit: f6f2599df312d51ae40ffe558b66739340b84765
Parents: a749c43
Author: marios <ma...@redhat.com>
Authored: Mon Apr 22 19:33:36 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Mon Apr 22 19:33:36 2013 +0300
----------------------------------------------------------------------
.../mock/data/cimi/system_machine/sysmach1.json | 8 --
.../mock/data/cimi/system_volume/sysvol1.json | 8 --
tests/Rakefile | 4 +
tests/cimi/system1_test.rb | 65 +++++++++++----
tests/cimi/test_helper.rb | 19 ++++
5 files changed, 72 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6f2599d/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json
deleted file mode 100644
index 8fe2a92..0000000
--- a/server/lib/deltacloud/drivers/mock/data/cimi/system_machine/sysmach1.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{ "id": "http://cimi.example.org/systems/system1/machines/inst0",
- "name": "sysmach1",
- "created": "Fri Feb 08 12:15:15 EET 2013",
- "machine": { "href": "http://cimi.example.org/machines/inst0" },
- "operations": [
- { "rel": "delete", "href": "http://cimi.example.org/systems/system1/machines/inst0" }
- ]
-}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6f2599d/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json b/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json
deleted file mode 100644
index 12e3554..0000000
--- a/server/lib/deltacloud/drivers/mock/data/cimi/system_volume/sysvol1.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{ "id": "http://cimi.example.org/systems/system1/volumes/vol1",
- "name": "sysvol1",
- "created": "Fri Feb 08 12:15:15 EET 2013",
- "volume": { "href": "http://cimi.example.org/volumes/vol1" },
- "operations": [
- { "rel": "delete", "href": "http://cimi.example.org/systems/system1/volumes/vol1" }
- ]
-}
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6f2599d/tests/Rakefile
----------------------------------------------------------------------
diff --git a/tests/Rakefile b/tests/Rakefile
index 30f878d..1856c55 100644
--- a/tests/Rakefile
+++ b/tests/Rakefile
@@ -42,4 +42,8 @@ namespace :test do
t.test_files = FileList["cimi/part*_test.rb", "cimi/cep_test.rb"]
end
+ Rake::TestTask.new(:cimiplan_pf2) do |t|
+ t.test_files =FileList["cimi/system1_test.rb", "cimi/rmd*_test.rb", "cimi/machex*_test.rb"]
+ end
+
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6f2599d/tests/cimi/system1_test.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/system1_test.rb b/tests/cimi/system1_test.rb
index c9bd121..6102c37 100644
--- a/tests/cimi/system1_test.rb
+++ b/tests/cimi/system1_test.rb
@@ -23,6 +23,7 @@ class SystemTemplate < CIMI::Test::Spec
ROOTS = [ "machines" , "systemTemplates" , "volumeTemplates"]
need_capability('add', 'systems')
+ need_collection("systems")
# Cleanup for resources created for the test
MiniTest::Unit.after_tests { teardown(@@created_resources, api.basic_auth) }
@@ -66,20 +67,24 @@ class SystemTemplate < CIMI::Test::Spec
rescue RuntimeError =>e
end
- system_add_uri = discover_uri_for("add", "systems")
+ if collection_supported("systems")
+ system_add_uri = discover_uri_for("add", "systems")
# 1.4 Create a new system from the systemTemplate
- system_created = post(system_add_uri,
- "<systemCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
- "<name>test_system</name>" +
- "<systemTemplate href=\"" + get_a(cep_json, "systemTemplate") + "\"/>" +
- "</systemCreate>", :content_type => :xml)
+ system_created = post(system_add_uri,
+ "<systemCreate xmlns=\"#{CIMI::Test::CIMI_NAMESPACE}\">" +
+ "<name>test_system</name>" +
+ "<systemTemplate href=\"" + get_a(cep_json, "systemTemplate") + "\"/>" +
+ "</systemCreate>", :content_type => :xml)
+ end
model :systems do |fmt|
get cep_json.json["systems"]["href"], :accept => fmt
end
- it "should add resource machine resource for cleanup", :only => :json do
- @@created_resources[:machines] << system_created.headers[:location]
+ it "should add system resource for cleanup", :only => :json do
+ @@created_resources ||= {}
+ @@created_resources[:systems] ||= []
+ @@created_resources[:systems] << system_created.headers[:location]
end
it "should allow a system to be created" do
@@ -110,13 +115,14 @@ class SystemTemplate < CIMI::Test::Spec
end
# 1.7 Query the System SystemVolume collection
- it "should contain a single entry referencing a Volume named as indicated in the SystemTemplate", :only => :json do
+ #OPTIONAL for this pf - commenting out for now (created system from template1.json[mock] has no volumes)
+# it "should contain a single entry referencing a Volume named as indicated in the SystemTemplate", :only => :json do
#test_system_created
- test_system_created = get(fetch(system_created.headers[:location]).id, :accept => :json)
- system_volumes = get(test_system_created.json["volumes"]["href"], :accept => :json)
- system_volumes.json["count"].must_equal 1
- #system_volumes.json["systemVolumes"][0]["id"].must_equal "volume from template"
- end
+# test_system_created = get(fetch(system_created.headers[:location]).id, :accept => :json)
+# system_volumes = get(test_system_created.json["volumes"]["href"], :accept => :json)
+# system_volumes.json["count"].must_equal 1
+# #system_volumes.json["systemVolumes"][0]["id"].must_equal "volume from template"
+# end
# 1.8 Check that the volume is attached to machine(s)
# Optional - skipping
@@ -135,15 +141,42 @@ class SystemTemplate < CIMI::Test::Spec
"</Action>",
:accept => :xml, :content_type => :xml)
response.code.must_equal 202
- poll_state(get(fetch(system_created.headers[:location]).id, :accept => :json), "STARTED")
+ poll_state(fetch(system_created.headers[:location]), "STARTED")
get(fetch(system_created.headers[:location]).id, :accept => :json).json["state"].upcase.must_equal "STARTED"
end
end
# 1.11 Check that the machines are started
+ it "should check that the system machines were started successfully", :only => :json do
+ test_system_created = fetch(system_created.headers[:location])
+ sys_mach_coll = fetch(test_system_created.machines.href)
+ sys_mach_coll.system_machines.each do |sys_mach|
+ fetch(sys_mach.machine.href).state.upcase.must_equal "STARTED"
+ end
+ end
# 1.12 Stop the new System
+ it "should be able to stop the system", :only => :json do
+ test_system_created = get(fetch(system_created.headers[:location]).id, :accept => :json)
+ unless test_system_created.json["state"].eql?("STOPPED")
+ uri = discover_uri_for("stop", "", test_system_created.json["operations"])
+ response = post( uri,
+ "<Action xmlns=\"http://schemas.dmtf.org/cimi/1\">" +
+ "<action> http://http://schemas.dmtf.org/cimi/1/action/stop</action>" +
+ "</Action>",
+ :accept => :xml, :content_type => :xml)
+ response.code.must_equal 202
+ poll_state(fetch(system_created.headers[:location]), "STOPPED")
+ get(fetch(system_created.headers[:location]).id, :accept => :json).json["state"].upcase.must_equal "STOPPED"
+ end
+ end
# 1.13 Check that the machines are stopped
-
+ it "should check that the system machines were stopped successfully", :only => :json do
+ test_system_created = fetch(system_created.headers[:location])
+ sys_mach_coll = fetch(test_system_created.machines.href)
+ sys_mach_coll.system_machines.each do |sys_mach|
+ fetch(sys_mach.machine.href).state.upcase.must_equal "STOPPED"
+ end
+ end
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/f6f2599d/tests/cimi/test_helper.rb
----------------------------------------------------------------------
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index aa614d6..c4bedac 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -286,6 +286,12 @@ module CIMI::Test::Methods
end
end
+ #convenience method for checking if collection :foo is supported:
+ def collection_supported(name)
+ api.collections.include?(name.to_sym)
+ end
+
+
def need_capability(op, collection)
before :each do
begin
@@ -330,6 +336,19 @@ module CIMI::Test::Methods
def teardown(created_resources, api_basic_auth)
@@created_resources = created_resources
puts "CLEANING UP... resources for deletion: #{@@created_resources.inspect}"
+ #systems:
+ if @@created_resources[:systems]
+ @@created_resources[:systems].each do |sys_id|
+ sys = get(sys_id, :accept=>:json)
+ delete_op = sys.json["operations"].find { |op| op["rel"] =~ /delete$/ }
+ if delete_op
+ delete_res = RestClient.delete( delete_op["href"],
+ {'Authorization' => api_basic_auth, :accept => :json} )
+ @@created_resources[:systems].delete(sys_id) if (200..207).include? delete_res.code
+ @@created_resources.delete(:systems) if @@created_resources[:systems].empty?
+ end
+ end
+ end
# machines:
if not @@created_resources[:machines].nil?