mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2073 from burns/openstack_image_tests
[openstack|image] strip unused headers in #update_image
This commit is contained in:
commit
b1c8268f6d
3 changed files with 84 additions and 71 deletions
|
@ -52,23 +52,23 @@ module Fog
|
||||||
|
|
||||||
image_id = Fog::Mock.random_hex(32)
|
image_id = Fog::Mock.random_hex(32)
|
||||||
image = self.data[:images][image_id] = {
|
image = self.data[:images][image_id] = {
|
||||||
'name' => attributes['name'] || attributes[:name],
|
'name' => attributes[:name],
|
||||||
'size' => Fog::Mock.random_numbers(8).to_i,
|
'size' => attributes[:size] || Fog::Mock.random_numbers(8).to_i,
|
||||||
'min_disk' => 0,
|
'min_disk' => attributes[:min_disk] || 0,
|
||||||
'disk_format' => attributes['disk_format'] || attributes[:disk_format] || 'raw',
|
'disk_format' => attributes[:disk_format] || 'raw',
|
||||||
'created_at' => Time.now.to_s,
|
'created_at' => Time.now.strftime('%FT%T.%6N'),
|
||||||
'container_format' => attributes['container_format'] || attributes[:container_format] || 'bare',
|
'container_format' => attributes[:container_format] || 'bare',
|
||||||
'deleted_at' => nil,
|
'deleted_at' => nil,
|
||||||
'updated_at' => Time.now.to_s,
|
'updated_at' => Time.now.strftime('%FT%T.%6N'),
|
||||||
'checksum' => Fog::Mock.random_hex(32),
|
'checksum' => attributes[:checksum] || Fog::Mock.random_hex(32),
|
||||||
'id' => image_id,
|
'id' => image_id,
|
||||||
'deleted' => false,
|
'deleted' => false,
|
||||||
'protected' => false,
|
'protected' => false,
|
||||||
'is_public' => false,
|
'is_public' => attributes[:is_public].to_s == 'true',
|
||||||
'status' => 'queued',
|
'status' => 'queued',
|
||||||
'min_ram' => 0,
|
'min_ram' => attributes[:min_ram] || 0,
|
||||||
'owner' => attributes['owner'] || attributes[:owner],
|
'owner' => attributes[:owner],
|
||||||
'properties' => attributes['properties'] || attributes[:properties] || {}
|
'properties' => attributes[:properties] || {}
|
||||||
}
|
}
|
||||||
response.body = { 'image'=> image }
|
response.body = { 'image'=> image }
|
||||||
response
|
response
|
||||||
|
|
|
@ -4,18 +4,17 @@ module Fog
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
def update_image(attributes)
|
def update_image(attributes)
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"x-image-meta-name" => attributes[:name],
|
'x-image-meta-name' => attributes[:name],
|
||||||
"x-image-meta-disk-format" => attributes[:disk_format],
|
'x-image-meta-disk-format' => attributes[:disk_format],
|
||||||
"x-image-meta-container-format" => attributes[:container_format],
|
'x-image-meta-container-format' => attributes[:container_format],
|
||||||
"x-image-meta-size" => attributes[:size],
|
'x-image-meta-size' => attributes[:size],
|
||||||
"x-image-meta-is-public" => attributes[:is_public],
|
'x-image-meta-is-public' => attributes[:is_public],
|
||||||
"x-image-meta-min-ram" => attributes[:min_ram],
|
'x-image-meta-min-ram' => attributes[:min_ram],
|
||||||
"x-image-meta-min-disk" => attributes[:min_disk],
|
'x-image-meta-min-disk' => attributes[:min_disk],
|
||||||
"x-image-meta-checksum" => attributes[:checksum],
|
'x-image-meta-checksum' => attributes[:checksum],
|
||||||
"x-image-meta-owner" => attributes[:owner]
|
'x-image-meta-owner' => attributes[:owner]
|
||||||
}
|
}.reject {|k,v| v.nil? }
|
||||||
|
|
||||||
unless attributes[:properties].nil?
|
unless attributes[:properties].nil?
|
||||||
attributes[:properties].each do |key,value|
|
attributes[:properties].each do |key,value|
|
||||||
|
@ -61,7 +60,6 @@ module Fog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response
|
response
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
|
Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
|
||||||
openstack = Fog::Identity[:openstack]
|
openstack = Fog::Identity[:openstack]
|
||||||
@image_attributes = {
|
@image_attributes = {
|
||||||
'name' => 'new image',
|
:name => 'new image',
|
||||||
'owner' => openstack.current_tenant['id'],
|
:owner => openstack.current_tenant['id'],
|
||||||
'is_public' => 'true',
|
:is_public => true,
|
||||||
'copy_from' => 'http://website.com/image.iso',
|
:copy_from => 'http://website.com/image.iso',
|
||||||
'disk_format' => 'iso',
|
:disk_format => 'iso',
|
||||||
'properties' =>
|
:properties =>
|
||||||
{'user_id' => openstack.current_user['id'],
|
{:user_id => openstack.current_user['id'],
|
||||||
'owner_id' => openstack.current_tenant['id']},
|
:owner_id => openstack.current_tenant['id']},
|
||||||
'container_format'=> 'bare' }
|
:container_format => 'bare' }
|
||||||
|
|
||||||
@image_format = {
|
@image_format = {
|
||||||
'name' => String,
|
'name' => String,
|
||||||
|
@ -72,23 +72,38 @@ Shindo.tests('Fog::Image[:openstack] | image requests', ['openstack']) do
|
||||||
]
|
]
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
tests('#list_public_images').formats({'images' => [@image_format]}) do
|
tests('#list_public_images').data_matches_schema({'images' => [@image_format]}) do
|
||||||
Fog::Image[:openstack].list_public_images.body
|
Fog::Image[:openstack].list_public_images.body
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#list_public_images_detailed').formats({'images' => [@detailed_image_format]}) do
|
tests('#list_public_images_detailed').data_matches_schema({'images' => [@detailed_image_format]}) do
|
||||||
Fog::Image[:openstack].list_public_images_detailed.body
|
Fog::Image[:openstack].list_public_images_detailed.body
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#create_image').formats({'image' => @detailed_image_format}) do
|
tests('#create_image').data_matches_schema({'image' => @detailed_image_format}) do
|
||||||
@instance = Fog::Image[:openstack].create_image(@image_attributes).body
|
begin
|
||||||
|
if Fog.mocking?
|
||||||
|
image_attributes = @image_attributes
|
||||||
|
else
|
||||||
|
require 'tempfile'
|
||||||
|
image_attributes = @image_attributes.dup
|
||||||
|
image_attributes.delete(:copy_from)
|
||||||
|
test_iso = Tempfile.new(['fog_test_iso', '.iso'])
|
||||||
|
test_iso.write Fog::Mock.random_hex(32)
|
||||||
|
test_iso.close
|
||||||
|
image_attributes[:location] = test_iso.path
|
||||||
|
end
|
||||||
|
@instance = Fog::Image[:openstack].create_image(image_attributes).body
|
||||||
|
ensure
|
||||||
|
test_iso.delete if test_iso
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#get_image').formats(@image_meta_format) do
|
tests('#get_image').data_matches_schema(@image_meta_format) do
|
||||||
Fog::Image[:openstack].get_image(@instance['image']['id']).headers
|
Fog::Image[:openstack].get_image(@instance['image']['id']).headers
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#update_image').formats(@detailed_image_format) do
|
tests('#update_image').data_matches_schema(@detailed_image_format) do
|
||||||
Fog::Image[:openstack].update_image({:id => @instance['image']['id'],
|
Fog::Image[:openstack].update_image({:id => @instance['image']['id'],
|
||||||
:name => 'edit image'}).body['image']
|
:name => 'edit image'}).body['image']
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue