This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
/
run_volume_test.go
151 lines (130 loc) · 3.14 KB
/
run_volume_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
package e2e
import (
"fmt"
"os"
"os/exec"
"strings"
"testing"
"gotest.tools/assert"
"github.com/weaveworks/ignite/e2e/util"
)
// runVolume is a helper for testing volume persistence
// vmName should be unique for each test
func runVolume(t *testing.T, vmName, runtime, networkPlugin string) {
assert.Assert(t, e2eHome != "", "IGNITE_E2E_HOME should be set")
// Create a loop device backed by a test-specific file
volFile := "/tmp/" + vmName + "_vol"
createDiskCmd := exec.Command(
"dd",
"if=/dev/zero",
"of="+volFile,
"bs=1M",
"count=1024",
)
createDiskOut, createDiskErr := createDiskCmd.CombinedOutput()
assert.Check(t, createDiskErr, fmt.Sprintf("create disk: \n%q\n%s", createDiskCmd.Args, createDiskOut))
if createDiskErr != nil {
return
}
defer func() {
os.Remove(volFile)
}()
mkfsCmd := exec.Command(
"mkfs.ext4",
volFile,
)
mkfsOut, mkfsErr := mkfsCmd.CombinedOutput()
assert.Check(t, mkfsErr, fmt.Sprintf("create disk: \n%q\n%s", mkfsCmd.Args, mkfsOut))
if mkfsErr != nil {
return
}
losetupCmd := exec.Command(
"losetup",
"--find",
"--show",
volFile,
)
losetupOut, losetupErr := losetupCmd.CombinedOutput()
assert.Check(t, losetupErr, fmt.Sprintf("vm losetup: \n%q\n%s", losetupCmd.Args, losetupOut))
if losetupErr != nil {
return
}
loopPath := strings.TrimSpace(string(losetupOut))
defer func() {
detachLoopCmd := exec.Command(
"losetup",
"--detach",
loopPath,
)
detachLoopOut, detachLoopErr := detachLoopCmd.CombinedOutput()
assert.Check(t, detachLoopErr, fmt.Sprintf("loop detach: \n%q\n%s", detachLoopCmd.Args, detachLoopOut))
}()
igniteCmd := util.NewCommand(t, igniteBin)
// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", vmName).
Run()
// Run a vm with the loop-device mounted as a volume @ /my-vol
igniteCmd.New().
WithRuntime(runtime).
WithNetwork(networkPlugin).
With("run").
With("--name=" + vmName).
With("--ssh").
With("--volumes=" + loopPath + ":/my-vol").
With(util.DefaultVMImage).
Run()
// Touch a file in /my-vol
igniteCmd.New().
With("exec", vmName).
With("touch", "/my-vol/hello-world").
Run()
// Stop the vm without force.
igniteCmd.New().
With("stop", vmName).
Run()
secondVMName := vmName + "-2"
// Clean-up the following VM.
defer igniteCmd.New().
With("rm", "-f", secondVMName).
Run()
// Start another vm so we can check my-vol
igniteCmd.New().
WithRuntime(runtime).
WithNetwork(networkPlugin).
With("run").
With("--name=" + secondVMName).
With("--ssh").
With("--volumes=" + loopPath + ":/my-vol").
With(util.DefaultVMImage).
Run()
// Stat the file in /my-vol using the new vm
igniteCmd.New().
With("exec", secondVMName).
With("stat", "/my-vol/hello-world").
Run()
}
func TestVolumeWithDockerAndDockerBridge(t *testing.T) {
runVolume(
t,
"e2e-test-volume-docker-and-docker-bridge",
"docker",
"docker-bridge",
)
}
func TestVolumeWithDockerAndCNI(t *testing.T) {
runVolume(
t,
"e2e-test-volume-docker-and-cni",
"docker",
"cni",
)
}
func TestVolumeWithContainerdAndCNI(t *testing.T) {
runVolume(
t,
"e2e-test-volume-containerd-and-cni",
"containerd",
"cni",
)
}