class Solano::BuildAgent

Constants

MAXIMUM_ATTACHMENT_SIZE

Public Class Methods

new() click to toggle source
# File lib/solano/agent/solano.rb, line 12
def initialize
end

Public Instance Methods

attach(data, metadata) click to toggle source

Attach a blob to the session – excessive storage use is billable @param data blob that is convertible into a string @param metadata hash of metadata options @note See attach_file for description of options

# File lib/solano/agent/solano.rb, line 67
def attach(data, metadata)
  if data.size > MAXIMUM_ATTACHMENT_SIZE then
    raise SolanoError.new("Data are too large to attach to session")
  end

  if !metadata.member?(:name) then
    guid = SecureRandom.hex(4)
    metadata[:name] = "user.#{guid}.dat"
  end

  guid = SecureRandom.hex(8)
  temp_path = File.join(ENV['HOME'], 'tmp', "attach-#{guid}.dat")
  File.open(temp_path, File::CREAT|File::TRUNC|File::RDWR, 0600) do |file|
    file.write(data)
    attach_file(temp_path, metadata)
  end
end
attach_file(path, metadata={}) click to toggle source

Attach a blob to the session – excessive storage use is billable @param data blob that is convertible into a string @param [Hash] metadata hash of metadata options @option metadata [String] :name Override name of attachment @option metadata [String] :exec_id Attach to named test execution

# File lib/solano/agent/solano.rb, line 90
def attach_file(path, metadata={})
  if !File.exists?(path) then
    raise Errno::ENOENT.new(path)
  end
  if File.size(path) > MAXIMUM_ATTACHMENT_SIZE then
    raise SolanoError.new("Data are too large to attach to session")
  end
  name = metadata[:name] || File.basename(path)
  attach_path = attachment_path(name, metadata[:exec_id])
  FileUtils.cp(path, attach_path)
end
attachment_path(name, exec_id=nil) click to toggle source

FUTURE: convert to call to internal agent API server Unregistered and authenticated files will be ignored

# File lib/solano/agent/solano.rb, line 104
def attachment_path(name, exec_id=nil)
  path = File.join(ENV['HOME'], 'results', session_id.to_s)
  if exec_id.nil? then
    path = File.join(path, 'session', name)
  else
    path = File.join(path, exec_id.to_s, name)
  end
  return path
end
build_status(which=:current) click to toggle source

Status of build @param which :current or :last @return 'passed', 'failed', 'error', or 'unknown'

# File lib/solano/agent/solano.rb, line 45
def build_status(which=:current)
  status = 'unknown'
  case which
  when :current
    status = ENV['SOLANO_BUILD_STATUS']
  when :last
    status = ENV['SOLANO_LAST_BUILD_STATUS']
  end
  status ||= 'unknown'
  return status
end
current_branch() click to toggle source

BOTCH: must be SCM agnostic

# File lib/solano/agent/solano.rb, line 58
def current_branch
  cmd = "cd #{ENV['SOLANO_REPO_ROOT']} && git symbolic-ref HEAD"
  `#{cmd}`.gsub("\n", "").split("/")[2..-1].join("/")
end
environment() click to toggle source

@return Solano environment (batch, interactive, etc.)

# File lib/solano/agent/solano.rb, line 37
def environment
  env = ENV['SOLANO_MODE'] || 'none'
  return env
end
session_id() click to toggle source

@return Current session ID

# File lib/solano/agent/solano.rb, line 27
def session_id
  return fetch_id('SESSION_ID')
end
solano?() click to toggle source

@return Boolean indicating whether or not we are running inside Solano

# File lib/solano/agent/solano.rb, line 16
def solano?
  return ENV.member?('SOLANO') || ENV.member?('TDDIUM')
end
test_exec_id() click to toggle source

@return Per-execution unique ID of currently running test

# File lib/solano/agent/solano.rb, line 32
def test_exec_id
  return fetch_id('TEST_EXEC_ID')
end
thread_id() click to toggle source

@return The current worker thread ID @note Id is not unique across workers; there is no accessible GUID

# File lib/solano/agent/solano.rb, line 22
def thread_id
  return fetch_id('TID')
end

Protected Instance Methods

fetch_id(name) click to toggle source
# File lib/solano/agent/solano.rb, line 116
def fetch_id(name)
  return nil unless solano?
  %w(TDDIUM SOLANO).each do |prefix|
    qualified_name = "#{prefix}_#{name}"
    if ENV.member?(qualified_name) then
      id = ENV[qualified_name]
      return id.to_i
    end
  end
  return nil
end