Skip to content

Commit 3281bd3

Browse files
committed
fix: remove mount dependency
Signed-off-by: Yejin Seo <[email protected]>
1 parent 2ffef23 commit 3281bd3

File tree

9 files changed

+51
-55
lines changed

9 files changed

+51
-55
lines changed

e2e/limavm/debian.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ type Debian struct {
44
VM
55
}
66

7-
func NewDebian(mountDir string) (Debian, error) {
8-
vm, err := newVM("debian", mountDir)
7+
func NewDebian() (Debian, error) {
8+
vm, err := newVM("debian")
99
if err != nil {
1010
return Debian{}, err
1111
}

e2e/limavm/docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type Docker struct {
88
VM
99
}
1010

11-
func NewDocker(mountDir string) (Docker, error) {
12-
vm, err := newVM("docker", mountDir)
11+
func NewDocker() (Docker, error) {
12+
vm, err := newVM("docker")
1313
if err != nil {
1414
return Docker{}, err
1515
}

e2e/limavm/limavm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ var BinBuildEnv = map[string]string{
1717
"GOOS": "linux",
1818
}
1919

20-
func newVM(template string, mountDir string) (VM, error) {
21-
vmName, err := scripts.PrepareLimaVM(template, mountDir)
20+
func newVM(template string) (VM, error) {
21+
vmName, err := scripts.PrepareLimaVM(template)
2222
return VM{name: vmName}, err
2323
}
2424

e2e/limavm/podman.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ type Podman struct {
88
VM
99
}
1010

11-
func NewPodman(mountDir string) (Podman, error) {
12-
vm, err := newVM("podman", mountDir)
11+
func NewPodman() (Podman, error) {
12+
vm, err := newVM("podman")
1313
if err != nil {
1414
return Podman{}, err
1515
}

e2e/limavm/scripts/prepare-lima-vm.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ MOUNT_DIR=""
1010
usage() {
1111
echo "Usage: $0 <template> <mount-dir>" >&2
1212
echo " template: Lima template to use (docker or podman)" >&2
13-
echo " mount-dir: Directory attached in the vm" >&2
1413
exit 1
1514
}
1615

@@ -22,7 +21,7 @@ cleanup_on_failure() {
2221

2322
create_vm() {
2423
echo "Creating Lima VM..." >&2
25-
if ! limactl create --tty=false --name "$VM_NAME" --set ".mounts += [{\"location\":\"$MOUNT_DIR\",\"writable\":true}]" "template://$TEMPLATE"; then
24+
if ! limactl create --tty=false --name "$VM_NAME" "template://$TEMPLATE"; then
2625
echo "Error: Failed to create VM" >&2
2726
exit 1
2827
fi
@@ -38,12 +37,11 @@ start_vm() {
3837
}
3938

4039
main() {
41-
if [ $# -ne 2 ]; then
40+
if [ $# -ne 1 ]; then
4241
usage
4342
fi
4443

4544
TEMPLATE="$1"
46-
MOUNT_DIR="$2"
4745

4846
VM_NAME="remoteproc-test-vm-$(date +%s)"
4947
echo "Creating VM: $VM_NAME" >&2

e2e/limavm/scripts/scripts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ var (
1818
teardownLimaVMScript = filepath.Join(scriptsDir, "teardown-lima-vm.sh")
1919
)
2020

21-
func PrepareLimaVM(template string, mountDir string) (string, error) {
22-
prepareCmd := exec.Command(prepareLimaVMScript, template, mountDir)
21+
func PrepareLimaVM(template string) (string, error) {
22+
prepareCmd := exec.Command(prepareLimaVMScript, template)
2323
prepareStreamer := runner.NewStreamingCmd(prepareCmd).WithPrefix("prepare-vm")
2424

2525
if err := prepareStreamer.Start(nil); err != nil {

e2e/runtime_test.go

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@ import (
2020
func TestRuntime(t *testing.T) {
2121
limavm.Require(t)
2222

23-
dirMountedInVM := t.TempDir()
24-
25-
rootpathPrefix := filepath.Join(dirMountedInVM, "fake-root")
26-
runtimeBin, err := repo.BuildRuntimeBin(t.TempDir(), rootpathPrefix, limavm.BinBuildEnv)
23+
rootpathPrefixInVM := filepath.Join("/tmp", "remoteproc-simulator-fake-root-for-standalone-runtime")
24+
runtimeBin, err := repo.BuildRuntimeBin(t.TempDir(), rootpathPrefixInVM, limavm.BinBuildEnv)
2725
require.NoError(t, err)
2826

29-
vm, err := limavm.NewDebian(dirMountedInVM)
27+
vm, err := limavm.NewDebian()
3028
require.NoError(t, err)
3129
defer vm.Cleanup()
3230

33-
_, _, err = vm.RunCommand("mkdir", "-p", filepath.Join(rootpathPrefix))
34-
require.NoError(t, err)
35-
defer func() {
36-
_, _, err := vm.RunCommand("rm", "-rf", filepath.Join(rootpathPrefix))
37-
require.NoError(t, err)
38-
}()
39-
4031
installedRuntime, err := vm.InstallBin(runtimeBin)
4132
require.NoError(t, err)
4233

@@ -48,15 +39,15 @@ func TestRuntime(t *testing.T) {
4839

4940
t.Run("basic container lifecycle", func(t *testing.T) {
5041
remoteprocName := "yolo-device"
51-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(remoteprocName).WithIndex(getTestNumber())
42+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(remoteprocName).WithIndex(getTestNumber())
5243
if err := sim.Start(); err != nil {
5344
t.Fatalf("failed to run simulator: %s", err)
5445
}
5546
t.Cleanup(func() { _ = sim.Stop() })
5647

5748
uniqueID := testID(t)
5849
containerName := uniqueID
59-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
50+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
6051
require.NoError(t, generateBundle(t, bundlePath, remoteprocName))
6152
copiedBundlePathInVM, err := copyToVM(t, vm.VM, bundlePath)
6253
require.NoError(t, err)
@@ -85,15 +76,16 @@ func TestRuntime(t *testing.T) {
8576

8677
t.Run("errors when requested remoteproc name doesn't exist", func(t *testing.T) {
8778
processorName := "some-processor"
88-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(processorName).WithIndex(getTestNumber())
79+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(processorName).WithIndex(getTestNumber())
8980
if err := sim.Start(); err != nil {
9081
t.Fatalf("failed to run simulator: %s", err)
9182
}
9283
t.Cleanup(func() { _ = sim.Stop() })
9384

9485
uniqueID := testID(t)
86+
9587
containerName := uniqueID
96-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
88+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
9789
require.NoError(t, generateBundle(t, bundlePath, "other-processor"))
9890
copiedBundlePathInVM, err := copyToVM(t, vm.VM, bundlePath)
9991
require.NoError(t, err)
@@ -106,15 +98,15 @@ func TestRuntime(t *testing.T) {
10698

10799
t.Run("killing process by pid stops the running container", func(t *testing.T) {
108100
remoteprocName := "nice-processor"
109-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(remoteprocName).WithIndex(getTestNumber())
101+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(remoteprocName).WithIndex(getTestNumber())
110102
if err := sim.Start(); err != nil {
111103
t.Fatalf("failed to run simulator: %s", err)
112104
}
113105
t.Cleanup(func() { _ = sim.Stop() })
114106

115107
uniqueID := testID(t)
116108
containerName := uniqueID
117-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
109+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
118110
require.NoError(t, generateBundle(t, bundlePath, remoteprocName))
119111
copiedBundlePathInVM, err := copyToVM(t, vm.VM, bundlePath)
120112
require.NoError(t, err)
@@ -137,15 +129,15 @@ func TestRuntime(t *testing.T) {
137129

138130
t.Run("writes pid to file specified by --pid-file", func(t *testing.T) {
139131
remoteprocName := "oh-what-a-device"
140-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(remoteprocName).WithIndex(getTestNumber())
132+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(remoteprocName).WithIndex(getTestNumber())
141133
if err := sim.Start(); err != nil {
142134
t.Fatalf("failed to run simulator: %s", err)
143135
}
144136
t.Cleanup(func() { _ = sim.Stop() })
145137

146138
uniqueID := testID(t)
147139
containerName := uniqueID
148-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
140+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
149141
require.NoError(t, generateBundle(t, bundlePath, remoteprocName))
150142
copiedBundlePathInVM, err := copyToVM(t, vm.VM, bundlePath)
151143
require.NoError(t, err)
@@ -162,25 +154,24 @@ func TestRuntime(t *testing.T) {
162154
pid, err := getContainerPid(installedRuntime, containerName)
163155
require.NoError(t, err)
164156
require.Greater(t, pid, 0)
165-
166-
require.FileExists(t, pidFile)
167-
assertFileContent(t, pidFile, fmt.Sprintf("%d", pid))
157+
requireFileExistsInVM(t, vm.VM, pidFile)
158+
assertFileContentInVM(t, vm.VM, pidFile, fmt.Sprintf("%d", pid))
168159
})
169160

170161
t.Run("proxy process namespacing", func(t *testing.T) {
171162
installedRuntimeSudo := limavm.NewSudo(installedRuntime)
172163

173164
t.Run("creates process in requested namespace when root", func(t *testing.T) {
174165
remoteprocName := "lovely-blue-device"
175-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(remoteprocName).WithIndex(getTestNumber())
166+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(remoteprocName).WithIndex(getTestNumber())
176167
if err := sim.Start(); err != nil {
177168
t.Fatalf("failed to run simulator: %s", err)
178169
}
179170
t.Cleanup(func() { _ = sim.Stop() })
180171

181172
uniqueID := testID(t)
182173
containerName := uniqueID
183-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
174+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
184175
require.NoError(t, generateBundle(
185176
t,
186177
bundlePath,
@@ -212,15 +203,15 @@ func TestRuntime(t *testing.T) {
212203

213204
t.Run("creates process in user's namespace when not root", func(t *testing.T) {
214205
remoteprocName := "lovely-green-device"
215-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(remoteprocName).WithIndex(getTestNumber())
206+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(remoteprocName).WithIndex(getTestNumber())
216207
if err := sim.Start(); err != nil {
217208
t.Fatalf("failed to run simulator: %s", err)
218209
}
219210
t.Cleanup(func() { _ = sim.Stop() })
220211

221212
uniqueID := testID(t)
222213
containerName := uniqueID
223-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
214+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
224215
require.NoError(t, generateBundle(
225216
t,
226217
bundlePath,
@@ -253,15 +244,15 @@ func TestRuntime(t *testing.T) {
253244

254245
t.Run("When a custom path is set in /sys/module/firmware_class/parameters/path, the firmware will be stored there", func(t *testing.T) {
255246
remoteprocName := "nice-device"
256-
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefix).WithName(remoteprocName).WithIndex(getTestNumber())
247+
sim := remoteproc.NewSimulator(installedSimulator, rootpathPrefixInVM).WithName(remoteprocName).WithIndex(getTestNumber())
257248
if err := sim.Start(); err != nil {
258249
t.Fatalf("failed to run simulator: %s", err)
259250
}
260251
t.Cleanup(func() { _ = sim.Stop() })
261252

262253
uniqueID := testID(t)
263254
containerName := uniqueID
264-
bundlePath := filepath.Join(dirMountedInVM, uniqueID)
255+
bundlePath := filepath.Join(t.TempDir(), uniqueID)
265256
require.NoError(t, generateBundle(t, bundlePath, remoteprocName))
266257
copiedBundlePathInVM, err := copyToVM(t, vm.VM, bundlePath)
267258
require.NoError(t, err)
@@ -272,12 +263,12 @@ func TestRuntime(t *testing.T) {
272263
containerName)
273264
require.NoError(t, err, "stderr: %s", stderr)
274265

275-
customFirmwareStorageDirectory := filepath.Join(rootpathPrefix, "my", "firmware", "path")
266+
customFirmwareStorageDirectory := filepath.Join(rootpathPrefixInVM, "my", "firmware", "path")
276267

277268
_, _, err = vm.RunCommand("sh", "-c", fmt.Sprintf("echo -n %s > %s",
278269
customFirmwareStorageDirectory,
279270
filepath.Join(
280-
rootpathPrefix,
271+
rootpathPrefixInVM,
281272
"sys",
282273
"module",
283274
"firmware_class",
@@ -291,14 +282,15 @@ func TestRuntime(t *testing.T) {
291282
require.NoError(t, err, "stderr: %s", stderr)
292283
assertContainerStatus(t, installedRuntime, containerName, specs.StateRunning)
293284

294-
assertFirmwareFileExists(t, customFirmwareStorageDirectory)
285+
assertFirmwareFileExistsInVM(t, vm.VM, customFirmwareStorageDirectory)
295286
})
296287
}
297288

298-
func assertFirmwareFileExists(t *testing.T, firmwareStorageDirectory string) {
289+
func assertFirmwareFileExistsInVM(t *testing.T, vm limavm.VM, firmwareStorageDirectory string) {
299290
t.Helper()
300-
entries, err := os.ReadDir(firmwareStorageDirectory)
291+
entriesInString, _, err := vm.RunCommand("ls", firmwareStorageDirectory)
301292
require.NoError(t, err)
293+
entries := strings.Split(entriesInString, "\n")
302294
require.Greater(t, len(entries), 0, "expected at least one firmware file in %s", firmwareStorageDirectory)
303295
}
304296

@@ -309,14 +301,20 @@ func assertContainerStatus(t testing.TB, runtime limavm.Runnable, containerName
309301
assert.Equal(t, wantStatus, state.Status)
310302
}
311303

312-
func assertFileContent(t *testing.T, path string, wantContent string) {
304+
func assertFileContentInVM(t *testing.T, vm limavm.VM, path string, wantContent string) {
313305
t.Helper()
314-
gotContent, err := os.ReadFile(path)
306+
gotContent, err := vm.ReadFile(path)
315307
if assert.NoError(t, err) {
316-
assert.Equal(t, wantContent, string(gotContent))
308+
assert.Equal(t, wantContent, gotContent)
317309
}
318310
}
319311

312+
func requireFileExistsInVM(t *testing.T, vm limavm.VM, path string) {
313+
t.Helper()
314+
_, stderr, err := vm.RunCommand("test", "-e", path)
315+
require.NoError(t, err, "failed to check file existence %s in VM: stderr: %s", path, stderr)
316+
}
317+
320318
func requireSameMountNamespace(t testing.TB, vm limavm.Debian, pid uint) {
321319
t.Helper()
322320
hostMountNS, stderr, err := vm.RunCommand("readlink", "/proc/self/ns/mnt")

e2e/runtime_via_podman_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
func TestPodman(t *testing.T) {
1717
limavm.Require(t)
1818

19-
rootpathPrefix := filepath.Join("/tmp", "remoteproc-simulator-fake-root")
19+
rootpathPrefix := filepath.Join("/tmp", "remoteproc-simulator-fake-root-for-podman")
2020
runtimeBin, err := repo.BuildRuntimeBin(t.TempDir(), rootpathPrefix, limavm.BinBuildEnv)
2121
require.NoError(t, err)
2222

23-
vm, err := limavm.NewPodman(t.TempDir())
23+
vm, err := limavm.NewPodman()
2424
require.NoError(t, err)
2525
defer vm.Cleanup()
2626

e2e/shim_via_docker_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
func TestDocker(t *testing.T) {
1919
limavm.Require(t)
2020

21-
rootpathPrefix := filepath.Join("/tmp", "remoteproc-simulator-fake-root")
21+
rootpathPrefix := filepath.Join("/tmp", "remoteproc-simulator-fake-root-for-docker")
2222
bins, err := repo.BuildBothBins(t.TempDir(), rootpathPrefix, limavm.BinBuildEnv)
2323
require.NoError(t, err)
2424

25-
vm, err := limavm.NewDocker(t.TempDir())
25+
vm, err := limavm.NewDocker()
2626
require.NoError(t, err)
2727
defer vm.Cleanup()
2828

0 commit comments

Comments
 (0)