teuton 2.6.0 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/docs/changelog/todo.md +4 -8
  3. data/docs/changelog/v2.7.md +11 -0
  4. data/docs/diagram.md +16 -15
  5. data/docs/learn/06-cmd_check.md +3 -2
  6. data/docs/learn/21-exit_codes.md +19 -14
  7. data/lib/teuton/case/case.rb +25 -44
  8. data/lib/teuton/case/close.rb +2 -0
  9. data/lib/teuton/case/config.rb +3 -3
  10. data/lib/teuton/case/{runner.rb → deprecated/runner.rb} +14 -10
  11. data/lib/teuton/case/deprecated/utils.rb +40 -0
  12. data/lib/teuton/case/dsl/all.rb +8 -0
  13. data/lib/teuton/case/dsl/expect.rb +25 -9
  14. data/lib/teuton/case/dsl/goto.rb +10 -9
  15. data/lib/teuton/case/dsl/log.rb +1 -2
  16. data/lib/teuton/case/dsl/macro.rb +2 -2
  17. data/lib/teuton/case/dsl/send.rb +3 -8
  18. data/lib/teuton/case/execute/copy_ssh.rb +70 -0
  19. data/lib/teuton/case/execute/execute_base.rb +55 -0
  20. data/lib/teuton/case/execute/execute_local.rb +29 -0
  21. data/lib/teuton/case/execute/execute_manager.rb +56 -0
  22. data/lib/teuton/case/execute/execute_ssh.rb +90 -0
  23. data/lib/teuton/case/execute/execute_telnet.rb +56 -0
  24. data/lib/teuton/case/play.rb +6 -6
  25. data/lib/teuton/case_manager/case_manager.rb +12 -8
  26. data/lib/teuton/case_manager/check_cases.rb +14 -12
  27. data/lib/teuton/case_manager/dsl.rb +6 -8
  28. data/lib/teuton/case_manager/export_manager.rb +2 -3
  29. data/lib/teuton/case_manager/hall_of_fame.rb +9 -10
  30. data/lib/teuton/case_manager/report.rb +11 -9
  31. data/lib/teuton/case_manager/show_report.rb +5 -7
  32. data/lib/teuton/case_manager/utils.rb +2 -48
  33. data/lib/teuton/check/dsl.rb +1 -2
  34. data/lib/teuton/check/laboratory.rb +7 -7
  35. data/lib/teuton/check/show.rb +5 -8
  36. data/lib/teuton/cli.rb +10 -0
  37. data/lib/teuton/readme/dsl.rb +5 -7
  38. data/lib/teuton/readme/lang.rb +3 -2
  39. data/lib/teuton/readme/readme.rb +15 -18
  40. data/lib/teuton/report/formatter/default/array.rb +6 -5
  41. data/lib/teuton/report/formatter/default/txt.rb +1 -0
  42. data/lib/teuton/report/formatter/formatter.rb +1 -1
  43. data/lib/teuton/report/formatter/resume/array.rb +3 -3
  44. data/lib/teuton/report/formatter/resume/html.rb +2 -2
  45. data/lib/teuton/report/report.rb +6 -5
  46. data/lib/teuton/skeleton.rb +8 -10
  47. data/lib/teuton/{application.rb → utils/application.rb} +13 -5
  48. data/lib/teuton/utils/name_file_finder.rb +40 -45
  49. data/lib/teuton/utils/project.rb +73 -0
  50. data/lib/teuton/{result → utils/result}/result.rb +9 -7
  51. data/lib/teuton/utils/settings.rb +12 -0
  52. data/lib/teuton/utils/verbose.rb +2 -2
  53. data/lib/teuton/version.rb +1 -1
  54. data/lib/teuton.rb +19 -18
  55. metadata +20 -9
  56. data/lib/teuton/case/dsl.rb +0 -10
  57. /data/lib/teuton/{result → utils/result}/ext_array.rb +0 -0
  58. /data/lib/teuton/{result → utils/result}/ext_compare.rb +0 -0
  59. /data/lib/teuton/{result → utils/result}/ext_filter.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d4dba357b30b42efc7a32e8389bd6c7dfa98e835f46907d2f4a3dbe7e5942e8
