This repository was archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 227
/
Copy pathvm_lifecycle_test.go
203 lines (166 loc) · 4.28 KB
/
vm_lifecycle_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package e2e
import (
"fmt"
"strings"
"testing"
"github.com/weaveworks/ignite/e2e/util"
"gotest.tools/assert"
)
// runVMLifecycle is a helper for testing the VM lifecycle.
// vmName should be unique for each test.
func runVMLifecycle(t *testing.T, vmName, runtime, networkPlugin string) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")
igniteCmd := util.NewCommand(t, igniteBin)
// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", vmName).
Run()
// Run VM.
igniteCmd.New().
WithRuntime(runtime).
WithNetwork(networkPlugin).
With("run").
With("--name=" + vmName).
With("--ssh").
With(util.DefaultVMImage).
Run()
// Check network access.
igniteCmd.New().
With("exec", vmName).
With("curl", "google.com").
Run()
// Stop VM.
igniteCmd.New().
With("stop", vmName).
Run()
// Start VM with explicit runtime and network because these info are
// removed when VM is stopped. Without it, the VM will start with the
// default provider configurations.
igniteCmd.New().
With("start", vmName).
WithRuntime(runtime).
WithNetwork(networkPlugin).
Run()
// Check network access after reboot.
igniteCmd.New().
With("exec", vmName).
With("curl", "google.com").
Run()
}
func TestVMLifecycleWithDockerAndDockerBridge(t *testing.T) {
runVMLifecycle(
t,
"e2e-test-vm-lifecycle-docker-and-docker-bridge",
"docker",
"docker-bridge",
)
}
func TestVMLifecycleWithDockerAndCNI(t *testing.T) {
runVMLifecycle(
t,
"e2e-test-vm-lifecycle-docker-and-cni",
"docker",
"cni",
)
}
func TestVMLifecycleWithContainerdAndCNI(t *testing.T) {
runVMLifecycle(
t,
"e2e-test-vm-lifecycle-containerd-and-cni",
"containerd",
"cni",
)
}
// TestVMProviderSwitch tests that a VM's runtime and network-plugin can be
// changed.
func TestVMProviderSwitch(t *testing.T) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")
vmName := "e2e-test-vm-providers-switch"
igniteCmd := util.NewCommand(t, igniteBin)
// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", vmName).
Run()
// Run VM.
igniteCmd.New().
WithRuntime("containerd").
WithNetwork("cni").
With("run").
With("--name=" + vmName).
With("--ssh").
With(util.DefaultVMImage).
Run()
// Check network access.
igniteCmd.New().
With("exec", vmName).
With("curl", "google.com").
Run()
// Stop VM.
igniteCmd.New().
With("stop", vmName).
Run()
// Start VM with different providers.
igniteCmd.New().
With("start", vmName).
WithRuntime("docker").
WithNetwork("docker-bridge").
Run()
// Check network access.
igniteCmd.New().
With("exec", vmName).
With("curl", "google.com").
Run()
}
func TestVMStartNonDefaultProvider(t *testing.T) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")
vmName := "e2e-test-vm-start-non-default-providers"
igniteCmd := util.NewCommand(t, igniteBin)
wantInspect := "docker docker-bridge"
// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", vmName).
Run()
// Create VM.
igniteCmd.New().
WithRuntime("docker").
WithNetwork("docker-bridge").
With("create").
With(util.DefaultVMImage).
With("--name=" + vmName).
Run()
// Start the VM.
igniteCmd.New().
With("start", vmName).
Run()
// Inspect the VM runtime and network-plugin.
inspect := igniteCmd.New().
With("inspect", "vm", vmName).
With("-t", "{{.Status.Runtime.Name}} {{.Status.Network.Plugin}}")
inspectOut, inspectErr := inspect.Cmd.CombinedOutput()
assert.Check(t, inspectErr, fmt.Sprintf("cmd: \n%q\n%s", inspect.Cmd, inspectOut))
gotInspect := strings.TrimSpace(string(inspectOut))
assert.Equal(t, gotInspect, wantInspect, fmt.Sprintf("unexpected VM properties:\n\t(WNT): %q\n\t(GOT): %q", wantInspect, gotInspect))
}
func TestVMStopStartDefaultProviders(t *testing.T) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")
vmName := "e2e-test-vm-stop-start-default-providers"
igniteCmd := util.NewCommand(t, igniteBin)
// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", vmName).
Run()
// Run the VM.
igniteCmd.New().
With("run").
With(util.DefaultVMImage).
With("--name=" + vmName).
Run()
// Stop the VM.
igniteCmd.New().
With("stop", vmName).
Run()
// Start the VM.
igniteCmd.New().
With("start", vmName).
Run()
}