Return-Path: X-Original-To: apmail-deltacloud-dev-archive@www.apache.org Delivered-To: apmail-deltacloud-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D2869DEF0 for ; Fri, 30 Nov 2012 11:58:40 +0000 (UTC) Received: (qmail 93168 invoked by uid 500); 30 Nov 2012 11:58:40 -0000 Delivered-To: apmail-deltacloud-dev-archive@deltacloud.apache.org Received: (qmail 93095 invoked by uid 500); 30 Nov 2012 11:58:39 -0000 Mailing-List: contact dev-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list dev@deltacloud.apache.org Received: (qmail 93053 invoked by uid 99); 30 Nov 2012 11:58:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Nov 2012 11:58:38 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of marios@redhat.com designates 209.132.183.28 as permitted sender) Received: from [209.132.183.28] (HELO mx1.redhat.com) (209.132.183.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Nov 2012 11:58:32 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAUBwBKW003604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 30 Nov 2012 06:58:11 -0500 Received: from name.redhat.com (ovpn-112-24.ams2.redhat.com [10.36.112.24]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qAUBw8V0031653; Fri, 30 Nov 2012 06:58:09 -0500 From: marios@redhat.com To: dev@deltacloud.apache.org Cc: rlandy@redhat.com Subject: [PATCH] CIMI API Tests - adds discovery for URIs Date: Fri, 30 Nov 2012 13:58:07 +0200 Message-Id: <1354276687-7128-1-git-send-email-marios@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Virus-Checked: Checked by ClamAV on apache.org From: marios Signed-off-by: marios --- tests/cimi/part2_test.rb | 6 +++--- tests/cimi/part4_test.rb | 19 +++++++++++-------- tests/cimi/part5_test.rb | 16 +++++++++------- tests/cimi/test_helper.rb | 21 ++++++++++++++++++++- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/tests/cimi/part2_test.rb b/tests/cimi/part2_test.rb index 0742a90..d04e026 100644 --- a/tests/cimi/part2_test.rb +++ b/tests/cimi/part2_test.rb @@ -48,12 +48,12 @@ 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 do |fmt| cep_json = cep(:accept => :json) - - RestClient.post(cep_json.json["machines"]["href"], + #discover the 'addURI' for creating Machine + add_uri = discover_uri_for("add", "machines") + RestClient.post(add_uri, "" + "cimi_machine_" + fmt.to_s() + "" + "" + diff --git a/tests/cimi/part4_test.rb b/tests/cimi/part4_test.rb index e5c1433..8e27c9c 100644 --- a/tests/cimi/part4_test.rb +++ b/tests/cimi/part4_test.rb @@ -49,7 +49,8 @@ class AddVolumeToMachine < CIMI::Test::Spec # Create a machine to attach the volume cep_json = cep(:accept => :json) - machine = RestClient.post(cep_json.json["machines"]["href"], + machine_add_uri = discover_uri_for("add", "machines") + machine = RestClient.post(machine_add_uri, "" + "cimi_machine" + "" + @@ -63,7 +64,8 @@ class AddVolumeToMachine < CIMI::Test::Spec # 4.3: Create a new Volume model :volume do |fmt| - RestClient.post(cep_json.json["volumes"]["href"], + volume_add_uri = discover_uri_for("add", "volumes") + RestClient.post(volume_add_uri, "" + "cimi_volume_" + fmt.to_s() +"" + "volume for testing" + @@ -99,9 +101,9 @@ class AddVolumeToMachine < CIMI::Test::Spec last_response.json["resourceURI"].must_equal RESOURCE_URI.gsub("Create", "") end - # 4.4: Attach the new Volume to a Machine log.info(machine.json["id"].to_s() + " is the machine id") - volume = RestClient.post(cep_json.json["volumes"]["href"], + volume_add_uri = discover_uri_for("add", "volumes") + volume = RestClient.post(volume_add_uri, "" + "cimi_volume_for_attach" + "volume for attach testing" + @@ -114,9 +116,10 @@ class AddVolumeToMachine < CIMI::Test::Spec {'Authorization' => api.basic_auth, :accept => :json}) log.info(volume.json["id"].to_s() + " is the volume id") - + # 4.4: Attach the new Volume to a Machine model :machineWithVolume, :only => :xml do - RestClient.put(machine.json["id"] + "/volume_attach", + attach_uri = discover_uri_for_subcollection("add", machine.json['id'], "volumes") + RestClient.post(attach_uri, "" + "/dev/sdf" + "" + @@ -138,8 +141,8 @@ class AddVolumeToMachine < CIMI::Test::Spec log.info( machine.json["id"] + "/volumes/" + volume.json["id"].split("/volumes/")[1]) sleep 5 - response = RestClient.delete(machine.json["id"] + - "/volumes/" + volume.json["id"].split("/volumes/")[1], + detach_uri = discover_uri_for("delete", "", machineWithVolume.operations) + response = RestClient.delete(detach_uri, {'Authorization' => api.basic_auth, :accept => :xml}) response.code.must_equal 200 end diff --git a/tests/cimi/part5_test.rb b/tests/cimi/part5_test.rb index 52f8b58..a5a58a9 100644 --- a/tests/cimi/part5_test.rb +++ b/tests/cimi/part5_test.rb @@ -29,7 +29,9 @@ class ManipulateAMachine < CIMI::Test::Spec # 2.1: Query the Machine # For some providers - need to create a machine before querying it. cep_json = cep(:accept => :json) - machine_created = RestClient.post(cep_json.json["machines"]["href"], + #discover machine create URI: + machine_add_uri = discover_uri_for("add", "machines") + machine_created = RestClient.post(machine_add_uri, "" + "cimi_machine_part5" + "" + @@ -99,13 +101,13 @@ class ManipulateAMachine < CIMI::Test::Spec 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") + assert_silent { discover_uri_for("restart","", machine.operations) } + assert_silent { discover_uri_for("stop","", machine.operations) } + assert_silent { discover_uri_for("capture","", machine.operations) } 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/destroy") - machine[:operations][2][0].must_include RESOURCE_URI.gsub( "Machine", "action/capture") + assert_silent { discover_uri_for(/\/start/,"", machine.operations) } + assert_silent { discover_uri_for("delete","", machine.operations) } + assert_silent { discover_uri_for("capture","", machine.operations) } else log.info("machine is in an intermediate state: " + machine.state) end diff --git a/tests/cimi/test_helper.rb b/tests/cimi/test_helper.rb index ace38bd..49356dd 100644 --- a/tests/cimi/test_helper.rb +++ b/tests/cimi/test_helper.rb @@ -103,6 +103,24 @@ module CIMI::Test::Methods get(api.cep_url, params) end + def discover_uri_for(op, collection, operations = nil) + unless operations + cep_json = cep(:accept => :json) + #get the collection operations: + operations = get(cep_json.json["#{collection}"]["href"], {:accept=> :json}).json["operations"] + end + op_regex = Regexp.new(op, Regexp::IGNORECASE) # "add" == /add/i + op_uri = operations.inject(""){|res,current| res = current["href"] if current["rel"] =~ op_regex; res} + raise "Couldn't discover the #{collection} Collection #{op} URI" if op_uri.empty? + op_uri + end + + def discover_uri_for_subcollection(op, resource_id, subcollection) + subcollection_uri = get(resource_id, {:accept=> :json}).json[subcollection]["href"] + subcollection_ops = get(subcollection_uri, {:accept=> :json}).json["operations"] + discover_uri_for(op, "", subcollection_ops) + end + def get(path, params = {}) RestClient.get absolute_url(path), headers(params) end @@ -174,7 +192,8 @@ module CIMI::Test::Methods end def machine_stop_start(machine, action, state) - response = RestClient.post( machine.id + "/" + action, + uri = discover_uri_for(action, "", machine.operations) + response = RestClient.post( uri, "" + " http://http://schemas.dmtf.org/cimi/1/action/" + action + "" + "", -- 1.7.11.7