4
- data.tar.gz: 0bb5add96b17f02f791568d02e2fc8ca698cc9138c9e25e9075d2e686fb6ba88
3
+ metadata.gz: ffeca52de938d3464c4c9f4bacf4acb7fd229cc3a02daa9d653d68dfe2d65750
4
+ data.tar.gz: 96a03b03bba6ff9ca381ce1b248f93f341b9aa53c2727258032e6a8d24d42454
5
5
  SHA512:
6
- metadata.gz: 694a956fde1cb64e76d78bf4513df7f011001654aef7d305c9ac54ea0df6748b945d8b0b69514c7172c2e56404093824dd59636f54e647b33d0b068d9d3ef5eb
7
- data.tar.gz: 4a8d0fa96fdc396d2da7cd129b1458525abe0d6acb15944f965a3facc692980cd76c33d2321a4997a5e03e3af087eea020054ff308b62d37a9b848778d6c8b79
6
+ metadata.gz: 8ef9650f56b556eaa91c81c04a07c0e621f9903416333a8b12ea8febb6a07e91cddeaabe80a17d9d82fdaaac337cba2af9e6aa7bc881c3801fee8f90a5ed636c
7
+ data.tar.gz: a2003337f9a7ae148b0976cdd87cd0ef1fdb255a18bec08a390adec32c94f7c13a71db9bfa83452fed93259e8d5a53db34e5bfec265831a0d3237390be2de6de
@@ -1,20 +1,16 @@
1
1
 
2
-
3
2
  ## TO-DO
4
3
 
5
4
  New features:
6
- - Parse new input format, and detect parse errors
7
- - Teuton readme --lang=es
8
- - Export files with other langs
9
- - Snode Dockerfile
5
+ - Teuton readme --lang=es and export files with other langs
6
+ - Snode Dockerfile with SSH server
7
+ - Auto Parse new input format, and detect parse errors
10
8
 
11
9
  Revise:
12
10
  * verify get(:key) and get('key') works fine!
13
- * Formatter: xml,
11
+ * Formatter: xml
14
12
 
15
13
  Internal changes:
16
- * Application to Settings
17
14
  * Laboratory to Checker
18
15
  * Unify messages ERROR, INFO, WARN. etc
19
- * Create SendManager as ExportManager?
20
16
  * Add tt_label as alias of tt_members
@@ -0,0 +1,11 @@
1
+
2
+ ## [2.7.0]
3
+
4
+ New features:
5
+ - [ADD] "teuton config PROJECTPATH" will suggest suitable configuration for the project.
6
+ - [ADD] Every one line command output is registered into reports.
7
+ - [ADD] "expect_exit 1", check last command exit code is equal to 1.
8
+
9
+ Internal changes:
10
+ * Application class splited into Settings and Project classes
11
+ * Create SendManager similar to ExportManager
data/docs/diagram.md CHANGED
@@ -13,42 +13,43 @@ subgraph "create\nnew\nproject"
13
13
  Teuton -- create --> Skeleton("Sekeleton\nFiles")
14
14
  end
15
15
 
16
- subgraph "check\nproject files"
16
+ subgraph "Check\nproject files"
17
17
  Teuton -- check --> Laboratory("Laboratory\nDSL\nShow\nBuiltin!")
18
18
  end
19
19
 
20
- subgraph "create readme\nfrom project"
20
+ subgraph "Create readme\nfrom project"
21
21
  Teuton -- readme --> Readme("Readme\nDSL\nLang!")
22
22
  end
23
23
 
24
24
  subgraph manager
25
- Teuton -- require --> manager/DSL
25
+ Teuton -- run --> manager/DSL
26
26
  manager/DSL -- play --> CaseManager("CaseManager\ncheck_cases\nExportManager\nSendManager\nShowReport")
27
27
  ReportManager --> HallOfFame
28
28
  end
29
29
 
30
+ subgraph "case folder"
31
+ CaseManager --> Case("Case\nConfig\nClose\nPlay\nRunner\ncase/DSL\ncase/builtin!")
32
+ end
33
+
30
34
  subgraph utils
