Detect underlying disk mount/unmount (#8408)

This commit is contained in:
Krishna Srinivas
2019-10-25 10:37:53 -07:00
committed by kannappanr
parent 8aaaa46be9
commit 980bf78b4d
13 changed files with 415 additions and 239 deletions
+81 -37
View File
@@ -94,11 +94,20 @@ func newPosixTestSetup() (StorageAPI, string, error) {
return nil, "", err
}
// Initialize a new posix layer.
posixStorage, err := newPosix(diskPath)
storage, err := newPosix(diskPath)
if err != nil {
return nil, "", err
}
return posixStorage, diskPath, nil
err = storage.MakeVol(minioMetaBucket)
if err != nil {
return nil, "", err
}
// Create a sample format.json file
err = storage.WriteAll(minioMetaBucket, formatConfigFile, bytes.NewBufferString(`{"version":"1","format":"xl","id":"592a41c2-b7cc-4130-b883-c4b5cb15965b","xl":{"version":"3","this":"da017d62-70e3-45f1-8a1a-587707e69ad1","sets":[["e07285a6-8c73-4962-89c6-047fb939f803","33b8d431-482d-4376-b63c-626d229f0a29","cff6513a-4439-4dc1-bcaa-56c9e880c352","da017d62-70e3-45f1-8a1a-587707e69ad1","9c9f21d5-1f15-4737-bce6-835faa0d9626","0a59b346-1424-4fc2-9fa2-a2e80541d0c1","7924a3dc-b69a-4971-9a2e-014966d6aebb","4d2b8dd9-4e48-444b-bdca-c89194b26042"]],"distributionAlgo":"CRCMOD"}}`))
if err != nil {
return nil, "", err
}
return &posixDiskIDCheck{storage: storage, diskID: "da017d62-70e3-45f1-8a1a-587707e69ad1"}, diskPath, nil
}
// createPermDeniedFile - creates temporary directory and file with path '/mybucket/myobject'
@@ -303,9 +312,9 @@ func TestPosixReadAll(t *testing.T) {
}
// TestPosixing for faulty disk.
// Setting ioErrCount > maxAllowedIOError.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(6)
p.storage.ioErrCount = int32(6)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -421,9 +430,9 @@ func TestPosixMakeVol(t *testing.T) {
}
for i, testCase := range testCases {
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCount)
p.storage.ioErrCount = int32(testCase.ioErrCount)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -535,11 +544,11 @@ func TestPosixDeleteVol(t *testing.T) {
}
for i, testCase := range testCases {
if posixType, ok := posixStorage.(*posix); ok {
if posixDiskCheck, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCount)
posixDiskCheck.storage.ioErrCount = int32(testCase.ioErrCount)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
t.Errorf("Expected the StorageAPI to be of type *posixDiskIDCheck")
}
if err = posixStorage.DeleteVol(testCase.volName); err != testCase.expectedErr {
t.Fatalf("TestPosix: %d, expected: %s, got: %s", i+1, testCase.expectedErr, err)
@@ -648,9 +657,9 @@ func TestPosixStatVol(t *testing.T) {
for i, testCase := range testCases {
var volInfo VolInfo
// setting ioErrCnt from the test case.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCount)
p.storage.ioErrCount = int32(testCase.ioErrCount)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -689,30 +698,42 @@ func TestPosixListVols(t *testing.T) {
t.Fatalf("Unable to create posix test setup, %s", err)
}
var volInfo []VolInfo
var volInfos []VolInfo
// TestPosix empty list vols.
if volInfo, err = posixStorage.ListVols(); err != nil {
if volInfos, err = posixStorage.ListVols(); err != nil {
t.Fatalf("expected: <nil>, got: %s", err)
} else if len(volInfo) != 0 {
t.Fatalf("expected: [], got: %s", volInfo)
} else if len(volInfos) != 1 {
t.Fatalf("expected: one entry, got: %s", volInfos)
}
// TestPosix non-empty list vols.
if err = posixStorage.MakeVol("success-vol"); err != nil {
t.Fatalf("Unable to create volume, %s", err)
}
if volInfo, err = posixStorage.ListVols(); err != nil {
volInfos, err = posixStorage.ListVols()
if err != nil {
t.Fatalf("expected: <nil>, got: %s", err)
} else if len(volInfo) != 1 {
t.Fatalf("expected: 1, got: %d", len(volInfo))
} else if volInfo[0].Name != "success-vol" {
t.Errorf("expected: success-vol, got: %s", volInfo[0].Name)
}
if len(volInfos) != 2 {
t.Fatalf("expected: 2, got: %d", len(volInfos))
}
volFound := false
for _, info := range volInfos {
if info.Name == "success-vol" {
volFound = true
break
}
}
if !volFound {
t.Errorf("expected: success-vol to be created")
}
// setting ioErrCnt to be > maxAllowedIOError.
// should fail with errFaultyDisk.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(6)
p.storage.ioErrCount = int32(6)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -723,9 +744,9 @@ func TestPosixListVols(t *testing.T) {
os.RemoveAll(path)
// Resetting the IO error.
// should fail with errDiskNotFound.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(0)
p.storage.ioErrCount = int32(0)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -832,9 +853,9 @@ func TestPosixPosixListDir(t *testing.T) {
for i, testCase := range testCases {
var dirList []string
// setting ioErrCnt from the test case.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCnt)
p.storage.ioErrCount = int32(testCase.ioErrCnt)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -986,9 +1007,9 @@ func TestPosixDeleteFile(t *testing.T) {
for i, testCase := range testCases {
// setting ioErrCnt from the test case.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCnt)
p.storage.ioErrCount = int32(testCase.ioErrCnt)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}
@@ -1225,9 +1246,9 @@ func TestPosixReadFile(t *testing.T) {
// TestPosixing for faulty disk.
// setting ioErrCnt to 6.
// should fail with errFaultyDisk.
if posixType, ok := posixStorage.(*posix); ok {
if posixType, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(6)
posixType.storage.ioErrCount = int32(6)
// Common read buffer.
var buf = make([]byte, 10)
_, err = posixType.ReadFile("abc", "yes", 0, buf, nil)
@@ -1312,6 +1333,29 @@ func TestPosixReadFileWithVerify(t *testing.T) {
}
}
// TestPosixFormatFileChange - to test if changing the diskID makes the calls fail.
func TestPosixFormatFileChange(t *testing.T) {
posixStorage, path, err := newPosixTestSetup()
if err != nil {
t.Fatalf("Unable to create posix test setup, %s", err)
}
defer os.RemoveAll(path)
if err = posixStorage.MakeVol(volume); err != nil {
t.Fatalf("MakeVol failed with %s", err)
}
// Change the format.json such that "this" is changed to "randomid".
if err = ioutil.WriteFile(pathJoin(posixStorage.String(), minioMetaBucket, formatConfigFile), []byte(`{"version":"1","format":"xl","id":"592a41c2-b7cc-4130-b883-c4b5cb15965b","xl":{"version":"3","this":"randomid","sets":[["e07285a6-8c73-4962-89c6-047fb939f803","33b8d431-482d-4376-b63c-626d229f0a29","cff6513a-4439-4dc1-bcaa-56c9e880c352","randomid","9c9f21d5-1f15-4737-bce6-835faa0d9626","0a59b346-1424-4fc2-9fa2-a2e80541d0c1","7924a3dc-b69a-4971-9a2e-014966d6aebb","4d2b8dd9-4e48-444b-bdca-c89194b26042"]],"distributionAlgo":"CRCMOD"}}`), 0644); err != nil {
t.Fatalf("ioutil.WriteFile failed with %s", err)
}
err = posixStorage.MakeVol(volume)
if err != errDiskNotFound {
t.Fatalf("MakeVol expected to fail with errDiskNotFound but failed with %s", err)
}
}
// TestPosix posix.AppendFile()
func TestPosixAppendFile(t *testing.T) {
// create posix test setup
@@ -1394,10 +1438,10 @@ func TestPosixAppendFile(t *testing.T) {
// setting ioErrCnt to 6.
// should fail with errFaultyDisk.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(6)
err = posixType.AppendFile("abc", "yes", []byte("hello, world"))
p.storage.ioErrCount = int32(6)
err = p.AppendFile("abc", "yes", []byte("hello, world"))
if err != errFaultyDisk {
t.Fatalf("Expected \"Faulty Disk\", got: \"%s\"", err)
}
@@ -1647,9 +1691,9 @@ func TestPosixRenameFile(t *testing.T) {
for i, testCase := range testCases {
// setting ioErrCnt from the test case.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCnt)
p.storage.ioErrCount = int32(testCase.ioErrCnt)
} else {
t.Fatalf("Expected the StorageAPI to be of type *posix")
}
@@ -1748,9 +1792,9 @@ func TestPosixStatFile(t *testing.T) {
for i, testCase := range testCases {
// setting ioErrCnt from the test case.
if posixType, ok := posixStorage.(*posix); ok {
if p, ok := posixStorage.(*posixDiskIDCheck); ok {
// setting the io error count from as specified in the test case.
posixType.ioErrCount = int32(testCase.ioErrCnt)
p.storage.ioErrCount = int32(testCase.ioErrCnt)
} else {
t.Errorf("Expected the StorageAPI to be of type *posix")
}