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

better attribute names, fixes for model specs

This commit is contained in:
Wesley Beary 2009-12-05 14:53:42 -08:00
parent bae0ef8ec2
commit e1fdfa8144
20 changed files with 132 additions and 137 deletions

View file

@ -7,7 +7,7 @@ require "#{current_directory}/lib/fog"
begin begin
require 'jeweler' require 'jeweler'
Jeweler::Tasks.new do |gem| Jeweler::Tasks.new do |gem|
gem.add_dependency('excon', '>=0.0.10') gem.add_dependency('excon', '>=0.0.11')
gem.add_dependency('mime-types') gem.add_dependency('mime-types')
gem.add_dependency('nokogiri') gem.add_dependency('nokogiri')
gem.add_dependency('ruby-hmac') gem.add_dependency('ruby-hmac')

View file

@ -16,8 +16,6 @@ module Fog
end end
def instance=(new_instance) def instance=(new_instance)
requires :public_ip
if new_instance if new_instance
associate(new_instance) associate(new_instance)
else else
@ -41,7 +39,7 @@ module Fog
@instance = new_instance @instance = new_instance
else else
@instance = nil @instance = nil
@instance_id = new_instance.instance_id @instance_id = new_instance.id
connection.associate_address(@instance_id, @public_ip) connection.associate_address(@instance_id, @public_ip)
end end
end end

View file

@ -44,7 +44,11 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
if instance
super({ :instance => instance }.merge!(attributes)) super({ :instance => instance }.merge!(attributes))
else
super(attributes)
end
end end
end end

View file

@ -4,15 +4,15 @@ module Fog
class Instance < Fog::Model class Instance < Fog::Model
identity :instance_id, 'instanceId' identity :id, 'instanceId'
attribute :ami_launch_index, 'amiLaunchIndex' attribute :ami_launch_index, 'amiLaunchIndex'
attribute :availability_zone, 'availabilityZone' attribute :availability_zone, 'availabilityZone'
attribute :dns_name, 'dnsName' attribute :dns_name, 'dnsName'
attribute :group_id, 'groupId' attribute :group_id, 'groupId'
attribute :image_id, 'imageId' attribute :image_id, 'imageId'
attribute :instance_state, 'instanceState' attribute :state, 'instanceState'
attribute :instance_type, 'instanceType' attribute :type, 'instanceType'
attribute :kernel_id, 'kernelId' attribute :kernel_id, 'kernelId'
attribute :key_name, 'keyName' attribute :key_name, 'keyName'
attribute :launch_time, 'launchTime' attribute :launch_time, 'launchTime'
@ -24,15 +24,15 @@ module Fog
attribute :user_data attribute :user_data
def addresses def addresses
requires :instance_id requires :id
connection.addresses(:instance => self) connection.addresses(:instance => self)
end end
def destroy def destroy
requires :instance_id requires :id
connection.terminate_instances(@instance_id) connection.terminate_instances(@id)
true true
end end
@ -71,9 +71,9 @@ module Fog
end end
def reboot def reboot
requires :instance_id requires :id
connection.reboot_instances(@instance_id) connection.reboot_instances(@id)
true true
end end
@ -87,8 +87,8 @@ module Fog
if @group_id if @group_id
options['SecurityGroup'] = @group_id options['SecurityGroup'] = @group_id
end end
if @instance_type if @type
options['InstanceType'] = @instance_type options['InstanceType'] = @type
end end
if @kernel_id if @kernel_id
options['KernelId'] = @kernel_id options['KernelId'] = @kernel_id
@ -111,18 +111,18 @@ module Fog
end end
def volumes def volumes
requires :instance_id requires :id
connection.volumes(:instance => self) connection.volumes(:instance => self)
end end
private private
def instance_state=(new_instance_state) def state=(new_state)
if new_instance_state.is_a?(Hash) if new_state.is_a?(Hash)
@instance_state = new_instance_state['name'] @state = new_state['name']
else else
@instance_state = new_instance_state @state = new_state
end end
end end

