github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/volume/vmd_test.go (about) 1 // Package volume provides volume (a.k.a. pool of disks) abstraction and methods to configure, store, 2 // and validate the corresponding metadata. AIS volume is built on top of mountpaths (fs package). 3 /* 4 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 5 */ 6 package volume_test 7 8 import ( 9 "reflect" 10 "testing" 11 12 "github.com/NVIDIA/aistore/fs" 13 "github.com/NVIDIA/aistore/tools" 14 "github.com/NVIDIA/aistore/tools/tassert" 15 "github.com/NVIDIA/aistore/volume" 16 ) 17 18 func TestVMD(t *testing.T) { 19 const ( 20 mpathsCnt = 10 21 daemonID = "testDaemonID" 22 ) 23 mpaths := tools.PrepareMountPaths(t, mpathsCnt) 24 defer tools.RemoveMpaths(t, mpaths) 25 26 t.Run("CreateNewVMD", func(t *testing.T) { testVMDCreate(t, mpaths, daemonID) }) 27 t.Run("VMDPersist", func(t *testing.T) { testVMDPersist(t, daemonID) }) 28 } 29 30 func testVMDCreate(t *testing.T, mpaths fs.MPI, daemonID string) { 31 var ( 32 vmd, err = volume.NewFromMPI(daemonID) 33 mpathsCnt = len(mpaths) 34 ) 35 36 tassert.Errorf(t, err == nil, "expected vmd to be created without error") 37 tassert.Errorf(t, vmd.DaemonID == daemonID, "incorrect daemonID, expected %q, got %q", daemonID, vmd.DaemonID) 38 tassert.Errorf(t, len(vmd.Mountpaths) == mpathsCnt, "expected %d mpaths, got %d", mpathsCnt, len(vmd.Mountpaths)) 39 40 for _, dev := range vmd.Mountpaths { 41 _, ok := mpaths[dev.Path] 42 tassert.Errorf(t, ok, "vmd has unknown %q mountpath", dev.Path) 43 } 44 tassert.Errorf(t, len(mpaths) == len(vmd.Mountpaths), 45 "expected mpath set to have size %d, got %d", len(mpaths), len(vmd.Mountpaths)) 46 } 47 48 func testVMDPersist(t *testing.T, daemonID string) { 49 vmd, err := volume.NewFromMPI(daemonID) 50 tassert.CheckFatal(t, err) 51 52 newVMD, err := volume.LoadVMDTest() 53 tassert.Fatalf(t, err == nil, "expected no error while loading VMD") 54 tassert.Errorf(t, newVMD.DaemonID == vmd.DaemonID, 55 "expected VMDs to have same daemon ID. got: %s vs %s", newVMD.DaemonID, vmd.DaemonID) 56 tassert.Errorf(t, reflect.DeepEqual(newVMD.Mountpaths, vmd.Mountpaths), 57 "expected VMDs to be equal. got: %+v vs %+v", newVMD, vmd) 58 }