disk: NewPartitionTable can wrap plain partitions in LVM

Add a new parameter `lvmify` to `NewPartitionTable` that, if set to
`true`, will cause the root partition to be wrapped in LVM in case
it is not in a LVM volume group. Set this to `false` for now so no
actual change should happen anywhere. Layouts where the root is
directly on a LUKS container are not yet supported.
Add tests for this.
This commit is contained in:
Christian Kellner 2022-02-25 14:28:27 +01:00
parent bd2849340c
commit e57cccc3fe
8 changed files with 85 additions and 10 deletions

View file

@ -66,7 +66,7 @@ func TestDisk_DynamicallyResizePartitionTable(t *testing.T) {
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(rand.NewSource(0))
newpt, err := NewPartitionTable(&pt, mountpoints, 1024, rng)
newpt, err := NewPartitionTable(&pt, mountpoints, 1024, false, rng)
assert.NoError(t, err)
assert.GreaterOrEqual(t, newpt.Size, expectedSize)
}
@ -358,7 +358,7 @@ func TestCreatePartitionTable(t *testing.T) {
rng := rand.New(rand.NewSource(13))
for name := range testPartitionTables {
pt := testPartitionTables[name]
mpt, err := NewPartitionTable(&pt, bp, uint64(13*1024*1024), rng)
mpt, err := NewPartitionTable(&pt, bp, uint64(13*1024*1024), false, rng)
assert.NoError(err, "Partition table generation failed: %s (%s)", name, err)
assert.NotNil(mpt, "Partition table generation failed: %s (nil partition table)", name)
assert.Greater(mpt.GetSize(), uint64(37*1024*1024*1024))
@ -369,3 +369,33 @@ func TestCreatePartitionTable(t *testing.T) {
assert.NotNil(mnt, "Partition table '%s': failed to find root mountable", name)
}
}
func TestCreatePartitionTableLVMify(t *testing.T) {
assert := assert.New(t)
// math/rand is good enough in this case
/* #nosec G404 */
rng := rand.New(rand.NewSource(13))
for name := range testPartitionTables {
pt := testPartitionTables[name]
if name == "btrfs" || name == "luks" {
assert.Panics(func() {
_, _ = NewPartitionTable(&pt, bp, uint64(13*1024*1024), true, rng)
})
continue
}
mpt, err := NewPartitionTable(&pt, bp, uint64(13*1024*1024), true, rng)
assert.NoError(err, "Partition table generation failed: %s (%s)", name, err)
rootPath := entityPath(mpt, "/")
if rootPath == nil {
panic("no root mountpoint for PartitionTable")
}
parent := rootPath[1]
_, ok := parent.(*LVMLogicalVolume)
assert.True(ok, "Partition table '%s': root's parent (%q) is not an LVM logical volume", name, parent)
}
}