lib/beaker/hypervisor/aws_sdk.rb in beaker-aws-0.9.0 vs lib/beaker/hypervisor/aws_sdk.rb in beaker-aws-1.0.0

- old
+ new

@@ -160,11 +160,16 @@ # Provided an id return an instance object. # Instance object will respond to methods described here: {http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html AWS Instance Object}. # @param [String] id The id of the instance to return # @return [Aws::EC2::Types::Instance] An Aws::EC2 instance object def instance_by_id(id) - client.describe_instances(:instance_ids => [id]).reservations.first.instances.first + begin + client.describe_instances(:instance_ids => [id]).reservations.first.instances.first + rescue Aws::EC2::Errors::InvalidInstanceIDNotFound + @logger.notify("aws-sdk: Error while trying to describe instance (id: #{id}). Likely the instance is not created yet.") + nil + end end # Return all instances currently on ec2. # @see AwsSdk#instance_by_id # @return [Array<Aws::Ec2::Types::Instance>] An array of Aws::EC2 instance objects @@ -505,11 +510,11 @@ # TODO: should probably be a in a shared method somewhere for tries in 1..10 refreshed_instance = instance_by_id(instance.instance_id) if refreshed_instance.nil? - @logger.debug("Instance #{name} not yet available (#{e})") + @logger.debug("Instance #{name} not yet available") else if block_given? test_result = yield refreshed_instance else test_result = refreshed_instance.state.name.to_s == state_name.to_s @@ -1163,5 +1168,6 @@ end end end end end +