Skip to content

Commit

Permalink
Merge pull request #433 from alexander-demichev/filter-params
Browse files Browse the repository at this point in the history
Filter unsupported params for volume update request
  • Loading branch information
gildub committed Oct 11, 2018
2 parents 9ea6a8c + 1012318 commit a2b2071
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 71 deletions.
11 changes: 0 additions & 11 deletions lib/fog/openstack/volume/requests/update_volume.rb
@@ -1,17 +1,6 @@
module Fog
module OpenStack
class Volume
module Real
def update_volume(volume_id, data = {})
request(
:body => Fog::JSON.encode('volume' => data),
:expects => 200,
:method => 'PUT',
:path => "volumes/#{volume_id}"
)
end
end

module Mock
def update_volume(volume_id, data = {})
response = Excon::Response.new
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/openstack/volume/v1/models/volume.rb
Expand Up @@ -17,7 +17,8 @@ def save
data = if id.nil?
service.create_volume(display_name, display_description, size, attributes)
else
service.update_volume(id, attributes.reject { |k, _v| k == :id })
attrib = attributes.select { |key| %i(display_name display_description metadata).include?(key) }
service.update_volume(id, attrib)
end
merge_attributes(data.body['volume'])
true
Expand Down
17 changes: 17 additions & 0 deletions lib/fog/openstack/volume/v1/requests/update_volume.rb
@@ -1,2 +1,19 @@
require 'fog/openstack/volume/requests/update_volume'
require 'fog/openstack/volume/v1/requests/real'

module Fog
module OpenStack
class Volume
module Real
def update_volume(volume_id, data = {})
request(
:body => Fog::JSON.encode('volume' => data),
:expects => 200,
:method => 'PUT',
:path => "volumes/#{volume_id}"
)
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/fog/openstack/volume/v2/models/volume.rb
Expand Up @@ -17,7 +17,7 @@ def save
data = if id.nil?
service.create_volume(name, description, size, attributes)
else
service.update_volume(id, attributes.reject { |k, _v| k == :id })
service.update_volume(id, attributes.select { |key| %i(name description metadata).include?(key) })
end
merge_attributes(data.body['volume'])
true
Expand Down
18 changes: 18 additions & 0 deletions lib/fog/openstack/volume/v2/requests/update_volume.rb
@@ -1,2 +1,20 @@
require 'fog/openstack/volume/requests/update_volume'
require 'fog/openstack/volume/v2/requests/real'

module Fog
module OpenStack
class Volume
module Real
def update_volume(volume_id, data = {})
data = data.select { |key| key == :name || key == :description || key == :metadata }
request(
:body => Fog::JSON.encode('volume' => data),
:expects => 200,
:method => 'PUT',
:path => "volumes/#{volume_id}"
)
end
end
end
end
end
39 changes: 19 additions & 20 deletions spec/fixtures/openstack/volume/volume_crud.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2b2071

Please sign in to comment.