31
- manager/DSL -- use/macros/groups --> Application("Application\nNameFileFinder")
35
+ Verbose
36
+
32
37
  Readme --> ConfigFileReader
33
38
  Laboratory --> ConfigFileReader
34
39
  CaseManager --> ConfigFileReader
35
- Verbose
36
- end
37
-
38
- subgraph "case folder"
39
- CaseManager --> Case("Case\nConfig\nClose\nPlay\nRunner")
40
- Case --> case/DSL
41
- end
42
40
 
43
- subgraph "result class"
44
41
  Laboratory --> Result
45
42
  Readme --> Result("Result\next_array\next_compare\next_filter")
46
43
  Case --> Result
44
+
45
+ Laboratory --> Application
46
+ Readme --> Application
47
+ manager/DSL -- use/macros/groups --> Application("Application\nNameFileFinder")
48
+ Case --> Application
47
49
  end
48
50
 
49
51
  subgraph report
50
- CaseManager --> Report
51
- Report --> Formatter
52
- Formatter --> files/template
52
+ CaseManager --> Report("Report\nFormatter\nfiles/template")
53
+ Case --> Report
53
54
  end
54
55
  ```
@@ -3,10 +3,10 @@
3
3
 
4
4
  # check test
5
5
 
6
- Check Teuton test syntax and show statistics.
6
+ Check Teuton check syntax and show statistics.
7
7
 
8
8
  ```
9
- ❯ teuton check examples/05-use
9
+ ❯ teuton check examples/05-use
10
10
 
11
11
  +--------------------------+
12
12
  | GROUP: Using file: users |
@@ -32,6 +32,7 @@ Check Teuton test syntax and show statistics.
32
32
  +-------------+-------+
33
33
  | DSL Stats | Count |
34
34
  +-------------+-------+
35
+ | Uses | 2 |
35
36
  | Groups | 2 |
36
37
  | Targets | 3 |
37
38
  | Runs | 3 |
@@ -1,24 +1,29 @@
1
1
  [<< back](README.md)
2
2
 
3
- # Example: 16-exit_codes
3
+ # Example: exit_codes
4
4
 
5
- _I am sorry! We have not solved the problem of getting the exit code of the commands so that it works for any platform. But we can help you do this work._
5
+ `result` stores information from the last command executed by a "run" action. [Offers many functions](../dsl/definition/result.md)) that transforms output data, and also exitcode is captured.
6
6
 
7
- `result` stores information from the last command executed by a "run" action. [Offers many functions](../dsl/definition/result.md)) that transforms output data, but also we have been added tow more: first and last.
7
+ ## Example
8
8
 
9
- ## Description
10
-
11
- Take a look at this section:
12
9
  ```ruby
13
- target "Exist user root"
14
- run "id root;echo $?"
15
- expect_last "0"
10
+ target "Exist user root (exit code ok)"
11
+ run "id root"
12
+ expect_exit 0
13
+
14
+ target "No user vader (exit code fail)"
15
+ run "id vader"
16
+ expect_exit 1
16
17
  ```
17
18
 
18
- It is posible to invoke the execution of several commands in sequence "cmd1;cmd2". Keep in mind that the last one must show the exit code. In the case of GNU/Linux is "echo $?", but it is different on others OOSS.
19
+ ## More examples
19
20
 
20
- All terminal output generated by `run` action is captured (Use `result.debug` to show result content into screen), and as we need only the last line, we use `expect_last "0"`.
21
+ ```ruby
22
+ target "Using a range"
23
+ run "id vader"
24
+ expect_exit 1..3
21
25
 
22
- > More information about:
23
- > * [expect](../dsl/definition/expect.md) keyword.
24
- > * [result](../dsl/execution/result.md) keyword.
26
+ target "Using a list"
27
+ run "id vader"
28
+ expect_exit [1, 3, 7]
29
+ ```
@@ -1,67 +1,60 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../application"
3
+ require_relative "../utils/project"
4
+ require_relative "../utils/verbose"
5
+ require_relative "../utils/result/result"
4
6
  require_relative "../report/report"
