mirror of https://github.com/ceph/go-ceph
rbd: add a test to verify that encrypted volumes can be resized
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>
This commit is contained in:
parent
755481f8c2
commit
bb2a449faf
|
@ -128,3 +128,69 @@ func TestEncryptionLoad(t *testing.T) {
|
||||||
conn.DeletePool(poolname)
|
conn.DeletePool(poolname)
|
||||||
conn.Shutdown()
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue