Class: Tddium::BuildAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/tddium/agent/tddium.rb

Constant Summary collapse

MAXIMUM_ATTACHMENT_SIZE =
16*1024*1024

Instance Method Summary collapse

Constructor Details

#initializeBuildAgent

Returns a new instance of BuildAgent.



12
13
# File 'lib/tddium/agent/tddium.rb', line 12

def initialize
end

Instance Method Details

#attach(data, metadata) ⇒ Object

Note:

See attach_file for description of options

Attach a blob to the session – excessive storage use is billable

Parameters:

  • data

    blob that is convertible into a string

  • metadata

    hash of metadata options



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/tddium/agent/tddium.rb', line 67

def attach(data, )
  if data.size > MAXIMUM_ATTACHMENT_SIZE then
    raise TddiumError.new("Data are too large to attach to session")
  end

  if !.member?(:name) then
    guid = SecureRandom.hex(4)
    [: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, )
  end
end

#attach_file(path, metadata = {}) ⇒ Object

Attach a blob to the session – excessive storage use is billable

Parameters:

  • data

    blob that is convertible into a string

  • metadata (Hash) (defaults to: {})

    hash of metadata options

Options Hash (metadata):

  • :name (String)

    Override name of attachment

  • :exec_id (String)

    Attach to named test execution



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/tddium/agent/tddium.rb', line 90

def attach_file(path, ={})
  if !File.exists?(path) then
    raise Errno::ENOENT.new(path)
  end
  if File.size(path) > MAXIMUM_ATTACHMENT_SIZE then
    raise TddiumError.new("Data are too large to attach to session")
  end
  name = [:name] || File.basename(path)
  attach_path = attachment_path(name, [:exec_id])
  FileUtils.cp(path, attach_path)
end

#attachment_path(name, exec_id = nil) ⇒ Object

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



104
105
106
107
108
109
110
111
112
# File 'lib/tddium/agent/tddium.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) ⇒ Object

Status of build

Parameters:

  • which (defaults to: :current)

    :current or :last



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tddium/agent/tddium.rb', line 45

def build_status(which=:current)
  status = 'unknown'
  case which
  when :current
    status = ENV['TDDIUM_BUILD_STATUS']
  when :last
    status = ENV['TDDIUM_LAST_BUILD_STATUS']
  end
  status ||= 'unknown'
  return status
end

#current_branchObject

BOTCH: must be SCM agnostic



58
59
60
61
# File 'lib/tddium/agent/tddium.rb', line 58

def current_branch
  cmd = "cd #{ENV['TDDIUM_REPO_ROOT']} && git symbolic-ref HEAD"
  `#{cmd}`.gsub("\n", "").split("/")[2..-1].join("/")
end

#environmentObject

Returns Tddium environment (batch, interactive, etc.).

Returns:

  • Tddium environment (batch, interactive, etc.)



37
38
39
40
# File 'lib/tddium/agent/tddium.rb', line 37

def environment
  env = ENV['TDDIUM_MODE'] || 'none'
  return env
end

#session_idObject

Returns Current session ID.

Returns:

  • Current session ID



27
28
29
# File 'lib/tddium/agent/tddium.rb', line 27

def session_id
  return fetch_id('TDDIUM_SESSION_ID')
end

#tddium?Boolean

Returns Boolean indicating whether or not we are running inside Tddium.

Returns:

  • (Boolean)

    Boolean indicating whether or not we are running inside Tddium



16
17
18
# File 'lib/tddium/agent/tddium.rb', line 16

def tddium?
  return ENV.member?('TDDIUM')
end

#test_exec_idObject

Returns Per-execution unique ID of currently running test.

Returns:

  • Per-execution unique ID of currently running test



32
33
34
# File 'lib/tddium/agent/tddium.rb', line 32

def test_exec_id
  return fetch_id('TDDIUM_TEST_EXEC_ID')
end

#thread_idObject

Note:

Id is not unique across workers; there is no accessible GUID

Returns The current worker thread ID.

Returns:

  • The current worker thread ID



22
23
24
# File 'lib/tddium/agent/tddium.rb', line 22

def thread_id
  return fetch_id('TDDIUM_TID')
end