Skip to content
Browse files

[aws_cpi] use another way to do dynamic method calls

  • Loading branch information...
1 parent ed289cf commit da3b2d83b93319455e76a19d21b6bc1785d23630 @pmenglund pmenglund committed Mar 13, 2013
Showing with 40 additions and 42 deletions.
  1. +1 −3 bosh_aws_cpi/lib/cloud/aws/resource_wait.rb
  2. +39 −39 bosh_aws_cpi/spec/unit/resource_wait_spec.rb
View
4 bosh_aws_cpi/lib/cloud/aws/resource_wait.rb
@@ -137,9 +137,7 @@ def for_resource(args)
Bosh::Common.retryable(tries: tries, sleep: sleep_cb, on: errors, ensure: ensure_cb ) do
Bosh::AwsCloud::ResourceWait.task_checkpoint # from config
- # for some obscure reason AWS::EC2::Subnet does not have the call method,
- # so a little hackery is required :(
- state = resource.instance_of?(AWS::EC2::Subnet) ? resource.__send__(state_method) : resource.call(state_method)
+ state = resource.method(state_method).call
if state == :error || state == :failed
raise Bosh::Clouds::CloudError, "#{desc} state is #{state}, expected #{target_state}"
View
78 bosh_aws_cpi/spec/unit/resource_wait_spec.rb
@@ -12,27 +12,27 @@
context 'deletion' do
it 'should wait until the state is terminated' do
- instance.should_receive(:call).with(:status).and_return(:shutting_down)
- instance.should_receive(:call).with(:status).and_return(:shutting_down)
- instance.should_receive(:call).with(:status).and_return(:terminated)
+ instance.should_receive(:status).and_return(:shutting_down)
+ instance.should_receive(:status).and_return(:shutting_down)
+ instance.should_receive(:status).and_return(:terminated)
described_class.for_instance(instance: instance, state: :terminated)
end
end
context 'creation' do
it 'should wait until the state is running' do
- instance.should_receive(:call).with(:status).and_raise(AWS::EC2::Errors::InvalidInstanceID::NotFound)
- instance.should_receive(:call).with(:status).and_return(:pending)
- instance.should_receive(:call).with(:status).and_return(:running)
+ instance.should_receive(:status).and_raise(AWS::EC2::Errors::InvalidInstanceID::NotFound)
+ instance.should_receive(:status).and_return(:pending)
+ instance.should_receive(:status).and_return(:running)
described_class.for_instance(instance: instance, state: :running)
end
it 'should fail if AWS terminates the instance' do
- instance.should_receive(:call).with(:status).and_return(:pending)
- instance.should_receive(:call).with(:status).and_return(:pending)
- instance.should_receive(:call).with(:status).and_return(:terminated)
+ instance.should_receive(:status).and_return(:pending)
+ instance.should_receive(:status).and_return(:pending)
+ instance.should_receive(:status).and_return(:terminated)
expect {
described_class.for_instance(instance: instance, state: :running)
@@ -46,24 +46,24 @@
context 'attachment' do
it 'should wait until the state is attached' do
- attachment.should_receive(:call).with(:status).and_return(:attaching)
- attachment.should_receive(:call).with(:status).and_return(:attached)
+ attachment.should_receive(:status).and_return(:attaching)
+ attachment.should_receive(:status).and_return(:attached)
described_class.for_attachment(attachment: attachment, state: :attached)
end
end
context 'detachment' do
it 'should wait until the state is detached' do
- attachment.should_receive(:call).with(:status).and_return(:detaching)
- attachment.should_receive(:call).with(:status).and_return(:detached)
+ attachment.should_receive(:status).and_return(:detaching)
+ attachment.should_receive(:status).and_return(:detached)
described_class.for_attachment(attachment: attachment, state: :detached)
end
it 'should consider AWS::Core::Resource::NotFound to be detached' do
- attachment.should_receive(:call).with(:status).and_return(:detaching)
- attachment.should_receive(:call).with(:status).and_raise(AWS::Core::Resource::NotFound)
+ attachment.should_receive(:status).and_return(:detaching)
+ attachment.should_receive(:status).and_raise(AWS::Core::Resource::NotFound)
described_class.for_attachment(attachment: attachment, state: :detached)
end
@@ -75,16 +75,16 @@
context 'creation' do
it 'should wait until the state is available' do
- volume.should_receive(:call).with(:status).and_return(:creating)
- volume.should_receive(:call).with(:status).and_return(:available)
+ volume.should_receive(:status).and_return(:creating)
+ volume.should_receive(:status).and_return(:available)
described_class.for_volume(volume: volume, state: :available)
end
#:error
it 'should raise an error on error state' do
- volume.should_receive(:call).with(:status).and_return(:creating)
- volume.should_receive(:call).with(:status).and_return(:error)
+ volume.should_receive(:status).and_return(:creating)
+ volume.should_receive(:status).and_return(:error)
expect {
described_class.for_volume(volume: volume, state: :available)
@@ -94,15 +94,15 @@
context 'deletion' do
it 'should wait until the state is deleted' do
- volume.should_receive(:call).with(:status).and_return(:deleting)
- volume.should_receive(:call).with(:status).and_return(:deleted)
+ volume.should_receive(:status).and_return(:deleting)
+ volume.should_receive(:status).and_return(:deleted)
described_class.for_volume(volume: volume, state: :deleted)
end
it 'should consider InvalidVolume error to mean deleted' do
- volume.should_receive(:call).with(:status).and_return(:deleting)
- volume.should_receive(:call).with(:status).and_raise(AWS::EC2::Errors::InvalidVolume::NotFound)
+ volume.should_receive(:status).and_return(:deleting)
+ volume.should_receive(:status).and_raise(AWS::EC2::Errors::InvalidVolume::NotFound)
described_class.for_volume(volume: volume, state: :deleted)
end
@@ -113,15 +113,15 @@
let(:snapshot) { double(AWS::EC2::Snapshot, id: 'snap-123') }
context 'creation' do
it 'should wait until the state is completed' do
- snapshot.should_receive(:call).with(:status).and_return(:pending)
- snapshot.should_receive(:call).with(:status).and_return(:completed)
+ snapshot.should_receive(:status).and_return(:pending)
+ snapshot.should_receive(:status).and_return(:completed)
described_class.for_snapshot(snapshot: snapshot, state: :completed)
end
it 'should raise an error if the state is error' do
- snapshot.should_receive(:call).with(:status).and_return(:pending)
- snapshot.should_receive(:call).with(:status).and_return(:error)
+ snapshot.should_receive(:status).and_return(:pending)
+ snapshot.should_receive(:status).and_return(:error)
expect {
described_class.for_snapshot(snapshot: snapshot, state: :completed)
@@ -135,23 +135,23 @@
context 'creation' do
it 'should wait until the state is available' do
- image.should_receive(:call).with(:state).and_return(:pending)
- image.should_receive(:call).with(:state).and_return(:available)
+ image.should_receive(:state).and_return(:pending)
+ image.should_receive(:state).and_return(:available)
described_class.for_image(image: image, state: :available)
end
it 'should wait if AWS::EC2::Errors::InvalidAMIID::NotFound raised' do
- image.should_receive(:call).with(:state).and_raise(AWS::EC2::Errors::InvalidAMIID::NotFound)
- image.should_receive(:call).with(:state).and_return(:pending)
- image.should_receive(:call).with(:state).and_return(:available)
+ image.should_receive(:state).and_raise(AWS::EC2::Errors::InvalidAMIID::NotFound)
+ image.should_receive(:state).and_return(:pending)
+ image.should_receive(:state).and_return(:available)
described_class.for_image(image: image, state: :available)
end
it 'should raise an error if the state is failed' do
- image.should_receive(:call).with(:state).and_return(:pending)
- image.should_receive(:call).with(:state).and_return(:failed)
+ image.should_receive(:state).and_return(:pending)
+ image.should_receive(:state).and_return(:failed)
expect {
described_class.for_image(image: image, state: :available)
@@ -161,9 +161,9 @@
context 'deletion' do
it 'should wait until the state is deleted' do
- image.should_receive(:call).with(:state).and_return(:available)
- image.should_receive(:call).with(:state).and_return(:pending)
- image.should_receive(:call).with(:state).and_return(:deleted)
+ image.should_receive(:state).and_return(:available)
+ image.should_receive(:state).and_return(:pending)
+ image.should_receive(:state).and_return(:deleted)
described_class.for_image(image: image, state: :deleted)
end
@@ -175,8 +175,8 @@
context 'creation' do
it 'should wait until the state is completed' do
- subnet.should_receive(:call).with(:state).and_return(:pending)
- subnet.should_receive(:call).with(:state).and_return(:available)
+ subnet.should_receive(:state).and_return(:pending)
+ subnet.should_receive(:state).and_return(:available)
described_class.for_subnet(subnet: subnet, state: :available)
end

0 comments on commit da3b2d8

Please sign in to comment.
Something went wrong with that request. Please try again.