Sha256: efa667229d727bd1a1f2c19b35b40aa45283622d70a4ae38e2b2d8fd2293cd72

Contents?: true

Size: 1.41 KB

Versions: 24

Compression:

Stored size: 1.41 KB

Contents

class Brightbox
  module Compute
    module TestSupport
      # Find a suitable image for testing with
      # For speed of server building we're using an empty image
      #
      # Unless the tester has credentials this will fail so we rescue
      # any errors and return nil.
      #
      # This is used in the shared file +tests/compute/helper.rb+ so unfortunately
      # makes all tests reliant on hardcoded values and each other
      #
      # @return [String,NilClass] the most suitable test image's identifier or nil
      def self.image_id
        return @image_id unless @image_id.nil?
        image = select_testing_image_from_api
        @image_id = image["id"]
      rescue
        @image_id = nil
      end

      # Prepare a test server, wait for it to be usable but raise if it fails
      def self.get_test_server
        test_server_options = {:image_id => image_id}
        server = Fog::Compute[:brightbox].servers.create(test_server_options)
        server.wait_for {
          raise "Test server failed to build" if state == "failed"
          ready?
        }
        server
      end

      private
      def self.select_testing_image_from_api
        images = Fog::Compute[:brightbox].list_images
        raise "No available images!" if images.empty?
        images.select { |img| img["official"] && img["virtual_size"] != 0 }.sort_by { |img| img["disk_size"] }.first || images.first
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/tests/brightbox/requests/compute/helper.rb
fog-1.33.0 tests/brightbox/requests/compute/helper.rb
fog-1.32.0 tests/brightbox/requests/compute/helper.rb
fog-1.31.0 tests/brightbox/requests/compute/helper.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/tests/brightbox/requests/compute/helper.rb
fog-1.30.0 tests/brightbox/requests/compute/helper.rb
fog-1.29.0 tests/brightbox/requests/compute/helper.rb
fog-1.28.0 tests/brightbox/requests/compute/helper.rb
fog-1.27.0 tests/brightbox/requests/compute/helper.rb
fog-1.26.0 tests/brightbox/requests/compute/helper.rb
fog-1.25.0 tests/brightbox/requests/compute/helper.rb
nsidc-fog-1.24.1 tests/brightbox/requests/compute/helper.rb
fog-1.24.0 tests/brightbox/requests/compute/helper.rb
ns-fog-1.22.11 tests/brightbox/requests/compute/helper.rb
ns-fog-1.22.10 tests/brightbox/requests/compute/helper.rb
ns-fog-1.22.9 tests/brightbox/requests/compute/helper.rb
ns-fog-1.22.8 tests/brightbox/requests/compute/helper.rb
ns-fog-1.22.7 tests/brightbox/requests/compute/helper.rb
ns-fog-1.22.6 tests/brightbox/requests/compute/helper.rb
fog-1.23.0 tests/brightbox/requests/compute/helper.rb