MCPcopy
hub / github.com/containerd/containerd / TestPoolDevice

Function TestPoolDevice

plugins/snapshots/devmapper/pool_device_test.go:57–171  ·  view source on GitHub ↗

TestPoolDevice runs integration tests for pool device. The following scenario implemented: - Create pool device with name 'test-pool-device' - Create two thin volumes 'thin-1' and 'thin-2' - Write ext4 file system on 'thin-1' and make sure it'errs moutable - Write v1 test file on 'thin-1' volume - T

(t *testing.T)

Source from the content-addressed store, hash-verified

55// - Mount 'snap-1' and make sure test file is v1
56// - Unmount volumes and remove all devices
57func TestPoolDevice(t *testing.T) {
58 testutil.RequiresRoot(t)
59
60 assert.NoError(t, log.SetLevel("debug"))
61 ctx := context.Background()
62
63 tempDir := t.TempDir()
64
65 _, loopDataDevice := createLoopbackDevice(t, tempDir)
66 _, loopMetaDevice := createLoopbackDevice(t, tempDir)
67
68 poolName := fmt.Sprintf("test-pool-device-%d", time.Now().Nanosecond())
69 err := dmsetup.CreatePool(poolName, loopDataDevice, loopMetaDevice, 64*1024/dmsetup.SectorSize)
70 assert.Nil(t, err, "failed to create pool %q", poolName)
71
72 defer func() {
73 // Detach loop devices and remove images
74 err := mount.DetachLoopDevice(loopDataDevice, loopMetaDevice)
75 assert.NoError(t, err)
76 }()
77
78 config := &Config{
79 PoolName: poolName,
80 RootPath: tempDir,
81 BaseImageSize: "16mb",
82 BaseImageSizeBytes: 16 * 1024 * 1024,
83 DiscardBlocks: true,
84 }
85
86 pool, err := NewPoolDevice(ctx, config)
87 assert.Nil(t, err, "can't create device pool")
88 assert.True(t, pool != nil)
89
90 defer func() {
91 err := pool.RemovePool(ctx)
92 assert.Nil(t, err, "can't close device pool")
93 }()
94
95 // Create thin devices
96 t.Run("CreateThinDevice", func(t *testing.T) {
97 testCreateThinDevice(t, pool)
98 })
99
100 // Make ext4 filesystem on 'thin-1'
101 t.Run("MakeFileSystem", func(t *testing.T) {
102 testMakeFileSystem(t, pool)
103 })
104
105 // Mount 'thin-1' and write v1 test file on 'thin-1' device
106 err = mount.WithTempMount(ctx, getMounts(thinDevice1), func(thin1MountPath string) error {
107 // Write v1 test file on 'thin-1' device
108 thin1TestFilePath := filepath.Join(thin1MountPath, "TEST")
109 err := os.WriteFile(thin1TestFilePath, []byte("test file (v1)"), 0700)
110 assert.Nil(t, err, "failed to write test file v1 on '%s' volume", thinDevice1)
111
112 return nil
113 })
114

Callers

nothing calls this directly

Calls 15

RemovePoolMethod · 0.95
CreateSnapshotDeviceMethod · 0.95
DeactivateDeviceMethod · 0.95
rollbackActivateMethod · 0.95
RequiresRootFunction · 0.92
CreatePoolFunction · 0.92
DetachLoopDeviceFunction · 0.92
WithTempMountFunction · 0.92
NewPoolDeviceFunction · 0.85
testCreateThinDeviceFunction · 0.85
testMakeFileSystemFunction · 0.85
getMountsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…