View file

@ -4,45 +4,45 @@ module Fog
class SecurityGroup < Fog::Model class SecurityGroup < Fog::Model
identity :group_name, 'groupName' identity :name, 'groupName'
attribute :group_description, 'groupDescription' attribute :description, 'groupDescription'
attribute :ip_permissions, 'ipPermissions' attribute :ip_permissions, 'ipPermissions'
attribute :owner_id, 'ownerId' attribute :owner_id, 'ownerId'
def authorize_group_and_owner(group, owner) def authorize_group_and_owner(group, owner)
requires :group_name requires :name
connection.authorize_security_group_ingress( connection.authorize_security_group_ingress(
'GroupName' => @group_name, 'GroupName' => @name,
'SourceSecurityGroupName' => group, 'SourceSecurityGroupName' => group,
'SourceSecurityGroupOwnerId' => owner 'SourceSecurityGroupOwnerId' => owner
) )
end end
def authorize_port_range(range, options = {}) def authorize_port_range(range, options = {})
requires :group_name requires :name
connection.authorize_security_group_ingress( connection.authorize_security_group_ingress(
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0', 'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
'FromPort' => range.min, 'FromPort' => range.min,
'GroupName' => @group_name, 'GroupName' => @name,
'ToPort' => range.max, 'ToPort' => range.max,
'IpProtocol' => options[:ip_protocol] || 'tcp' 'IpProtocol' => options[:ip_protocol] || 'tcp'
) )
end end
def destroy def destroy
requires :group_name requires :name
connection.delete_security_group(@group_name) connection.delete_security_group(@name)
true true
end end
def save def save
requires :group_name requires :name
data = connection.create_security_group(@group_name, @group_description).body data = connection.create_security_group(@name, @description).body
true true
end end

View file

@ -4,7 +4,7 @@ module Fog
class Snapshot < Fog::Model class Snapshot < Fog::Model
identity :snapshot_id, 'snapshotId' identity :id, 'snapshotId'
attribute :progress attribute :progress
attribute :start_time, 'startTime' attribute :start_time, 'startTime'
@ -12,9 +12,9 @@ module Fog
attribute :volume_id, 'volumeId' attribute :volume_id, 'volumeId'
def destroy def destroy
requires :snapshot_id requires :id
connection.delete_snapshot(@snapshot_id) connection.delete_snapshot(@id)
true true
end end
@ -28,7 +28,7 @@ module Fog
end end
def volume def volume
requires :snapshot_id requires :id
connection.describe_volumes(@volume_id) connection.describe_volumes(@volume_id)
end end

View file

@ -11,7 +11,7 @@ module Fog
class Snapshots < Fog::Collection class Snapshots < Fog::Collection
attribute :snapshot_id attribute :snapshot_id
attribute :volume_id attribute :volume
model Fog::AWS::EC2::Snapshot model Fog::AWS::EC2::Snapshot
@ -32,8 +32,8 @@ module Fog
:connection => connection :connection => connection
}.merge!(snapshot)) }.merge!(snapshot))
end end
if volume_id if volume
snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume_id} snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume.id}
end end
snapshots snapshots
end end
@ -47,11 +47,11 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
snapshot = super(attributes) if volume
if volume_id super({ :volume_id => volume.id }.merge!(attributes))
snapshot.volume_id = volume_id else
super
end end
snapshot
end end
end end

View file

