rbd: move snapshot test funcs to a new file

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-02-28 11:26:10 -05:00 committed by Niels de Vos
parent f0dba686df
commit 4fc730ad39
2 changed files with 107 additions and 99 deletions

View File

@ -839,54 +839,6 @@ func TestImageCopy(t *testing.T) {
conn.Shutdown()
}
func TestCreateSnapshot(t *testing.T) {
conn := radosConnect(t)
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
name := GetUUID()
err = quickCreate(ioctx, name, testImageSize, testImageOrder)
assert.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
_, err = img.CreateSnapshot("mysnap")
assert.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
snapImage, err := OpenImage(ioctx, name, "mysnap")
assert.NoError(t, err)
err = snapImage.Close()
assert.NoError(t, err)
img2, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
snapshot := img2.GetSnapshot("mysnap")
err = snapshot.Remove()
assert.NoError(t, err)
err = img2.Close()
assert.NoError(t, err)
err = img.Remove()
assert.NoError(t, err)
ioctx.Destroy()
conn.DeletePool(poolname)
conn.Shutdown()
}
func TestParentInfo(t *testing.T) {
conn := radosConnect(t)
@ -1095,57 +1047,6 @@ func TestNotFound(t *testing.T) {
conn.Shutdown()
}
func TestErrorSnapshotNoName(t *testing.T) {
conn := radosConnect(t)
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
name := GetUUID()
err = quickCreate(ioctx, name, testImageSize, testImageOrder)
assert.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
// this actually works for some reason?!
snapshot, err := img.CreateSnapshot("")
assert.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
err = snapshot.Remove()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Rollback()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Protect()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Unprotect()
assert.Equal(t, err, ErrSnapshotNoName)
_, err = snapshot.IsProtected()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Set()
assert.Equal(t, err, ErrSnapshotNoName)
// image can not be removed as the snapshot still exists
// err = img.Remove()
// assert.NoError(t, err)
ioctx.Destroy()
conn.DeletePool(poolname)
conn.Shutdown()
}
func TestTrashImage(t *testing.T) {
conn := radosConnect(t)

107
rbd/snapshot_test.go Normal file
View File

@ -0,0 +1,107 @@
package rbd
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCreateSnapshot(t *testing.T) {
conn := radosConnect(t)
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
name := GetUUID()
err = quickCreate(ioctx, name, testImageSize, testImageOrder)
assert.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
_, err = img.CreateSnapshot("mysnap")
assert.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
snapImage, err := OpenImage(ioctx, name, "mysnap")
assert.NoError(t, err)
err = snapImage.Close()
assert.NoError(t, err)
img2, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
snapshot := img2.GetSnapshot("mysnap")
err = snapshot.Remove()
assert.NoError(t, err)
err = img2.Close()
assert.NoError(t, err)
err = img.Remove()
assert.NoError(t, err)
ioctx.Destroy()
conn.DeletePool(poolname)
conn.Shutdown()
}
func TestErrorSnapshotNoName(t *testing.T) {
conn := radosConnect(t)
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
name := GetUUID()
err = quickCreate(ioctx, name, testImageSize, testImageOrder)
assert.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
// this actually works for some reason?!
snapshot, err := img.CreateSnapshot("")
assert.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
err = snapshot.Remove()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Rollback()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Protect()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Unprotect()
assert.Equal(t, err, ErrSnapshotNoName)
_, err = snapshot.IsProtected()
assert.Equal(t, err, ErrSnapshotNoName)
err = snapshot.Set()
assert.Equal(t, err, ErrSnapshotNoName)
// image can not be removed as the snapshot still exists
// err = img.Remove()
// assert.NoError(t, err)
ioctx.Destroy()
conn.DeletePool(poolname)
conn.Shutdown()
}