diff --git a/lib/fog/aws/models/ec2/address.rb b/lib/fog/aws/models/ec2/address.rb index dc72dbc38..c1ff6497e 100644 --- a/lib/fog/aws/models/ec2/address.rb +++ b/lib/fog/aws/models/ec2/address.rb @@ -42,7 +42,7 @@ module Fog data = connection.allocate_address @public_ip = data.body['publicIp'] if @instance - instance = @instance + self.instance = @instance end true end diff --git a/lib/fog/aws/models/ec2/volume.rb b/lib/fog/aws/models/ec2/volume.rb index 8819bb159..b458a9cfc 100644 --- a/lib/fog/aws/models/ec2/volume.rb +++ b/lib/fog/aws/models/ec2/volume.rb @@ -46,7 +46,7 @@ module Fog new_attributes = data.reject {|key,value| key == 'requestId'} merge_attributes(new_attributes) if @instance - instance = @instance + self.instance = @instance end true end diff --git a/spec/aws/models/ec2/address_spec.rb b/spec/aws/models/ec2/address_spec.rb index 50535624c..ade728198 100644 --- a/spec/aws/models/ec2/address_spec.rb +++ b/spec/aws/models/ec2/address_spec.rb @@ -37,6 +37,37 @@ describe 'Fog::AWS::EC2::Address' do end + describe "#instance=" do + before(:each) do + @address = ec2.addresses.new + @instance = ec2.instances.create(:image_id => GENTOO_AMI) + end + + after(:each) do + if @address.public_ip + @address.destroy + end + @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 + @address.instance = @instance + @address.instance_id.should == @instance.instance_id + end + end + describe "#reload" do before(:each) do diff --git a/spec/aws/models/ec2/instance_spec.rb b/spec/aws/models/ec2/instance_spec.rb index 81e7c6d5f..0dc8cd888 100644 --- a/spec/aws/models/ec2/instance_spec.rb +++ b/spec/aws/models/ec2/instance_spec.rb @@ -11,23 +11,19 @@ describe 'Fog::AWS::EC2::Instance' do 'groupId' => 'group_id', 'imageId' => 'image_id', 'instanceId' => 'instance_id', - 'instanceState' => { 'name' => 'instance_state' }, 'instanceType' => 'instance_type', 'kernelId' => 'kernel_id', 'keyName' => 'key_name', 'launchTime' => 'launch_time', - 'placement' => { 'availabilityZone' => 'availability_zone'}, 'productCodes' => 'product_codes', 'privateDnsName' => 'private_dns_name', 'ramdiskId' => 'ramdisk_id' }) instance.ami_launch_index.should == 'ami_launch_index' - instance.availability_zone.should == 'availability_zone' 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_state.should == 'instance_state' instance.instance_type.should == 'instance_type' instance.kernel_id.should == 'kernel_id' instance.key_name.should == 'key_name' @@ -46,21 +42,26 @@ describe 'Fog::AWS::EC2::Instance' do instance.addresses.should be_a(Fog::AWS::EC2::Addresses) end - it "should not associate the address to a not yet saved instance" - it "should associate the address after saving a new instance" - it "should associate the address to an existing instance" - end describe "#destroy" do it "should return true if the instance is deleted" do - instance = ec2.instances.create(:image_id => 'ami-5ee70037') + instance = ec2.instances.create(:image_id => GENTOO_AMI) instance.destroy.should be_true end end + describe "#instance_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' + end + end + describe "#instances" do it "should return a Fog::AWS::EC2::Instances" do @@ -83,17 +84,29 @@ describe 'Fog::AWS::EC2::Instance' do end describe "#monitoring=" do - it "should have tests" + it "should remap values out of hash" do + instance = Fog::AWS::EC2::Instance.new({ + 'monitoring' => { 'state' => true } + }) + instance.monitoring.should == true + end end describe "#placement=" do - it "should have tests" + + it "should remap values into availability_zone" do + instance = Fog::AWS::EC2::Instance.new({ + 'placement' => { 'availabilityZone' => 'availability_zone' } + }) + instance.availability_zone.should == 'availability_zone' + end + end describe "#reload" do before(:each) do - @instance = ec2.instances.create(:image_id => 'ami-5ee70037') + @instance = ec2.instances.create(:image_id => GENTOO_AMI) @reloaded = @instance.reload end @@ -141,10 +154,6 @@ describe 'Fog::AWS::EC2::Instance' do instance.volumes.should be_a(Fog::AWS::EC2::Volumes) end - it "should not attach the volume to a not yet saved instance" - it "should attach the volume after saving a new instance" - it "should attach the volume to an existing instance" - end end diff --git a/spec/aws/models/ec2/instances_spec.rb b/spec/aws/models/ec2/instances_spec.rb index e804d6107..185a6e814 100644 --- a/spec/aws/models/ec2/instances_spec.rb +++ b/spec/aws/models/ec2/instances_spec.rb @@ -9,7 +9,7 @@ describe 'Fog::AWS::EC2::Instances' do end it "should include persisted instances" do - instance = ec2.instances.create(:image_id => 'ami-5ee70037') + instance = ec2.instances.create(:image_id => GENTOO_AMI) ec2.instances.get(instance.instance_id).should_not be_nil instance.destroy end @@ -19,7 +19,7 @@ describe 'Fog::AWS::EC2::Instances' do describe "#create" do before(:each) do - @instance = ec2.instances.create(:image_id => 'ami-5ee70037') + @instance = ec2.instances.create(:image_id => GENTOO_AMI) end after(:each) do @@ -39,7 +39,7 @@ describe 'Fog::AWS::EC2::Instances' do describe "#get" do it "should return a Fog::AWS::EC2::Instance if a matching instance exists" do - instance = ec2.instances.create(:image_id => 'ami-5ee70037') + instance = ec2.instances.create(:image_id => GENTOO_AMI) get = ec2.instances.get(instance.instance_id) instance.attributes.should == get.attributes instance.destroy @@ -54,7 +54,7 @@ describe 'Fog::AWS::EC2::Instances' do describe "#new" do it "should return a Fog::AWS::EC2::Instance" do - ec2.instances.new(:image_id => 'ami-5ee70037').should be_a(Fog::AWS::EC2::Instance) + ec2.instances.new(:image_id => GENTOO_AMI).should be_a(Fog::AWS::EC2::Instance) end end diff --git a/spec/aws/models/ec2/volume_spec.rb b/spec/aws/models/ec2/volume_spec.rb index 8cf962e2a..95bc19d6a 100644 --- a/spec/aws/models/ec2/volume_spec.rb +++ b/spec/aws/models/ec2/volume_spec.rb @@ -45,6 +45,37 @@ describe 'Fog::AWS::EC2::Volume' do end + describe "#instance=" do + before(:each) do + @volume = ec2.volumes.new + @instance = ec2.instances.create(:image_id => GENTOO_AMI) + end + + after(:each) do + if @volume.volume_id + @volume.destroy + end + @instance.destroy + end + + it "should not attach to instance if the address has not been saved" do + @volume.instance = @instance + @volume.instance_id.should_not == @instance.instance_id + end + + it "should attach to instance when the address is saved" do + @volume.instance = @instance + @volume.save.should be_true + @volume.instance_id.should == @instance.instance_id + end + + it "should attach to instance to an already saved address" do + @volume.save.should be_true + @volume.instance = @instance + @volume.instance_id.should == @instance.instance_id + end + end + describe "#reload" do before(:each) do diff --git a/spec/aws/requests/ec2/associate_address_spec.rb b/spec/aws/requests/ec2/associate_address_spec.rb index e8ca66bfe..1e22cc828 100644 --- a/spec/aws/requests/ec2/associate_address_spec.rb +++ b/spec/aws/requests/ec2/associate_address_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.associate_address' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] @public_ip = ec2.allocate_address.body['publicIp'] end @@ -31,7 +31,7 @@ describe 'EC2.associate_address' do end it "should raise a BadRequest error if the address does not exist" do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] lambda { ec2.associate_address(@instance_id, '127.0.0.1') }.should raise_error(Fog::Errors::BadRequest) diff --git a/spec/aws/requests/ec2/attach_volume_spec.rb b/spec/aws/requests/ec2/attach_volume_spec.rb index be6b97625..a7ade0564 100644 --- a/spec/aws/requests/ec2/attach_volume_spec.rb +++ b/spec/aws/requests/ec2/attach_volume_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.attach_volume' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId'] @volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId'] end @@ -42,7 +42,7 @@ describe 'EC2.attach_volume' do end it "should raise a BadRequest error if the address does not exist" do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] lambda { ec2.attach_volume(@instance_id, 'vol-00000000', '/dev/sdh') }.should raise_error(Fog::Errors::BadRequest) diff --git a/spec/aws/requests/ec2/describe_images_spec.rb b/spec/aws/requests/ec2/describe_images_spec.rb index 16b3d0ed7..06754c10b 100644 --- a/spec/aws/requests/ec2/describe_images_spec.rb +++ b/spec/aws/requests/ec2/describe_images_spec.rb @@ -20,7 +20,7 @@ describe 'EC2.describe_images' do end it "should return proper attributes with params" do - actual = ec2.describe_images('ImageId' => 'ami-5ee70037') + actual = ec2.describe_images('ImageId' => GENTOO_AMI) actual.body['requestId'].should be_a(String) image = actual.body['imagesSet'].first image['architecture'].should be_a(String) diff --git a/spec/aws/requests/ec2/describe_instances_spec.rb b/spec/aws/requests/ec2/describe_instances_spec.rb index 09cee3ff5..82aed1168 100644 --- a/spec/aws/requests/ec2/describe_instances_spec.rb +++ b/spec/aws/requests/ec2/describe_instances_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.describe_instances' do describe 'success' do before(:each) do - run_instances = ec2.run_instances('ami-5ee70037', 1, 1).body + run_instances = ec2.run_instances(GENTOO_AMI, 1, 1).body @instance_id = run_instances['instancesSet'].first['instanceId'] @reservation_id = run_instances['reservationId'] end diff --git a/spec/aws/requests/ec2/detach_volume_spec.rb b/spec/aws/requests/ec2/detach_volume_spec.rb index cc7f501f2..daf9827dd 100644 --- a/spec/aws/requests/ec2/detach_volume_spec.rb +++ b/spec/aws/requests/ec2/detach_volume_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.detach_volume' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1, {'Placement.AvailabilityZone' => 'us-east-1a'}).body['instancesSet'].first['instanceId'] @volume_id = ec2.create_volume('us-east-1a', 1).body['volumeId'] eventually(128) do ec2.attach_volume(@instance_id, @volume_id, '/dev/sdh') diff --git a/spec/aws/requests/ec2/disassociate_address_spec.rb b/spec/aws/requests/ec2/disassociate_address_spec.rb index 2453fb0e3..3a7898ae9 100644 --- a/spec/aws/requests/ec2/disassociate_address_spec.rb +++ b/spec/aws/requests/ec2/disassociate_address_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.disassociate_address' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] @public_ip = ec2.allocate_address.body['publicIp'] ec2.associate_address(@instance_id, @public_ip) end diff --git a/spec/aws/requests/ec2/get_console_output_spec.rb b/spec/aws/requests/ec2/get_console_output_spec.rb index 3d5102866..d77a8cc1a 100644 --- a/spec/aws/requests/ec2/get_console_output_spec.rb +++ b/spec/aws/requests/ec2/get_console_output_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.get_console_output' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] end after(:each) do diff --git a/spec/aws/requests/ec2/reboot_instances_spec.rb b/spec/aws/requests/ec2/reboot_instances_spec.rb index 3e8bfb9d1..0b6b599da 100644 --- a/spec/aws/requests/ec2/reboot_instances_spec.rb +++ b/spec/aws/requests/ec2/reboot_instances_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.reboot_instances' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] end after(:each) do diff --git a/spec/aws/requests/ec2/run_instances_spec.rb b/spec/aws/requests/ec2/run_instances_spec.rb index 51244f70f..b70274aa0 100644 --- a/spec/aws/requests/ec2/run_instances_spec.rb +++ b/spec/aws/requests/ec2/run_instances_spec.rb @@ -9,7 +9,7 @@ describe 'EC2.run_instances' do it "should return proper attributes" do # ami-5ee70037 = gentoo - actual = ec2.run_instances('ami-5ee70037', 1, 1) + actual = ec2.run_instances(GENTOO_AMI, 1, 1) @instance_id = actual.body['instancesSet'].first['instanceId'] actual.body['groupSet'].should be_an(Array) actual.body['groupSet'].first.should be_a(String) diff --git a/spec/aws/requests/ec2/terminate_instances_spec.rb b/spec/aws/requests/ec2/terminate_instances_spec.rb index 1546cc820..15db5d4a8 100644 --- a/spec/aws/requests/ec2/terminate_instances_spec.rb +++ b/spec/aws/requests/ec2/terminate_instances_spec.rb @@ -4,7 +4,7 @@ describe 'EC2.terminate_instances' do describe 'success' do before(:each) do - @instance_id = ec2.run_instances('ami-5ee70037', 1, 1).body['instancesSet'].first['instanceId'] + @instance_id = ec2.run_instances(GENTOO_AMI, 1, 1).body['instancesSet'].first['instanceId'] end it "should return proper attributes" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c3fbbb029..0ef247b38 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -78,4 +78,6 @@ def eventually(max_delay = 16, &block) raise error if delay >= max_delay end end -end \ No newline at end of file +end + +GENTOO_AMI = 'ami-5ee70037'