class Solano::BuildAgent
Constants
- MAXIMUM_ATTACHMENT_SIZE
Public Class Methods
# File lib/solano/agent/solano.rb, line 12 def initialize end
Public Instance Methods
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 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
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
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
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
@return Solano
environment (batch, interactive, etc.)
# File lib/solano/agent/solano.rb, line 37 def environment env = ENV['SOLANO_MODE'] || 'none' return env end
@return Current session ID
# File lib/solano/agent/solano.rb, line 27 def session_id return fetch_id('SESSION_ID') end
@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
@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
@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
# 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