mirror of https://github.com/ceph/go-ceph
rbd/features: add test for Image.GetFeatures()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
8b58ab92c4
commit
20031cf70f
|
@ -0,0 +1,52 @@
|
|||
package rbd
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetFeatures(t *testing.T) {
|
||||
conn := radosConnect(t)
|
||||
require.NotNil(t, conn)
|
||||
defer conn.Shutdown()
|
||||
|
||||
poolname := GetUUID()
|
||||
err := conn.MakePool(poolname)
|
||||
require.NoError(t, err)
|
||||
defer conn.DeletePool(poolname)
|
||||
|
||||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
require.NoError(t, err)
|
||||
defer ioctx.Destroy()
|
||||
|
||||
name := GetUUID()
|
||||
|
||||
options := NewRbdImageOptions()
|
||||
err = options.SetUint64(RbdImageOptionFeatures, FeatureLayering|FeatureStripingV2)
|
||||
require.NoError(t, err)
|
||||
// FeatureStripingV2 only works with additional arguments
|
||||
err = options.SetUint64(RbdImageOptionStripeUnit, 1024*1024)
|
||||
require.NoError(t, err)
|
||||
err = options.SetUint64(RbdImageOptionStripeCount, 4)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = CreateImage(ioctx, name, 16*1024*1024, options)
|
||||
require.NoError(t, err)
|
||||
defer func() { assert.NoError(t, RemoveImage(ioctx, name)) }()
|
||||
|
||||
image, err := OpenImageReadOnly(ioctx, name, NoSnapshot)
|
||||
assert.NoError(t, err)
|
||||
defer func() { assert.NoError(t, image.Close()) }()
|
||||
|
||||
features, err := image.GetFeatures()
|
||||
assert.NoError(t, err)
|
||||
|
||||
t.Run("compareBits", func(t *testing.T) {
|
||||
hasLayering := (features & FeatureLayering) == FeatureLayering
|
||||
hasStripingV2 := (features & FeatureStripingV2) == FeatureStripingV2
|
||||
assert.True(t, hasLayering, "FeatureLayering is not set")
|
||||
assert.True(t, hasStripingV2, "FeatureStripingV2 is not set")
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue