-
Notifications
You must be signed in to change notification settings - Fork 61
/
macvtap_linux_test.go
136 lines (110 loc) · 3.37 KB
/
macvtap_linux_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package tenus
import (
"net"
"testing"
"time"
)
type macvtpTest struct {
masterDev string
}
var macvtpTests = []macvtpTest{
{"master01"},
}
func Test_NewMacVtapLink(t *testing.T) {
for _, tt := range macvtpTests {
tl := &testLink{}
if err := tl.prepTestLink(tt.masterDev, "dummy"); err != nil {
t.Skipf("NewMacVtapLink test requries external command: %v", err)
}
if err := tl.create(); err != nil {
t.Fatalf("testLink.create failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
macvtp, err := NewMacVtapLink(tt.masterDev)
if err != nil {
t.Fatalf("NewMacVtapLink(%s) failed to run: %s", tt.masterDev, err)
}
mvtpName := macvtp.NetInterface().Name
if _, err := net.InterfaceByName(mvtpName); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", mvtpName, err)
}
testRes, err := linkInfo(mvtpName, "macvtap")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", mvtpName, err)
}
if testRes.linkType != "macvtap" {
tl.teardown()
t.Fatalf("NewMacVtapLink(%s) failed: expected macvtap, returned %s",
tt.masterDev, testRes.linkType)
}
if testRes.linkData != "bridge" {
tl.teardown()
t.Fatalf("NewMacVtapLink(%s) failed: expected bridge, returned %s",
tt.masterDev, testRes.linkData)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
}
type macvtpWithOptionsTest struct {
masterDev string
opts *MacVlanOptions
}
var macvtpWithOptionsTests = []macvtpWithOptionsTest{
{"master01", &MacVlanOptions{Dev: "test", MacAddr: "aa:aa:aa:aa:aa:aa", Mode: "bridge"}},
}
func Test_NewMacVtapLinkWithOptions(t *testing.T) {
for _, tt := range macvtpWithOptionsTests {
var iface *net.Interface
tl := &testLink{}
if err := tl.prepTestLink(tt.masterDev, "dummy"); err != nil {
t.Skipf("NewMacVtapLinkWithOptions test requries external command: %v", err)
}
if err := tl.create(); err != nil {
t.Fatalf("testLink.create failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
macvtp, err := NewMacVtapLinkWithOptions(tt.masterDev, *tt.opts)
if err != nil {
t.Fatalf("NewMacVtapLinkWithOptions(%s, %s) failed to run: %s", tt.masterDev, *tt.opts, err)
}
iface = macvtp.NetInterface()
if iface.HardwareAddr.String() != tt.opts.MacAddr {
tl.teardown()
t.Fatalf("NewMacVtapLinkWithOptions(%s, %s) failed: expected %s, returned %s",
tt.masterDev, *tt.opts, tt.opts.MacAddr, iface.HardwareAddr.String())
}
mvtpName := iface.Name
if _, err := net.InterfaceByName(mvtpName); err != nil {
tl.teardown()
t.Fatalf("Could not find %s on the host: %s", mvtpName, err)
}
testRes, err := linkInfo(mvtpName, "macvtap")
if err != nil {
tl.teardown()
t.Fatalf("Failed to list %s operation mode: %s", mvtpName, err)
}
if testRes.linkType != "macvtap" {
tl.teardown()
t.Fatalf("NewMacVtapLinkWithOptions(%s, %s) failed: expected macvtap, returned %s",
tt.masterDev, *tt.opts, testRes.linkType)
}
if testRes.linkData != "bridge" {
tl.teardown()
t.Fatalf("NewMacVtapLinkWithOptions(%s, %s) failed: expected bridge, returned %s",
tt.masterDev, *tt.opts, testRes.linkData)
}
if err := tl.teardown(); err != nil {
t.Fatalf("testLink.teardown failed: %v", err)
} else {
time.Sleep(10 * time.Millisecond)
}
}
}