diff --git a/fs-v1.go b/fs-v1.go index 26a8169bb..652e0a4da 100644 --- a/fs-v1.go +++ b/fs-v1.go @@ -81,7 +81,7 @@ func shutdownFS(storage StorageAPI) { // newFSObjects - initialize new fs object layer. func newFSObjects(disk string) (ObjectLayer, error) { storage, err := newStorageAPI(disk) - if err != nil { + if err != nil && err != errDiskNotFound { return nil, err } diff --git a/fs-v1_test.go b/fs-v1_test.go new file mode 100644 index 000000000..49f9e6131 --- /dev/null +++ b/fs-v1_test.go @@ -0,0 +1,39 @@ +/* + * Minio Cloud Storage, (C) 2016 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package main + +import ( + "os" + "path/filepath" + "testing" +) + +// TestNewFS - tests initialization of all input disks +// and constructs a valid `FS` object layer. +func TestNewFS(t *testing.T) { + // Do not attempt to create this path, the test validates + // so that newFSObjects initializes non existing paths + // and successfully returns initialized object layer. + disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix()) + defer removeAll(disk) + + // Initializes single disk, validate if there is no error. + _, err := newFSObjects(disk) + if err != nil { + t.Fatalf("Unable to initialize erasure, %s", err) + } +} diff --git a/posix.go b/posix.go index f482bbca8..ed68fe0e8 100644 --- a/posix.go +++ b/posix.go @@ -101,7 +101,11 @@ func newPosix(diskPath string) (StorageAPI, error) { st, err := os.Stat(preparePath(diskPath)) if err != nil { if os.IsNotExist(err) { - return fs, errDiskNotFound + // Disk not found create it. + if err = os.MkdirAll(diskPath, 0777); err != nil { + return fs, err + } + return fs, nil } return fs, err } diff --git a/test-utils_test.go b/test-utils_test.go index 698c344f6..dc595bbee 100644 --- a/test-utils_test.go +++ b/test-utils_test.go @@ -30,7 +30,9 @@ import ( "os" "regexp" "sort" + "strconv" "strings" + "sync" "testing" "time" "unicode/utf8" @@ -61,6 +63,32 @@ const ( letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits ) +// Random number state. +// We generate random temporary file names so that there's a good +// chance the file doesn't exist yet. +var randN uint32 +var randmu sync.Mutex + +// reseed - returns a new seed everytime the function is called. +func reseed() uint32 { + return uint32(time.Now().UnixNano() + int64(os.Getpid())) +} + +// nextSuffix - provides a new unique suffix everytime the function is called. +func nextSuffix() string { + randmu.Lock() + r := randN + // Initial seed required, generate one. + if r == 0 { + r = reseed() + } + // constants from Numerical Recipes + r = r*1664525 + 1013904223 + randN = r + randmu.Unlock() + return strconv.Itoa(int(1e9 + r%1e9))[1:] +} + // TestServer encapsulates an instantiation of a Minio instance with a temporary backend. // Example usage: // s := StartTestServer(t,"XL") diff --git a/xl-v1.go b/xl-v1.go index b886106e9..3211f8eac 100644 --- a/xl-v1.go +++ b/xl-v1.go @@ -128,7 +128,9 @@ func newXLObjects(disks []string) (ObjectLayer, error) { // Attempt to load all `format.json`. formatConfigs, sErrs := loadAllFormats(storageDisks) - // Generic format check validates all necessary cases. + // Generic format check validates + // if (no quorum) return error + // if (disks not recognized) // Always error. if err := genericFormatCheck(formatConfigs, sErrs); err != nil { return nil, err } diff --git a/xl-v1_test.go b/xl-v1_test.go index c7af8e2d0..a2cf6f1ba 100644 --- a/xl-v1_test.go +++ b/xl-v1_test.go @@ -16,7 +16,11 @@ package main -import "testing" +import ( + "os" + "path/filepath" + "testing" +) // Collection of disks verbatim used for tests. var disks = []string{ @@ -112,3 +116,23 @@ func TestStorageInfo(t *testing.T) { t.Fatalf("Diskinfo total values should be greater 0") } } + +// TestNewXL - tests initialization of all input disks +// and constructs a valid `XL` object +func TestNewXL(t *testing.T) { + var nDisks = 16 // Maximum disks. + var erasureDisks []string + for i := 0; i < nDisks; i++ { + // Do not attempt to create this path, the test validates + // so that newFSObjects initializes non existing paths + // and successfully returns initialized object layer. + disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix()) + erasureDisks = append(erasureDisks, disk) + defer removeAll(disk) + } + // Initializes all erasure disks + _, err := newXLObjects(erasureDisks) + if err != nil { + t.Fatalf("Unable to initialize erasure, %s", err) + } +}