mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
852cf4b61d
Specify a new interface for managing "raw" feature data. This is the first step to separate raw feature data from node labels. None of the feature sources implement this interface, yet. This patch unifies the data format of "raw" features by dividing them into three different basic types. - keys, a set of names without any associated values, e.g. CPUID flags or loaded kernel modules - values, a map of key-value pairs, for features with a single value, e.g. kernel config flags or os version - instances, a list of instances each of which has multiple attributes (key-value pairs of their own), e.g. PCI or USB devices The new feature data types are defined in a new "pkg/api/feature" package, catering decoupling and re-usability of code e.g. within future extentions of the NFD gRPC API. Rename the Discover() method of LabelSource interface to GetLabels().
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
/*
|
|
Copyright 2021 The Kubernetes Authors.
|
|
|
|
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 source_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
source "sigs.k8s.io/node-feature-discovery/source"
|
|
|
|
// Register all source packages
|
|
_ "sigs.k8s.io/node-feature-discovery/source/cpu"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/custom"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/fake"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/iommu"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/kernel"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/local"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/memory"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/network"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/pci"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/storage"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/system"
|
|
_ "sigs.k8s.io/node-feature-discovery/source/usb"
|
|
)
|
|
|
|
func TestLabelSources(t *testing.T) {
|
|
sources := source.GetAllLabelSources()
|
|
assert.NotZero(t, len(sources))
|
|
|
|
for n, s := range sources {
|
|
assert.Equalf(t, n, s.Name(), "testing labelsource %q failed", n)
|
|
}
|
|
}
|
|
|
|
func TestConfigurableSources(t *testing.T) {
|
|
sources := source.GetAllConfigurableSources()
|
|
assert.NotZero(t, len(sources))
|
|
|
|
for n, s := range sources {
|
|
assert.Equalf(t, n, s.Name(), "testing ConfigurableSource %q failed", n)
|
|
|
|
c := s.NewConfig()
|
|
s.SetConfig(c)
|
|
rc := s.GetConfig()
|
|
|
|
assert.Equalf(t, c, rc, "testing ConfigurableSource %q failed", n)
|
|
}
|
|
}
|
|
|
|
func TestFeatureSources(t *testing.T) {
|
|
sources := source.GetAllFeatureSources()
|
|
|
|
for n, s := range sources {
|
|
msg := fmt.Sprintf("testing FeatureSource %q failed", n)
|
|
|
|
assert.Equal(t, n, s.Name(), msg)
|
|
|
|
f := s.GetFeatures()
|
|
assert.NotNil(t, f, msg)
|
|
assert.Empty(t, (*f).Keys, msg)
|
|
assert.Empty(t, (*f).Values, msg)
|
|
assert.Empty(t, (*f).Instances, msg)
|
|
}
|
|
}
|