Class: Case

Inherits:
Object
  • Object
show all
Includes:
DSL, Utils
Defined in:
lib/teuton/case_manager/case/case.rb,
lib/teuton/case_manager/case/play.rb,
lib/teuton/case_manager/case/close.rb,
lib/teuton/case_manager/case/config.rb,
lib/teuton/case_manager/case/runner.rb,
lib/teuton/case_manager/case/builtin/main.rb

Overview

Class Case::Config

  • get

  • set

  • unset

  • missing_method

Defined Under Namespace

Classes: Config

Constant Summary collapse

@@id =

First case ID value

"01"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#encode_and_split, #ensure_dir, #my_execute, #verbose, #verboseln

Methods included from DSL

#expect, #expect2, #expect_any, #expect_first, #expect_last, #expect_none, #expect_one, #get, #gett, #goto, #log, #macro, #method_missing, #readme, #remote_tempdir, #remote_tempfile, #respond_to_missing?, #run, #send, #set, #target, #tempdir, #tempfile, #unique, #unset, #weight

Constructor Details

#initialize(config) ⇒ Case

Initialize case from specified config

Parameters:

  • config (Hash)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/teuton/case_manager/case/case.rb', line 35

def initialize(config)
  app = Application.instance
  @config = Case::Config.new(local: config, global: app.global)
  @groups = app.groups

  @id = @@id
  @@id = @@id.next

  # Define Case Report
  @report = Report.new(@id)
  @report.output_dir = File.join("var", @config.global[:tt_testname])
  ensure_dir @report.output_dir

  # Default configuration
  @skip = false
  @skip = get(:tt_skip) unless get(:tt_skip) == "NODATA"
  unless app.options["case"].nil?
    @skip = true
    @skip = false if app.options["case"].include? @id.to_i
  end

  @conn_status = {}
  @tmpdir = File.join("var", @config.get(:tt_testname), "tmp", @id.to_s)
  # ensure_dir @tmpdir # REVISE: When we will need this? Samba?
  @remote_tmpdir = File.join("/", "tmp")

  @unique_values = {}
  @result = Result.new

  @debug = Application.instance.debug
  @verbose = Application.instance.verbose

  @action_counter = 0
  @action = {
    id: 0,
    weight: 1.0,
    description: "No description!",
    groupname: nil
  }
  @uniques = []
  @sessions = {} # Store opened sessions for this case
  tempfile :default
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DSL

Instance Attribute Details

#actionObject

TODO: why not reader only???



27
28
29
# File 'lib/teuton/case_manager/case/case.rb', line 27

def action
  @action
end

#configObject (readonly)

Returns the value of attribute config.



28
29
30
# File 'lib/teuton/case_manager/case/case.rb', line 28

def config
  @config
end

#conn_statusObject (readonly)

Returns the value of attribute conn_status.



28
29
30
# File 'lib/teuton/case_manager/case/case.rb', line 28

def conn_status
  @conn_status
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/teuton/case_manager/case/case.rb', line 28

def id
  @id
end

#resultObject

Returns the value of attribute result.



26
27
28
# File 'lib/teuton/case_manager/case/case.rb', line 26

def result
  @result
end

#skipObject (readonly) Also known as: skip?

Returns the value of attribute skip.



29
30
31
# File 'lib/teuton/case_manager/case/case.rb', line 29

def skip
  @skip
end

#uniquesObject (readonly)

Returns the value of attribute uniques.



28
29
30
# File 'lib/teuton/case_manager/case/case.rb', line 28

def uniques
  @uniques
end

Instance Method Details

#close(uniques) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/teuton/case_manager/case/close.rb', line 4

def close(uniques)
  fails = 0
  @uniques.each do |key|
    next unless uniques[key].include?(id) && uniques[key].count > 1

    fails += 1
    log_unique_message(key, uniques[key])
  end
  @report.tail[:unique_fault] = fails
  @report.close
end

#close_opened_sessionsObject



27
28
29
30
31
# File 'lib/teuton/case_manager/case/play.rb', line 27

def close_opened_sessions
  @sessions.each_value do |s|
    s.close if s.instance_of? Net::SSH::Connection::Session
  end
end

#export(format) ⇒ Object



79
80
81
82
83
# File 'lib/teuton/case_manager/case/case.rb', line 79

def export(format)
  return if skip?

  @report.export format
end

#filenameObject



85
86
87
# File 'lib/teuton/case_manager/case/case.rb', line 85

def filename
  @report.filename
end

#gradeObject



89
90
91
92
93
# File 'lib/teuton/case_manager/case/case.rb', line 89

def grade
  return 0.0 if skip

  @report.tail[:grade]
end

#host(host = "localhost") ⇒ Object



4
5
6
# File 'lib/teuton/case_manager/case/builtin/main.rb', line 4

def host(host = "localhost")
  TeutonHost.new(self, host)
end

#membersObject



95
96
97
98
99
# File 'lib/teuton/case_manager/case/case.rb', line 95

def members
  return "-" if skip

  @report.head[:tt_members] || "noname"
end

#playObject Also known as: start



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/teuton/case_manager/case/play.rb', line 10

def play
  if skip?
    verbose "Skipping case <#{@config.get(:tt_members)}>\n"
    return false
  end
  # TODO: Delete old reports???
  start_time = Time.now
  if get(:tt_sequence) == true
    play_in_sequence
  else
    play_in_parallel
  end
  fill_report(start_time, Time.now)
  close_opened_sessions
end

#showObject



103
104
105
# File 'lib/teuton/case_manager/case/case.rb', line 103

def show
  @report.show
end