@@ -4,7 +4,6 @@ package gcs
44
55import (
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.
3838func 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
172174func 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