@ -4,7 +4,7 @@ module Fog
class Volume < Fog::Model class Volume < Fog::Model
identity :volume_id, 'volumeId' identity :id, 'volumeId'
attribute :attach_time, 'attachTime' attribute :attach_time, 'attachTime'
attribute :availability_zone, 'availabilityZone' attribute :availability_zone, 'availabilityZone'
@ -23,15 +23,13 @@ module Fog
end end
def destroy def destroy
requires :volume_id requires :id
connection.delete_volume(@volume_id) connection.delete_volume(@id)
true true
end end
def instance=(new_instance) def instance=(new_instance)
requires :volume_id
if new_instance if new_instance
attach(new_instance) attach(new_instance)
else else
@ -40,7 +38,7 @@ module Fog
end end
def save def save
requires :availability_zone, :size, :snapshot_id requires :availability_zone, :size
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'}
@ -52,9 +50,9 @@ module Fog
end end
def snapshots def snapshots
requires :volume_id requires :id
connection.snapshots(:volume_id => @volume_id) connection.snapshots(:volume => self)
end end
private private
@ -65,8 +63,8 @@ module Fog
@availability_zone = new_instance.availability_zone @availability_zone = new_instance.availability_zone
elsif new_instance elsif new_instance
@instance = nil @instance = nil
@instance_id = new_instance.instance_id @instance_id = new_instance.id
connection.attach_volume(@instance_id, @volume_id, @device) connection.attach_volume(@instance_id, @id, @device)
end end
end end
@ -74,7 +72,7 @@ module Fog
@instance = nil @instance = nil
@instance_id = nil @instance_id = nil
unless new_record? unless new_record?
connection.detach_volume(@volume_id) connection.detach_volume(@id)
end end
end end

View file

@ -33,7 +33,7 @@ module Fog
}.merge!(volume)) }.merge!(volume))
end end
if instance if instance
volumes = volumes.select {|volume| volume.instance_id == instance.instance_id} volumes = volumes.select {|volume| volume.instance_id == instance.id}
end end
volumes volumes
end end
@ -47,7 +47,11 @@ module Fog
end end
def new(attributes = {}) def new(attributes = {})
if instance
super({ :instance => instance }.merge!(attributes)) super({ :instance => instance }.merge!(attributes))
else
super
end
end end
end end

View file

@ -33,6 +33,8 @@ module Fog
Marshal.dump(attributes) Marshal.dump(attributes)
end end
attr_accessor :connection
def attributes def attributes
attributes = {} attributes = {}
for attribute in self.class.attributes for attribute in self.class.attributes
@ -45,14 +47,6 @@ module Fog
@collection @collection
end end
def connection=(new_connection)
@connection = new_connection
end
def connection
@connection
end
def identity def identity
send(self.class.instance_variable_get('@identity')) send(self.class.instance_variable_get('@identity'))
end end

View file

@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::Address' do
describe "#initialize" do describe "#initialize" do
it "should remap attributes from parser" do it "should remap attributes from parser" do
address = Fog::AWS::EC2::Address.new( address = ec2.addresses.new(
'instanceId' => 'i-00000000', 'instanceId' => 'i-00000000',
'publicIp' => '0.0.0.0' 'publicIp' => '0.0.0.0'
) )
@ -50,21 +50,13 @@ describe 'Fog::AWS::EC2::Address' do
@instance.destroy @instance.destroy
end end
it "should not associate with instance if the address has not been saved" do
@address.instance = @instance
@address.instance_id.should_not == @instance.instance_id
end
it "should associate with instance when the address is saved" do
@address.instance = @instance
@address.save.should be_true
@address.instance_id.should == @instance.instance_id
end
it "should associate with instance to an already saved address" do it "should associate with instance to an already saved address" do
@address.save.should be_true @address.save.should be_true
while @instance.state == 'pending'
@instance.reload
end
@address.instance = @instance @address.instance = @instance
@address.instance_id.should == @instance.instance_id @address.instance_id.should == @instance.id
end end
end end

View file

