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

  • run_local_cmd

  • run_remote_cmd

  • run_remote_cmd_ssh

  • reconfigure_command_with_gateway

  • run_remote_cmd_telnet

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_none, #expect_one, #get, #gett, #goto, #log, #macro, #method_missing, #readme, #remote_tempdir, #remote_tempfile, #run, #send, #set, #target, #tempdir, #tempfile, #unique, #unset, #weight

Constructor Details

#initialize(config) ⇒ Case

Initialize case from specified config

Parameters:

  • config (Hash)


34
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
# File 'lib/teuton/case_manager/case/case.rb', line 34

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

#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



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

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

Close opened sessions for this case



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

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

#export(format) ⇒ Object

Export Case with specific output format

Parameters:

  • format (Symbol)


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

Return case report filename

Returns:

  • String



88
89
90
# File 'lib/teuton/case_manager/case/case.rb', line 88

def filename
  @report.filename
end

#gradeObject

Return case grade

Returns:

  • grade



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

def grade
  return 0.0 if skip

  @report.tail[:grade]
end

#host(host = 'localhost') ⇒ Object



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

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

#membersObject

Return case members

Returns:

  • members



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

def members
  return '-' if skip

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

#playObject Also known as: start

Execute “play” order on this case



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

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

#showObject

Show case report data on screen



119
120
121
# File 'lib/teuton/case_manager/case/case.rb', line 119

def show
  @report.show
end

#skipObject Also known as: skip?

Return case skip value

Returns:

  • skip



112
113
114
# File 'lib/teuton/case_manager/case/case.rb', line 112

def skip
  @skip
end