2020-01-20 17:22:32 +00:00
|
|
|
package rbd
|
2019-11-26 09:08:56 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRbdOptions(t *testing.T) {
|
|
|
|
var i uint64
|
|
|
|
var s string
|
|
|
|
var err error
|
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
options := NewRbdImageOptions()
|
2019-11-26 09:08:56 +00:00
|
|
|
defer options.Destroy()
|
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionFormat, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionFormat, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionFormat)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionFormat)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err := options.IsSet(RbdImageOptionFormat)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionFormat)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionFeatures, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionFeatures, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionFeatures)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionFeatures)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionFeatures)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionFeatures)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionOrder, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionOrder, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionStripeUnit, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionStripeUnit, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionStripeUnit)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionStripeUnit)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionStripeUnit)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionStripeUnit)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionStripeCount, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionStripeCount, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionStripeCount)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionStripeCount)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionStripeCount)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionStripeCount)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionJournalOrder, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionJournalOrder, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionJournalOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionJournalOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionJournalOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionJournalOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionJournalSplayWidth, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionJournalSplayWidth, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionJournalSplayWidth)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionJournalSplayWidth)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionJournalSplayWidth)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionJournalSplayWidth)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionJournalPool, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionJournalPool, "journal")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetUint64(RbdImageOptionJournalPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
s, err = options.GetString(RbdImageOptionJournalPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, s == "journal")
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionJournalPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionJournalPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionFeaturesSet, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionFeaturesSet, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionFeaturesSet)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionFeaturesSet)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionFeaturesSet)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionFeaturesSet)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionFeaturesClear, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionFeaturesClear, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionFeaturesClear)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionFeaturesClear)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionFeaturesClear)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionFeaturesClear)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionDataPool, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionDataPool, "data")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetUint64(RbdImageOptionDataPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
s, err = options.GetString(RbdImageOptionDataPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, s == "data")
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionDataPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionDataPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
|
|
|
/* introduced with Ceph Mimic, can not be tested on Luminous
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetUint64(RbdImageOptionFlatten, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.SetString(RbdImageOptionFlatten, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
i, err = options.GetUint64(RbdImageOptionFlatten)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.GetString(RbdImageOptionFlatten)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-01-20 17:22:32 +00:00
|
|
|
set, err = options.IsSet(RbdImageOptionFlatten)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOptionFlatten)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestRbdOptionsClear(t *testing.T) {
|
2020-01-20 17:22:32 +00:00
|
|
|
options := NewRbdImageOptions()
|
2019-11-26 09:08:56 +00:00
|
|
|
|
|
|
|
// set at least one option
|
2020-01-20 17:22:32 +00:00
|
|
|
err := options.SetUint64(RbdImageOptionFormat, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
empty := options.IsEmpty()
|
|
|
|
assert.False(t, empty)
|
|
|
|
|
|
|
|
options.Clear()
|
|
|
|
empty = options.IsEmpty()
|
|
|
|
assert.True(t, empty)
|
|
|
|
|
|
|
|
options.Destroy()
|
|
|
|
}
|
2020-01-20 16:32:44 +00:00
|
|
|
|
|
|
|
func TestInvalidRbdOption(t *testing.T) {
|
2020-01-20 17:22:32 +00:00
|
|
|
options := NewRbdImageOptions()
|
2020-01-20 16:32:44 +00:00
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err := options.SetUint64(RbdImageOption(-1), 1)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
_, err = options.IsSet(RbdImageOption(-1))
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2020-01-20 17:22:32 +00:00
|
|
|
err = options.Unset(RbdImageOption(-1))
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
options.Destroy()
|
|
|
|
}
|