@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::Instance' do
describe "#initialize" do describe "#initialize" do
it "should remap attributes from parser" do it "should remap attributes from parser" do
instance = Fog::AWS::EC2::Instance.new({ instance = ec2.instances.new({
'amiLaunchIndex' => 'ami_launch_index', 'amiLaunchIndex' => 'ami_launch_index',
'dnsName' => 'dns_name', 'dnsName' => 'dns_name',
'groupId' => 'group_id', 'groupId' => 'group_id',
@ -23,8 +23,8 @@ describe 'Fog::AWS::EC2::Instance' do
instance.dns_name.should == 'dns_name' instance.dns_name.should == 'dns_name'
instance.group_id.should == 'group_id' instance.group_id.should == 'group_id'
instance.image_id.should == 'image_id' instance.image_id.should == 'image_id'
instance.instance_id.should == 'instance_id' instance.id.should == 'instance_id'
instance.instance_type.should == 'instance_type' instance.type.should == 'instance_type'
instance.kernel_id.should == 'kernel_id' instance.kernel_id.should == 'kernel_id'
instance.key_name.should == 'key_name' instance.key_name.should == 'key_name'
instance.launch_time.should == 'launch_time' instance.launch_time.should == 'launch_time'
@ -38,8 +38,9 @@ describe 'Fog::AWS::EC2::Instance' do
describe "#addresses" do describe "#addresses" do
it "should return a Fog::AWS::EC2::Addresses" do it "should return a Fog::AWS::EC2::Addresses" do
instance = ec2.instances.new instance = ec2.instances.create(:image_id => GENTOO_AMI)
instance.addresses.should be_a(Fog::AWS::EC2::Addresses) instance.addresses.should be_a(Fog::AWS::EC2::Addresses)
instance.destroy
end end
end end
@ -53,12 +54,12 @@ describe 'Fog::AWS::EC2::Instance' do
end end
describe "#instance_state" do describe "#state" do
it "should remap values out of hash" do it "should remap values out of hash" do
instance = Fog::AWS::EC2::Instance.new({ instance = Fog::AWS::EC2::Instance.new({
'instanceState' => { 'name' => 'instance_state' }, 'instanceState' => { 'name' => 'instance_state' },
}) })
instance.instance_state.should == 'instance_state' instance.state.should == 'instance_state'
end end
end end
@ -136,12 +137,12 @@ describe 'Fog::AWS::EC2::Instance' do
end end
it "should not exist in instances before save" do it "should not exist in instances before save" do
ec2.instances.get(@instance.instance_id).should be_nil ec2.instances.get(@instance.id).should be_nil
end end
it "should exist in buckets after save" do it "should exist in buckets after save" do
@instance.save @instance.save
ec2.instances.get(@instance.instance_id).should_not be_nil ec2.instances.get(@instance.id).should_not be_nil
@instance.destroy @instance.destroy
end end
@ -150,8 +151,9 @@ describe 'Fog::AWS::EC2::Instance' do
describe "#volumes" do describe "#volumes" do
it "should return a Fog::AWS::EC2::Volumes" do it "should return a Fog::AWS::EC2::Volumes" do
instance = ec2.instances.new instance = ec2.instances.create(:image_id => GENTOO_AMI)
instance.volumes.should be_a(Fog::AWS::EC2::Volumes) instance.volumes.should be_a(Fog::AWS::EC2::Volumes)
instance.destroy
end end
end end

View file

@ -10,7 +10,7 @@ describe 'Fog::AWS::EC2::Instances' do
it "should include persisted instances" do it "should include persisted instances" do
instance = ec2.instances.create(:image_id => GENTOO_AMI) instance = ec2.instances.create(:image_id => GENTOO_AMI)
ec2.instances.get(instance.instance_id).should_not be_nil ec2.instances.get(instance.id).should_not be_nil
instance.destroy instance.destroy
end end
@ -31,7 +31,7 @@ describe 'Fog::AWS::EC2::Instances' do
end end
it "should exist on ec2" do it "should exist on ec2" do
ec2.instances.get(@instance.instance_id).should_not be_nil ec2.instances.get(@instance.id).should_not be_nil
end end
end end
@ -40,7 +40,7 @@ describe 'Fog::AWS::EC2::Instances' do
it "should return a Fog::AWS::EC2::Instance if a matching instance exists" do it "should return a Fog::AWS::EC2::Instance if a matching instance exists" do
instance = ec2.instances.create(:image_id => GENTOO_AMI) instance = ec2.instances.create(:image_id => GENTOO_AMI)
get = ec2.instances.get(instance.instance_id) get = ec2.instances.get(instance.id)
instance.attributes.should == get.attributes instance.attributes.should == get.attributes
instance.destroy instance.destroy
end end

View file

@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::KeyPair' do
describe "#initialize" do describe "#initialize" do
it "should remap attributes from parser" do it "should remap attributes from parser" do
key_pair = Fog::AWS::EC2::KeyPair.new( key_pair = ec2.key_pairs.new(
'keyFingerprint' => 'fingerprint', 'keyFingerprint' => 'fingerprint',
'keyMaterial' => 'material', 'keyMaterial' => 'material',
'keyName' => 'name' 'keyName' => 'name'

View file

@ -5,14 +5,14 @@ describe 'Fog::AWS::EC2::SecurityGroup' do
describe "#initialize" do describe "#initialize" do
it "should remap attributes from parser" do it "should remap attributes from parser" do
security_group = Fog::AWS::EC2::SecurityGroup.new( security_group = ec2.security_groups.new(
'groupDescription' => 'description', 'groupDescription' => 'description',
'groupName' => 'name', 'groupName' => 'name',
'ipPermissions' => 'permissions', 'ipPermissions' => 'permissions',
'ownerId' => 'owner' 'ownerId' => 'owner'
) )
security_group.group_description.should == 'description' security_group.description.should == 'description'
security_group.group_name.should == 'name' security_group.name.should == 'name'
security_group.ip_permissions.should == 'permissions' security_group.ip_permissions.should == 'permissions'
security_group.owner_id.should == 'owner' security_group.owner_id.should == 'owner'
end end
@ -35,7 +35,7 @@ describe 'Fog::AWS::EC2::SecurityGroup' do
describe "#destroy" do describe "#destroy" do
it "should return true if the security_group is deleted" do it "should return true if the security_group is deleted" do
address = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') address = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname')
address.destroy.should be_true address.destroy.should be_true
end end
@ -44,7 +44,7 @@ describe 'Fog::AWS::EC2::SecurityGroup' do
describe "#reload" do describe "#reload" do
before(:each) do before(:each) do
@security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') @security_group = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname')
@reloaded = @security_group.reload @reloaded = @security_group.reload
end end
@ -65,7 +65,7 @@ describe 'Fog::AWS::EC2::SecurityGroup' do
describe "#save" do describe "#save" do
before(:each) do before(:each) do
@security_group = ec2.security_groups.new(:group_description => 'groupdescription', :group_name => 'keyname') @security_group = ec2.security_groups.new(:description => 'groupdescription', :name => 'keyname')
end end
it "should return true when it succeeds" do it "should return true when it succeeds" do
@ -74,12 +74,12 @@ describe 'Fog::AWS::EC2::SecurityGroup' do
end end
it "should not exist in security_groups before save" do it "should not exist in security_groups before save" do
ec2.security_groups.get(@security_group.group_name).should be_nil ec2.security_groups.get(@security_group.name).should be_nil
end end
it "should exist in buckets after save" do it "should exist in buckets after save" do
@security_group.save @security_group.save
ec2.security_groups.get(@security_group.group_name).should_not be_nil ec2.security_groups.get(@security_group.name).should_not be_nil
@security_group.destroy @security_group.destroy
end end

View file

@ -9,8 +9,8 @@ describe 'Fog::AWS::EC2::SecurityGroups' do
end end
it "should include persisted security_groups" do it "should include persisted security_groups" do
security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') security_group = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname')
ec2.security_groups.get(security_group.group_name).should_not be_nil ec2.security_groups.get(security_group.name).should_not be_nil
security_group.destroy security_group.destroy
end end
@ -19,7 +19,7 @@ describe 'Fog::AWS::EC2::SecurityGroups' do
describe "#create" do describe "#create" do
before(:each) do before(:each) do
@security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') @security_group = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname')
end end
after(:each) do after(:each) do
@ -31,7 +31,7 @@ describe 'Fog::AWS::EC2::SecurityGroups' do
end end
it "should exist on ec2" do it "should exist on ec2" do
ec2.security_groups.get(@security_group.group_name).should_not be_nil ec2.security_groups.get(@security_group.name).should_not be_nil
end end
end end
@ -39,10 +39,10 @@ describe 'Fog::AWS::EC2::SecurityGroups' do
describe "#get" do describe "#get" do
it "should return a Fog::AWS::EC2::SecurityGroup if a matching security_group exists" do it "should return a Fog::AWS::EC2::SecurityGroup if a matching security_group exists" do
security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') security_group = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname')
get = ec2.security_groups.get(security_group.group_name) get = ec2.security_groups.get(security_group.name)
security_group.attributes[:fingerprint].should == get.attributes[:fingerprint] security_group.attributes[:fingerprint].should == get.attributes[:fingerprint]
security_group.attributes[:group_name].should == get.attributes[:group_name] security_group.attributes[:name].should == get.attributes[:name]
security_group.destroy security_group.destroy
end end
@ -55,7 +55,7 @@ describe 'Fog::AWS::EC2::SecurityGroups' do
describe "#new" do describe "#new" do
it "should return a Fog::AWS::EC2::SecurityGroup" do it "should return a Fog::AWS::EC2::SecurityGroup" do
ec2.security_groups.new(:group_description => 'groupdescription', :group_name => 'keyname').should be_a(Fog::AWS::EC2::SecurityGroup) ec2.security_groups.new(:description => 'groupdescription', :name => 'keyname').should be_a(Fog::AWS::EC2::SecurityGroup)
end end
end end

View file

@ -5,12 +5,12 @@ describe 'Fog::AWS::EC2::Snapshots' do
describe "#initialize" do describe "#initialize" do
it "should remap attributes from parser" do it "should remap attributes from parser" do
snapshot = Fog::AWS::EC2::Snapshot.new( snapshot = ec2.snapshots.new(
'snapshotId' => 'snap-00000000', 'snapshotId' => 'snap-00000000',
'startTime' => 'now', 'startTime' => 'now',
'volumeId' => 'vol-00000000' 'volumeId' => 'vol-00000000'
) )
snapshot.snapshot_id.should == 'snap-00000000' snapshot.id.should == 'snap-00000000'
snapshot.start_time.should == 'now' snapshot.start_time.should == 'now'
snapshot.volume_id.should == 'vol-00000000' snapshot.volume_id.should == 'vol-00000000'
end end
@ -81,12 +81,12 @@ describe 'Fog::AWS::EC2::Snapshots' do
end end
it "should not exist in addresses before save" do it "should not exist in addresses before save" do
ec2.snapshots.get(@snapshot.snapshot_id).should be_nil ec2.snapshots.get(@snapshot.id).should be_nil
end end
it "should exist in buckets after save" do it "should exist in buckets after save" do
@snapshot.save @snapshot.save
ec2.snapshots.get(@snapshot.snapshot_id).should_not be_nil ec2.snapshots.get(@snapshot.id).should_not be_nil
@snapshot.destroy @snapshot.destroy
end end

View file

@ -11,16 +11,16 @@ describe 'Fog::AWS::EC2::Snapshots' do
it "should include persisted snapshots" do it "should include persisted snapshots" do
volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
snapshot = volume.snapshots.create snapshot = volume.snapshots.create
ec2.snapshots.all.map {|snapshot| snapshot.snapshot_id}.should include(snapshot.snapshot_id) ec2.snapshots.all.map {|snapshot| snapshot.id}.should include(snapshot.id)
snapshot.destroy snapshot.destroy
volume.destroy volume.destroy
end end
it "should limit snapshots by volume_id if present" do it "should limit snapshots by volume if present" do
volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
other_volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') other_volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
snapshot = volume.snapshots.create snapshot = volume.snapshots.create
other_volume.snapshots.all.map {|snapshot| snapshot.snapshot_id}.should_not include(snapshot.snapshot_id) other_volume.snapshots.all.map {|snapshot| snapshot.id}.should_not include(snapshot.id)
snapshot.destroy snapshot.destroy
other_volume.destroy other_volume.destroy
volume.destroy volume.destroy
@ -45,7 +45,7 @@ describe 'Fog::AWS::EC2::Snapshots' do
end end
it "should exist on ec2" do it "should exist on ec2" do
ec2.snapshots.get(@snapshot.snapshot_id).should_not be_nil ec2.snapshots.get(@snapshot.id).should_not be_nil
end end
end end
@ -55,8 +55,8 @@ describe 'Fog::AWS::EC2::Snapshots' do
it "should return a Fog::AWS::EC2::Snapshot if a matching snapshot exists" do it "should return a Fog::AWS::EC2::Snapshot if a matching snapshot exists" do
volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
snapshot = volume.snapshots.create snapshot = volume.snapshots.create
get = ec2.snapshots.get(snapshot.snapshot_id) get = ec2.snapshots.get(snapshot.id)
snapshot.attributes.reject {|key, value| ['progress', 'status'].include?(key)}.should == get.attributes.reject {|key, value| ['progress', 'status'].include?(key)} snapshot.attributes.reject {|key, value| [:progress, :status].include?(key)}.should == get.attributes.reject {|key, value| [:progress, :status].include?(key)}
snapshot.destroy snapshot.destroy
end end

View file

@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::Volume' do
describe "#initialize" do describe "#initialize" do
it "should remap attributes from parser" do it "should remap attributes from parser" do
volume = Fog::AWS::EC2::Volume.new( volume = ec2.volumes.new(
'attachTime' => 'now', 'attachTime' => 'now',
'availabilityZone' => 'us-east-1a', 'availabilityZone' => 'us-east-1a',
'createTime' => 'recently', 'createTime' => 'recently',
@ -18,7 +18,7 @@ describe 'Fog::AWS::EC2::Volume' do
volume.create_time.should == 'recently' volume.create_time.should == 'recently'
volume.instance_id.should == 'i-00000000' volume.instance_id.should == 'i-00000000'
volume.snapshot_id.should == 'snap-00000000' volume.snapshot_id.should == 'snap-00000000'
volume.volume_id.should == 'vol-00000000' volume.id.should == 'vol-00000000'
end end
end end
@ -39,7 +39,7 @@ describe 'Fog::AWS::EC2::Volume' do
describe "#destroy" do describe "#destroy" do
it "should return true if the volume is deleted" do it "should return true if the volume is deleted" do
volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
volume.destroy.should be_true volume.destroy.should be_true
end end
@ -48,26 +48,29 @@ describe 'Fog::AWS::EC2::Volume' do
describe "#instance=" do describe "#instance=" do
before(:each) do before(:each) do
@instance = ec2.instances.create(:image_id => GENTOO_AMI) @instance = ec2.instances.create(:image_id => GENTOO_AMI)
@volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => 'dev/sdz1') @volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => '/dev/sdz1')
while @instance.instance_state == 'pending' while @instance.state == 'pending'
@instance.reload @instance.reload
end end
while @volume.status == 'creating'
@volume.reload
end
end end
after(:each) do after(:each) do
@instance.destroy @instance.destroy
if @volume.volume_id if @volume.id
while ['attaching', 'creating'].include?(@volume.status)
@volume.reload
end
@volume.instance = nil @volume.instance = nil
while ['attached', 'detaching'].include?(@volume.status)
@volume.reload
end
@volume.destroy @volume.destroy
end end
end end
it "should not attach to instance if the volume has not been saved" do it "should not attach to instance if the volume has not been saved" do
@volume.instance = @instance @volume.instance = @instance
@volume.instance_id.should_not == @instance.instance_id @volume.instance_id.should_not == @instance.id
end end
it "should change the availability_zone if the volume has not been saved" do it "should change the availability_zone if the volume has not been saved" do
@ -78,13 +81,13 @@ describe 'Fog::AWS::EC2::Volume' do
it "should attach to instance when the volume is saved" do it "should attach to instance when the volume is saved" do
@volume.instance = @instance @volume.instance = @instance
@volume.save.should be_true @volume.save.should be_true
@volume.instance_id.should == @instance.instance_id @volume.instance_id.should == @instance.id
end end
it "should attach to instance to an already saved volume" do it "should attach to instance to an already saved volume" do
@volume.save.should be_true @volume.save.should be_true
@volume.instance = @instance @volume.instance = @instance
@volume.instance_id.should == @instance.instance_id @volume.instance_id.should == @instance.id
end end
it "should not change the availability_zone if the volume has been saved" do it "should not change the availability_zone if the volume has been saved" do
@ -97,7 +100,7 @@ describe 'Fog::AWS::EC2::Volume' do
describe "#reload" do describe "#reload" do
before(:each) do before(:each) do
@volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') @volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
@reloaded = @volume.reload @reloaded = @volume.reload
end end
@ -118,7 +121,7 @@ describe 'Fog::AWS::EC2::Volume' do
describe "#save" do describe "#save" do
before(:each) do before(:each) do
@volume = ec2.volumes.new(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') @volume = ec2.volumes.new(:availability_zone => 'us-east-1a', :size => 1, :device => '/dev/sdz1')
end end
it "should return true when it succeeds" do it "should return true when it succeeds" do
@ -127,12 +130,12 @@ describe 'Fog::AWS::EC2::Volume' do
end end
it "should not exist in volumes before save" do it "should not exist in volumes before save" do
ec2.volumes.get(@volume.volume_id).should be_nil ec2.volumes.get(@volume.id).should be_nil
end end
it "should exist in buckets after save" do it "should exist in buckets after save" do
@volume.save @volume.save
ec2.volumes.get(@volume.volume_id).should_not be_nil ec2.volumes.get(@volume.id).should_not be_nil
@volume.destroy @volume.destroy
end end

View file

@ -10,7 +10,7 @@ describe 'Fog::AWS::EC2::Volumes' do
it "should include persisted volumes" do it "should include persisted volumes" do
volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
ec2.volumes.get(volume.volume_id).should_not be_nil ec2.volumes.get(volume.id).should_not be_nil
volume.destroy volume.destroy
end end
@ -31,7 +31,7 @@ describe 'Fog::AWS::EC2::Volumes' do
end end
it "should exist on ec2" do it "should exist on ec2" do
ec2.volumes.get(@volume.volume_id).should_not be_nil ec2.volumes.get(@volume.id).should_not be_nil
end end
end end
@ -40,8 +40,8 @@ describe 'Fog::AWS::EC2::Volumes' do
it "should return a Fog::AWS::EC2::Volume if a matching volume exists" do it "should return a Fog::AWS::EC2::Volume if a matching volume exists" do
volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1')
get = ec2.volumes.get(volume.volume_id) get = ec2.volumes.get(volume.id)
volume.attributes.reject { |key, value| key == :device }.should == get.attributes.reject { |key, value| key == :device } volume.attributes.reject { |key, value| [:device, :status].include?(key) }.should == get.attributes.reject { |key, value| [:device, :status].include?(key) }
volume.destroy volume.destroy
end end