5
- require_relative "../case_manager/utils"
6
- require_relative "../result/result"
7
- require_relative "dsl"
7
+ require_relative "dsl/all"
8
8
  require_relative "config"
9
9
  require_relative "close"
10
10
  require_relative "play"
11
- require_relative "runner"
12
11
  require_relative "builtin/main"
13
12
 
14
- # Case class
15
- # * initialize
16
- # * export
17
- # * filename
18
- # * grade
19
- # * members
20
- # * skip
21
- # * read_filename ???
22
13
  class Case
14
+ # Case: export, filename, grade, members,skip
23
15
  include DSL
24
- include Utils
16
+ include Verbose
25
17
 
26
- attr_accessor :result
27
- attr_accessor :action # TODO: why not reader only???
28
- attr_reader :id, :config, :uniques, :conn_status
18
+ attr_accessor :action # Updated by ExecuteManager
19
+ attr_accessor :result # Updated by ExecuteManager
20
+ attr_accessor :sessions # Updated by ExecuteManager
21
+ attr_accessor :conn_status # Updated by ExecuteManager
22
+
23
+ attr_reader :id
24
+ attr_reader :config # Readed by ExecuteManager
25
+ attr_reader :uniques
29
26
  attr_reader :skip
30
27
  @@id = "01" # First case ID value
31
28
 
32
29
  def initialize(config)
33
- app = Application.instance
34
- @config = Case::Config.new(local: config, global: app.global)
35
- @groups = app.groups
30
+ @config = Case::Config.new(
31
+ local: config,
32
+ global: Project.value[:global]
33
+ )
34
+ @groups = Project.value[:groups]
36
35
 
37
36
  @id = @@id
38
37
  @@id = @@id.next
39
38
 
40
39
  # Define Case Report
41
40
  @report = Report.new(@id)
42
- # TODO: Move folder creation from case to parent classes?
43
41
  @report.output_dir = File.join("var", @config.global[:tt_testname])
44
- ensure_dir @report.output_dir
45
42
 
46
43
  # Default configuration
47
44
  @skip = false
48
45
  @skip = get(:tt_skip) unless get(:tt_skip) == "NODATA"
49
- unless app.options["case"].nil?
46
+ unless Project.value[:options]["case"].nil?
50
47
  @skip = true
51
- @skip = false if app.options["case"].include? @id.to_i
48
+ @skip = false if Project.value[:options]["case"].include? @id.to_i
52
49
  end
50
+ @debug = Project.debug?
51
+ @verbose = Project.value[:verbose]
53
52
 
54
- @conn_status = {}
55
53
  @tmpdir = File.join("var", @config.get(:tt_testname), "tmp", @id.to_s)
56
54
  # ensure_dir @tmpdir # REVISE: When we will need this? Samba?
57
- @remote_tmpdir = File.join("/", "tmp")
58
55
 
59
56
  @unique_values = {}
60
57
  @result = Result.new
61
-
62
- @debug = Application.instance.debug
63
- @verbose = Application.instance.verbose
64
-
65
58
  @action_counter = 0
66
59
  @action = {
67
60
  id: 0,
@@ -71,6 +64,7 @@ class Case
71
64
  }
72
65
  @uniques = []
73
66
  @sessions = {} # Store opened sessions for this case
67
+ @conn_status = {}
74
68
  tempfile :default
75
69
  end
76
70
 
@@ -81,6 +75,7 @@ class Case
81
75
  end
82
76
 
83
77
  def filename
78
+ # called from: close_main_report
84
79
  @report.filename
85
80
  end
86
81
 
@@ -97,18 +92,4 @@ class Case
97
92
  end
98
93
 
99
94
  alias_method :skip?, :skip
100
-
101
- private
102
-
103
- def read_filename(filename)
104
- begin
105
- file = File.open(filename, "r")
106
- item = file.readlines
107
- file.close
108
- item.map! { |i| i.sub(/\n/, "") }
109
- rescue
110
- item = []
111
- end
112
- item
113
- end
114
95
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  class Case
4
4
  def close(uniques)
5
+ # Invoked from check_cases!
6
+
5
7
  fails = 0
