1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

volume models and specs

This commit is contained in:
Wesley Beary 2009-09-23 21:23:54 -07:00
parent 01ab1e7d01
commit b2c3ad554a
5 changed files with 175 additions and 4 deletions

View file

@ -28,6 +28,8 @@ module Fog
load "fog/aws/models/ec2/address.rb" load "fog/aws/models/ec2/address.rb"
load "fog/aws/models/ec2/addresses.rb" load "fog/aws/models/ec2/addresses.rb"
load "fog/aws/models/ec2/volume.rb"
load "fog/aws/models/ec2/volumes.rb"
load "fog/aws/parsers/ec2/allocate_address.rb" load "fog/aws/parsers/ec2/allocate_address.rb"
load "fog/aws/parsers/ec2/attach_volume.rb" load "fog/aws/parsers/ec2/attach_volume.rb"

View file

@ -16,7 +16,7 @@ module Fog
def initialize(attributes = {}) def initialize(attributes = {})
if attributes['attachmentSet'] if attributes['attachmentSet']
attributes.merge!(attributes.delete('attachmentSet')) attributes.merge!(attributes.delete('attachmentSet').first || {})
end end
super super
end end
@ -34,7 +34,7 @@ module Fog
def save def save
data = connection.create_volume(@availability_zone, @size, @snapshot_id).body data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
new_attributes = data.reject {|key,value| key == 'requestId'} new_attributes = data.reject {|key,value| key == 'requestId'}
update_attributes(new_attributes) merge_attributes(new_attributes)
true true
end end

View file

@ -8,9 +8,14 @@ module Fog
class Volumes < Fog::Collection class Volumes < Fog::Collection
attribute :volume_id
def all(volume_id = []) def all(volume_id = [])
data = connection.describe_volumes(volume_id) data = connection.describe_volumes(volume_id).body
volumes = Fog::AWS::EC2::Volumes.new(:connection => connection) volumes = Fog::AWS::EC2::Volumes.new(
:connection => connection,
:volume_id => volume_id
)
data['volumeSet'].each do |volume| data['volumeSet'].each do |volume|
volumes << Fog::AWS::EC2::Volume.new({ volumes << Fog::AWS::EC2::Volume.new({
:connection => connection, :connection => connection,
@ -26,6 +31,12 @@ module Fog
volume volume
end end
def get(volume_id)
all(volume_id).first
rescue Fog::Errors::BadRequest
nil
end
def new(attributes = {}) def new(attributes = {})
Fog::AWS::EC2::Volume.new( Fog::AWS::EC2::Volume.new(
attributes.merge!( attributes.merge!(
@ -35,6 +46,10 @@ module Fog
) )
end end
def reload
all(volume_id)
end
end end
end end

View file

@ -0,0 +1,84 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::Volume' do
describe "#initialize" do
it "should remap attributes from parser" # do
# volume = Fog::AWS::EC2::Volume.new(
# 'instanceId' => 'i-00000000',
# 'publicIp' => '0.0.0.0'
# )
# address.instance_id.should == 'i-00000000'
# address.public_ip.should == '0.0.0.0'
# end
end
describe "#volumes" do
it "should return a Fog::AWS::EC2::Volumes" do
ec2.volumes.new.volumes.should be_a(Fog::AWS::EC2::Volumes)
end
it "should be the volumes the volume is related to" do
volumes = ec2.volumes
volumes.new.volumes.should == volumes
end
end
describe "#destroy" do
it "should return true if the volume is deleted" do
volume = ec2.volumes.create
volume.destroy.should be_true
end
end
describe "#reload" do
before(:each) do
@volume = ec2.volumes.create
@reloaded = @volume.reload
end
after(:each) do
@volume.destroy
end
it "should return a Fog::AWS::EC2::Volume" do
@reloaded.should be_a(Fog::AWS::EC2::Volume)
end
it "should reset attributes to remote state" do
@volume.attributes.should == @reloaded.attributes
end
end
describe "#save" do
before(:each) do
@volume = ec2.volumes.new
end
it "should return true when it succeeds" do
@volume.save.should be_true
@volume.destroy
end
it "should not exist in addresses before save" do
@volume.volumes.get(@volume.volume_id).should be_nil
end
it "should exist in buckets after save" do
@volume.save
@volume.volumes.get(@volume.volume_id).should_not be_nil
@volume.destroy
end
end
end

View file

@ -0,0 +1,70 @@
require File.dirname(__FILE__) + '/../../../spec_helper'
describe 'Fog::AWS::EC2::Volumes' do
describe "#all" do
it "should return a Fog::AWS::EC2::Volumes" do
ec2.volumes.all.should be_a(Fog::AWS::EC2::Volumes)
end
it "should include persisted volumes" do
volume = ec2.volumes.create
ec2.volumes.get(volume.volume_id).should_not be_nil
volume.destroy
end
end
describe "#create" do
before(:each) do
@volume = ec2.volumes.create
end
after(:each) do
@volume.destroy
end
it "should return a Fog::AWS::EC2::Volume" do
@volume.should be_a(Fog::AWS::EC2::Volume)
end
it "should exist on ec2" do
ec2.volumes.get(@volume.volume_id).should_not be_nil
end
end
describe "#get" do
it "should return a Fog::AWS::EC2::Volume if a matching volume exists" do
volume = ec2.volumes.create
get = ec2.volumes.get(volume.volume_id)
volume.attributes.should == get.attributes
volume.destroy
end
it "should return nil if no matching address exists" do
ec2.volumes.get('vol-00000000').should be_nil
end
end
describe "#new" do
it "should return a Fog::AWS::EC2::Volume" do
ec2.volumes.new.should be_a(Fog::AWS::EC2::Volume)
end
end
describe "#reload" do
it "should return a Fog::AWS::EC2::Volumes" do
ec2.volumes.all.reload.should be_a(Fog::AWS::EC2::Volumes)
end
end
end