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