-
Notifications
You must be signed in to change notification settings - Fork 34
/
ssh_test.go
77 lines (64 loc) · 1.69 KB
/
ssh_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
72
73
74
75
76
77
package ssh
import (
"fmt"
"testing"
"time"
)
func TestSSHRunner(t *testing.T) {
user := ""
password := ""
ipPort := "ip:22"
cmds := make([]string, 0)
cmds = append(cmds, "dis clock")
cmds = append(cmds, "dis clock")
cmds = append(cmds, "dis clock")
IsLogDebug = false
result, err := RunCommandsWithBrand(user, password, ipPort, H3C, cmds...)
if err != nil {
LogError("RunCommands err:%s", err.Error())
}
fmt.Printf("RunCommands result:\n%s", result)
time.Sleep(11 * time.Second)
result2, err := RunCommandsWithBrand(user, password, ipPort, H3C, cmds...)
if err != nil {
LogError("RunCommands err:%s", err.Error())
}
fmt.Printf("RunCommands result2:\n%s", result2)
time.Sleep(time.Second)
}
func TestSSHRunnerMultiple(t *testing.T) {
user := ""
password := ""
ipPort := "ip:22"
cmds := make([]string, 0)
cmds = append(cmds, "dis clock")
cmds = append(cmds, "dis vlan")
for i := 0; i < 3; i++ {
go func(i int) {
result, err := RunCommands(user, password, ipPort, cmds...)
if err != nil {
LogError("RunCommands<%d> err:%s", i, err.Error())
}
LogDebug("RunCommands<%d> result:\n%s", i, result)
}(i)
}
time.Sleep(60 * time.Second)
}
func TestGetSSHBrand(t *testing.T) {
user := ""
password := ""
ipPorts := make([]string, 0)
ipPorts = append(ipPorts, "ip:22") //huawei
ipPorts = append(ipPorts, "ip:22") //h3c
ipPorts = append(ipPorts, "ip:22") //cisco_nexus
ipPorts = append(ipPorts, "ip:22") //cisco
for _, ipPort := range ipPorts {
brand, err := GetSSHBrand(user, password, ipPort)
if err != nil {
LogError("GetSSHBrand<%s> err:%s", ipPort, err.Error())
return
}
LogDebug("GetSSHBrand <%s, %s>", ipPort, brand)
time.Sleep(time.Second)
}
}