1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #43008 from thaJeztah/20.10_backport_fix_TestBuildUserNamespaceValidateCapabilitiesAreV2

[20.10 backport] TestBuildUserNamespaceValidateCapabilitiesAreV2: cleanup daemon storage
This commit is contained in:
Akihiro Suda 2021-11-11 15:36:36 +09:00 committed by GitHub
commit 7bd682c48c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 1 deletions

View file

@ -41,6 +41,7 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
dUserRemap.Start(t, "--userns-remap", "default")
ctx := context.Background()
clientUserRemap := dUserRemap.NewClientT(t)
defer clientUserRemap.Close()
err = load.FrozenImagesLinux(clientUserRemap, "debian:bullseye")
assert.NilError(t, err)
@ -49,6 +50,7 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
defer func() {
if dUserRemapRunning {
dUserRemap.Stop(t)
dUserRemap.Cleanup(t)
}
}()
@ -89,12 +91,17 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
dNoUserRemap := daemon.New(t)
dNoUserRemap.Start(t)
defer dNoUserRemap.Stop(t)
defer func() {
dNoUserRemap.Stop(t)
dNoUserRemap.Cleanup(t)
}()
clientNoUserRemap := dNoUserRemap.NewClientT(t)
defer clientNoUserRemap.Close()
tarFile, err := os.Open(tmp + "/image.tar")
assert.NilError(t, err, "failed to open image tar file")
defer tarFile.Close()
tarReader := bufio.NewReader(tarFile)
loadResp, err := clientNoUserRemap.ImageLoad(ctx, tarReader, false)
@ -112,6 +119,7 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
ShowStdout: true,
})
assert.NilError(t, err)
defer logReader.Close()
actualStdout := new(bytes.Buffer)
actualStderr := ioutil.Discard

View file

@ -281,6 +281,7 @@ func (d *Daemon) Cleanup(t testing.TB) {
t.Helper()
cleanupMount(t, d)
cleanupRaftDir(t, d)
cleanupDaemonStorage(t, d)
cleanupNetworkNamespace(t, d)
}
@ -822,3 +823,36 @@ func cleanupRaftDir(t testing.TB, d *Daemon) {
}
}
}
// cleanupDaemonStorage removes the daemon's storage directory.
//
// Note that we don't delete the whole directory, as some files (e.g. daemon
// logs) are collected for inclusion in the "bundles" that are stored as Jenkins
// artifacts.
//
// We currently do not include container logs in the bundles, so this also
// removes the "containers" sub-directory.
func cleanupDaemonStorage(t testing.TB, d *Daemon) {
t.Helper()
dirs := []string{
"builder",
"buildkit",
"containers",
"image",
"network",
"plugins",
"tmp",
"trust",
"volumes",
// note: this assumes storage-driver name matches the subdirectory,
// which is currently true, but not guaranteed.
d.storageDriver,
}
for _, p := range dirs {
dir := filepath.Join(d.Root, p)
if err := os.RemoveAll(dir); err != nil {
t.Logf("[%s] error removing %v: %v", d.id, dir, err)
}
}
}