mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
c0ea69411b
This builds on the PCI support to enable the discovery of USB devices. This is primarily intended to be used for the discovery of Edge-based heterogeneous accelerators that are connected via USB, such as the Coral USB Accelerator and the Intel NCS2 - our main motivation for adding this capability to NFD, and as part of our work in the SODALITE H2020 project. USB devices may define their base class at either the device or interface levels. In the case where no device class is set, the per-device interfaces are enumerated instead. USB devices may furthermore have multiple interfaces, which may or may not use the identical class across each interface. We therefore report device existence for each unique class definition to enable more fine-grained labelling and node selection. The default labelling format includes the class, vendor and device (product) IDs, as follows: feature.node.kubernetes.io/usb-fe_1a6e_089a.present=true As with PCI, a subset of device classes are whitelisted for matching. By default, there are only a subset of device classes under which accelerators tend to be mapped, which is used as the basis for the whitelist. These are: - Video - Miscellaneous - Application Specific - Vendor Specific For those interested in matching other classes, this may be extended by using the UsbId rule provided through the custom source. A full list of class codes is provided by the USB-IF at: https://www.usb.org/defined-class-codes For the moment, owing to a lack of a demonstrable use case, neither the subclass nor the protocol information are exposed. If this becomes necessary, support for these attributes can be trivially added. Signed-off-by: Paul Mundt <paul.mundt@adaptant.io>
81 lines
2.9 KiB
Go
81 lines
2.9 KiB
Go
/*
|
|
Copyright 2019 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 main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
)
|
|
|
|
var allSources = []string{"cpu", "custom", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system", "usb"}
|
|
|
|
func TestArgsParse(t *testing.T) {
|
|
Convey("When parsing command line arguments", t, func() {
|
|
Convey("When --no-publish and --oneshot flags are passed", func() {
|
|
args, err := argsParse([]string{"--no-publish", "--oneshot"})
|
|
|
|
Convey("noPublish is set and args.sources is set to the default value", func() {
|
|
So(args.SleepInterval, ShouldEqual, 60*time.Second)
|
|
So(args.NoPublish, ShouldBeTrue)
|
|
So(args.Oneshot, ShouldBeTrue)
|
|
So(args.Sources, ShouldResemble, allSources)
|
|
So(len(args.LabelWhiteList), ShouldEqual, 0)
|
|
So(err, ShouldBeNil)
|
|
})
|
|
})
|
|
|
|
Convey("When --sources flag is passed and set to some values, --sleep-inteval is specified", func() {
|
|
args, err := argsParse([]string{"--sources=fake1,fake2,fake3", "--sleep-interval=30s"})
|
|
|
|
Convey("args.sources is set to appropriate values", func() {
|
|
So(args.SleepInterval, ShouldEqual, 30*time.Second)
|
|
So(args.NoPublish, ShouldBeFalse)
|
|
So(args.Oneshot, ShouldBeFalse)
|
|
So(args.Sources, ShouldResemble, []string{"fake1", "fake2", "fake3"})
|
|
So(len(args.LabelWhiteList), ShouldEqual, 0)
|
|
So(err, ShouldBeNil)
|
|
})
|
|
})
|
|
|
|
Convey("When --label-whitelist flag is passed and set to some value", func() {
|
|
args, err := argsParse([]string{"--label-whitelist=.*rdt.*"})
|
|
|
|
Convey("args.labelWhiteList is set to appropriate value and args.sources is set to default value", func() {
|
|
So(args.NoPublish, ShouldBeFalse)
|
|
So(args.Sources, ShouldResemble, allSources)
|
|
So(args.LabelWhiteList, ShouldResemble, ".*rdt.*")
|
|
So(err, ShouldBeNil)
|
|
})
|
|
})
|
|
|
|
Convey("When valid args are specified", func() {
|
|
args, err := argsParse([]string{"--no-publish", "--sources=fake1,fake2,fake3", "--ca-file=ca", "--cert-file=crt", "--key-file=key"})
|
|
|
|
Convey("--no-publish is set and args.sources is set to appropriate values", func() {
|
|
So(args.NoPublish, ShouldBeTrue)
|
|
So(args.CaFile, ShouldEqual, "ca")
|
|
So(args.CertFile, ShouldEqual, "crt")
|
|
So(args.KeyFile, ShouldEqual, "key")
|
|
So(args.Sources, ShouldResemble, []string{"fake1", "fake2", "fake3"})
|
|
So(len(args.LabelWhiteList), ShouldEqual, 0)
|
|
So(err, ShouldBeNil)
|
|
})
|
|
})
|
|
})
|
|
}
|