devmapper: proper cleanup in pool device test
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
parent
734989c2a0
commit
208957ba3c
@ -28,6 +28,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/pkg/testutil"
|
||||
"github.com/containerd/containerd/snapshots/devmapper/dmsetup"
|
||||
"github.com/containerd/containerd/snapshots/devmapper/losetup"
|
||||
@ -107,13 +108,10 @@ func TestPoolDevice(t *testing.T) {
|
||||
})
|
||||
|
||||
// Mount 'thin-1'
|
||||
thin1MountPath := tempMountPath(t)
|
||||
output, err := exec.Command("mount", dmsetup.GetFullDevicePath(thinDevice1), thin1MountPath).CombinedOutput()
|
||||
assert.NilError(t, err, "failed to mount '%s': %s", thinDevice1, string(output))
|
||||
|
||||
err = mount.WithTempMount(ctx, getMounts(thinDevice1), func(thin1MountPath string) error {
|
||||
// Write v1 test file on 'thin-1' device
|
||||
thin1TestFilePath := filepath.Join(thin1MountPath, "TEST")
|
||||
err = ioutil.WriteFile(thin1TestFilePath, []byte("test file (v1)"), 0700)
|
||||
err := ioutil.WriteFile(thin1TestFilePath, []byte("test file (v1)"), 0700)
|
||||
assert.NilError(t, err, "failed to write test file v1 on '%s' volume", thinDevice1)
|
||||
|
||||
// Take snapshot of 'thin-1'
|
||||
@ -125,19 +123,22 @@ func TestPoolDevice(t *testing.T) {
|
||||
err = ioutil.WriteFile(thin1TestFilePath, []byte("test file (v2)"), 0700)
|
||||
assert.NilError(t, err, "failed to write test file v2 on 'thin-1' volume after taking snapshot")
|
||||
|
||||
// Mount 'snap-1' and make sure TEST file is v1
|
||||
snap1MountPath := tempMountPath(t)
|
||||
output, err = exec.Command("mount", dmsetup.GetFullDevicePath(snapDevice1), snap1MountPath).CombinedOutput()
|
||||
assert.NilError(t, err, "failed to mount '%s' device: %s", snapDevice1, string(output))
|
||||
return nil
|
||||
})
|
||||
|
||||
assert.NilError(t, err)
|
||||
|
||||
// Mount 'snap-1' and make sure TEST file is v1
|
||||
err = mount.WithTempMount(ctx, getMounts(snapDevice1), func(snap1MountPath string) error {
|
||||
// Read test file from snapshot device and make sure it's v1
|
||||
fileData, err := ioutil.ReadFile(filepath.Join(snap1MountPath, "TEST"))
|
||||
assert.NilError(t, err, "couldn't read test file from '%s' device", snapDevice1)
|
||||
assert.Assert(t, string(fileData) == "test file (v1)", "test file content is invalid on snapshot")
|
||||
assert.Equal(t, "test file (v1)", string(fileData), "test file content is invalid on snapshot")
|
||||
|
||||
// Unmount devices before removing
|
||||
output, err = exec.Command("umount", thin1MountPath, snap1MountPath).CombinedOutput()
|
||||
assert.NilError(t, err, "failed to unmount devices: %s", string(output))
|
||||
return nil
|
||||
})
|
||||
|
||||
assert.NilError(t, err)
|
||||
|
||||
t.Run("DeactivateDevice", func(t *testing.T) {
|
||||
testDeactivateThinDevice(t, pool)
|
||||
@ -207,11 +208,13 @@ func testRemoveThinDevice(t *testing.T, pool *PoolDevice) {
|
||||
assert.NilError(t, err, "should delete thin device from pool")
|
||||
}
|
||||
|
||||
func tempMountPath(t *testing.T) string {
|
||||
path, err := ioutil.TempDir("", "devmapper-snapshotter-mount-")
|
||||
assert.NilError(t, err, "failed to get temp directory for mount")
|
||||
|
||||
return path
|
||||
func getMounts(thinDeviceName string) []mount.Mount {
|
||||
return []mount.Mount{
|
||||
{
|
||||
Source: dmsetup.GetFullDevicePath(thinDeviceName),
|
||||
Type: "ext4",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func createLoopbackDevice(t *testing.T, dir string) (string, string) {
|
||||
|
Loading…
Reference in New Issue
Block a user