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

Merge pull request #443 from fog/lanej/fix-volume-attach

fix: attach volume on #save, remove #server=
This commit is contained in:
Josh Lane 2018-04-23 09:31:38 -07:00 committed by GitHub
commit e0447b033e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 25 deletions

View file

@ -21,7 +21,7 @@ module Fog
def initialize(attributes = {})
# assign server first to prevent race condition with persisted?
self.server = attributes.delete(:server)
@server = attributes.delete(:server)
super
end
@ -70,10 +70,10 @@ module Fog
service.create_tags(identity, tags)
end
attach(@service, device) if @server
true
attach(@server, device) if @server && device
end
true
end
def server
@ -81,8 +81,6 @@ module Fog
service.servers.get(server_id)
end
attr_writer :server
def snapshots
requires :id
service.snapshots(:volume => self)
@ -119,6 +117,10 @@ module Fog
end
end
def server=(_)
raise NoMethodError, 'use Fog::Compute::AWS::Volume#attach(server, device)'
end
private
def attachmentSet=(new_attachment_set)

View file

@ -8,39 +8,38 @@ Shindo.tests('Fog::Compute[:aws] | volume', ['aws']) do
availability_zone: @server.availability_zone,
size: 1,
tags: { 'key' => 'value' },
type: 'gp2'
type: 'gp2',
server: @server,
device: '/dev/sdz1'
},
true
) do
@instance.wait_for { ready? }
tests('#attach(server, device)').succeeds do
@instance.attach(@server, '/dev/sdz1')
end
@instance.wait_for { state == 'in-use' }
tests('#server').succeeds do
@instance.server.id == @server.id
tests('attached').succeeds do
@instance.server == @server
end
tests('#detach').succeeds do
@instance.detach
@instance.wait_for { ready? }
@instance.server.nil?
end
@instance.wait_for { ready? }
tests('#server=').raises(NoMethodError, 'use Fog::Compute::AWS::Volume#attach(server, device)') do
@instance.server = @server
end
@instance.attach(@server, '/dev/sdz1')
@instance.wait_for { state == 'in-use' }
tests('#attach(server, device)').succeeds do
@instance.attach(@server, '/dev/sdz1')
@instance.server == @server
end
tests('#force_detach').succeeds do
@instance.force_detach
@instance.wait_for { ready? }
@instance.server.nil?
end
@instance.wait_for { ready? }
@instance.type = 'io1'
@instance.iops = 5000
@instance.size = 100
@ -56,10 +55,9 @@ Shindo.tests('Fog::Compute[:aws] | volume', ['aws']) do
returns(5000) { @instance.iops }
returns(100) { @instance.size }
tests('@instance.reload.tags').returns({'key' => 'value'}) do
@instance.reload.tags
tests('@instance.tags').returns({'key' => 'value'}) do
@instance.tags
end
end
@server.destroy