diff --git a/Rakefile b/Rakefile index 6a8b1ec2e..85cad15ea 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ require "#{current_directory}/lib/fog" begin require 'jeweler' 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('nokogiri') gem.add_dependency('ruby-hmac') diff --git a/lib/fog/aws/models/ec2/address.rb b/lib/fog/aws/models/ec2/address.rb index de7e75ecb..4b8c41b52 100644 --- a/lib/fog/aws/models/ec2/address.rb +++ b/lib/fog/aws/models/ec2/address.rb @@ -16,8 +16,6 @@ module Fog end def instance=(new_instance) - requires :public_ip - if new_instance associate(new_instance) else @@ -41,7 +39,7 @@ module Fog @instance = new_instance else @instance = nil - @instance_id = new_instance.instance_id + @instance_id = new_instance.id connection.associate_address(@instance_id, @public_ip) end end diff --git a/lib/fog/aws/models/ec2/addresses.rb b/lib/fog/aws/models/ec2/addresses.rb index c2cdbf39b..33d6cc1b7 100644 --- a/lib/fog/aws/models/ec2/addresses.rb +++ b/lib/fog/aws/models/ec2/addresses.rb @@ -44,7 +44,11 @@ module Fog end def new(attributes = {}) - super({ :instance => instance }.merge!(attributes)) + if instance + super({ :instance => instance }.merge!(attributes)) + else + super(attributes) + end end end diff --git a/lib/fog/aws/models/ec2/instance.rb b/lib/fog/aws/models/ec2/instance.rb index 2b5b6977b..729c2e257 100644 --- a/lib/fog/aws/models/ec2/instance.rb +++ b/lib/fog/aws/models/ec2/instance.rb @@ -4,15 +4,15 @@ module Fog class Instance < Fog::Model - identity :instance_id, 'instanceId' + identity :id, 'instanceId' attribute :ami_launch_index, 'amiLaunchIndex' attribute :availability_zone, 'availabilityZone' attribute :dns_name, 'dnsName' attribute :group_id, 'groupId' attribute :image_id, 'imageId' - attribute :instance_state, 'instanceState' - attribute :instance_type, 'instanceType' + attribute :state, 'instanceState' + attribute :type, 'instanceType' attribute :kernel_id, 'kernelId' attribute :key_name, 'keyName' attribute :launch_time, 'launchTime' @@ -24,15 +24,15 @@ module Fog attribute :user_data def addresses - requires :instance_id + requires :id connection.addresses(:instance => self) end def destroy - requires :instance_id + requires :id - connection.terminate_instances(@instance_id) + connection.terminate_instances(@id) true end @@ -71,9 +71,9 @@ module Fog end def reboot - requires :instance_id + requires :id - connection.reboot_instances(@instance_id) + connection.reboot_instances(@id) true end @@ -87,8 +87,8 @@ module Fog if @group_id options['SecurityGroup'] = @group_id end - if @instance_type - options['InstanceType'] = @instance_type + if @type + options['InstanceType'] = @type end if @kernel_id options['KernelId'] = @kernel_id @@ -111,18 +111,18 @@ module Fog end def volumes - requires :instance_id + requires :id connection.volumes(:instance => self) end private - def instance_state=(new_instance_state) - if new_instance_state.is_a?(Hash) - @instance_state = new_instance_state['name'] + def state=(new_state) + if new_state.is_a?(Hash) + @state = new_state['name'] else - @instance_state = new_instance_state + @state = new_state end end diff --git a/lib/fog/aws/models/ec2/security_group.rb b/lib/fog/aws/models/ec2/security_group.rb index c01c107b2..733a08931 100644 --- a/lib/fog/aws/models/ec2/security_group.rb +++ b/lib/fog/aws/models/ec2/security_group.rb @@ -4,45 +4,45 @@ module Fog class SecurityGroup < Fog::Model - identity :group_name, 'groupName' + identity :name, 'groupName' - attribute :group_description, 'groupDescription' - attribute :ip_permissions, 'ipPermissions' - attribute :owner_id, 'ownerId' + attribute :description, 'groupDescription' + attribute :ip_permissions, 'ipPermissions' + attribute :owner_id, 'ownerId' def authorize_group_and_owner(group, owner) - requires :group_name + requires :name connection.authorize_security_group_ingress( - 'GroupName' => @group_name, + 'GroupName' => @name, 'SourceSecurityGroupName' => group, 'SourceSecurityGroupOwnerId' => owner ) end def authorize_port_range(range, options = {}) - requires :group_name + requires :name connection.authorize_security_group_ingress( 'CidrIp' => options[:cidr_ip] || '0.0.0.0/0', 'FromPort' => range.min, - 'GroupName' => @group_name, + 'GroupName' => @name, 'ToPort' => range.max, 'IpProtocol' => options[:ip_protocol] || 'tcp' ) end def destroy - requires :group_name + requires :name - connection.delete_security_group(@group_name) + connection.delete_security_group(@name) true end 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 end diff --git a/lib/fog/aws/models/ec2/snapshot.rb b/lib/fog/aws/models/ec2/snapshot.rb index 8bf3ba0d7..746c31f6c 100644 --- a/lib/fog/aws/models/ec2/snapshot.rb +++ b/lib/fog/aws/models/ec2/snapshot.rb @@ -4,7 +4,7 @@ module Fog class Snapshot < Fog::Model - identity :snapshot_id, 'snapshotId' + identity :id, 'snapshotId' attribute :progress attribute :start_time, 'startTime' @@ -12,9 +12,9 @@ module Fog attribute :volume_id, 'volumeId' def destroy - requires :snapshot_id + requires :id - connection.delete_snapshot(@snapshot_id) + connection.delete_snapshot(@id) true end @@ -28,7 +28,7 @@ module Fog end def volume - requires :snapshot_id + requires :id connection.describe_volumes(@volume_id) end diff --git a/lib/fog/aws/models/ec2/snapshots.rb b/lib/fog/aws/models/ec2/snapshots.rb index 436a9f0bf..3ddaff417 100644 --- a/lib/fog/aws/models/ec2/snapshots.rb +++ b/lib/fog/aws/models/ec2/snapshots.rb @@ -11,7 +11,7 @@ module Fog class Snapshots < Fog::Collection attribute :snapshot_id - attribute :volume_id + attribute :volume model Fog::AWS::EC2::Snapshot @@ -32,8 +32,8 @@ module Fog :connection => connection }.merge!(snapshot)) end - if volume_id - snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume_id} + if volume + snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume.id} end snapshots end @@ -47,11 +47,11 @@ module Fog end def new(attributes = {}) - snapshot = super(attributes) - if volume_id - snapshot.volume_id = volume_id + if volume + super({ :volume_id => volume.id }.merge!(attributes)) + else + super end - snapshot end end diff --git a/lib/fog/aws/models/ec2/volume.rb b/lib/fog/aws/models/ec2/volume.rb index 82bd6988d..15c5c7deb 100644 --- a/lib/fog/aws/models/ec2/volume.rb +++ b/lib/fog/aws/models/ec2/volume.rb @@ -4,7 +4,7 @@ module Fog class Volume < Fog::Model - identity :volume_id, 'volumeId' + identity :id, 'volumeId' attribute :attach_time, 'attachTime' attribute :availability_zone, 'availabilityZone' @@ -23,15 +23,13 @@ module Fog end def destroy - requires :volume_id + requires :id - connection.delete_volume(@volume_id) + connection.delete_volume(@id) true end def instance=(new_instance) - requires :volume_id - if new_instance attach(new_instance) else @@ -40,7 +38,7 @@ module Fog end def save - requires :availability_zone, :size, :snapshot_id + requires :availability_zone, :size data = connection.create_volume(@availability_zone, @size, @snapshot_id).body new_attributes = data.reject {|key,value| key == 'requestId'} @@ -52,9 +50,9 @@ module Fog end def snapshots - requires :volume_id + requires :id - connection.snapshots(:volume_id => @volume_id) + connection.snapshots(:volume => self) end private @@ -65,8 +63,8 @@ module Fog @availability_zone = new_instance.availability_zone elsif new_instance @instance = nil - @instance_id = new_instance.instance_id - connection.attach_volume(@instance_id, @volume_id, @device) + @instance_id = new_instance.id + connection.attach_volume(@instance_id, @id, @device) end end @@ -74,7 +72,7 @@ module Fog @instance = nil @instance_id = nil unless new_record? - connection.detach_volume(@volume_id) + connection.detach_volume(@id) end end diff --git a/lib/fog/aws/models/ec2/volumes.rb b/lib/fog/aws/models/ec2/volumes.rb index aadb01e92..3d78a84a5 100644 --- a/lib/fog/aws/models/ec2/volumes.rb +++ b/lib/fog/aws/models/ec2/volumes.rb @@ -33,7 +33,7 @@ module Fog }.merge!(volume)) end if instance - volumes = volumes.select {|volume| volume.instance_id == instance.instance_id} + volumes = volumes.select {|volume| volume.instance_id == instance.id} end volumes end @@ -47,7 +47,11 @@ module Fog end def new(attributes = {}) - super({ :instance => instance }.merge!(attributes)) + if instance + super({ :instance => instance }.merge!(attributes)) + else + super + end end end diff --git a/lib/fog/model.rb b/lib/fog/model.rb index 116ef3d66..f60940f7a 100644 --- a/lib/fog/model.rb +++ b/lib/fog/model.rb @@ -33,6 +33,8 @@ module Fog Marshal.dump(attributes) end + attr_accessor :connection + def attributes attributes = {} for attribute in self.class.attributes @@ -45,14 +47,6 @@ module Fog @collection end - def connection=(new_connection) - @connection = new_connection - end - - def connection - @connection - end - def identity send(self.class.instance_variable_get('@identity')) end diff --git a/spec/aws/models/ec2/address_spec.rb b/spec/aws/models/ec2/address_spec.rb index fceb2b735..6b0ae9807 100644 --- a/spec/aws/models/ec2/address_spec.rb +++ b/spec/aws/models/ec2/address_spec.rb @@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::Address' do describe "#initialize" do it "should remap attributes from parser" do - address = Fog::AWS::EC2::Address.new( + address = ec2.addresses.new( 'instanceId' => 'i-00000000', 'publicIp' => '0.0.0.0' ) @@ -50,21 +50,13 @@ describe 'Fog::AWS::EC2::Address' do @instance.destroy 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 @address.save.should be_true + while @instance.state == 'pending' + @instance.reload + end @address.instance = @instance - @address.instance_id.should == @instance.instance_id + @address.instance_id.should == @instance.id end end diff --git a/spec/aws/models/ec2/instance_spec.rb b/spec/aws/models/ec2/instance_spec.rb index 09ec1a517..4f88a2d74 100644 --- a/spec/aws/models/ec2/instance_spec.rb +++ b/spec/aws/models/ec2/instance_spec.rb @@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::Instance' do describe "#initialize" do it "should remap attributes from parser" do - instance = Fog::AWS::EC2::Instance.new({ + instance = ec2.instances.new({ 'amiLaunchIndex' => 'ami_launch_index', 'dnsName' => 'dns_name', 'groupId' => 'group_id', @@ -23,8 +23,8 @@ describe 'Fog::AWS::EC2::Instance' do instance.dns_name.should == 'dns_name' instance.group_id.should == 'group_id' instance.image_id.should == 'image_id' - instance.instance_id.should == 'instance_id' - instance.instance_type.should == 'instance_type' + instance.id.should == 'instance_id' + instance.type.should == 'instance_type' instance.kernel_id.should == 'kernel_id' instance.key_name.should == 'key_name' instance.launch_time.should == 'launch_time' @@ -38,8 +38,9 @@ describe 'Fog::AWS::EC2::Instance' do describe "#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.destroy end end @@ -53,12 +54,12 @@ describe 'Fog::AWS::EC2::Instance' do end - describe "#instance_state" do + describe "#state" do it "should remap values out of hash" do instance = Fog::AWS::EC2::Instance.new({ 'instanceState' => { 'name' => 'instance_state' }, }) - instance.instance_state.should == 'instance_state' + instance.state.should == 'instance_state' end end @@ -136,12 +137,12 @@ describe 'Fog::AWS::EC2::Instance' do end 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 it "should exist in buckets after save" do @instance.save - ec2.instances.get(@instance.instance_id).should_not be_nil + ec2.instances.get(@instance.id).should_not be_nil @instance.destroy end @@ -150,8 +151,9 @@ describe 'Fog::AWS::EC2::Instance' do describe "#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.destroy end end diff --git a/spec/aws/models/ec2/instances_spec.rb b/spec/aws/models/ec2/instances_spec.rb index 185a6e814..c40e4d152 100644 --- a/spec/aws/models/ec2/instances_spec.rb +++ b/spec/aws/models/ec2/instances_spec.rb @@ -10,7 +10,7 @@ describe 'Fog::AWS::EC2::Instances' do it "should include persisted instances" do 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 end @@ -31,7 +31,7 @@ describe 'Fog::AWS::EC2::Instances' do end 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 @@ -40,7 +40,7 @@ describe 'Fog::AWS::EC2::Instances' do it "should return a Fog::AWS::EC2::Instance if a matching instance exists" do 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.destroy end diff --git a/spec/aws/models/ec2/key_pair_spec.rb b/spec/aws/models/ec2/key_pair_spec.rb index 2501210c9..495ed6d92 100644 --- a/spec/aws/models/ec2/key_pair_spec.rb +++ b/spec/aws/models/ec2/key_pair_spec.rb @@ -5,7 +5,7 @@ describe 'Fog::AWS::EC2::KeyPair' do describe "#initialize" do it "should remap attributes from parser" do - key_pair = Fog::AWS::EC2::KeyPair.new( + key_pair = ec2.key_pairs.new( 'keyFingerprint' => 'fingerprint', 'keyMaterial' => 'material', 'keyName' => 'name' diff --git a/spec/aws/models/ec2/security_group_spec.rb b/spec/aws/models/ec2/security_group_spec.rb index 61484957c..2cf24a952 100644 --- a/spec/aws/models/ec2/security_group_spec.rb +++ b/spec/aws/models/ec2/security_group_spec.rb @@ -5,14 +5,14 @@ describe 'Fog::AWS::EC2::SecurityGroup' do describe "#initialize" do it "should remap attributes from parser" do - security_group = Fog::AWS::EC2::SecurityGroup.new( + security_group = ec2.security_groups.new( 'groupDescription' => 'description', 'groupName' => 'name', 'ipPermissions' => 'permissions', 'ownerId' => 'owner' ) - security_group.group_description.should == 'description' - security_group.group_name.should == 'name' + security_group.description.should == 'description' + security_group.name.should == 'name' security_group.ip_permissions.should == 'permissions' security_group.owner_id.should == 'owner' end @@ -35,7 +35,7 @@ describe 'Fog::AWS::EC2::SecurityGroup' do describe "#destroy" 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 end @@ -44,7 +44,7 @@ describe 'Fog::AWS::EC2::SecurityGroup' do describe "#reload" 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 end @@ -65,7 +65,7 @@ describe 'Fog::AWS::EC2::SecurityGroup' do describe "#save" 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 it "should return true when it succeeds" do @@ -74,12 +74,12 @@ describe 'Fog::AWS::EC2::SecurityGroup' do end 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 it "should exist in buckets after save" do @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 end diff --git a/spec/aws/models/ec2/security_groups_spec.rb b/spec/aws/models/ec2/security_groups_spec.rb index c732a7f09..b3b98dfb8 100644 --- a/spec/aws/models/ec2/security_groups_spec.rb +++ b/spec/aws/models/ec2/security_groups_spec.rb @@ -9,8 +9,8 @@ describe 'Fog::AWS::EC2::SecurityGroups' do end it "should include persisted security_groups" do - security_group = ec2.security_groups.create(:group_description => 'groupdescription', :group_name => 'keyname') - ec2.security_groups.get(security_group.group_name).should_not be_nil + security_group = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname') + ec2.security_groups.get(security_group.name).should_not be_nil security_group.destroy end @@ -19,7 +19,7 @@ describe 'Fog::AWS::EC2::SecurityGroups' do describe "#create" 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 after(:each) do @@ -31,7 +31,7 @@ describe 'Fog::AWS::EC2::SecurityGroups' do end 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 @@ -39,10 +39,10 @@ describe 'Fog::AWS::EC2::SecurityGroups' do describe "#get" 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') - get = ec2.security_groups.get(security_group.group_name) + security_group = ec2.security_groups.create(:description => 'groupdescription', :name => 'keyname') + get = ec2.security_groups.get(security_group.name) 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 end @@ -55,7 +55,7 @@ describe 'Fog::AWS::EC2::SecurityGroups' do describe "#new" 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 diff --git a/spec/aws/models/ec2/snapshot_spec.rb b/spec/aws/models/ec2/snapshot_spec.rb index 99c54b80c..e134e3b6b 100644 --- a/spec/aws/models/ec2/snapshot_spec.rb +++ b/spec/aws/models/ec2/snapshot_spec.rb @@ -5,12 +5,12 @@ describe 'Fog::AWS::EC2::Snapshots' do describe "#initialize" do it "should remap attributes from parser" do - snapshot = Fog::AWS::EC2::Snapshot.new( + snapshot = ec2.snapshots.new( 'snapshotId' => 'snap-00000000', 'startTime' => 'now', 'volumeId' => 'vol-00000000' ) - snapshot.snapshot_id.should == 'snap-00000000' + snapshot.id.should == 'snap-00000000' snapshot.start_time.should == 'now' snapshot.volume_id.should == 'vol-00000000' end @@ -81,12 +81,12 @@ describe 'Fog::AWS::EC2::Snapshots' do end 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 it "should exist in buckets after save" do @snapshot.save - ec2.snapshots.get(@snapshot.snapshot_id).should_not be_nil + ec2.snapshots.get(@snapshot.id).should_not be_nil @snapshot.destroy end diff --git a/spec/aws/models/ec2/snapshots_spec.rb b/spec/aws/models/ec2/snapshots_spec.rb index 843eaac86..221e01f89 100644 --- a/spec/aws/models/ec2/snapshots_spec.rb +++ b/spec/aws/models/ec2/snapshots_spec.rb @@ -11,16 +11,16 @@ describe 'Fog::AWS::EC2::Snapshots' do it "should include persisted snapshots" do volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') 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 volume.destroy 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') other_volume = ec2.volumes.create(:availability_zone => 'us-east-1a', :size => 1, :device => 'dev/sdz1') 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 other_volume.destroy volume.destroy @@ -45,7 +45,7 @@ describe 'Fog::AWS::EC2::Snapshots' do end 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 @@ -55,8 +55,8 @@ describe 'Fog::AWS::EC2::Snapshots' 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') snapshot = volume.snapshots.create - get = ec2.snapshots.get(snapshot.snapshot_id) - snapshot.attributes.reject {|key, value| ['progress', 'status'].include?(key)}.should == get.attributes.reject {|key, value| ['progress', 'status'].include?(key)} + 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.destroy end diff --git a/spec/aws/models/ec2/volume_spec.rb b/spec/aws/models/ec2/volume_spec.rb index 17767f96b..74bb280e5 100644 --- a/spec/aws/models/ec2/volume_spec.rb +++ b/spec/aws/models/ec2/volume_spec.rb @@ -5,8 +5,8 @@ describe 'Fog::AWS::EC2::Volume' do describe "#initialize" do it "should remap attributes from parser" do - volume = Fog::AWS::EC2::Volume.new( - 'attachTime' => 'now', + volume = ec2.volumes.new( + 'attachTime' => 'now', 'availabilityZone' => 'us-east-1a', 'createTime' => 'recently', 'instanceId' => 'i-00000000', @@ -18,7 +18,7 @@ describe 'Fog::AWS::EC2::Volume' do volume.create_time.should == 'recently' volume.instance_id.should == 'i-00000000' volume.snapshot_id.should == 'snap-00000000' - volume.volume_id.should == 'vol-00000000' + volume.id.should == 'vol-00000000' end end @@ -39,7 +39,7 @@ describe 'Fog::AWS::EC2::Volume' do describe "#destroy" 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 end @@ -48,26 +48,29 @@ describe 'Fog::AWS::EC2::Volume' do describe "#instance=" do before(:each) do @instance = ec2.instances.create(:image_id => GENTOO_AMI) - @volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => 'dev/sdz1') - while @instance.instance_state == 'pending' + @volume = ec2.volumes.new(:availability_zone => @instance.availability_zone, :size => 1, :device => '/dev/sdz1') + while @instance.state == 'pending' @instance.reload end - while @volume.status == 'creating' - @volume.reload - end end after(:each) do @instance.destroy - if @volume.volume_id + if @volume.id + while ['attaching', 'creating'].include?(@volume.status) + @volume.reload + end @volume.instance = nil + while ['attached', 'detaching'].include?(@volume.status) + @volume.reload + end @volume.destroy end end it "should not attach to instance if the volume has not been saved" do @volume.instance = @instance - @volume.instance_id.should_not == @instance.instance_id + @volume.instance_id.should_not == @instance.id end 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 @volume.instance = @instance @volume.save.should be_true - @volume.instance_id.should == @instance.instance_id + @volume.instance_id.should == @instance.id end it "should attach to instance to an already saved volume" do @volume.save.should be_true @volume.instance = @instance - @volume.instance_id.should == @instance.instance_id + @volume.instance_id.should == @instance.id end 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 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 end @@ -118,7 +121,7 @@ describe 'Fog::AWS::EC2::Volume' do describe "#save" 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 it "should return true when it succeeds" do @@ -127,12 +130,12 @@ describe 'Fog::AWS::EC2::Volume' do end 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 it "should exist in buckets after save" do @volume.save - ec2.volumes.get(@volume.volume_id).should_not be_nil + ec2.volumes.get(@volume.id).should_not be_nil @volume.destroy end diff --git a/spec/aws/models/ec2/volumes_spec.rb b/spec/aws/models/ec2/volumes_spec.rb index 5ea1e6d63..f4ea5a591 100644 --- a/spec/aws/models/ec2/volumes_spec.rb +++ b/spec/aws/models/ec2/volumes_spec.rb @@ -10,7 +10,7 @@ describe 'Fog::AWS::EC2::Volumes' do it "should include persisted volumes" do 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 end @@ -31,7 +31,7 @@ describe 'Fog::AWS::EC2::Volumes' do end 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 @@ -40,8 +40,8 @@ describe 'Fog::AWS::EC2::Volumes' 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') - get = ec2.volumes.get(volume.volume_id) - volume.attributes.reject { |key, value| key == :device }.should == get.attributes.reject { |key, value| key == :device } + get = ec2.volumes.get(volume.id) + volume.attributes.reject { |key, value| [:device, :status].include?(key) }.should == get.attributes.reject { |key, value| [:device, :status].include?(key) } volume.destroy end