Sha256: b718360459f3a666e836edac2a4c06db3a9af24c01ea28c6fcfcb7f234a149a3

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'awsum/ec2'
require 'awsum/s3'

def functional(description, &block)
  describe "Functional: #{description}" do
    let(:keys) do
      rc_file = File.join(File.expand_path('~'), '.awsumrc')
      unless File.exists?(rc_file)
        raise 'Unable to run functional specs with out access and secret keys. Place them in ~/.awsumrc'
      end
      YAML.load(File.read(rc_file))
    end

    let(:access_key) { keys['access_key'] }
    let(:secret_key) { keys['secret_key'] }

    instance_eval(&block)

    after(:all) do
      ec2.instances(:filter => {'instance-state-name' => ['running', 'stopped']},
                    :tags => {'Name' => 'awsum.test'}).each do |instance|
        begin
          instance.terminate
          wait_for instance, 'terminated'
        rescue
          puts "Could not terminate instance #{instance.id}"
          puts $!.inspect
          puts $!.backtrace
        end
      end

      ec2.volumes(:filter => {'status' => ['available', 'in-use']},
                  :tags => {'Name' => 'awsum.test'}).each do |volume|
        begin
          volume.delete!
        rescue
          puts "Could not delete volume #{volume.id}"
          puts $!.inspect
          puts $!.backtrace
        end
      end

      ec2.snapshots(:filter => {'status' => ['pending', 'completed']},
                  :tags => {'Name' => 'awsum.test'}).each do |snapshot|
        begin
          snapshot.delete
        rescue
          puts "Could not delete snapshot #{snapshot.id}"
          puts $!.inspect
          puts $!.backtrace
        end
      end
    end
  end
end

def run(description, &block)
  puts description
  yield
end

def wait_for(object, state = 'available')
  print "waiting for #{state} on #{object.class}(#{object.id}) "
  while (object.respond_to?(:state) ? object.state : object.status) != state
    sleep 1
    object.reload
    print '.'
  end
  puts
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
awsum-0.5.4 functional/spec_helper.rb
awsum-0.5.3 functional/spec_helper.rb
awsum-0.5.2 functional/spec_helper.rb
awsum-0.5.1 functional/spec_helper.rb