6
8
  @uniques.each do |key|
7
9
  next unless uniques[key].include?(id) && uniques[key].count > 1
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../application"
3
+ require_relative "../utils/project"
4
4
 
5
5
  # Class Case::Config
6
6
  # * get
@@ -13,8 +13,8 @@ class Case
13
13
  attr_reader :ialias, :global, :local, :running
14
14
 
15
15
  def initialize(args)
16
- @ialias = args[:alias] || Application.instance.ialias.clone
17
- @global = args[:global] || Application.instance.global.clone
16
+ @ialias = args[:alias] || Project.value[:ialias].clone
17
+ @global = args[:global] || Project.value[:global].clone
18
18
  @local = args[:local] || {}
19
19
  @running = {}
20
20
 
@@ -6,6 +6,8 @@ require_relative "dsl/log"
6
6
  class Case
7
7
  private
8
8
 
9
+ # READ: @config
10
+ # WRITE: @action, @result, @session
9
11
  def run_cmd_on(host)
10
12
  protocol = @config.get("#{host}_protocol".to_sym)
11
13
  ip = @config.get("#{host}_ip".to_sym)
@@ -30,15 +32,13 @@ class Case
30
32
 
31
33
  def run_cmd_localhost
32
34
  @action[:conn_type] = :local
33
- i = my_execute(@action[:command], @action[:encoding])
34
- @result.exitstatus = i[:exitstatus]
35
- @result.content = i[:content]
35
+ resp = my_execute(@action[:command], @action[:encoding])
36
+ @result.exitcode = resp[:exitcode]
37
+ @result.content = resp[:content]
36
38
  end
37
39
 
38
- ##
39
- # Run remote command
40
- # @param input_hostname (Symbol or String)
41
40
  def run_cmd_remote(input_hostname)
41
+ # @param input_hostname (Symbol or String)
42
42
  hostname = input_hostname.to_s
43
43
  i = (hostname + "_protocol").to_sym
44
44
  protocol = @config.get(i) if @config.get(i)
@@ -86,6 +86,7 @@ class Case
86
86
  end
87
87
 
88
88
  text = ""
89
+ exitcode = 0
89
90
  begin
90
91
  if @sessions[hostname].nil?
91
92
  @sessions[hostname] = Net::SSH.start(
@@ -100,23 +101,24 @@ class Case
100
101
  end
101
102
  text = if @sessions[hostname].instance_of? Net::SSH::Connection::Session
102
103
  @sessions[hostname].exec!(@action[:command])
103
- # ssh.exec!("ls -l /home/jamis") do |channel, stream, data|
104
- # stdout << data if stream == :stdout
105
- # end
106
104
  else
107
105
  "SSH: NO CONNECTION!"
108
106
  end
107
+ exitcode = text.exitstatus
109
108
  rescue Errno::EHOSTUNREACH
110
109
  @sessions[hostname] = :nosession
111
110
  @conn_status[hostname] = :host_unreachable
111
+ exitcode = -1
112
112
  log("Host #{ip} unreachable!", :error)
113
113
  rescue Net::SSH::AuthenticationFailed
114
114
  @sessions[hostname] = :nosession
115
115
  @conn_status[hostname] = :error_authentication_failed
116
+ exitcode = -1
116
117
  log("SSH::AuthenticationFailed!", :error)
117
118
  rescue Net::SSH::HostKeyMismatch
118
119
  @sessions[hostname] = :nosession
119
120
  @conn_status[hostname] = :host_key_mismatch
121
+ exitcode = -1
120
122
  log("SSH::HostKeyMismatch!", :error)
121
123
  log("* The destination server's fingerprint is not matching " \
122
124
  "what is in your local known_hosts file.", :error)
@@ -126,11 +128,12 @@ class Case
126
128
  rescue => e
127
129
  @sessions[hostname] = :nosession
128
130
  @conn_status[hostname] = :error
131
+ exitcode = -1
129
132
  log("[#{e.class}] SSH on <#{username}@#{ip}>" \
130
133
  " exec: #{@action[:command]}", :error)
131
134
  end
132
135
  output = encode_and_split(@action[:encoding], text)
133
- # revise: @result.exitstatus = text.exitstatus
136
+ @result.exitcode = exitcode
134
137
  @result.content = output
135
138
  @result.content.compact!
136
139
  end
@@ -180,6 +183,7 @@ class Case
180
183
  " ip=<#{ip}>, HOSTID=<#{hostname}>", :warn)
