Skip to content

Commit

Permalink
rbd: add a test to verify that encrypted volumes can be resized
Browse files Browse the repository at this point in the history
Add a test to verify that an encrypted volume can be resized to
the desired unencrypted size similar to how the rbd command line
tool is documented as able to do.

Fixes: #972

Original-Version-By: Will Gorman <will.gorman@gmail.com>
Signed-off-by: John Mulligan <jmulligan@redhat.com>
  • Loading branch information
phlogistonjohn authored and mergify[bot] committed Mar 21, 2024
1 parent 755481f commit bb2a449
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions rbd/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,69 @@ func TestEncryptionLoad(t *testing.T) {
conn.DeletePool(poolname)
conn.Shutdown()
}

func TestEncryptedResize(t *testing.T) {
conn := radosConnect(t)
defer conn.Shutdown()

poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
defer conn.DeletePool(poolname)

imageName := "resizeme"
imageSize := uint64(50) * 1024 * 1024
encOpts := EncryptionOptionsLUKS2{
Alg: EncryptionAlgorithmAES256,
Passphrase: []byte("test-password"),
}

t.Run("create", func(t *testing.T) {
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
defer ioctx.Destroy()

err = CreateImage(ioctx, imageName, imageSize, NewRbdImageOptions())
require.NoError(t, err)

image, err := OpenImage(ioctx, imageName, NoSnapshot)
require.NoError(t, err)
defer image.Close()

s, err := image.GetSize()
require.NoError(t, err)
t.Logf("image size before encryption: %d", s)

err = image.EncryptionFormat(encOpts)
require.NoError(t, err)

s, err = image.GetSize()
require.NoError(t, err)
t.Logf("image size after encryption: %d", s)
})

t.Run("resize", func(t *testing.T) {
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
defer ioctx.Destroy()

image, err := OpenImage(ioctx, imageName, NoSnapshot)
require.NoError(t, err)
defer image.Close()

err = image.EncryptionLoad(encOpts)
assert.NoError(t, err)

s, err := image.GetSize()
require.NoError(t, err)
t.Logf("image size before resize: %d", s)
assert.NotEqual(t, s, imageSize)

err = image.Resize(imageSize)
assert.NoError(t, err)

s, err = image.GetSize()
require.NoError(t, err)
t.Logf("image size after resize of encrypted image: %d", s)
})
}

0 comments on commit bb2a449

Please sign in to comment.