Files
my-rook-config/pkg/operator/ceph/file/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

185 lines
6.4 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 mds to manage a rook filesystem.
package file
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"
cephconfig "github.com/rook/rook/pkg/daemon/ceph/config"
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 TestFilesystemChanged(t *testing.T) {
// no change
old := cephv1.FilesystemSpec{MetadataServer: cephv1.MetadataServerSpec{ActiveCount: 1, ActiveStandby: true}}
new := cephv1.FilesystemSpec{MetadataServer: cephv1.MetadataServerSpec{ActiveCount: 1, ActiveStandby: true}}
changed := filesystemChanged(old, new)
assert.False(t, changed)
// changed properties
new = cephv1.FilesystemSpec{MetadataServer: cephv1.MetadataServerSpec{ActiveCount: 2, ActiveStandby: true}}
assert.True(t, filesystemChanged(old, new))
new = cephv1.FilesystemSpec{MetadataServer: cephv1.MetadataServerSpec{ActiveCount: 1, ActiveStandby: false}}
assert.True(t, filesystemChanged(old, new))
}
func TestGetFilesystemObject(t *testing.T) {
// get a current version filesystem object, should return with no error and no migration needed
filesystem, migrationNeeded, err := getFilesystemObject(&cephv1.CephFilesystem{})
assert.NotNil(t, filesystem)
assert.False(t, migrationNeeded)
assert.Nil(t, err)
// get a legacy version filesystem object, should return with no error and yes migration needed
filesystem, migrationNeeded, err = getFilesystemObject(&cephbeta.Filesystem{})
assert.NotNil(t, filesystem)
assert.True(t, migrationNeeded)
assert.Nil(t, err)
// try to get an object that isn't a filesystem, should return with an error
filesystem, migrationNeeded, err = getFilesystemObject(&map[string]string{})
assert.Nil(t, filesystem)
assert.False(t, migrationNeeded)
assert.NotNil(t, err)
}
func TestMigrateFilesystemObject(t *testing.T) {
// create a legacy filesystem that will get migrated
legacyFilesystem := &cephbeta.Filesystem{
ObjectMeta: metav1.ObjectMeta{
Name: "legacy-filesystem-861",
Namespace: "rook-267",
},
}
// create fake core and rook clientsets and a filesystem controller
clientset := testop.New(3)
context := &clusterd.Context{
Clientset: clientset,
RookClientset: rookfake.NewSimpleClientset(legacyFilesystem),
}
clusterInfo := &cephconfig.ClusterInfo{FSID: "myfsid"}
controller := NewFilesystemController(clusterInfo, context, "", cephv1.CephVersionSpec{}, false, metav1.OwnerReference{}, "/var/lib/rook/")
// convert the legacy filesystem object in memory and assert that a migration is needed
convertedFilesystem, migrationNeeded, err := getFilesystemObject(legacyFilesystem)
assert.NotNil(t, convertedFilesystem)
assert.True(t, migrationNeeded)
assert.Nil(t, err)
// perform the migration of the converted legacy filesystem
err = controller.migrateFilesystemObject(convertedFilesystem, legacyFilesystem)
assert.Nil(t, err)
// assert that a current filesystem object was created via the migration
migratedFilesystem, err := context.RookClientset.CephV1().CephFilesystems(legacyFilesystem.Namespace).Get(
legacyFilesystem.Name, metav1.GetOptions{})
assert.NotNil(t, migratedFilesystem)
assert.Nil(t, err)
// assert that the legacy filesystem object was deleted
_, err = context.RookClientset.CephV1beta1().Filesystems(legacyFilesystem.Namespace).Get(legacyFilesystem.Name, metav1.GetOptions{})
assert.NotNil(t, err)
assert.True(t, errors.IsNotFound(err))
}
func TestConvertLegacyFilesystem(t *testing.T) {
legacyFilesystem := cephbeta.Filesystem{
ObjectMeta: metav1.ObjectMeta{
Name: "legacy-filesystem-3215",
Namespace: "rook-6468",
},
Spec: cephbeta.FilesystemSpec{
MetadataPool: cephbeta.PoolSpec{
FailureDomain: "fd1",
Replicated: cephbeta.ReplicatedSpec{Size: 5}},
DataPools: []cephbeta.PoolSpec{
{
CrushRoot: "root32",
ErasureCoded: cephbeta.ErasureCodedSpec{
CodingChunks: 5,
DataChunks: 10,
Algorithm: "ec-algorithm-048",
},
},
},
MetadataServer: cephbeta.MetadataServerSpec{
ActiveCount: 2,
ActiveStandby: true,
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")}},
},
},
}
expectedFilesystem := cephv1.CephFilesystem{
ObjectMeta: metav1.ObjectMeta{
Name: "legacy-filesystem-3215",
Namespace: "rook-6468",
},
Spec: cephv1.FilesystemSpec{
MetadataPool: cephv1.PoolSpec{
FailureDomain: "fd1",
Replicated: cephv1.ReplicatedSpec{Size: 5}},
DataPools: []cephv1.PoolSpec{
{
CrushRoot: "root32",
ErasureCoded: cephv1.ErasureCodedSpec{
CodingChunks: 5,
DataChunks: 10,
Algorithm: "ec-algorithm-048",
},
},
},
MetadataServer: cephv1.MetadataServerSpec{
ActiveCount: 2,
ActiveStandby: true,
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, expectedFilesystem, *convertRookLegacyFilesystem(&legacyFilesystem))
}