Skip to content

Commit 9fd0e72

Browse files
authored
[gcs.test] update scratch space cleanup order (#1794)
Signed-off-by: Hamza El-Saawy <[email protected]>
1 parent e322ac5 commit 9fd0e72

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

scripts/Test-LCOW-UVM.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ param (
5151

5252
# gcs test/container options
5353

54+
# we can no longer specify the guest/destination path for SCSI mounts, so hope the rootfs is the first
55+
# path to be SCSI-mounted
5456
[string]
55-
$ContainerRootFSMount = '/run/rootfs',
57+
$ContainerRootFSMount = '/run/mounts/scsi/m0',
5658

5759
[string]
5860
$ContainerRootFSPath = (Join-Path $BootFilesPath 'rootfs.vhd'),
@@ -79,10 +81,10 @@ $UVMBootPath = Resolve-Path $UVMBootPath
7981

8082
$shell = ( $Action -eq 'Shell' )
8183

84+
$date = Get-Date
8285
if ( $shell ) {
8386
$cmd = 'ash'
8487
} else {
85-
$date = Get-Date
8688
$waitfiles = "$ContainerRootFSMount"
8789
$gcspath = 'gcs.test'
8890
if ( -not $SkipGCSTestMount ) {
@@ -124,7 +126,7 @@ $boot = "$UVMBootPath -gcs lcow " + `
124126
"-boot-files-path $BootFilesPath " + `
125127
"-root-fs-type $BootFSType " + `
126128
'-kernel-file vmlinux ' + `
127-
"-mount-scsi `"$ContainerRootFSPath,$ContainerRootFSMount`" "
129+
"-mount-scsi `"$ContainerRootFSPath`" "
128130

129131
if ( -not $SkipGCSTestMount ) {
130132
$boot += "-share `"$GCSTestPath,$GCSTestMount`" "

test/gcs/container_bench_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ func BenchmarkContainerCreate(b *testing.B) {
4545
// create launches background go-routines
4646
// so kill container to end those and avoid future perf hits
4747
killContainer(ctx, b, c)
48-
deleteContainer(ctx, b, c)
49-
removeContainer(ctx, b, host, id)
50-
unmountRootfs(ctx, b, scratch)
48+
cleanupContainer(ctx, b, host, c)
5149
}
5250
}
5351

test/gcs/helper_container_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package gcs
44

55
import (
66
"context"
7-
"os"
87
"path/filepath"
98
"syscall"
109
"testing"
@@ -34,7 +33,8 @@ const tailNull = "tail -f /dev/null"
3433

3534
// Creates an overlay mount, and then a container using that mount that runs until stopped.
3635
// The container is created on its own, and not associated with a sandbox pod, and is therefore not CRI compliant.
37-
// [unmountRootfs] is added to the test cleanup.
36+
//
37+
// [unmountRootfs] must be called on the scratch directory before deleting the container.
3838
func createStandaloneContainer(ctx context.Context, tb testing.TB, host *hcsv2.Host, id string, extra ...ctrdoci.SpecOpts) *hcsv2.Container {
3939
tb.Helper()
4040
ctx = namespaces.WithNamespace(ctx, testoci.DefaultNamespace)
@@ -51,6 +51,8 @@ func createStandaloneContainer(ctx context.Context, tb testing.TB, host *hcsv2.H
5151
OCISpecification: s,
5252
}
5353

54+
// should be called before the container is deleted, but call it again incase the test errors before
55+
// the container is created/cleanup is scheduled
5456
tb.Cleanup(func() {
5557
unmountRootfs(ctx, tb, scratch)
5658
})
@@ -171,6 +173,9 @@ func deleteContainer(ctx context.Context, tb testing.TB, c *hcsv2.Container) {
171173

172174
func cleanupContainer(ctx context.Context, tb testing.TB, host *hcsv2.Host, c *hcsv2.Container) {
173175
tb.Helper()
176+
// assume scratch space was created by [mountRootfs]
177+
scratch := filepath.Join(guestpath.LCOWRootPrefixInUVM, c.ID())
178+
unmountRootfs(ctx, tb, scratch)
174179
deleteContainer(ctx, tb, c)
175180
removeContainer(ctx, tb, host, c.ID())
176181
}
@@ -257,9 +262,6 @@ func unmountRootfs(ctx context.Context, tb testing.TB, path string) {
257262
if err := storage.UnmountAllInPath(ctx, path, true); err != nil {
258263
tb.Fatalf("could not unmount container rootfs: %v", err)
259264
}
260-
if err := os.RemoveAll(path); err != nil {
261-
tb.Fatalf("could not remove container directory: %v", err)
262-
}
263265
}
264266

265267
//

0 commit comments

Comments
 (0)