Files
my-rook-config/pkg/operator/discover/discover_test.go
T
travisn bdc3cf8146 osd: fix the device filter and improve device provisioning reliability
All devices detected by the discovery pod were being passed to the OSD provisioning pod
thus not always honoring the desired device list that should be provisioned.
Now the provisioning pod will be given the desired state from the crd,
then apply that state depending on the actual devices detected.
Also added a helper to ensure OSDsPerDevice is always valid.

Signed-off-by: travisn <tnielsen@redhat.com>
2019-02-26 16:11:25 -07:00

120 lines
6.0 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 discover to discover devices on storage nodes.
package discover
import (
"os"
"testing"
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
"github.com/rook/rook/pkg/clusterd"
discoverDaemon "github.com/rook/rook/pkg/daemon/discover"
"github.com/rook/rook/pkg/operator/k8sutil"
"github.com/rook/rook/pkg/operator/test"
"github.com/stretchr/testify/assert"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestStartDiscoveryDaemonset(t *testing.T) {
clientset := test.New(3)
os.Setenv(k8sutil.PodNamespaceEnvVar, "rook-system")
defer os.Unsetenv(k8sutil.PodNamespaceEnvVar)
os.Setenv(k8sutil.PodNameEnvVar, "rook-operator")
defer os.Unsetenv(k8sutil.PodNameEnvVar)
namespace := "ns"
a := New(clientset)
// start a basic cluster
err := a.Start(namespace, "rook/rook:myversion", "mysa")
assert.Nil(t, err)
// check daemonset parameters
agentDS, err := clientset.Apps().DaemonSets(namespace).Get("rook-discover", metav1.GetOptions{})
assert.Nil(t, err)
assert.Equal(t, namespace, agentDS.Namespace)
assert.Equal(t, "rook-discover", agentDS.Name)
assert.Equal(t, "mysa", agentDS.Spec.Template.Spec.ServiceAccountName)
assert.True(t, *agentDS.Spec.Template.Spec.Containers[0].SecurityContext.Privileged)
volumes := agentDS.Spec.Template.Spec.Volumes
assert.Equal(t, 3, len(volumes))
volumeMounts := agentDS.Spec.Template.Spec.Containers[0].VolumeMounts
assert.Equal(t, 3, len(volumeMounts))
envs := agentDS.Spec.Template.Spec.Containers[0].Env
assert.Equal(t, 2, len(envs))
image := agentDS.Spec.Template.Spec.Containers[0].Image
assert.Equal(t, "rook/rook:myversion", image)
assert.Nil(t, agentDS.Spec.Template.Spec.Tolerations)
}
func TestGetAvailableDevices(t *testing.T) {
clientset := test.New(3)
ns := "rook-system"
nodeName := "node123"
os.Setenv(k8sutil.PodNamespaceEnvVar, ns)
defer os.Unsetenv(k8sutil.PodNamespaceEnvVar)
os.Setenv(k8sutil.PodNameEnvVar, "rook-operator")
defer os.Unsetenv(k8sutil.PodNameEnvVar)
data := make(map[string]string, 1)
data[discoverDaemon.LocalDiskCMData] = `[{"name":"sdd","parent":"","hasChildren":false,"devLinks":"/dev/disk/by-id/scsi-36001405f826bd553d8c4dbf9f41c18be /dev/disk/by-id/wwn-0x6001405f826bd553d8c4dbf9f41c18be /dev/disk/by-path/ip-127.0.0.1:3260-iscsi-iqn.2016-06.world.srv:storage.target01-lun-1","size":10737418240,"uuid":"","serial":"36001405f826bd553d8c4dbf9f41c18be","type":"disk","rotational":true,"readOnly":false,"ownPartition":true,"filesystem":"","vendor":"LIO-ORG","model":"disk02","wwn":"0x6001405f826bd553","wwnVendorExtension":"0x6001405f826bd553d8c4dbf9f41c18be","empty":true},{"name":"sdb","parent":"","hasChildren":false,"devLinks":"/dev/disk/by-id/scsi-3600140577f462d9908b409d94114e042 /dev/disk/by-id/wwn-0x600140577f462d9908b409d94114e042 /dev/disk/by-path/ip-127.0.0.1:3260-iscsi-iqn.2016-06.world.srv:storage.target01-lun-3","size":5368709120,"uuid":"","serial":"3600140577f462d9908b409d94114e042","type":"disk","rotational":true,"readOnly":false,"ownPartition":false,"filesystem":"","vendor":"LIO-ORG","model":"disk04","wwn":"0x600140577f462d99","wwnVendorExtension":"0x600140577f462d9908b409d94114e042","empty":true},{"name":"sdc","parent":"","hasChildren":false,"devLinks":"/dev/disk/by-id/scsi-3600140568c0bd28d4ee43769387c9f02 /dev/disk/by-id/wwn-0x600140568c0bd28d4ee43769387c9f02 /dev/disk/by-path/ip-127.0.0.1:3260-iscsi-iqn.2016-06.world.srv:storage.target01-lun-2","size":5368709120,"uuid":"","serial":"3600140568c0bd28d4ee43769387c9f02","type":"disk","rotational":true,"readOnly":false,"ownPartition":true,"filesystem":"","vendor":"LIO-ORG","model":"disk03","wwn":"0x600140568c0bd28d","wwnVendorExtension":"0x600140568c0bd28d4ee43769387c9f02","empty":true},{"name":"sda","parent":"","hasChildren":false,"devLinks":"/dev/disk/by-id/scsi-36001405fc00c75fb4c243aa9d61987bd /dev/disk/by-id/wwn-0x6001405fc00c75fb4c243aa9d61987bd /dev/disk/by-path/ip-127.0.0.1:3260-iscsi-iqn.2016-06.world.srv:storage.target01-lun-0","size":10737418240,"uuid":"","serial":"36001405fc00c75fb4c243aa9d61987bd","type":"disk","rotational":true,"readOnly":false,"ownPartition":false,"filesystem":"","vendor":"LIO-ORG","model":"disk01","wwn":"0x6001405fc00c75fb","wwnVendorExtension":"0x6001405fc00c75fb4c243aa9d61987bd","empty":true},{"name":"nvme0n1","parent":"","hasChildren":false,"devLinks":"/dev/disk/by-id/nvme-eui.002538c5710091a7","size":512110190592,"uuid":"","serial":"","type":"disk","rotational":false,"readOnly":false,"ownPartition":false,"filesystem":"","vendor":"","model":"","wwn":"","wwnVendorExtension":"","empty":true}]`
cm := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "local-device-" + nodeName,
Namespace: ns,
Labels: map[string]string{
k8sutil.AppAttr: discoverDaemon.AppName,
discoverDaemon.NodeAttr: nodeName,
},
},
Data: data,
}
_, err := clientset.CoreV1().ConfigMaps(ns).Create(cm)
assert.Nil(t, err)
context := &clusterd.Context{
Clientset: clientset,
}
d := []rookalpha.Device{
{
Name: "sdc",
},
{
Name: "foo",
},
}
nodeDevices, err := ListDevices(context, ns, "" /* all nodes */)
assert.Nil(t, err)
assert.Equal(t, 1, len(nodeDevices))
devices, err := GetAvailableDevices(context, nodeName, ns, d, "^sd.", false)
assert.Nil(t, err)
assert.Equal(t, 1, len(devices))
// devices should be in use now, 2nd try gets the same list
devices, err = GetAvailableDevices(context, nodeName, ns, d, "^sd.", false)
assert.Nil(t, err)
assert.Equal(t, 1, len(devices))
}