Files
my-rook-config/pkg/operator/ceph/object/controller_test.go
T
Sébastien Han d4c48bb293 ceph: expose /var/log/ceph to the host
It's quite convinient to expose /var/log/ceph so that we can decide to
activate logs locally on the machine and see what's going on.
This is only a placeholder when a daemon is stuck crashlooping and we
want to allow administrator to gather log files.
We still do not log on file but this can be activated via a config
option passed to the centralized config option store.

For some daemons, which typically do not store any data (rgw, rbd-mirror
and mds) we had to propagate dataDirHostPath from the cluster spec to
each creation call so that the bindmount can happen.

Fixes: https://github.com/rook/rook/issues/2881
Signed-off-by: Sébastien Han <seb@redhat.com>
2019-04-15 10:47:09 +02:00

194 lines
7.2 KiB
Go

/*
Copyright 2016 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 rgw to manage a rook object store.
package object
import (
"testing"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
cephbeta "github.com/rook/rook/pkg/apis/ceph.rook.io/v1beta1"
rookv1alpha2 "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
rookfake "github.com/rook/rook/pkg/client/clientset/versioned/fake"
"github.com/rook/rook/pkg/clusterd"
testop "github.com/rook/rook/pkg/operator/test"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestObjectStoreChanged(t *testing.T) {
old := cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
new := cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
// nothing changed
assert.False(t, storeChanged(old, new))
// there was a change
new = cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 81, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 80, SecurePort: 444, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 80, SecurePort: 443, Instances: 2, AllNodes: false, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: true, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = cephv1.ObjectStoreSpec{Gateway: cephv1.GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: "mysecret"}}
assert.True(t, storeChanged(old, new))
}
func TestGetObjectStoreObject(t *testing.T) {
// get a current version objectstore object, should return with no error and no migration needed
objectstore, migrationNeeded, err := getObjectStoreObject(&cephv1.CephObjectStore{})
assert.NotNil(t, objectstore)
assert.False(t, migrationNeeded)
assert.Nil(t, err)
// get a legacy version objectstore object, should return with no error and yes migration needed
objectstore, migrationNeeded, err = getObjectStoreObject(&cephbeta.ObjectStore{})
assert.NotNil(t, objectstore)
assert.True(t, migrationNeeded)
assert.Nil(t, err)
// try to get an object that isn't a objectstore, should return with an error
objectstore, migrationNeeded, err = getObjectStoreObject(&map[string]string{})
assert.Nil(t, objectstore)
assert.False(t, migrationNeeded)
assert.NotNil(t, err)
}
func TestMigrateObjectStoreObject(t *testing.T) {
// create a legacy objectstore that will get migrated
legacyObjectStore := &cephbeta.ObjectStore{
ObjectMeta: metav1.ObjectMeta{
Name: "legacy-objectstore-861",
Namespace: "rook-267",
},
}
// create fake core and rook clientsets and a objectstore controller
clientset := testop.New(3)
context := &clusterd.Context{
Clientset: clientset,
RookClientset: rookfake.NewSimpleClientset(legacyObjectStore),
}
info := testop.CreateConfigDir(1)
controller := NewObjectStoreController(info, context, "", cephv1.CephVersionSpec{}, false, metav1.OwnerReference{}, "/var/lib/rook/")
// convert the legacy objectstore object in memory and assert that a migration is needed
convertedObjectStore, migrationNeeded, err := getObjectStoreObject(legacyObjectStore)
assert.NotNil(t, convertedObjectStore)
assert.True(t, migrationNeeded)
assert.Nil(t, err)
// perform the migration of the converted legacy objectstore
err = controller.migrateObjectStoreObject(convertedObjectStore, legacyObjectStore)
assert.Nil(t, err)
// assert that a current objectstore object was created via the migration
migratedObjectStore, err := context.RookClientset.CephV1().CephObjectStores(legacyObjectStore.Namespace).Get(
legacyObjectStore.Name, metav1.GetOptions{})
assert.NotNil(t, migratedObjectStore)
assert.Nil(t, err)
// assert that the legacy objectstore object was deleted
_, err = context.RookClientset.CephV1beta1().ObjectStores(legacyObjectStore.Namespace).Get(legacyObjectStore.Name, metav1.GetOptions{})
assert.NotNil(t, err)
assert.True(t, errors.IsNotFound(err))
}
func TestConvertLegacyObjectStore(t *testing.T) {
legacyObjectStore := cephbeta.ObjectStore{
ObjectMeta: metav1.ObjectMeta{
Name: "legacy-objectstore-3545",
Namespace: "rook-96874",
},
Spec: cephbeta.ObjectStoreSpec{
MetadataPool: cephbeta.PoolSpec{
FailureDomain: "fd1",
Replicated: cephbeta.ReplicatedSpec{Size: 5},
},
DataPool: cephbeta.PoolSpec{
CrushRoot: "root329",
ErasureCoded: cephbeta.ErasureCodedSpec{
CodingChunks: 5,
DataChunks: 10,
Algorithm: "ec-algorithm-367",
},
},
Gateway: cephbeta.GatewaySpec{
Port: 3093,
SecurePort: 2022,
Instances: 2,
AllNodes: true,
SSLCertificateRef: "my-ssl-cert",
Placement: rookv1alpha2.Placement{
PodAntiAffinity: &v1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
{LabelSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}}},
},
},
},
Resources: v1.ResourceRequirements{Limits: v1.ResourceList{v1.ResourceMemory: resource.MustParse("100Mi")}},
},
},
}
expectedObjectStore := cephv1.CephObjectStore{
ObjectMeta: metav1.ObjectMeta{
Name: "legacy-objectstore-3545",
Namespace: "rook-96874",
},
Spec: cephv1.ObjectStoreSpec{
MetadataPool: cephv1.PoolSpec{
FailureDomain: "fd1",
Replicated: cephv1.ReplicatedSpec{Size: 5},
},
DataPool: cephv1.PoolSpec{
CrushRoot: "root329",
ErasureCoded: cephv1.ErasureCodedSpec{
CodingChunks: 5,
DataChunks: 10,
Algorithm: "ec-algorithm-367",
},
},
Gateway: cephv1.GatewaySpec{
Port: 3093,
SecurePort: 2022,
Instances: 2,
AllNodes: true,
SSLCertificateRef: "my-ssl-cert",
Placement: rookv1alpha2.Placement{
PodAntiAffinity: &v1.PodAntiAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: []v1.PodAffinityTerm{
{LabelSelector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}}},
},
},
},
Resources: v1.ResourceRequirements{Limits: v1.ResourceList{v1.ResourceMemory: resource.MustParse("100Mi")}},
},
},
}
assert.Equal(t, expectedObjectStore, *convertRookLegacyObjectStore(&legacyObjectStore))
}