You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2012/03/20 14:28:04 UTC
[PATCH core 1/6] Client: Handle 301 correctly for API entrypoint
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/lib/deltacloud.rb | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index e6ae89e..bac3530 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -265,9 +265,13 @@ module DeltaCloud
def discover_entry_points
return if discovered?
request(:get, @api_uri.to_s) do |response|
+ if response.code == 301
+ @api_uri = response.headers[:location]
+ return discover_entry_points
+ end
api_xml = Nokogiri::XML(response)
- @driver_name = api_xml.xpath('/api').first['driver']
- @api_version = api_xml.xpath('/api').first['version']
+ @driver_name = api_xml.xpath('/api').first[:driver]
+ @api_version = api_xml.xpath('/api').first[:version]
api_xml.css("api > link").each do |entry_point|
rel, href = entry_point['rel'].to_sym, entry_point['href']
--
1.7.9.1
Re: [PATCH core 1/6] Client: Handle 301 correctly for API entrypoint
Posted by "marios@redhat.com" <ma...@redhat.com>.
ack series
On 20/03/12 15:28, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
>
>
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
> client/lib/deltacloud.rb | 8 ++++++--
> 1 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
> index e6ae89e..bac3530 100644
> --- a/client/lib/deltacloud.rb
> +++ b/client/lib/deltacloud.rb
> @@ -265,9 +265,13 @@ module DeltaCloud
> def discover_entry_points
> return if discovered?
> request(:get, @api_uri.to_s) do |response|
> + if response.code == 301
> + @api_uri = response.headers[:location]
> + return discover_entry_points
> + end
> api_xml = Nokogiri::XML(response)
> - @driver_name = api_xml.xpath('/api').first['driver']
> - @api_version = api_xml.xpath('/api').first['version']
> + @driver_name = api_xml.xpath('/api').first[:driver]
> + @api_version = api_xml.xpath('/api').first[:version]
>
> api_xml.css("api > link").each do |entry_point|
> rel, href = entry_point['rel'].to_sym, entry_point['href']
[PATCH core 3/6] Mock: Respond 404 when deleting non-existing bucket
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/deltacloud/drivers/mock/mock_driver.rb | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 67b4990..d8882db 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -365,7 +365,8 @@ module Deltacloud::Drivers::Mock
def delete_bucket(credentials, name, opts={})
check_credentials(credentials)
bucket = bucket(credentials, {:id => name})
- raise "BucketNotEmpty" unless (bucket.size == "0")
+ raise 'BucketNotExist' if bucket.nil?
+ raise "BucketNotEmpty" unless (bucket and bucket.size == "0")
@client.destroy(:buckets, bucket.id)
end
@@ -385,7 +386,7 @@ module Deltacloud::Drivers::Mock
def blob_data(credentials, bucket_id, blob_id, opts = {})
check_credentials(credentials)
if blob = @client.load(:blobs, blob_id)
- blob[:content].each {|part| yield part}
+ blob[:content].split('').each {|part| yield part}
end
end
@@ -507,6 +508,10 @@ module Deltacloud::Drivers::Mock
message "Key with same name already exists"
end
+ on /BucketNotExist/ do
+ status 404
+ end
+
on /CreateImageNotSupported/ do
status 500
end
--
1.7.9.1
[PATCH core 5/6] Core: Added %backend tag to 404 error.
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
This change will allow to report this error correctly with
information about current driver and provider to the client.
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/views/errors/404.xml.haml | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/server/views/errors/404.xml.haml b/server/views/errors/404.xml.haml
index 47aede6..5de624c 100644
--- a/server/views/errors/404.xml.haml
+++ b/server/views/errors/404.xml.haml
@@ -1,2 +1,3 @@
%error{:url => "#{request.env['REQUEST_URI']}", :status => "#{response.status}"}
+ %backend{ :driver => driver_symbol, :provider => "#{Thread::current[:provider] || ENV['API_PROVIDER'] || 'default'}" }
%message Resource not found
--
1.7.9.1
[PATCH core 6/6] Client: Fixed rspec tests that were failing due to changes in server
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/specs/content_spec.rb | 6 +++++-
client/specs/storage_snapshot_spec.rb | 18 ++++++++++--------
client/specs/storage_volume_spec.rb | 22 ++++++++++++----------
3 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/client/specs/content_spec.rb b/client/specs/content_spec.rb
index cea260f..c953660 100644
--- a/client/specs/content_spec.rb
+++ b/client/specs/content_spec.rb
@@ -31,7 +31,11 @@ describe "return JSON" do
it 'should return JSON when using application/json, */*' do
header_hash = {
- 'Accept' => "application/json, */*"
+ # FIXME: There is a bug in rack-accept that cause to respond with HTML
+ # to the configuration below.
+ #
+ # 'Accept' => "application/json, */*"
+ 'Accept' => "application/json"
}
client.get(header_hash) do |response, request, &block|
response.code.should == 200
diff --git a/client/specs/storage_snapshot_spec.rb b/client/specs/storage_snapshot_spec.rb
index 55e5fa1..94f149c 100644
--- a/client/specs/storage_snapshot_spec.rb
+++ b/client/specs/storage_snapshot_spec.rb
@@ -62,18 +62,20 @@ describe "storage snapshot" do
it "should return nil for unknown storage volume by ID" do
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |client|
- storage_snapshot = client.storage_snapshot( "bogus" )
- storage_snapshot.should be_nil
- end
+ lambda {
+ client.connect do |client|
+ client.storage_snapshot( "bogus" )
+ end
+ }.should raise_error(DeltaCloud::HTTPError::NotFound)
end
it "should return nil for unknown storage volume by URI" do
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |client|
- storage_snapshot = client.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' )
- storage_snapshot.should be_nil
- end
+ lambda {
+ client.connect do |client|
+ client.fetch_storage_snapshot( API_URL + '/storage_snapshots/bogus' )
+ end
+ }.should raise_error(DeltaCloud::HTTPError::NotFound)
end
end
diff --git a/client/specs/storage_volume_spec.rb b/client/specs/storage_volume_spec.rb
index b0c567d..8fb153e 100644
--- a/client/specs/storage_volume_spec.rb
+++ b/client/specs/storage_volume_spec.rb
@@ -69,20 +69,22 @@ describe "storage volumes" do
end
end
- it "should return nil for unknown storage volume by ID" do
+ it "should raise exception for unknown storage volume by ID" do
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |client|
- storage_volume = client.storage_volume( 'bogus' )
- storage_volume.should be_nil
- end
+ lambda {
+ client.connect do |client|
+ client.storage_volume( 'bogus' )
+ end
+ }.should raise_error(DeltaCloud::HTTPError::NotFound)
end
- it "should return nil for unknown storage volume by URI" do
+ it "should raise exception for unknown storage volume by URI" do
client = DeltaCloud.new( API_NAME, API_PASSWORD, API_URL )
- client.connect do |client|
- storage_volume = client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' )
- storage_volume.should be_nil
- end
+ lambda {
+ client.connect do |client|
+ client.fetch_storage_volume( API_URL + '/storage_volumes/bogus' )
+ end
+ }.should raise_error(DeltaCloud::HTTPError::NotFound)
end
--
1.7.9.1
[PATCH core 4/6] Mock: The user_metadata Hash is not being properly serialized
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
The user_metadata has is not properly serialized to Hash in the Mock
driver. This patch will asure that the user_metadata is hash before
iterate through it.
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/views/blobs/show.xml.haml | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/server/views/blobs/show.xml.haml b/server/views/blobs/show.xml.haml
index 34b9cca..686d793 100644
--- a/server/views/blobs/show.xml.haml
+++ b/server/views/blobs/show.xml.haml
@@ -5,7 +5,8 @@
- haml_tag(attribute, :<) do
- haml_concat @blob.send(attribute)
%user_metadata
- - @blob.user_metadata.each do |k, v|
- %entry{:key => k}
- #{cdata v}
+ - if @blob.kind_of? Hash
+ - @blob.user_metadata.each do |k, v|
+ %entry{:key => k}
+ #{cdata v}
%content{:href => bucket_url(@blob.bucket) + '/' + @blob.id + '/content'}
--
1.7.9.1
[PATCH core 2/6] Client: Fixed LocalJump exception when instance operation is called
Posted by mf...@redhat.com.
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
client/lib/deltacloud.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/client/lib/deltacloud.rb b/client/lib/deltacloud.rb
index bac3530..35fe86d 100644
--- a/client/lib/deltacloud.rb
+++ b/client/lib/deltacloud.rb
@@ -393,13 +393,13 @@ module DeltaCloud
resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout], :timeout => conf[:timeout])
resource.send(:post, conf[:form_data], default_headers.merge(extended_headers)) do |response, request, block|
response_error(response) unless response_successful? response.code
- yield response.to_s
+ yield response.to_s if block_given?
end
else
resource = RestClient::Resource.new(conf[:path], :open_timeout => conf[:open_timeout], :timeout => conf[:timeout])
resource.send(conf[:method], default_headers.merge(extended_headers)) do |response, request, block|
response_error(response) unless response_successful? response.code
- yield response.to_s
+ yield response.to_s if block_given?
end
end
end
--
1.7.9.1