teuton 2.7.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/learn/21-exit_codes.md +14 -2
- data/lib/teuton/case/execute/copy_ssh.rb +70 -0
- data/lib/teuton/case/execute/execute_manager.rb +2 -2
- data/lib/teuton/case_manager/show_report.rb +1 -1
- data/lib/teuton/report/formatter/formatter.rb +1 -1
- data/lib/teuton/version.rb +1 -1
- data/lib/teuton.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffeca52de938d3464c4c9f4bacf4acb7fd229cc3a02daa9d653d68dfe2d65750
|
4
|
+
data.tar.gz: 96a03b03bba6ff9ca381ce1b248f93f341b9aa53c2727258032e6a8d24d42454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ef9650f56b556eaa91c81c04a07c0e621f9903416333a8b12ea8febb6a07e91cddeaabe80a17d9d82fdaaac337cba2af9e6aa7bc881c3801fee8f90a5ed636c
|
7
|
+
data.tar.gz: a2003337f9a7ae148b0976cdd87cd0ef1fdb255a18bec08a390adec32c94f7c13a71db9bfa83452fed93259e8d5a53db34e5bfec265831a0d3237390be2de6de
|
data/docs/learn/21-exit_codes.md
CHANGED
@@ -7,11 +7,23 @@
|
|
7
7
|
## Example
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
target "Exist user root"
|
10
|
+
target "Exist user root (exit code ok)"
|
11
11
|
run "id root"
|
12
12
|
expect_exit 0
|
13
13
|
|
14
|
-
target "No user vader"
|
14
|
+
target "No user vader (exit code fail)"
|
15
15
|
run "id vader"
|
16
16
|
expect_exit 1
|
17
17
|
```
|
18
|
+
|
19
|
+
## More examples
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
target "Using a range"
|
23
|
+
run "id vader"
|
24
|
+
expect_exit 1..3
|
25
|
+
|
26
|
+
target "Using a list"
|
27
|
+
run "id vader"
|
28
|
+
expect_exit [1, 3, 7]
|
29
|
+
```
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "net/ssh"
|
2
|
+
require "net/sftp"
|
3
|
+
require "rainbow"
|
4
|
+
require_relative "../../utils/project"
|
5
|
+
require_relative "../../utils/verbose"
|
6
|
+
require_relative "execute_base"
|
7
|
+
|
8
|
+
class CopySSH < ExecuteBase
|
9
|
+
def call(host, localfilename)
|
10
|
+
# Check params
|
11
|
+
unless config.get("#{host}_route".to_sym) == "NODATA"
|
12
|
+
log("'copy script' requires direct host access!", :error)
|
13
|
+
return false
|
14
|
+
end
|
15
|
+
|
16
|
+
host = host.to_s
|
17
|
+
|
18
|
+
begin
|
19
|
+
if sessions[host].nil?
|
20
|
+
# Open new SSH session
|
21
|
+
ip = config.get("#{host}_ip".to_sym).to_s
|
22
|
+
username = config.get("#{host}_username".to_sym).to_s
|
23
|
+
password = config.get("#{host}_password".to_sym).to_s
|
24
|
+
port = config.get("#{host}_port".to_sym).to_i
|
25
|
+
port = 22 if port.zero?
|
26
|
+
|
27
|
+
sessions[host] = Net::SSH.start(
|
28
|
+
ip,
|
29
|
+
username,
|
30
|
+
port: port,
|
31
|
+
password: password,
|
32
|
+
keepalive: true,
|
33
|
+
timeout: 30,
|
34
|
+
non_interactive: true
|
35
|
+
)
|
36
|
+
end
|
37
|
+
if sessions[host].instance_of? Net::SSH::Connection::Session
|
38
|
+
copy_to(host, localfilename)
|
39
|
+
else
|
40
|
+
"SSH: NO CONNECTION!"
|
41
|
+
end
|
42
|
+
rescue => e
|
43
|
+
sessions[host] = :nosession
|
44
|
+
conn_status[host] = :error
|
45
|
+
log("[#{e.class}] SSH on <#{username}@#{ip}>", :error)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def copy_to(host, localfilename)
|
50
|
+
ip = get((host + "_ip").to_sym)
|
51
|
+
username = get((host + "_username").to_sym).to_s
|
52
|
+
password = get((host + "_password").to_sym).to_s
|
53
|
+
port = get((host + "_port").to_sym).to_i
|
54
|
+
port = 22 if port.zero?
|
55
|
+
|
56
|
+
localfilepath = File.join(Dir.pwd, localfilename)
|
57
|
+
remotefilepath = File.join(".", File.basename(localfilename))
|
58
|
+
|
59
|
+
# Upload a file or directory to the remote host
|
60
|
+
begin
|
61
|
+
Net::SFTP.start(ip, username, password: password, port: port) do |sftp|
|
62
|
+
sftp.upload!(localfilepath, remotefilepath)
|
63
|
+
end
|
64
|
+
rescue
|
65
|
+
log("copy file: #{localfilename} => #{remotefilepath}", :error)
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
true
|
69
|
+
end
|
70
|
+
end
|
data/lib/teuton/version.rb
CHANGED
data/lib/teuton.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teuton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.7.
|
4
|
+
version: 2.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Vargas Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -281,6 +281,7 @@ files:
|
|
281
281
|
- lib/teuton/case/dsl/send.rb
|
282
282
|
- lib/teuton/case/dsl/target.rb
|
283
283
|
- lib/teuton/case/dsl/unique.rb
|
284
|
+
- lib/teuton/case/execute/copy_ssh.rb
|
284
285
|
- lib/teuton/case/execute/execute_base.rb
|
285
286
|
- lib/teuton/case/execute/execute_local.rb
|
286
287
|
- lib/teuton/case/execute/execute_manager.rb
|