In clusters where only two datacenters (or similar failure domains) are available, a different mon and osd approach is needed to deal with the network partitions or some other reason for one of the failure domains going down. The Ceph stretched cluster makes the mons aware of the failure domains by configuring one as the arbiter in a third zone, while keeping two replicas of the data in each of the data zoens. Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
128 lines
4.5 KiB
Go
128 lines
4.5 KiB
Go
/*
|
|
Copyright 2018 The Rook Authors. All rights reserved.
|
|
|
|
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 client
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/rook/rook/pkg/clusterd"
|
|
exectest "github.com/rook/rook/pkg/util/exec/test"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCephArgs(t *testing.T) {
|
|
// cluster a under /etc
|
|
args := []string{}
|
|
clusterInfo := AdminClusterInfo("a")
|
|
command, args := FinalizeCephCommandArgs(CephTool, clusterInfo, args, "/etc")
|
|
assert.Equal(t, CephTool, command)
|
|
assert.Equal(t, 5, len(args))
|
|
assert.Equal(t, "--connect-timeout=15", args[0])
|
|
assert.Equal(t, "--cluster=a", args[1])
|
|
assert.Equal(t, "--conf=/etc/a/a.config", args[2])
|
|
assert.Equal(t, "--name=client.admin", args[3])
|
|
assert.Equal(t, "--keyring=/etc/a/client.admin.keyring", args[4])
|
|
|
|
RunAllCephCommandsInToolbox = true
|
|
args = []string{}
|
|
command, args = FinalizeCephCommandArgs(CephTool, clusterInfo, args, "/etc")
|
|
assert.Equal(t, Kubectl, command)
|
|
assert.Equal(t, 8, len(args), fmt.Sprintf("%+v", args))
|
|
assert.Equal(t, "exec", args[0])
|
|
assert.Equal(t, "-i", args[1])
|
|
assert.Equal(t, "rook-ceph-tools", args[2])
|
|
assert.Equal(t, "-n", args[3])
|
|
assert.Equal(t, clusterInfo.Namespace, args[4])
|
|
assert.Equal(t, "--", args[5])
|
|
assert.Equal(t, CephTool, args[6])
|
|
assert.Equal(t, "--connect-timeout=15", args[7])
|
|
RunAllCephCommandsInToolbox = false
|
|
|
|
// cluster under /var/lib/rook
|
|
args = []string{"myarg"}
|
|
command, args = FinalizeCephCommandArgs(RBDTool, clusterInfo, args, "/var/lib/rook")
|
|
assert.Equal(t, RBDTool, command)
|
|
assert.Equal(t, 5, len(args))
|
|
assert.Equal(t, "myarg", args[0])
|
|
assert.Equal(t, "--cluster="+clusterInfo.Namespace, args[1])
|
|
assert.Equal(t, "--conf=/var/lib/rook/a/a.config", args[2])
|
|
assert.Equal(t, "--name=client.admin", args[3])
|
|
assert.Equal(t, "--keyring=/var/lib/rook/a/client.admin.keyring", args[4])
|
|
}
|
|
|
|
func TestStretchElectionStrategy(t *testing.T) {
|
|
executor := &exectest.MockExecutor{}
|
|
executor.MockExecuteCommandWithOutputFile = func(command, outputFile string, args ...string) (string, error) {
|
|
logger.Infof("Command: %s %v", command, args)
|
|
if args[0] == "mon" && args[1] == "set" && args[2] == "election_strategy" {
|
|
assert.Equal(t, "connectivity", args[3])
|
|
return "", nil
|
|
}
|
|
return "", errors.Errorf("unexpected ceph command %q", args)
|
|
}
|
|
context := &clusterd.Context{Executor: executor}
|
|
clusterInfo := AdminClusterInfo("mycluster")
|
|
|
|
err := EnableStretchElectionStrategy(context, clusterInfo)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestStretchClusterSettings(t *testing.T) {
|
|
monName := "a"
|
|
failureDomain := "rack"
|
|
zone := "rack-x"
|
|
executor := &exectest.MockExecutor{}
|
|
executor.MockExecuteCommandWithOutputFile = func(command, outputFile string, args ...string) (string, error) {
|
|
logger.Infof("Command: %s %v", command, args)
|
|
switch {
|
|
case args[0] == "mon" && args[1] == "set_location":
|
|
assert.Equal(t, monName, args[2])
|
|
assert.Equal(t, fmt.Sprintf("%s=%s", failureDomain, zone), args[3])
|
|
return "", nil
|
|
}
|
|
return "", errors.Errorf("unexpected ceph command %q", args)
|
|
}
|
|
context := &clusterd.Context{Executor: executor}
|
|
clusterInfo := AdminClusterInfo("mycluster")
|
|
|
|
err := SetMonStretchZone(context, clusterInfo, monName, failureDomain, zone)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestStretchClusterMonTiebreaker(t *testing.T) {
|
|
monName := "a"
|
|
failureDomain := "rack"
|
|
executor := &exectest.MockExecutor{}
|
|
executor.MockExecuteCommandWithOutputFile = func(command, outputFile string, args ...string) (string, error) {
|
|
logger.Infof("Command: %s %v", command, args)
|
|
switch {
|
|
case args[0] == "mon" && args[1] == "enable_stretch_mode":
|
|
assert.Equal(t, monName, args[2])
|
|
assert.Equal(t, defaultStretchCrushRuleName, args[3])
|
|
assert.Equal(t, failureDomain, args[4])
|
|
return "", nil
|
|
}
|
|
return "", errors.Errorf("unexpected ceph command %q", args)
|
|
}
|
|
context := &clusterd.Context{Executor: executor}
|
|
clusterInfo := AdminClusterInfo("mycluster")
|
|
|
|
err := SetMonStretchTiebreaker(context, clusterInfo, monName, failureDomain)
|
|
assert.NoError(t, err)
|
|
}
|