181
184
  end
182
185
  output = encode_and_split(@action[:encoding], text)
186
+ @result.exitcode = -1
183
187
  @result.content = output
184
188
  @result.content.compact!
185
189
  end
@@ -0,0 +1,40 @@
1
+ require "open3"
2
+ require "rainbow"
3
+ require_relative "../utils/project"
4
+
5
+ module Utils
6
+ def encode_and_split(encoding, text)
7
+ # Convert text to UTF-8 deleting unknown chars
8
+ text ||= "" # Ensure text is not nil
9
+ flag = [:default, "UTF-8"].include? encoding
10
+ return text.encode("UTF-8", invalid: :replace).split("\n") if flag
11
+
12
+ # Convert text from input ENCODING to UTF-8
13
+ ec = Encoding::Converter.new(encoding.to_s, "UTF-8")
14
+ begin
15
+ text = ec.convert(text)
16
+ rescue => e
17
+ warn "[ERROR] #{e}"
18
+ warn " Suggest declare text encoding, for example:"
19
+ warn " run 'command', on: :host, :encoding => 'ISO-8859-1'"
20
+ end
21
+
22
+ text.split("\n")
23
+ end
24
+
25
+ def my_execute(cmd, encoding = "UTF-8")
26
+ # TODO: mover a la clase ExecuteManager
27
+ return {exitstatus: 0, content: ""} if Project.debug?
28
+
29
+ begin
30
+ text, status = Open3.capture2e(cmd)
31
+ exitstatus = status.exitstatus
32
+ rescue => e
33
+ verbose Rainbow("!").green
34
+ text = e.to_s
35
+ exitstatus = 1
36
+ end
37
+ content = encode_and_split(encoding, text)
38
+ {exitstatus: exitstatus, content: content}
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ require_relative "expect"
2
+ require_relative "getset"
3
+ require_relative "goto"
4
+ require_relative "log"
5
+ require_relative "macro"
6
+ require_relative "send"
7
+ require_relative "target"
8
+ require_relative "unique"
@@ -1,6 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DSL
4
+ # expect, expect2, expect_any, expect_first, expect_last
5
+ # expect_nothing, expect_none, expect_one
6
+
4
7
  # expect <condition>, :weight => <value>
5
8
  def expect(input, args = {})
6
9
  if input.instance_of?(TrueClass) || input.instance_of?(FalseClass)
@@ -16,18 +19,16 @@ module DSL
16
19
  @action_counter += 1
17
20
  @action[:id] = @action_counter
18
21
  @action[:check] = cond
19
- @action[:result] = @result.value
20
22
 
21
- @action[:alterations] = @result.alterations
22
- @action[:expected] = @result.expected
23
- @action[:expected] = args[:expected] if args[:expected]
23
+ @action[:result] = (args[:value] || @result.value)
24
24
 
25
+ @action[:alterations] = @result.alterations
26
+ @action[:expected] = (args[:expected] || @result.expected)
25
27
  @report.lines << @action.clone
26
28
  weight(1.0)
27
29
 
28
- app = Application.instance
29
- c = app.letter[:bad]
30
- c = app.letter[:good] if cond
30
+ c = Settings.letter[:bad]
31
+ c = Settings.letter[:good] if cond
31
32
  verbose Rainbow(c).green
32
33
  end
33
34
 
@@ -40,6 +41,22 @@ module DSL
40
41
  expect2 result.count.gt(0), args
41
42
  end
42
43
 
44
+ def expect_exit(value)
45
+ @result.alterations = "Read exit code"
46
+ real_value = result.exitcode
47
+ cond = if value.is_a? Range
48
+ expect_value = "With range #{value}"
49
+ value.to_a.include? real_value
50
+ elsif value.is_a? Array
51
+ expect_value = "Inside list #{value}"
52
+ value.include? real_value
53
+ else
54
+ expect_value = value
55
+ (real_value == value.to_i)
56
+ end
57
+ expect2 cond, value: real_value, expected: expect_value
58
+ end
59
+
43
60
  def expect_first(input, args = {})
