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

  • run_remote_cmd_telnet

Defined Under Namespace

Classes: Config

Constant Summary collapse

@@id =
1

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

#check, #command, #expect, #expect2, #expect_any, #expect_none, #expect_one, #get, #gett, #goto, #log, #method_missing, #readme, #remote_tempdir, #remote_tempfile, #request, #run, #send, #set, #target, #tempdir, #tempfile, #unique, #unset, #weight

Constructor Details

#initialize(config) ⇒ Case

Returns a new instance of Case.



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

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

  @id = @@id
  @@id += 1

  # 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
  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



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

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

#export(format) ⇒ Object



73
74
75
76
# File 'lib/teuton/case_manager/case/case.rb', line 73

def export(format)
  return if skip?
  @report.export format
end

#filenameObject



78
79
80
# File 'lib/teuton/case_manager/case/case.rb', line 78

def filename
  @report.filename #+ '.' + @report.format.to_s
end

#gradeObject



82
83
84
85
# File 'lib/teuton/case_manager/case/case.rb', line 82

def grade
  return 0.0 if skip
  @report.tail[:grade]
end

#membersObject



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

def members
  return '-' if skip
  @report.head[:tt_members] || 'noname'
end

#package(param) ⇒ Object



7
8
9
10
11
# File 'lib/teuton/case_manager/case/builtin/main.rb', line 7

def package(param)
  @package = @package || Package.new(self)
  @package.param = param
  @package
end

#playObject Also known as: start



10
11
12
13
14
15
16
17
18
19
20
21
# 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
  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

#service(param) ⇒ Object



13
14
15
16
17
# File 'lib/teuton/case_manager/case/builtin/main.rb', line 13

def service(param)
  @service = @service || Service.new(self)
  @service.param = param
  @service
end

#showObject



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

def show
  @report.show
end

#skipObject Also known as: skip?



92
93
94
# File 'lib/teuton/case_manager/case/case.rb', line 92

def skip
  @skip
end

#user(param) ⇒ Object



19
20
21
22
23
# File 'lib/teuton/case_manager/case/builtin/main.rb', line 19

def user(param)
  @user = @user || User.new(self)
  @user.param = param
  @user
end