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-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionFormat, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionFormat, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionFormat)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionFormat)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err := options.IsSet(ImageOptionFormat)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionFormat)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionFeatures, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionFeatures, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionFeatures)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionFeatures)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionFeatures)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionFeatures)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionOrder, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionOrder, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionStripeUnit, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionStripeUnit, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionStripeUnit)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionStripeUnit)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionStripeUnit)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionStripeUnit)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionStripeCount, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionStripeCount, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionStripeCount)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionStripeCount)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionStripeCount)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionStripeCount)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionJournalOrder, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionJournalOrder, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionJournalOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionJournalOrder)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionJournalOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionJournalOrder)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionJournalSplayWidth, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionJournalSplayWidth, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionJournalSplayWidth)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionJournalSplayWidth)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionJournalSplayWidth)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionJournalSplayWidth)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionJournalPool, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionJournalPool, "journal")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetUint64(ImageOptionJournalPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
s, err = options.GetString(ImageOptionJournalPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, s == "journal")
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionJournalPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionJournalPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionFeaturesSet, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionFeaturesSet, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionFeaturesSet)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionFeaturesSet)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionFeaturesSet)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionFeaturesSet)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionFeaturesClear, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionFeaturesClear, "string not allowed")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
i, err = options.GetUint64(ImageOptionFeaturesClear)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, i == 1)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetString(ImageOptionFeaturesClear)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionFeaturesClear)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionFeaturesClear)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
2019-11-26 09:08:56 +00:00
|
|
|
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetUint64(ImageOptionDataPool, 1)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.SetString(ImageOptionDataPool, "data")
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
_, err = options.GetUint64(ImageOptionDataPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.Error(t, err)
|
2020-03-20 13:52:09 +00:00
|
|
|
s, err = options.GetString(ImageOptionDataPool)
|
2019-11-26 09:08:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, s == "data")
|
2020-03-20 13:52:09 +00:00
|
|
|
set, err = options.IsSet(ImageOptionDataPool)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.True(t, set)
|
2020-03-20 13:52:09 +00:00
|
|
|
err = options.Unset(ImageOptionDataPool)
|
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-03-20 13:52:09 +00:00
|
|
|
err := options.SetUint64(ImageOptionFormat, 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-02-25 19:13:45 +00:00
|
|
|
err := options.SetUint64(ImageOption(-1), 1)
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2020-02-25 19:13:45 +00:00
|
|
|
_, err = options.IsSet(ImageOption(-1))
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2020-02-25 19:13:45 +00:00
|
|
|
err = options.Unset(ImageOption(-1))
|
2020-01-20 16:32:44 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
options.Destroy()
|
|
|
|
}
|