44
61
  @result.first
45
62
  output = input
@@ -54,7 +71,6 @@ module DSL
54
71
  expect2 input, expected: output
55
72
  end
56
73
 
57
- # def expect_none(input, args = {})
58
74
  def expect_nothing(args = {})
59
75
  expect2 result.count.eq(0), args
60
76
  end
@@ -79,8 +95,8 @@ module DSL
79
95
  expect2 result.count.eq(1), args
80
96
  end
81
97
 
82
- # Set weight value for the action
83
98
  def weight(value = nil)
99
+ # Set weight value for the action
84
100
  if value.nil?
85
101
  @action[:weight]
86
102
  elsif value == :default
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../runner"
3
+ require_relative "../execute/execute_manager"
4
4
 
5
- # Case class -> DSL module:
6
- # * goto
7
- # * run
8
5
  module DSL
9
6
  ##
10
- # DLS run: It's the same as goto :localhost
7
+ # DSL run and goto
8
+ # run: It's the same as goto :localhost
11
9
  # @param command (String)
12
10
  # @param args (Hash)
13
11
  def run(command, args = {})
@@ -17,7 +15,7 @@ module DSL
17
15
  goto(host, args)
18
16
  end
19
17
 
20
- # Run command from the host identify as pHostname
18
+ # Run command from the host identify as "host"
21
19
  # goto :host1, :execute => "command"
22
20
  def goto(host = :localhost, args = {})
23
21
  @result.reset
@@ -27,9 +25,12 @@ module DSL
27
25
  tempfile(args[:tempfile]) if args[:tempfile]
28
26
  @action[:encoding] = args[:encoding] || "UTF-8"
29
27
 
30
- start_time = Time.now
31
- run_cmd_on(host)
32
- @action[:duration] = (Time.now - start_time).round(3)
28
+ ExecuteManager.new(self).call(host)
29
+ @action[:output] = if @result.content.size < 2
30
+ @result.value.clone
31
+ else
32
+ "(#{@result.content.size} lines)"
33
+ end
33
34
  end
34
35
  alias_method :on, :goto
35
36
  end
@@ -1,6 +1,5 @@
1
1
  require "rainbow"
2
- ##
3
- # Define DSL#log function
2
+
4
3
  module DSL
5
4
  ##
6
5
  # Record log message
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../../application"
3
+ require_relative "../../utils/project"
4
4
 
5
5
  # DSL module methods: assert, missing_method
6
6
  module DSL
@@ -9,7 +9,7 @@ module DSL
9
9
  # @param name (String) Macro name
10
10
  # @param input (Hash) Macro params
11
11
  def macro(name, input = {})
12
- macros = Application.instance.macros
12
+ macros = Project.value[:macros]
13
13
  unless macros[name]
14
14
  log("Macro #{name} not found!", :error)
15
15
  return
@@ -1,12 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Case->DSL#
4
- # * send
5
- # * tempfile
6
- # * tempdir
7
- # * remote_tempdir
8
- # * remote_tempfile
9
3
  module DSL
4
+ # * send, tempfile, tempdir, remote_tempdir, remote_tempfile
10
5
  def send(args = {})
11
6
  return if skip?
12
7
 
@@ -52,7 +47,7 @@ module DSL
52
47
  name = "teuton.tmp" if input == :default
53
48
 
54
49
  @action[:tempfile] = File.join(@tmpdir, name)
55
- @action[:remote_tempfile] = File.join(@remote_tmpdir, name)
50
+ @action[:remote_tempfile] = File.join(remote_tempdir, name)
56
51
 
57
52
  @action[:tempfile]
58
53
  end
@@ -66,6 +61,6 @@ module DSL
66
61
  end
67
62
 
68
63
  def remote_tempdir
69
- @remote_tmpdir
64
+ File.join("/", "tmp") # TODO: Remove this?
70
65
  end
71
66
  end