mirror of
https://github.com/minio/minio.git
synced 2025-01-25 21:53:16 -05:00
server: Exit gracefully if no endpoint is local to it. (#3442)
This commit is contained in:
parent
46fdd70114
commit
ab49498fc3
@ -17,6 +17,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
@ -360,6 +361,18 @@ func checkServerSyntax(c *cli.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks if any of the endpoints supplied is local to a server instance.
|
||||||
|
func isAnyEndpointLocal(eps []*url.URL) bool {
|
||||||
|
anyLocalEp := false
|
||||||
|
for _, ep := range eps {
|
||||||
|
if isLocalStorage(ep) {
|
||||||
|
anyLocalEp = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return anyLocalEp
|
||||||
|
}
|
||||||
|
|
||||||
// serverMain handler called for 'minio server' command.
|
// serverMain handler called for 'minio server' command.
|
||||||
func serverMain(c *cli.Context) {
|
func serverMain(c *cli.Context) {
|
||||||
if !c.Args().Present() || c.Args().First() == "help" {
|
if !c.Args().Present() || c.Args().First() == "help" {
|
||||||
@ -401,6 +414,11 @@ func serverMain(c *cli.Context) {
|
|||||||
endpoints, err := parseStorageEndpoints(c.Args())
|
endpoints, err := parseStorageEndpoints(c.Args())
|
||||||
fatalIf(err, "Unable to parse storage endpoints %s", c.Args())
|
fatalIf(err, "Unable to parse storage endpoints %s", c.Args())
|
||||||
|
|
||||||
|
// Should exit gracefully if none of the endpoints passed as command line argument is local to this server.
|
||||||
|
if !isAnyEndpointLocal(endpoints) {
|
||||||
|
fatalIf(errors.New("No endpoint is local to this server"), "None of the disks supplied are local to this instance. Please check the disks supplied.")
|
||||||
|
}
|
||||||
|
|
||||||
storageDisks, err := initStorageDisks(endpoints)
|
storageDisks, err := initStorageDisks(endpoints)
|
||||||
fatalIf(err, "Unable to initialize storage disk(s).")
|
fatalIf(err, "Unable to initialize storage disk(s).")
|
||||||
|
|
||||||
|
@ -347,3 +347,32 @@ func TestInitServerConfig(t *testing.T) {
|
|||||||
initServerConfig(ctx)
|
initServerConfig(ctx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tests isAnyEndpointLocal function with inputs such that it returns true and false respectively.
|
||||||
|
func TestIsAnyEndpointLocal(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
disks []string
|
||||||
|
result bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
disks: []string{"http://4.4.4.4/mnt/disk1",
|
||||||
|
"http://4.4.4.4/mnt/disk1"},
|
||||||
|
result: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
disks: []string{"http://localhost/mnt/disk1",
|
||||||
|
"http://localhost/mnt/disk1"},
|
||||||
|
result: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for i, test := range testCases {
|
||||||
|
endpoints, err := parseStorageEndpoints(test.disks)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Test %d - Failed to parse storage endpoints %v", i+1, err)
|
||||||
|
}
|
||||||
|
actual := isAnyEndpointLocal(endpoints)
|
||||||
|
if actual != test.result {
|
||||||
|
t.Errorf("Test %d - Expected %v but received %v", i+1, test.result, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user