Files
my-rook-config/pkg/operator/ceph/config/keyring/store_test.go
T
Sébastien Han 93b2448619 ceph: refactor rgw bootstrap
This commit does multiple things:

* remove support for AllNodes where we would deploy one rgw per node on
all the nodes.
* a transition path is implemented in the code so that if someone has an
existing deployment, daemonsets will be removed and replaced by an
deployments.
* when using "instances", each rgw deployed has its own key which makes
Ceph reporting the exact number of rgw running, see:

```
[root@rook-ceph-operator-775cf575c5-bh4sr /]# ceph -s
  cluster:
    id:     611fcf39-0669-4864-9a12-debb35c0397a
    health: HEALTH_OK

  services:
    mon: 3 daemons, quorum a,b,c (age 12h)
    mgr: a(active, since 12h)
    osd: 3 osds: 3 up (since 12h), 3 in (since 12h)
    rgw: 3 daemons active (my.store.a, my.store.b, my.store.c)

  data:
    pools:   6 pools, 600 pgs
    objects: 235 objects, 3.8 KiB
    usage:   3.0 GiB used, 84 GiB / 87 GiB avail
    pgs:     600 active+clean
```

Closes: https://github.com/rook/rook/issues/2474, https://github.com/rook/rook/issues/2957 and https://github.com/rook/rook/issues/3245
Signed-off-by: Sébastien Han <seb@redhat.com>
2019-06-14 17:55:15 +02:00

133 lines
4.1 KiB
Go

/*
Copyright 2019 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 keyring
import (
"fmt"
"path"
"testing"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/operator/k8sutil"
testop "github.com/rook/rook/pkg/operator/test"
exectest "github.com/rook/rook/pkg/util/exec/test"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestGenerateKey(t *testing.T) {
clientset := testop.New(1)
var generateKey = ""
var failGenerateKey = false
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutputFile: func(debug bool, actionName string, command string, outFileArg string, args ...string) (string, error) {
if failGenerateKey {
return "", fmt.Errorf("test error")
}
return "{\"key\": \"" + generateKey + "\"}", nil
},
}
ctx := &clusterd.Context{
Clientset: clientset,
Executor: executor,
}
ns := "rook-ceph"
owner := metav1.OwnerReference{}
s := GetSecretStore(ctx, ns, &owner)
generateKey = "generatedsecretkey"
failGenerateKey = false
k, e := s.GenerateKey("testuser", []string{"test", "access"})
assert.NoError(t, e)
assert.Equal(t, "generatedsecretkey", k)
generateKey = "differentsecretkey"
failGenerateKey = false
k, e = s.GenerateKey("testuser", []string{"test", "access"})
assert.NoError(t, e)
assert.Equal(t, "differentsecretkey", k)
// make sure error on fail
generateKey = "failgeneratekey"
failGenerateKey = true
_, e = s.GenerateKey("newuser", []string{"new", "access"})
assert.Error(t, e)
}
func TestKeyringStore(t *testing.T) {
clientset := testop.New(1)
ctx := &clusterd.Context{
Clientset: clientset,
}
ns := "rook-ceph"
owner := metav1.OwnerReference{}
k := GetSecretStore(ctx, ns, &owner)
assertKeyringData := func(keyringName, expectedKeyring string) {
s, e := clientset.CoreV1().Secrets(ns).Get(keyringName, metav1.GetOptions{})
assert.NoError(t, e)
assert.Equal(t, 1, len(s.StringData))
assert.Equal(t, expectedKeyring, s.StringData["keyring"])
assert.Equal(t, k8sutil.RookType, string(s.Type))
}
assertDoesNotExist := func(keyringName string) {
_, e := clientset.CoreV1().Secrets(ns).Get(keyringName, metav1.GetOptions{})
assert.True(t, errors.IsNotFound(e))
}
// create first key
k.CreateOrUpdate("test-resource", "qwertyuiop")
assertKeyringData("test-resource-keyring", "qwertyuiop")
// create second key
k.CreateOrUpdate("second-resource", "asdfghjkl")
assertKeyringData("test-resource-keyring", "qwertyuiop")
assertKeyringData("second-resource-keyring", "asdfghjkl")
// update a key
k.CreateOrUpdate("second-resource", "lkjhgfdsa")
assertKeyringData("test-resource-keyring", "qwertyuiop")
assertKeyringData("second-resource-keyring", "lkjhgfdsa")
// delete a key
k.Delete("test-resource")
assertDoesNotExist("test-resource-keyring")
assertKeyringData("second-resource-keyring", "lkjhgfdsa")
}
func TestResourceVolumeAndMount(t *testing.T) {
clientset := testop.New(1)
ctx := &clusterd.Context{
Clientset: clientset,
}
ns := "rook-ceph"
owner := metav1.OwnerReference{}
k := GetSecretStore(ctx, ns, &owner)
k.CreateOrUpdate("test-resource", "qwertyuiop")
k.CreateOrUpdate("second-resource", "asdfgyhujkl")
v := Volume().Resource("test-resource")
m := VolumeMount().Resource("test-resource")
// Test that the secret will make it into containers with the appropriate filename at the
// location where it is expected.
assert.Equal(t, v.Name, m.Name)
assert.Equal(t, "test-resource-keyring", v.VolumeSource.Secret.SecretName)
assert.Equal(t, VolumeMount().KeyringFilePath(), path.Join(m.MountPath, keyringFileName))
}