Sha256: b761ef540a55b60b779c2e74486d394a5ba870f71d53e4c04b516c2dab0ef2ee

Contents?: true

Size: 1.89 KB

Versions: 41

Compression:

Stored size: 1.89 KB

Contents

##
# Helper mixin for tests (especially compute-based ones). Provide access to the
# client in use via the #client method to use.

module ClientHelper
  # Check to see if an compute operation is finished.
  #
  # @param op [Google::Apis::ComputeV1::Operation] the operation object returned from an api call
  # @return [Bolean] true if the operation is no longer executing, false
  #   otherwise
  def operation_finished?(op)
    region = op.region
    zone = op.zone
    name = op.name

    if zone.nil?
      result = client.get_region_operation(region, name)
    else
      result = client.get_zone_operation(zone, name)
    end
    !%w(PENDING RUNNING).include?(result.status)
  end

  # Check to see if an SQL operation is finished.
  #
  # @param op [Google::Apis::SqladminV1beta4::Operation] the operation object
  #   returned from an SQL Admin api call
  # @return [Boolean] true if the operation is no longer executing, false
  #   otherwise
  def sql_operation_finished?(op)
    result = client.get_operation(op.name)
    !%w(PENDING RUNNING).include?(result.status)
  end

  # Pause execution until an operation (compute or sql) returned
  # from a passed block is finished.
  #
  # @example Pause until server is provisioned
  #   @result = wait_until_complete { client.insert_server(name, zone, opts) }
  # @yieldreturn The resulting operation object from a block.
  # @return the result of the operation

  def wait_until_complete
    result = yield

    case result.kind
    when "compute#operation"
      region = result.region
      zone = result.zone
      Fog.wait_for { operation_finished?(result) }
      if zone.nil?
        client.get_region_operation(region, result.name)
      else
        client.get_zone_operation(zone, result.name)
      end
    when "sql#operation"
      Fog.wait_for { sql_operation_finished?(result) }
      client.get_operation(result.name)
    else
      result
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
fog-google-1.24.1 test/helpers/client_helper.rb
fog-google-1.24.0 test/helpers/client_helper.rb
fog-google-1.23.0 test/helpers/client_helper.rb
fog-google-1.22.0 test/helpers/client_helper.rb
fog-google-1.21.1 test/helpers/client_helper.rb
fog-google-1.21.0 test/helpers/client_helper.rb
fog-google-1.20.0 test/helpers/client_helper.rb
fog-google-1.19.0 test/helpers/client_helper.rb
fog-google-1.18.0 test/helpers/client_helper.rb
fog-google-1.17.0 test/helpers/client_helper.rb
fog-google-1.16.1 test/helpers/client_helper.rb
fog-google-1.16.0 test/helpers/client_helper.rb
fog-google-1.15.0 test/helpers/client_helper.rb
fog-google-1.14.0 test/helpers/client_helper.rb
gitlab-fog-google-1.14.0 test/helpers/client_helper.rb
fog-google-1.13.0 test/helpers/client_helper.rb
gitlab-fog-google-1.13.0 test/helpers/client_helper.rb
fog-google-1.12.1 test/helpers/client_helper.rb
fog-google-1.12.0 test/helpers/client_helper.rb
fog-google-1.11.0 test/helpers/client_helper.rb