- Add argument to pool Export for history log string, hard force (ExportForce),

export and import tests, and overall tests fixes and improvements
This commit is contained in:
Faruk Kasumovic 2015-06-08 23:41:22 +02:00
parent 39d6835ce3
commit 507abac683
4 changed files with 111 additions and 30 deletions

View File

@ -9,6 +9,10 @@ import (
func Test(t *testing.T) {
zpoolTestPoolCreate(t)
zpoolTestExport(t)
zpoolTestImport(t)
zpoolTestExportForce(t)
zpoolTestImport(t)
zpoolTestPoolOpenAll(t)
zpoolTestFailPoolOpen(t)
@ -20,4 +24,6 @@ func Test(t *testing.T) {
zfsTestDatasetDestroy(t)
zpoolTestPoolDestroy(t)
cleanupVDisks()
}

View File

@ -23,8 +23,7 @@ func printDatasets(ds []zfs.Dataset) error {
if err != nil {
return err
}
fmt.Printf(" %30s | %10s\n", path,
p.Value)
fmt.Printf(" %30s | %10s\n", path, p.Value)
if len(d.Children) > 0 {
printDatasets(d.Children)
}
@ -159,13 +158,33 @@ func ExampleDatasetOpen() {
d, err := zfs.DatasetOpen("TESTPOOL/DATASET1")
if err != nil {
panic(err.Error())
return
}
defer d.Close()
var p zfs.Property
if p, err = d.GetProperty(zfs.ZFSPropAvailable); err != nil {
panic(err.Error())
return
}
println(d.PropertyToName(zfs.ZFSPropAvailable), " = ", p.Value)
}
func ExampleDatasetOpenAll() {
datasets, err := zfs.DatasetOpenAll()
if err != nil {
panic(err.Error())
}
defer zfs.DatasetCloseAll(datasets)
// Print out path and type of root datasets
for _, d := range datasets {
path, err := d.Path()
if err != nil {
panic(err.Error())
}
p, err := d.GetProperty(zfs.ZFSPropType)
if err != nil {
panic(err.Error())
}
fmt.Printf("%30s | %10s\n", path, p.Value)
}
}

View File

@ -549,13 +549,20 @@ func (pool *Pool) Destroy(logStr string) (err error) {
// Before exporting the pool, all datasets within the pool are unmounted.
// A pool can not be exported if it has a shared spare that is currently
// being used.
func (pool *Pool) Export(force bool) (err error) {
func (pool *Pool) Export(force bool, log string) (err error) {
var force_t C.boolean_t = 0
if force {
force_t = 1
}
retcode := C.zpool_export(pool.list.zph, force_t, nil)
if retcode != 0 {
if rc := C.zpool_export(pool.list.zph, force_t, C.CString(log)); rc != 0 {
err = LastError()
}
return
}
// Hard force
func (pool *Pool) ExportForce(log string) (err error) {
if rc := C.zpool_export_force(pool.list.zph, C.CString(log)); rc != 0 {
err = LastError()
}
return

View File

@ -26,6 +26,36 @@ func CreateTmpSparse(prefix string, size int64) (path string, err error) {
return
}
var s1path, s2path, s3path string
// This will create sparse files in tmp directory,
// for purpose of creating test pool.
func createTestpoolVdisks() (err error) {
if s1path, err = CreateTmpSparse("zfs_test_", 0x140000000); err != nil {
return
}
if s2path, err = CreateTmpSparse("zfs_test_", 0x140000000); err != nil {
// try cleanup
os.Remove(s1path)
return
}
if s3path, err = CreateTmpSparse("zfs_test_", 0x140000000); err != nil {
// try cleanup
os.Remove(s1path)
os.Remove(s2path)
return
}
return
}
// Cleanup sparse files used for tests
func cleanupVDisks() {
// try cleanup
os.Remove(s1path)
os.Remove(s2path)
os.Remove(s3path)
}
/* ------------------------------------------------------------------------- */
// TESTS:
@ -43,26 +73,13 @@ func zpoolTestPoolCreate(t *testing.T) {
p.Close()
TST_POOL_NAME += "0"
}
var s1path, s2path, s3path string
var err error
if s1path, err = CreateTmpSparse("zfs_test_", 0x140000000); err != nil {
t.Error(err)
return
}
if s2path, err = CreateTmpSparse("zfs_test_", 0x140000000); err != nil {
// try cleanup
os.Remove(s1path)
t.Error(err)
return
}
if s3path, err = CreateTmpSparse("zfs_test_", 0x140000000); err != nil {
// try cleanup
os.Remove(s1path)
os.Remove(s2path)
if err = createTestpoolVdisks(); err != nil {
t.Error(err)
return
}
disks := [2]string{s1path, s2path}
var vdevs, mdevs, sdevs []zfs.VDevSpec
@ -95,10 +112,7 @@ func zpoolTestPoolCreate(t *testing.T) {
return
}
defer pool.Close()
// try cleanup
os.Remove(s1path)
os.Remove(s2path)
os.Remove(s3path)
println("PASS\n")
}
@ -159,6 +173,44 @@ func zpoolTestFailPoolOpen(t *testing.T) {
p.Close()
}
func zpoolTestExport(t *testing.T) {
println("TEST POOL Export( ", TST_POOL_NAME, " ) ... ")
p, err := zfs.PoolOpen(TST_POOL_NAME)
if err != nil {
t.Error(err)
return
}
p.Export(false, "Test exporting pool")
defer p.Close()
println("PASS\n")
}
func zpoolTestExportForce(t *testing.T) {
println("TEST POOL ExportForce( ", TST_POOL_NAME, " ) ... ")
p, err := zfs.PoolOpen(TST_POOL_NAME)
if err != nil {
t.Error(err)
return
}
p.ExportForce("Test force exporting pool")
defer p.Close()
println("PASS\n")
}
func zpoolTestImport(t *testing.T) {
println("TEST POOL Import( ", TST_POOL_NAME, " ) ... ")
p, err := zfs.PoolImport(TST_POOL_NAME, []string{"/tmp"})
if err != nil {
t.Error(err)
return
}
defer p.Close()
println("PASS\n")
}
/* ------------------------------------------------------------------------- */
// EXAMPLES:
func ExamplePoolProp() {
if pool, err := zfs.PoolOpen("SSD"); err == nil {
print("Pool size is: ", pool.Properties[zfs.PoolPropSize].Value)
@ -169,9 +221,6 @@ func ExamplePoolProp() {
}
}
/* ------------------------------------------------------------------------- */
// EXAMPLES:
// Open and list all pools on system with them properties
func ExamplePoolOpenAll() {
// Lets open handles to all active pools on system