2016-03-07 08:55:15 +01:00
|
|
|
/*
|
|
|
|
* 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 fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2016-03-08 04:02:36 +01:00
|
|
|
"strconv"
|
2016-03-07 08:55:15 +01:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2016-03-12 07:33:36 +01:00
|
|
|
// The test not just includes asserting the correctness of the output,
|
|
|
|
// But also includes test cases for which the function should fail.
|
|
|
|
// For those cases for which it fails, its also asserted whether the function fails as expected.
|
|
|
|
func TestGetBucketInfo(t *testing.T) {
|
|
|
|
// Make a temporary directory to use as the filesystem.
|
|
|
|
directory, e := ioutil.TempDir("", "minio-metadata-test")
|
|
|
|
if e != nil {
|
|
|
|
t.Fatal(e)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(directory)
|
|
|
|
|
|
|
|
// Create the filesystem.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-13 00:27:10 +01:00
|
|
|
filesystem, err := New(directory)
|
2016-03-12 07:33:36 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creating few buckets.
|
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
err = filesystem.MakeBucket("meta-test-bucket." + strconv.Itoa(i))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
testCases := []struct {
|
|
|
|
bucketName string
|
|
|
|
metaData BucketInfo
|
|
|
|
e error
|
|
|
|
shouldPass bool
|
|
|
|
}{
|
|
|
|
// Test cases with invalid bucket names.
|
|
|
|
{".test", BucketInfo{}, BucketNameInvalid{Bucket: ".test"}, false},
|
|
|
|
{"Test", BucketInfo{}, BucketNameInvalid{Bucket: "Test"}, false},
|
|
|
|
{"---", BucketInfo{}, BucketNameInvalid{Bucket: "---"}, false},
|
|
|
|
{"ad", BucketInfo{}, BucketNameInvalid{Bucket: "ad"}, false},
|
|
|
|
// Test cases with non-existent buckets.
|
|
|
|
{"volatile-bucket-1", BucketInfo{}, BucketNotFound{Bucket: "volatile-bucket-1"}, false},
|
|
|
|
{"volatile-bucket-2", BucketInfo{}, BucketNotFound{Bucket: "volatile-bucket-2"}, false},
|
|
|
|
// Test cases with existing buckets.
|
|
|
|
{"meta-test-bucket.0", BucketInfo{Name: "meta-test-bucket.0"}, nil, true},
|
|
|
|
{"meta-test-bucket.1", BucketInfo{Name: "meta-test-bucket.1"}, nil, true},
|
|
|
|
{"meta-test-bucket.2", BucketInfo{Name: "meta-test-bucket.2"}, nil, true},
|
|
|
|
{"meta-test-bucket.3", BucketInfo{Name: "meta-test-bucket.3"}, nil, true},
|
|
|
|
}
|
|
|
|
for i, testCase := range testCases {
|
2016-03-17 01:30:22 +01:00
|
|
|
// The err returned is of type *probe.Error.
|
2016-03-12 07:33:36 +01:00
|
|
|
bucketInfo, err := filesystem.GetBucketInfo(testCase.bucketName)
|
|
|
|
|
|
|
|
if err != nil && testCase.shouldPass {
|
|
|
|
t.Errorf("Test %d: Expected to pass, but failed with: <ERROR> %s", i+1, err.Cause.Error())
|
|
|
|
}
|
|
|
|
if err == nil && !testCase.shouldPass {
|
|
|
|
t.Errorf("Test %d: Expected to fail with <ERROR> \"%s\", but passed instead", i+1, testCase.e.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
// Failed as expected, but does it fail for the expected reason.
|
|
|
|
if err != nil && !testCase.shouldPass {
|
|
|
|
if testCase.e.Error() != err.Cause.Error() {
|
|
|
|
t.Errorf("Test %d: Expected to fail with error \"%s\", but instead failed with error \"%s\" instead", i+1, testCase.e.Error(), err.Cause.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Since there are cases for which GetBucketInfo fails, this is necessary.
|
|
|
|
// Test passes as expected, but the output values are verified for correctness here.
|
|
|
|
if err == nil && testCase.shouldPass {
|
|
|
|
if testCase.bucketName != bucketInfo.Name {
|
|
|
|
t.Errorf("Test %d: Expected the bucket name to be \"%s\", but found \"%s\" instead", i+1, testCase.bucketName, bucketInfo.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 04:02:36 +01:00
|
|
|
func TestListBuckets(t *testing.T) {
|
|
|
|
// Make a temporary directory to use as the filesystem.
|
2016-03-12 07:33:36 +01:00
|
|
|
directory, e := ioutil.TempDir("", "minio-benchmark")
|
|
|
|
if e != nil {
|
|
|
|
t.Fatal(e)
|
2016-03-08 04:02:36 +01:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(directory)
|
|
|
|
|
|
|
|
// Create the filesystem.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-13 00:27:10 +01:00
|
|
|
filesystem, err := New(directory)
|
2016-03-08 04:02:36 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a few buckets.
|
|
|
|
for i := 0; i < 10; i++ {
|
2016-03-10 11:24:52 +01:00
|
|
|
err = filesystem.MakeBucket("testbucket." + strconv.Itoa(i))
|
2016-03-08 04:02:36 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// List, and ensure that they are all there.
|
|
|
|
metadatas, err := filesystem.ListBuckets()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(metadatas) != 10 {
|
2016-03-10 11:24:52 +01:00
|
|
|
t.Errorf("incorrect length of metadatas (%d)\n", len(metadatas))
|
2016-03-08 04:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over the buckets, ensuring that the name is correct.
|
|
|
|
for i := 0; i < len(metadatas); i++ {
|
|
|
|
if !strings.Contains(metadatas[i].Name, "testbucket") {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:55:15 +01:00
|
|
|
func TestDeleteBucket(t *testing.T) {
|
|
|
|
// Make a temporary directory to use as the filesystem.
|
2016-03-12 07:33:36 +01:00
|
|
|
directory, e := ioutil.TempDir("", "minio-benchmark")
|
|
|
|
if e != nil {
|
|
|
|
t.Fatal(e)
|
2016-03-07 08:55:15 +01:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(directory)
|
|
|
|
|
|
|
|
// Create the filesystem.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-13 00:27:10 +01:00
|
|
|
filesystem, err := New(directory)
|
2016-03-07 08:55:15 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deleting a bucket that doesn't exist should error.
|
|
|
|
err = filesystem.DeleteBucket("bucket")
|
|
|
|
if !strings.Contains(err.Cause.Error(), "Bucket not found:") {
|
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 04:02:36 +01:00
|
|
|
func BenchmarkListBuckets(b *testing.B) {
|
|
|
|
// Make a temporary directory to use as the filesystem.
|
2016-03-12 07:33:36 +01:00
|
|
|
directory, e := ioutil.TempDir("", "minio-benchmark")
|
|
|
|
if e != nil {
|
|
|
|
b.Fatal(e)
|
2016-03-08 04:02:36 +01:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(directory)
|
|
|
|
|
|
|
|
// Create the filesystem.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-13 00:27:10 +01:00
|
|
|
filesystem, err := New(directory)
|
2016-03-08 04:02:36 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a few buckets.
|
|
|
|
for i := 0; i < 20; i++ {
|
2016-03-10 11:24:52 +01:00
|
|
|
err = filesystem.MakeBucket("bucket." + strconv.Itoa(i))
|
2016-03-08 04:02:36 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
// List the buckets over and over and over.
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_, err = filesystem.ListBuckets()
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-07 08:55:15 +01:00
|
|
|
func BenchmarkDeleteBucket(b *testing.B) {
|
|
|
|
// Make a temporary directory to use as the filesystem.
|
2016-03-12 07:33:36 +01:00
|
|
|
directory, e := ioutil.TempDir("", "minio-benchmark")
|
|
|
|
if e != nil {
|
|
|
|
b.Fatal(e)
|
2016-03-07 08:55:15 +01:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(directory)
|
|
|
|
|
|
|
|
// Create the filesystem.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-13 00:27:10 +01:00
|
|
|
filesystem, err := New(directory)
|
2016-03-07 08:55:15 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
// Creating buckets takes time, so stop and start the timer.
|
|
|
|
b.StopTimer()
|
|
|
|
|
|
|
|
// Create and delete the bucket over and over.
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
err = filesystem.MakeBucket("bucket")
|
2016-03-07 08:55:15 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.StartTimer()
|
|
|
|
|
|
|
|
err = filesystem.DeleteBucket("bucket")
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-12 01:31:24 +01:00
|
|
|
func BenchmarkGetBucketInfo(b *testing.B) {
|
2016-03-07 08:55:15 +01:00
|
|
|
// Make a temporary directory to use as the filesystem.
|
2016-03-12 07:33:36 +01:00
|
|
|
directory, e := ioutil.TempDir("", "minio-benchmark")
|
|
|
|
if e != nil {
|
|
|
|
b.Fatal(e)
|
2016-03-07 08:55:15 +01:00
|
|
|
}
|
|
|
|
defer os.RemoveAll(directory)
|
|
|
|
|
|
|
|
// Create the filesystem.
|
config/main: Re-write config files - add to new config v3
- New config format.
```
{
"version": "3",
"address": ":9000",
"backend": {
"type": "fs",
"disk": "/path"
},
"credential": {
"accessKey": "WLGDGYAQYIGI833EV05A",
"secretKey": "BYvgJM101sHngl2uzjXS/OBF/aMxAN06JrJ3qJlF"
},
"region": "us-east-1",
"logger": {
"file": {
"enable": false,
"fileName": "",
"level": "error"
},
"syslog": {
"enable": false,
"address": "",
"level": "debug"
},
"console": {
"enable": true,
"level": "fatal"
}
}
}
```
New command lines in lieu of supporting XL.
Minio initialize filesystem backend.
~~~
$ minio init fs <path>
~~~
Minio initialize XL backend.
~~~
$ minio init xl <url1>...<url16>
~~~
For 'fs' backend it starts the server.
~~~
$ minio server
~~~
For 'xl' backend it waits for servers to join.
~~~
$ minio server
... [PROGRESS BAR] of servers connecting
~~~
Now on other servers execute 'join' and they connect.
~~~
....
minio join <url1> -- from <url2> && minio server
minio join <url1> -- from <url3> && minio server
...
...
minio join <url1> -- from <url16> && minio server
~~~
2016-02-13 00:27:10 +01:00
|
|
|
filesystem, err := New(directory)
|
2016-03-07 08:55:15 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put up a bucket with some metadata.
|
accessPolicy: Implement Put, Get, Delete access policy.
This patch implements Get,Put,Delete bucket policies
Supporting - http://docs.aws.amazon.com/AmazonS3/latest/dev/access-policy-language-overview.html
Currently supports following actions.
"*": true,
"s3:*": true,
"s3:GetObject": true,
"s3:ListBucket": true,
"s3:PutObject": true,
"s3:CreateBucket": true,
"s3:GetBucketLocation": true,
"s3:DeleteBucket": true,
"s3:DeleteObject": true,
"s3:AbortMultipartUpload": true,
"s3:ListBucketMultipartUploads": true,
"s3:ListMultipartUploadParts": true,
following conditions for "StringEquals" and "StringNotEquals"
"s3:prefix", "s3:max-keys"
2016-02-04 01:46:56 +01:00
|
|
|
err = filesystem.MakeBucket("bucket")
|
2016-03-07 08:55:15 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
// Retrieve the metadata!
|
2016-03-12 01:31:24 +01:00
|
|
|
_, err := filesystem.GetBucketInfo("bucket")
|
2016-03-07 08:55:15 +01:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|