You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by rl...@redhat.com on 2012/12/04 04:09:40 UTC
[PATCH] CIMI - tests modifying for runningtests against other drivers
From: Ronelle Landy <rl...@redhat.com>
---
tests/cimi/part2_test.rb | 42 +++++++++++++++++++++++++-----------------
tests/cimi/part3_test.rb | 10 +++++++++-
tests/cimi/part5_test.rb | 3 ++-
tests/cimi/test_helper.rb | 18 +++++++++++++-----
4 files changed, 49 insertions(+), 24 deletions(-)
diff --git a/tests/cimi/part2_test.rb b/tests/cimi/part2_test.rb
index c273614..b695885 100644
--- a/tests/cimi/part2_test.rb
+++ b/tests/cimi/part2_test.rb
@@ -52,24 +52,33 @@ 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
+ cep_json = cep(:accept => :json)
+ #discover the 'addURI' for creating Machine
+ add_uri = discover_uri_for("add", "machines")
+ machine_created = RestClient.post(add_uri,
+ "<Machine>" +
+ "<name>cimi_machine_part2" + "</name>" +
+ "<machineTemplate>" +
+ "<machineConfig " +
+ "href=\"" + get_a(cep_json, "machineConfig")+ "\"/>" +
+ "<machineImage " +
+ "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
+ "</machineTemplate>" +
+ "</Machine>",
+ {'Authorization' => api.basic_auth, :accept => :json})
+
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_" + fmt.to_s() + "</name>" +
- "<machineTemplate>" +
- "<machineConfig " +
- "href=\"" + get_a(cep_json, "machineConfig")+ "\"/>" +
- "<machineImage " +
- "href=\"" + get_a(cep_json, "machineImage") + "\"/>" +
- "</machineTemplate>" +
- "</Machine>",
- {'Authorization' => api.basic_auth, :accept => fmt})
+ attempts = 0
+ begin
+ get machine_created.json["id"], :accept => fmt
+ rescue Exception => e
+ sleep(10)
+ attempts += 1
+ retry if (attempts <= 5)
+ end
end
- it "should add resource for cleanup" do
+ it "should add resource for cleanup", :only => :json do
@@created_resources[:machines] << machine.id
end
@@ -79,8 +88,7 @@ end
end
it "should have a response code equal to 201" do
- machine
- last_response.code.must_equal 201
+ machine_created.code.must_equal 201
end
end
diff --git a/tests/cimi/part3_test.rb b/tests/cimi/part3_test.rb
index d7bb45b..823be11 100644
--- a/tests/cimi/part3_test.rb
+++ b/tests/cimi/part3_test.rb
@@ -102,7 +102,15 @@ class CreateNewMachineFromMachineTemplate < CIMI::Test::Spec
end
it "should add resource for cleanup" do
- @@created_resources[:machine_templates] << machineTemplate.id
+ attempts = 0
+ begin
+ get machine.json["id"], :accept => :json
+ rescue Exception => e
+ sleep(10)
+ attempts += 1
+ retry if (attempts <= 5)
+ end
+ @@created_resources[:machines] << machine.id
end
it "should have a name" do
diff --git a/tests/cimi/part5_test.rb b/tests/cimi/part5_test.rb
index f1ce6c9..cdc7b77 100644
--- a/tests/cimi/part5_test.rb
+++ b/tests/cimi/part5_test.rb
@@ -51,6 +51,7 @@ class ManipulateAMachine < CIMI::Test::Spec
end
it "should add resource for cleanup", :only => :json do
+ poll_state(machine, "STARTED")
@@created_resources[:machines] << machine_created.json["id"]
end
@@ -78,7 +79,7 @@ class ManipulateAMachine < CIMI::Test::Spec
end
it "should have a valid state" do
- s = Set.new ["RUNNING", "NEW", "PAUSED", "STOPPED", "STARTED"]
+ s = Set.new ["RUNNING", "NEW", "PAUSED", "STOPPED", "STARTED", "CREATING"]
log.info("machine state: " + machine.state.upcase)
s.must_include machine.state.upcase
end
diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb
index 9e5f6a3..20c744e 100644
--- a/tests/cimi/test_helper.rb
+++ b/tests/cimi/test_helper.rb
@@ -33,11 +33,18 @@ module CIMI
def initialize
@hash = Deltacloud::Test::yaml_config
- @cimi = @hash["cimi"]
+ end
+
+ def driver
+ xml.xpath("/c:CloudEntryPoint/c:name", ns).text
+ end
+
+ def preferred
+ @hash[driver]["preferred"] || {}
end
def cep_url
- @cimi["cep"]
+ @hash["cimi_url"]
end
def base_uri
@@ -45,13 +52,13 @@ module CIMI
end
def basic_auth(u = nil, p = nil)
- u ||= @cimi["user"]
- p ||= @cimi["password"]
+ u ||= @hash[driver]["user"]
+ p ||= @hash[driver]["password"]
"Basic #{Base64.encode64("#{u}:#{p}")}"
end
def preferred
- @cimi["preferred"] || {}
+ @hash[driver]["preferred"] || {}
end
def collections
@@ -193,6 +200,7 @@ module CIMI::Test::Methods
def poll_state(machine, state)
while not machine.state.upcase.eql?(state)
puts state
+ puts machine.state.upcase
puts 'waiting for machine to be: ' + state.to_s()
sleep(10)
machine = machine(:refetch => true)
--
1.7.7.6