mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] Add volume tests
This commit is contained in:
parent
8b84922ac7
commit
412a6cc3ae
10 changed files with 131 additions and 75 deletions
|
@ -226,7 +226,8 @@ module Fog
|
||||||
'volumes' => 10,
|
'volumes' => 10,
|
||||||
'cores' => 20,
|
'cores' => 20,
|
||||||
'ram' => 51200
|
'ram' => 51200
|
||||||
}
|
},
|
||||||
|
:volumes => {}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,16 +21,21 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def attach_volume(volume_id, server_id, device)
|
def attach_volume(volume_id, server_id, device)
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body ={ "volumeAttachment" => {
|
data = {
|
||||||
"id" => volume_id,
|
'id' => volume_id,
|
||||||
"volumeId" => volume_id
|
'volumeId' => volume_id,
|
||||||
}
|
'serverId' => server_id,
|
||||||
}
|
'device' => device
|
||||||
|
}
|
||||||
|
self.data[:volumes][volume_id]['attachments'] << data
|
||||||
|
response.body = { 'volumeAttachment' => data }
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,22 +31,23 @@ module Fog
|
||||||
def create_volume(name, description, size, options={})
|
def create_volume(name, description, size, options={})
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 202
|
response.status = 202
|
||||||
response.body = {
|
data = {
|
||||||
'volume' => {
|
'id' => Fog::Mock.random_numbers(2),
|
||||||
'id' => Fog::Mock.random_numbers(2),
|
'name' => name,
|
||||||
'display_name' => name,
|
'description' => description,
|
||||||
'display_description' => description,
|
'size' => size,
|
||||||
'size' => size,
|
'status' => 'creating',
|
||||||
'status' => 'creating',
|
'snapshot_id' => '4',
|
||||||
'snapshot_id' => '4',
|
'volume_type' => nil,
|
||||||
'volume_type' => nil,
|
'availability_zone' => 'nova',
|
||||||
'availability_zone' => 'nova',
|
'created_at' => Time.now,
|
||||||
'created_at' => Time.now,
|
'attachments' => []
|
||||||
'attachments' => []
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.data[:volumes][data['id']] = data
|
||||||
|
response.body = { 'volume' => data }
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,11 +14,18 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def delete_volume(volume_id)
|
def delete_volume(volume_id)
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 204
|
if list_volumes.body['volumes'].map { |v| v['id'] }.include? volume_id
|
||||||
response
|
self.data[:volumes].delete(volume_id)
|
||||||
|
response.status = 204
|
||||||
|
response
|
||||||
|
else
|
||||||
|
raise Fog::Compute::OpenStack::NotFound
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,10 +14,15 @@ module Fog
|
||||||
end
|
end
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def detach_volume(server_id, attachment_id)
|
def detach_volume(server_id, attachment_id)
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 202
|
if self.data[:volumes][attachment_id]['attachments'].reject! { |attachment| attachment['serverId'] == server_id }
|
||||||
response
|
response.status = 202
|
||||||
|
response
|
||||||
|
else
|
||||||
|
raise Fog::Compute::OpenStack::NotFound
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,16 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
|
def get_server_volumes(server_id)
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
data = self.data[:volumes].values.find_all do |vol|
|
||||||
|
vol['attachments'].find { |attachment| attachment["serverId"] == server_id }
|
||||||
|
end
|
||||||
|
response.body = { 'volumeAttachments' => data.collect! { |vol| vol['attachments'] }.flatten(1) }
|
||||||
|
response
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,22 +18,13 @@ module Fog
|
||||||
|
|
||||||
def get_volume_details(volume_id)
|
def get_volume_details(volume_id)
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
if data = self.data[:volumes][volume_id]
|
||||||
response.body = {
|
response.status = 200
|
||||||
'volume' => {
|
response.body = { 'volume' => data }
|
||||||
'id' => '1',
|
response
|
||||||
'display_name' => Fog::Mock.random_letters(rand(8) + 5),
|
else
|
||||||
'display_description' => Fog::Mock.random_letters(rand(12) + 10),
|
raise Fog::Compute::OpenStack::NotFound
|
||||||
'size' => 3,
|
end
|
||||||
'volume_type' => nil,
|
|
||||||
'snapshot_id' => '4',
|
|
||||||
'status' => 'online',
|
|
||||||
'availability_zone' => 'nova',
|
|
||||||
'created_at' => Time.now,
|
|
||||||
'attachments' => []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
response
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,32 +17,10 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def list_volumes(detailed=true)
|
def list_volumes(detailed=true)
|
||||||
response = Excon::Response.new
|
Excon::Response.new(
|
||||||
response.status = 200
|
:body => { 'volumes' => self.data[:volumes].values },
|
||||||
self.data[:volumes] ||= [
|
:status => 200
|
||||||
{ "status" => "available",
|
)
|
||||||
"display_description" => "",
|
|
||||||
"availability_zone" => "nova",
|
|
||||||
"display_name" => "test 1",
|
|
||||||
"attachments" => [{}],
|
|
||||||
"volume_type" => nil,
|
|
||||||
"snapshot_id" => nil,
|
|
||||||
"size" => 1,
|
|
||||||
"id" => Fog::Mock.random_hex(32),
|
|
||||||
"created_at" => Time.now },
|
|
||||||
{ "status" => "available",
|
|
||||||
"display_description" => "",
|
|
||||||
"availability_zone" => "nova",
|
|
||||||
"display_name" => "test 2",
|
|
||||||
"attachments" => [{}],
|
|
||||||
"volume_type" => nil,
|
|
||||||
"snapshot_id" => nil,
|
|
||||||
"size" => 1,
|
|
||||||
"id" => Fog::Mock.random_hex(32),
|
|
||||||
"created_at" => Time.now }
|
|
||||||
]
|
|
||||||
response.body = { 'volumes' => self.data[:volumes] }
|
|
||||||
response
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ Shindo.tests("Fog::Compute[:openstack] | server", ['openstack']) do
|
||||||
|
|
||||||
group = found_groups.first
|
group = found_groups.first
|
||||||
returns('my_group') { group.name }
|
returns('my_group') { group.name }
|
||||||
returns(server.connection) { group.connection }
|
returns(server.service) { group.service }
|
||||||
ensure
|
ensure
|
||||||
unless Fog.mocking? then
|
unless Fog.mocking? then
|
||||||
server.destroy if server
|
server.destroy if server
|
||||||
|
@ -79,7 +79,63 @@ Shindo.tests("Fog::Compute[:openstack] | server", ['openstack']) do
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
tests('#volumes').succeeds do
|
||||||
|
fog = Fog::Compute[:openstack]
|
||||||
|
|
||||||
|
begin
|
||||||
|
volume = fog.volumes.new(:name => 'test volume',
|
||||||
|
:description => 'test volume',
|
||||||
|
:size => 1)
|
||||||
|
volume.save
|
||||||
|
volume.wait_for { volume.status == 'available' } unless Fog.mocking?
|
||||||
|
|
||||||
|
flavor = fog.flavors.first.id
|
||||||
|
image = fog.images.first.id
|
||||||
|
|
||||||
|
server = fog.servers.new(:name => 'test server',
|
||||||
|
:flavor_ref => flavor,
|
||||||
|
:image_ref => image)
|
||||||
|
|
||||||
|
server.save
|
||||||
|
server.wait_for { server.state == "ACTIVE" } unless Fog.mocking?
|
||||||
|
|
||||||
|
server.attach_volume(volume.id, '/dev/vdc')
|
||||||
|
volume.wait_for { volume.status == 'in-use' } unless Fog.mocking?
|
||||||
|
|
||||||
|
found_volumes = server.volumes
|
||||||
|
returns(1) { found_volumes.length }
|
||||||
|
|
||||||
|
volume = found_volumes.first
|
||||||
|
returns('test volume') { volume.name }
|
||||||
|
|
||||||
|
found_attachments = server.volume_attachments
|
||||||
|
returns(1) { found_attachments.length }
|
||||||
|
|
||||||
|
attachment = found_attachments.first
|
||||||
|
returns('/dev/vdc') { attachment['device'] }
|
||||||
|
|
||||||
|
server.detach_volume(volume.id)
|
||||||
|
volume.wait_for { volume.status == 'available' } unless Fog.mocking?
|
||||||
|
|
||||||
|
found_volumes = server.volumes
|
||||||
|
returns(0) { found_volumes.length }
|
||||||
|
|
||||||
|
found_attachments = server.volume_attachments
|
||||||
|
returns(0) { found_attachments.length }
|
||||||
|
ensure
|
||||||
|
unless Fog.mocking? then
|
||||||
|
server.destroy if server
|
||||||
|
volume.destroy if volume
|
||||||
|
|
||||||
|
begin
|
||||||
|
fog.servers.get(server.id).wait_for do false end
|
||||||
|
fog.volumes.get(volume.id).wait_for do false end
|
||||||
|
rescue Fog::Errors::Error
|
||||||
|
# ignore, server went away
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,9 +4,9 @@ Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do
|
||||||
|
|
||||||
@volume_format = {
|
@volume_format = {
|
||||||
'id' => String,
|
'id' => String,
|
||||||
'display_name' => String,
|
'name' => String,
|
||||||
'size' => Integer,
|
'size' => Integer,
|
||||||
'display_description' => String,
|
'description' => String,
|
||||||
'status' => String,
|
'status' => String,
|
||||||
'snapshot_id' => Fog::Nullable::String,
|
'snapshot_id' => Fog::Nullable::String,
|
||||||
'availability_zone' => String,
|
'availability_zone' => String,
|
||||||
|
@ -16,23 +16,25 @@ Shindo.tests('Fog::Compute[:openstack] | volume requests', ['openstack']) do
|
||||||
}
|
}
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
|
tests('#create_volume').formats({'volume' => @volume_format}) do
|
||||||
|
pending unless Fog.mocking?
|
||||||
|
Fog::Compute[:openstack].create_volume('loud', 'this is a loud volume', 3).body
|
||||||
|
end
|
||||||
|
|
||||||
tests('#list_volumes').formats({'volumes' => [@volume_format]}) do
|
tests('#list_volumes').formats({'volumes' => [@volume_format]}) do
|
||||||
Fog::Compute[:openstack].list_volumes.body
|
Fog::Compute[:openstack].list_volumes.body
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#get_volume_detail').formats({'volume' => @volume_format}) do
|
tests('#get_volume_detail').formats({'volume' => @volume_format}) do
|
||||||
pending unless Fog.mocking?
|
pending unless Fog.mocking?
|
||||||
Fog::Compute[:openstack].get_volume_details(1).body
|
volume_id = Fog::Compute[:openstack].volumes.all.first.id
|
||||||
end
|
Fog::Compute[:openstack].get_volume_details(volume_id).body
|
||||||
|
|
||||||
tests('#create_volume').formats({'volume' => @volume_format}) do
|
|
||||||
pending unless Fog.mocking?
|
|
||||||
Fog::Compute[:openstack].create_volume('loud', 'this is a loud volume', 3).body
|
|
||||||
end
|
end
|
||||||
|
|
||||||
tests('#delete_volume').succeeds do
|
tests('#delete_volume').succeeds do
|
||||||
pending unless Fog.mocking?
|
pending unless Fog.mocking?
|
||||||
Fog::Compute[:openstack].delete_volume(1)
|
volume_id = Fog::Compute[:openstack].volumes.all.first.id
|
||||||
|
Fog::Compute[:openstack].delete_volume(volume_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue