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 3C3CFC841 for ; Mon, 21 May 2012 10:07:43 +0000 (UTC) Received: (qmail 78859 invoked by uid 500); 21 May 2012 10:07:43 -0000 Delivered-To: apmail-deltacloud-dev-archive@deltacloud.apache.org Received: (qmail 78840 invoked by uid 500); 21 May 2012 10:07:43 -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 78831 invoked by uid 99); 21 May 2012 10:07:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 May 2012 10:07:43 +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 mfojtik@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; Mon, 21 May 2012 10:07:36 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4LA7GH4000840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 May 2012 06:07:16 -0400 Received: from dhcp-29-121.brq.redhat.com (dhcp-29-121.brq.redhat.com [10.34.29.121]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4LA6sK0020488 for ; Mon, 21 May 2012 06:07:15 -0400 From: mfojtik@redhat.com To: dev@deltacloud.apache.org Subject: [PATCH core 20/51] Core: Fixed 19 vs 18 backward compatibility issue Date: Mon, 21 May 2012 12:07:01 +0200 Message-Id: <1337594852-42550-21-git-send-email-mfojtik@redhat.com> In-Reply-To: <1337594852-42550-1-git-send-email-mfojtik@redhat.com> References: <1337594852-42550-1-git-send-email-mfojtik@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Virus-Checked: Checked by ClamAV on apache.org From: Michal Fojtik Signed-off-by: Michal fojtik --- server/lib/deltacloud/collections/metrics.rb | 1 + server/lib/deltacloud/collections/realms.rb | 1 + server/lib/deltacloud/core_ext/string.rb | 4 +++ server/lib/deltacloud/drivers/base_driver.rb | 3 ++- server/lib/sinatra.rb | 1 + tests/mock/step_definitions/api_steps.rb | 36 +++++++++++++------------- tests/mock/support/env.rb | 23 ++++++++-------- 7 files changed, 39 insertions(+), 30 deletions(-) diff --git a/server/lib/deltacloud/collections/metrics.rb b/server/lib/deltacloud/collections/metrics.rb index acc951d..d13ba38 100644 --- a/server/lib/deltacloud/collections/metrics.rb +++ b/server/lib/deltacloud/collections/metrics.rb @@ -15,6 +15,7 @@ module Deltacloud::Collections class Metrics < Base + check_capability :for => lambda { |m| driver.respond_to? m } collection :metrics do description 'Metrics provide monitoring for the cloud resources' diff --git a/server/lib/deltacloud/collections/realms.rb b/server/lib/deltacloud/collections/realms.rb index 3f21625..609a1dd 100644 --- a/server/lib/deltacloud/collections/realms.rb +++ b/server/lib/deltacloud/collections/realms.rb @@ -15,6 +15,7 @@ module Deltacloud::Collections class Realms < Base + check_capability :for => lambda { |m| driver.respond_to? m } collection :realms do description "Within a cloud provider a realm represents a boundary containing resources" diff --git a/server/lib/deltacloud/core_ext/string.rb b/server/lib/deltacloud/core_ext/string.rb index 6c04282..abf4a28 100644 --- a/server/lib/deltacloud/core_ext/string.rb +++ b/server/lib/deltacloud/core_ext/string.rb @@ -72,4 +72,8 @@ class String "#{self[0..(length/2)]}#{end_string}" end + unless "".respond_to? :each + alias :each :each_line + end + end diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb index f3637b7..3d4c75d 100644 --- a/server/lib/deltacloud/drivers/base_driver.rb +++ b/server/lib/deltacloud/drivers/base_driver.rb @@ -144,7 +144,8 @@ module Deltacloud end def has_capability?(method) - (self.class.instance_methods - self.class.superclass.methods).include? method + method = (RUBY_VERSION =~ /^1\.9/) ? method : method.to_s + (self.class.instance_methods - self.class.superclass.instance_methods).include? method end ## Capabilities diff --git a/server/lib/sinatra.rb b/server/lib/sinatra.rb index 6179d55..13197f5 100644 --- a/server/lib/sinatra.rb +++ b/server/lib/sinatra.rb @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +require_relative 'sinatra/body_proxy' require_relative 'sinatra/rack_date' require_relative 'sinatra/rack_etag' require_relative 'sinatra/rack_matrix_params' diff --git a/tests/mock/step_definitions/api_steps.rb b/tests/mock/step_definitions/api_steps.rb index 27d1e8f..77c61fb 100644 --- a/tests/mock/step_definitions/api_steps.rb +++ b/tests/mock/step_definitions/api_steps.rb @@ -10,11 +10,11 @@ end Given /^URI ([\w\/\-_]+) exists in (.+) format$/ do |uri, format| @no_header = true case format.downcase - when 'xml': + when 'xml' then header 'Accept', 'application/xml;q=9' - when 'json' + when 'json' then header 'Accept', 'application/json;q=9' - when 'html' + when 'html' then header 'Accept', 'application/xml+xhtml;q=9' end @uri = uri @@ -55,11 +55,11 @@ Then /^this URI should be available in (.+) format$/ do |formats| @no_header = true formats.split(',').each do |format| case format.downcase - when 'xml': + when 'xml' then header 'Accept', 'application/xml;q=9' - when 'json' + when 'json' then header 'Accept', 'application/json;q=9' - when 'html' + when 'html' then header 'Accept', 'application/xml+xhtml;q=9' end get @uri, {} @@ -70,15 +70,15 @@ end Then /^each (\w+) should have '(.+)' attribute with valid (.+)$/ do |el, attr, t| case el - when 'link': + when 'link' then path = '/api/link' - when 'image': + when 'image' then path = '/images/image' - when 'instance': + when 'instance' then path = '/instances/instance' - when 'key': + when 'key' then path = '/keys/key' - when 'realm': + when 'realm' then path = '/realms/realm' end output_xml.xpath(path).each do |entry_point| @@ -92,11 +92,11 @@ end Then /^each ([\w\-]+) should have '(.+)' attribute set to '(.+)'$/ do |el, attr, v| case el - when 'image': + when 'image' then path = "/image/images" - when 'hardware_profile': + when 'hardware_profile' then path = "/hardware_profiles/hardware_profile" - when 'instance': + when 'instance' then path = "/instances/instance" end output_xml.xpath(path).each do |element| @@ -106,11 +106,11 @@ end Then /^each ([\w\-]+) should have '(.+)' element set to '(.+)'$/ do |el, child, v| case el - when 'image': + when 'image' then path = "/images/image" - when 'hardware_profile': + when 'hardware_profile' then path = "/hardware_profiles/hardware_profile" - when 'instance': + when 'instance' then path = "/instances/instance" end output_xml.xpath(path).each do |element| @@ -121,7 +121,7 @@ end Then /^each ([\w\-]+) should have '(.+)' property set to '(.+)'$/ do |el, property, v| case el - when 'hardware_profile': + when 'hardware_profile' then path = "/hardware_profiles/hardware_profile" end output_xml.xpath(path).each do |element| diff --git a/tests/mock/support/env.rb b/tests/mock/support/env.rb index 5f97b89..8b2581f 100644 --- a/tests/mock/support/env.rb +++ b/tests/mock/support/env.rb @@ -1,16 +1,13 @@ require 'rubygems' require 'nokogiri' - -SERVER_DIR = File::expand_path(File::join(File::dirname(__FILE__), "../../../server")) -$top_srcdir = SERVER_DIR -$:.unshift File::join($top_srcdir, 'lib') -Dir.chdir(SERVER_DIR) - -ENV['API_DRIVER'] = 'mock' -ENV.delete('API_VERBOSE') -load File.join($top_srcdir, 'lib', 'deltacloud', 'server.rb') - require 'rack/test' +load File.join(File.dirname(__FILE__), '..', '..', '..', 'server', 'lib', 'deltacloud_rack.rb') + +Deltacloud::configure do |server| + server.root_url '/api' + server.version '0.5.0' + server.klass 'Deltacloud::API' +end.require_frontend! CONFIG = { :username => 'mockuser', @@ -22,5 +19,9 @@ def output_xml end def app - Sinatra::Application + Rack::URLMap.new( + "/" => Deltacloud::API.new, + "/stylesheets" => Rack::Directory.new( "public/stylesheets" ), + "/javascripts" => Rack::Directory.new( "public/javascripts" ) + ) end -- 1.7.10.1