Skip to content

Commit

Permalink
Revert "support to wait 'pending' state for snapshot_disk"
Browse files Browse the repository at this point in the history
This reverts commit 2bb4f36.
  • Loading branch information
thausler786 committed Jun 22, 2015
1 parent 4b5e471 commit 1a4d588
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bosh_aws_cpi/lib/cloud/aws/cloud.rb
Expand Up @@ -349,7 +349,7 @@ def snapshot_disk(disk_id, metadata)
TagManager.tag(snapshot, 'device', devices.first) unless devices.empty?
TagManager.tag(snapshot, 'Name', name.join('/'))

ResourceWait.for_snapshot(snapshot: snapshot, states: [:pending, :completed])
ResourceWait.for_snapshot(snapshot: snapshot, state: :completed)
snapshot.id
end
end
Expand Down
10 changes: 5 additions & 5 deletions bosh_aws_cpi/lib/cloud/aws/resource_wait.rb
Expand Up @@ -96,12 +96,12 @@ def self.for_volume(args)

def self.for_snapshot(args)
snapshot = args.fetch(:snapshot) { raise ArgumentError, 'snapshot object required' }
target_states = args.fetch(:states) { raise ArgumentError, 'states array required' }
valid_states = [:pending, :completed]
target_states.each { |target_state| validate_states(valid_states, target_state) }
target_state = args.fetch(:state) { raise ArgumentError, 'state symbol required' }
valid_states = [:completed]
validate_states(valid_states, target_state)

new.for_resource(resource: snapshot, target_state: target_states, tries: 18) do |current_state|
target_states.include? current_state
new.for_resource(resource: snapshot, target_state: target_state, tries: 18) do |current_state|
current_state == target_state
end
end

Expand Down
2 changes: 1 addition & 1 deletion bosh_aws_cpi/lib/cloud/aws/stemcell_creator.rb
Expand Up @@ -19,7 +19,7 @@ def create(volume, ebs_volume, image_path)
copy_root_image

snapshot = volume.create_snapshot
ResourceWait.for_snapshot(snapshot: snapshot, states: [:completed])
ResourceWait.for_snapshot(snapshot: snapshot, state: :completed)

params = image_params(snapshot.id)
image = region.images.create(params)
Expand Down
19 changes: 6 additions & 13 deletions bosh_aws_cpi/spec/unit/resource_wait_spec.rb
Expand Up @@ -141,27 +141,20 @@
let(:snapshot) { double(AWS::EC2::Snapshot, id: 'snap-123') }

context 'creation' do
it 'should wait until the state is pending' do
expect(snapshot).to receive(:status).and_return(:pending)
described_class.for_snapshot(snapshot: snapshot, states: [:pending, :completed])
end

it 'should wait until the state is completed' do
expect(snapshot).to receive(:status).and_return(:pending)
expect(snapshot).to receive(:status).and_return(:completed)
described_class.for_snapshot(snapshot: snapshot, states: [:pending, :completed])
end

it 'should raise an error if the state is any other states rather than pending or complete' do
expect {
described_class.for_snapshot(snapshot: snapshot, states: [:other_state])
}.to raise_error ArgumentError, /target state must be one of pending, completed, `other_state' given/
described_class.for_snapshot(snapshot: snapshot, state: :completed)
end

it 'should raise an error if the state is error' do
expect(snapshot).to receive(:status).and_return(:pending)
expect(snapshot).to receive(:status).and_return(:error)

expect {
described_class.for_snapshot(snapshot: snapshot, states: [:pending, :completed])
}.to raise_error Bosh::Clouds::CloudError, /state is error, expected \[:pending, :completed\]/
described_class.for_snapshot(snapshot: snapshot, state: :completed)
}.to raise_error Bosh::Clouds::CloudError, /state is error, expected completed/
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions bosh_aws_cpi/spec/unit/snapshot_disk_spec.rb
Expand Up @@ -27,7 +27,7 @@
expect(volume).to receive(:create_snapshot).with('deployment/job/0/sdf').and_return(snapshot)

expect(Bosh::AwsCloud::ResourceWait).to receive(:for_snapshot).with(
snapshot: snapshot, states: [:pending, :completed]
snapshot: snapshot, state: :completed
)

expect(Bosh::AwsCloud::TagManager).to receive(:tag).with(snapshot, 'agent_id', 'agent')
Expand Down Expand Up @@ -59,7 +59,7 @@
allow(volume).to receive(:create_snapshot).with('deployment/job/0/sdf').and_return(snapshot)

allow(Bosh::AwsCloud::ResourceWait).to receive(:for_snapshot).with(
snapshot: snapshot, states: [:pending, :completed]
snapshot: snapshot, state: :completed
)

expect(Bosh::AwsCloud::TagManager).to receive(:tag).with(snapshot, 'agent_id', 'agent')
Expand All @@ -81,7 +81,7 @@
expect(volume).to receive(:create_snapshot).with('deployment/job/0').and_return(snapshot)

expect(Bosh::AwsCloud::ResourceWait).to receive(:for_snapshot).with(
snapshot: snapshot, states: [:pending, :completed]
snapshot: snapshot, state: :completed
)

expect(Bosh::AwsCloud::TagManager).to receive(:tag).with(snapshot, 'agent_id', 'agent')
Expand Down
2 changes: 1 addition & 1 deletion bosh_aws_cpi/spec/unit/stemcell_creator_spec.rb
Expand Up @@ -28,7 +28,7 @@

it "should create a real stemcell" do
creator = described_class.new(region, stemcell_properties)
allow(Bosh::AwsCloud::ResourceWait).to receive(:for_snapshot).with(snapshot: snapshot, states: [:completed])
allow(Bosh::AwsCloud::ResourceWait).to receive(:for_snapshot).with(snapshot: snapshot, state: :completed)
allow(Bosh::AwsCloud::ResourceWait).to receive(:for_image).with(image: image, state: :available)
allow(SecureRandom).to receive(:uuid).and_return("fake-uuid")
allow(region).to receive_message_chain(:images, :create).and_return(image)
Expand Down

0 comments on commit 1a4d588

Please sign in to comment.