diff options
| author | cl2017 <chenlin.liu@daocloud.io> | 2023-09-21 16:13:04 +0800 |
|---|---|---|
| committer | cl2017 <chenlin.liu@daocloud.io> | 2023-09-22 16:26:49 +0800 |
| commit | 75f9dcc1c1cf73ca04e9b4d1e28e3235314aba3e (patch) | |
| tree | 2d896d112ac3430479852d5a20927052baee0b5f /cloud | |
| parent | device crd v1beta1 edge (diff) | |
| download | kubeedge-75f9dcc1c1cf73ca04e9b4d1e28e3235314aba3e.tar.gz | |
device crd v1beta1 test
Signed-off-by: cl2017 <chenlin.liu@daocloud.io>
Diffstat (limited to 'cloud')
| -rw-r--r-- | cloud/test/integration/crds/validation_test.go | 343 | ||||
| -rw-r--r-- | cloud/test/integration/fixtures/constants.go | 87 | ||||
| -rw-r--r-- | cloud/test/integration/fixtures/device.go | 600 | ||||
| -rw-r--r-- | cloud/test/integration/fixtures/devicemodel.go | 158 |
4 files changed, 0 insertions, 1188 deletions
diff --git a/cloud/test/integration/crds/validation_test.go b/cloud/test/integration/crds/validation_test.go deleted file mode 100644 index e51facdb3..000000000 --- a/cloud/test/integration/crds/validation_test.go +++ /dev/null @@ -1,343 +0,0 @@ -/* -Copyright 2019 The KubeEdge 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 crds - -import ( - "context" - "os" - "testing" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/kubeedge/kubeedge/cloud/pkg/common/client" - "github.com/kubeedge/kubeedge/cloud/test/integration/fixtures" - cloudcoreConfig "github.com/kubeedge/kubeedge/pkg/apis/componentconfig/cloudcore/v1alpha1" - "github.com/kubeedge/kubeedge/pkg/apis/devices/v1alpha2" - crdClientset "github.com/kubeedge/kubeedge/pkg/client/clientset/versioned" -) - -func buildCrdClient(t *testing.T) crdClientset.Interface { - kubeConfigPath := os.Getenv("KUBE_CONFIG") - kubeAPIServerURL := os.Getenv("KUBE_APISERVER_URL") - - client.InitKubeEdgeClient(&cloudcoreConfig.KubeAPIConfig{KubeConfig: kubeConfigPath, Master: kubeAPIServerURL}) - - return client.GetCRDClient() -} - -func TestValidDeviceModel(t *testing.T) { - testNamespace := os.Getenv("TESTNS") - tests := map[string]struct { - deviceModelFn func() *v1alpha2.DeviceModel - }{ - "valid bluetooth device model": { - deviceModelFn: func() *v1alpha2.DeviceModel { - deviceModel := fixtures.NewDeviceModelBluetooth("bluetooth-device-model", testNamespace) - return deviceModel - }, - }, - "valid modbus rtu device model": { - deviceModelFn: func() *v1alpha2.DeviceModel { - deviceModel := fixtures.NewDeviceModelModbus("modbus-device-model", testNamespace) - return deviceModel - }, - }, - "valid opc ua device model": { - deviceModelFn: func() *v1alpha2.DeviceModel { - deviceModel := fixtures.NewDeviceModelOpcUA("opcua-device-model", testNamespace) - return deviceModel - }, - }, - "valid customized protocol device model": { - deviceModelFn: func() *v1alpha2.DeviceModel { - deviceModel := fixtures.NewDeviceModelCustomized("customized-device-model", testNamespace) - return deviceModel - }, - }, - } - - crdClient := buildCrdClient(t) - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - deviceModel := tc.deviceModelFn() - _, err := crdClient.DevicesV1alpha2().DeviceModels(deviceModel.Namespace).Create(context.TODO(), deviceModel, v1.CreateOptions{}) - if err != nil { - t.Fatalf("%s: expected nil err , got %v", name, err) - } - }) - } -} - -func TestInvalidDeviceModel(t *testing.T) { - testNamespace := os.Getenv("TESTNS") - tests := map[string]struct { - deviceModelFn func() *v1alpha2.DeviceModel - }{ - "device model with property no name": { - deviceModelFn: func() *v1alpha2.DeviceModel { - deviceModel := fixtures.DeviceModelWithPropertyNoName("device-model-property-no-name", testNamespace) - return deviceModel - }, - }, - - "device model with property bad access mode": { - deviceModelFn: func() *v1alpha2.DeviceModel { - deviceModel := fixtures.DeviceModelWithPropertyBadAccessMode("model-property-bad-access-mode", testNamespace) - return deviceModel - }, - }, - } - - crdClient := buildCrdClient(t) - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - deviceModel := tc.deviceModelFn() - _, err := crdClient.DevicesV1alpha2().DeviceModels(deviceModel.Namespace).Create(context.TODO(), deviceModel, v1.CreateOptions{}) - if err == nil { - t.Fatalf("%s: expected error", name) - } - }) - } -} - -func TestValidDevice(t *testing.T) { - testNamespace := os.Getenv("TESTNS") - tests := map[string]struct { - deviceInstanceFn func() v1alpha2.Device - }{ - "valid device with modbus rtu protocol": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTU("device-modbus-rtu", testNamespace) - return deviceInstance - }, - }, - "valid device with modbus tcp protocol": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusTCP("device-modbus-tcp", testNamespace) - return deviceInstance - }, - }, - "valid device with opc ua protocol": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceOpcUA("device-opcua", testNamespace) - return deviceInstance - }, - }, - "valid device with customized protocol": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceCustomized("device-customized", testNamespace) - return deviceInstance - }, - }, - } - - crdClient := buildCrdClient(t) - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - device := tc.deviceInstanceFn() - _, err := crdClient.DevicesV1alpha2().Devices(device.Namespace).Create(context.TODO(), &device, v1.CreateOptions{}) - if err != nil { - t.Fatalf("%s expected nil err , got %v", name, err) - } - }) - } -} - -func TestInvalidDevice(t *testing.T) { - testNamespace := os.Getenv("TESTNS") - tests := map[string]struct { - deviceInstanceFn func() v1alpha2.Device - }{ - "device modbus rtu no baud rate": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUNoBaudRate("device-modbus-rtu-no-baud-rate", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu bad baud rate": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUBadBaudRate("device-modbus-rtu-bad-baud-rate", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu no data bits": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUNoDataBits("device-modbus-rtu-no-data-bits", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu bad data bits": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUBadDataBits("device-modbus-rtu-bad-data-bits", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu no parity": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUNoParity("device-modbus-rtu-no-parity", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu bad parity": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUBadParity("device-modbus-rtu-bad-parity", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu no serial port": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUNoSerialPort("device-modbus-rtu-no-serial-port", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu no slave id": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUNoSlaveID("device-modbus-rtu-no-slaveID", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu bad slave id": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUBadSlaveID("device-modbus-bad-slaveID", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu no stop bits": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUNoStopBits("device-modbus-rtu-no-stopbits", testNamespace) - return deviceInstance - }, - }, - "device modbus rtu bad_stop_bits": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusRTUBadStopBits("device-modbus-rtu-bad-stopbits", testNamespace) - return deviceInstance - }, - }, - "device modbus tcp no IP": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusTCPNoIP("device-modbus-tcp-no-IP", testNamespace) - return deviceInstance - }, - }, - "device modbus tcp no port": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusTCPNoPort("device-modbus-tcp-no-port", testNamespace) - return deviceInstance - }, - }, - "device modbus tcp no slaveID": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusTCPNoSlaveID("device-modbus-tcp-no-slaveID", testNamespace) - return deviceInstance - }, - }, - "device opcua no url": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceOpcUANoURL("device-opcua-no-url", testNamespace) - return deviceInstance - }, - }, - "device customized no protocol name": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceCustomizedNoName("device-customized-no-name", testNamespace) - return deviceInstance - }, - }, - "device no model reference": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceNoModelReference("device-no-model-ref", "default") - return deviceInstance - }, - }, - "device with ble protocol property bad operation type": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceBluetoothBadOperationType("device-bluetooth-bad-operation-type", testNamespace) - return deviceInstance - }, - }, - "device with ble protocol property no start index": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceBluetoothNoStartIndex("device-bluetooth-no-start-index", testNamespace) - return deviceInstance - }, - }, - "device with ble protocol property no end index": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceBluetoothNoEndIndex("device-bluetooth-bad-operation-type", testNamespace) - return deviceInstance - }, - }, - "device with ble protocol property no characteristic UUID": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceBluetoothNoCharacteristicUUID("device-bluetooth-no-char-uuid", testNamespace) - return deviceInstance - }, - }, - "device with modbus protocol property bad register": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusBadRegister("device-modbus-bad-register", testNamespace) - return deviceInstance - }, - }, - "device with modbus protocol property no register": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusNoRegister("device-modbus-no-register", testNamespace) - return deviceInstance - }, - }, - "device with modbus protocol property no limit": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusNoLimit("device-modbus-no-limit", testNamespace) - return deviceInstance - }, - }, - "device with ble protocol with no offset": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceModbusNoOffset("device-modbus-no-offset", testNamespace) - return deviceInstance - }, - }, - "device with opc ua property no nodeID": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceOpcUANoNodeID("device-modbus-no-nodeID", testNamespace) - return deviceInstance - }, - }, - "device with customized protocol no configData": { - deviceInstanceFn: func() v1alpha2.Device { - deviceInstance := fixtures.NewDeviceCustomizedNoConfigData("device-customized-no-configdata", testNamespace) - return deviceInstance - }, - }, - } - - crdClient := buildCrdClient(t) - - for name, tc := range tests { - t.Run(name, func(t *testing.T) { - device := tc.deviceInstanceFn() - _, err := crdClient.DevicesV1alpha2().Devices(device.Namespace).Create(context.TODO(), &device, v1.CreateOptions{}) - if err == nil { - t.Fatalf("%s : expected error", name) - } - }) - } -} diff --git a/cloud/test/integration/fixtures/constants.go b/cloud/test/integration/fixtures/constants.go deleted file mode 100644 index 596606cb9..000000000 --- a/cloud/test/integration/fixtures/constants.go +++ /dev/null @@ -1,87 +0,0 @@ -/* -Copyright 2019 The KubeEdge 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 fixtures - -// CRD API Constants -const ( - apiVersion = "devices.kubeedge.io/v1alpha2" - deviceModelKind = "DeviceModel" - deviceKind = "Device" -) - -const ( - ResourceDeviceModel = "devicemodels" - ResourceDevice = "devices" -) - -// Device Model Constants -const ( - devicePropertyTemperature = "temperature" - devicePropertyTemperatureDesc = "temperature in degree celsius" - devicePropertyUnit = "degree celsius" -) - -// Property Vistor Constants -const ( - // time.Duration, nanosecond - reportCycle = 1000000000 - collectCycle = 500000000 -) - -// Device instance constants -const ( - DefaultNamespace = "default" - DeviceModelRef = "sensor-tag-model" -) - -type deviceProtocol string - -// Supported protocols constants -const ( - deviceProtocolBluetooth deviceProtocol = "bluetooth" - deviceProtocolModbus deviceProtocol = "modbus" - deviceProtocolModbusRTU deviceProtocol = "modbusRTU" - deviceProtocolModbusTCP deviceProtocol = "modbusTCP" - deviceProtocolOPCUA deviceProtocol = "opcua" - deviceProtocolCustomized deviceProtocol = "customizedProtocol" -) - -// integer property type constants -const ( - minimum = 0 - maximum = 100 -) - -// Bluetooth Protocol Constants -const ( - characteristicUUID = "f000aa0104514000b000000000000000" - startIndex = 1 - endIndex = 2 - operationValue = 0.03125 - offset = 2 - limit = 1 -) - -// Modbus RTU Protocol Constants -const ( - baudRate = 110 - dataBits = 8 - stopBits = 1 - serialPort = "1" - parity = "none" - slaveID = 100 -) diff --git a/cloud/test/integration/fixtures/device.go b/cloud/test/integration/fixtures/device.go deleted file mode 100644 index 79baa9d36..000000000 --- a/cloud/test/integration/fixtures/device.go +++ /dev/null @@ -1,600 +0,0 @@ -/* -Copyright 2019 The KubeEdge 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 fixtures - -import ( - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" - - "github.com/kubeedge/kubeedge/pkg/apis/devices/v1alpha2" -) - -type DeviceOp struct { - device v1alpha2.Device -} - -type DeviceOption func(*DeviceOp) - -func (op *DeviceOp) applyDeviceOpts(opts []DeviceOption) { - for _, opt := range opts { - opt(op) - } -} - -func newDeviceOp(opts ...DeviceOption) *DeviceOp { - op := &DeviceOp{ - device: v1alpha2.Device{ - Spec: v1alpha2.DeviceSpec{}, - ObjectMeta: metav1.ObjectMeta{}, - TypeMeta: metav1.TypeMeta{ - APIVersion: apiVersion, - Kind: deviceKind, - }, - }, - } - op.applyDeviceOpts(opts) - return op -} - -func withDeviceName(name string) DeviceOption { - return func(op *DeviceOp) { - op.device.ObjectMeta.Name = name - } -} - -func withDeviceNamespace(namespace string) DeviceOption { - return func(op *DeviceOp) { - op.device.ObjectMeta.Namespace = namespace - } -} - -func withDeviceModelReference(deviceModelRef string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.DeviceModelRef = &v1.LocalObjectReference{ - Name: deviceModelRef, - } - } -} - -func withProtocolConfig(protocol deviceProtocol) DeviceOption { - return func(op *DeviceOp) { - switch protocol { - case deviceProtocolModbusRTU: - op.device.Spec.Protocol = v1alpha2.ProtocolConfig{ - Modbus: &v1alpha2.ProtocolConfigModbus{ - SlaveID: pointer.Int64Ptr(1), - }, - Common: &v1alpha2.ProtocolConfigCommon{ - COM: &v1alpha2.ProtocolConfigCOM{}, - }, - } - case deviceProtocolModbusTCP: - op.device.Spec.Protocol = v1alpha2.ProtocolConfig{ - Modbus: &v1alpha2.ProtocolConfigModbus{ - SlaveID: pointer.Int64Ptr(1), - }, - Common: &v1alpha2.ProtocolConfigCommon{ - TCP: &v1alpha2.ProtocolConfigTCP{}, - }, - } - case deviceProtocolBluetooth: - op.device.Spec.Protocol = v1alpha2.ProtocolConfig{ - Bluetooth: &v1alpha2.ProtocolConfigBluetooth{}, - } - case deviceProtocolOPCUA: - op.device.Spec.Protocol = v1alpha2.ProtocolConfig{ - OpcUA: &v1alpha2.ProtocolConfigOpcUA{}, - } - case deviceProtocolCustomized: - op.device.Spec.Protocol = v1alpha2.ProtocolConfig{ - CustomizedProtocol: &v1alpha2.ProtocolConfigCustomized{}, - } - default: - } - } -} - -func withBaudRate(baudRate int64) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.COM.BaudRate = baudRate - } -} - -func withDataBits(dataBits int64) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.COM.DataBits = dataBits - } -} - -func withParity(parity string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.COM.Parity = parity - } -} - -func withSerialPort(serialPort string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.COM.SerialPort = serialPort - } -} - -func withStopBits(stopBits int64) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.COM.StopBits = stopBits - } -} - -func withSlaveID(slaveID int64) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Modbus.SlaveID = &slaveID - } -} - -func withTCPPort(port int64) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.TCP.Port = port - } -} - -func withTCPSlaveID(tcpSlaveID int64) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Modbus.SlaveID = &tcpSlaveID - } -} - -func withTCPServerIP(ip string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Common.TCP.IP = ip - } -} - -func withOPCUAServerURL(url string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.OpcUA.URL = url - } -} - -func withBluetoothMac(mac string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.Bluetooth.MACAddress = mac - } -} - -func withCustromizedProtocolName(name string) DeviceOption { - return func(op *DeviceOp) { - op.device.Spec.Protocol.CustomizedProtocol.ProtocolName = name - } -} - -type DevicePropertyVisitorOp struct { - devicePropertyVisitor v1alpha2.DevicePropertyVisitor -} - -type DevicePropertyVisitorOption func(*DevicePropertyVisitorOp) - -func withVisitorName(name string) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.PropertyName = name - } -} - -func withVisitorReportCycle(reportCycle int64) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.ReportCycle = reportCycle - } -} - -func withVisitorCollectCycle(collectCycle int64) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.CollectCycle = collectCycle - } -} - -func withVisitorConfig(protocol deviceProtocol) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - switch protocol { - case deviceProtocolBluetooth: - op.devicePropertyVisitor.VisitorConfig = v1alpha2.VisitorConfig{ - Bluetooth: &v1alpha2.VisitorConfigBluetooth{ - CharacteristicUUID: "", - BluetoothDataConverter: v1alpha2.BluetoothReadConverter{}, - }, - } - case deviceProtocolModbus: - op.devicePropertyVisitor.VisitorConfig = v1alpha2.VisitorConfig{ - Modbus: &v1alpha2.VisitorConfigModbus{}, - } - case deviceProtocolOPCUA: - op.devicePropertyVisitor.VisitorConfig = v1alpha2.VisitorConfig{ - OpcUA: &v1alpha2.VisitorConfigOPCUA{}, - } - case deviceProtocolCustomized: - op.devicePropertyVisitor.VisitorConfig = v1alpha2.VisitorConfig{ - CustomizedProtocol: &v1alpha2.VisitorConfigCustomized{}, - } - default: - } - } -} - -func withCharacteristicUUID(characteristicUUID string) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.Bluetooth.CharacteristicUUID = characteristicUUID - } -} - -func withStartIndex(startIndex int) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.Bluetooth.BluetoothDataConverter.StartIndex = startIndex - } -} - -func withEndIndex(endIndex int) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.Bluetooth.BluetoothDataConverter.EndIndex = endIndex - } -} - -func withOperation(operationType v1alpha2.BluetoothArithmeticOperationType, value float64) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - bluetoothOperation := v1alpha2.BluetoothOperations{ - BluetoothOperationType: operationType, - BluetoothOperationValue: value, - } - op.devicePropertyVisitor.VisitorConfig.Bluetooth.BluetoothDataConverter.OrderOfOperations = - append(op.devicePropertyVisitor.VisitorConfig.Bluetooth.BluetoothDataConverter.OrderOfOperations, bluetoothOperation) - } -} - -func withRegister(register v1alpha2.ModbusRegisterType) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.Modbus.Register = register - } -} - -func withOffset(offset int64) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.Modbus.Offset = &offset - } -} - -func withLimit(limit int64) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.Modbus.Limit = &limit - } -} - -func withNodeID(nodeID string) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.OpcUA.NodeID = nodeID - } -} - -func withBrowseName(browseName string) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.OpcUA.BrowseName = browseName - } -} - -func withProtocolName(protocolName string) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.CustomizedProtocol.ProtocolName = protocolName - } -} - -func withProtocolConfigData(configData *v1alpha2.CustomizedValue) DevicePropertyVisitorOption { - return func(op *DevicePropertyVisitorOp) { - op.devicePropertyVisitor.VisitorConfig.CustomizedProtocol.ConfigData = configData - } -} - -func (op *DevicePropertyVisitorOp) applyDevicePropVisitorOpts(opts []DevicePropertyVisitorOption) { - for _, opt := range opts { - opt(op) - } -} - -func newDevicePropVisitorOp(opts ...DevicePropertyVisitorOption) *DevicePropertyVisitorOp { - op := &DevicePropertyVisitorOp{ - devicePropertyVisitor: v1alpha2.DevicePropertyVisitor{}, - } - op.applyDevicePropVisitorOpts(opts) - return op -} - -func NewDeviceModbusRTU(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUNoBaudRate(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withDataBits(dataBits), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUBadBaudRate(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(100), withDataBits(dataBits), withParity(parity), - withSerialPort(serialPort), withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUNoDataBits(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUBadDataBits(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(10), withParity(parity), - withSerialPort(serialPort), withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUNoParity(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(10), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUBadParity(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity("test"), - withSerialPort(serialPort), withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUNoSerialPort(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), - withStopBits(stopBits), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUNoSlaveID(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), - withSerialPort(serialPort), withStopBits(stopBits)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUBadSlaveID(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), - withSerialPort(serialPort), withStopBits(stopBits), withSlaveID(300)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUNoStopBits(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), - withSerialPort(serialPort), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusRTUBadStopBits(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), - withSerialPort(serialPort), withStopBits(3), withSlaveID(slaveID)) - return deviceInstanceOp.device -} - -func NewDeviceModbusTCP(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusTCP), withTCPServerIP("127.0.0.1"), withTCPPort(8080), withTCPSlaveID(1)) - return deviceInstanceOp.device -} - -func NewDeviceModbusTCPNoIP(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusTCP), withTCPPort(8080), withTCPSlaveID(1)) - return deviceInstanceOp.device -} - -func NewDeviceModbusTCPNoPort(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusTCP), withTCPServerIP("127.0.0.1"), withTCPSlaveID(1)) - return deviceInstanceOp.device -} - -func NewDeviceModbusTCPNoSlaveID(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusTCP), withTCPPort(8080), withTCPServerIP("127.0.0.1")) - return deviceInstanceOp.device -} - -func NewDeviceOpcUA(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolOPCUA), withOPCUAServerURL("http://test-opcuaserver.com")) - return deviceInstanceOp.device -} - -func NewDeviceOpcUANoURL(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolOPCUA)) - return deviceInstanceOp.device -} - -func NewDeviceCustomized(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolCustomized), withCustromizedProtocolName("test-customized-protocol")) - return deviceInstanceOp.device -} - -func NewDeviceCustomizedNoName(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolCustomized)) - return deviceInstanceOp.device -} - -func NewDeviceNoModelReference(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withProtocolConfig(deviceProtocolOPCUA)) - return deviceInstanceOp.device -} - -func NewDeviceBluetoothBadOperationType(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolBluetooth), withBluetoothMac("BC:6A:29:AE:CC:96")) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolBluetooth), - withCharacteristicUUID(characteristicUUID), withStartIndex(startIndex), withEndIndex(endIndex), - withOperation("modulo", operationValue)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceBluetoothNoStartIndex(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolBluetooth), withBluetoothMac("BC:6A:29:AE:CC:96")) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolBluetooth), - withCharacteristicUUID(characteristicUUID), withEndIndex(endIndex), withOperation(v1alpha2.BluetoothAdd, operationValue)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceBluetoothNoEndIndex(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolBluetooth), withBluetoothMac("BC:6A:29:AE:CC:96")) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolBluetooth), - withCharacteristicUUID(characteristicUUID), withStartIndex(startIndex), withOperation(v1alpha2.BluetoothMultiply, operationValue)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceBluetoothNoCharacteristicUUID(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolBluetooth), withBluetoothMac("BC:6A:29:AE:CC:96")) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolBluetooth), - withStartIndex(startIndex), withEndIndex(endIndex), withOperation(v1alpha2.BluetoothAdd, operationValue)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceModbusBadRegister(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolModbus), - withRegister("test-register"), withLimit(limit), withOffset(offset)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceModbusNoLimit(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolModbus), - withRegister(v1alpha2.ModbusRegisterTypeCoilRegister), withOffset(offset)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceModbusNoOffset(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolModbus), - withRegister(v1alpha2.ModbusRegisterTypeCoilRegister), withLimit(limit)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceModbusNoRegister(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolModbusRTU), withBaudRate(baudRate), withDataBits(dataBits), withParity(parity), withSerialPort(serialPort), - withStopBits(stopBits), withSlaveID(slaveID)) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolModbus), - withLimit(limit), withOffset(offset)) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceOpcUANoNodeID(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolOPCUA), withOPCUAServerURL("http://test-opcuaserver.com")) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolOPCUA), - withBrowseName("test")) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} - -func NewDeviceCustomizedNoConfigData(name string, namespace string) v1alpha2.Device { - deviceInstanceOp := newDeviceOp(withDeviceName(name), withDeviceNamespace(namespace), withDeviceModelReference(DeviceModelRef), - withProtocolConfig(deviceProtocolCustomized), withCustromizedProtocolName("test-customized-protocol")) - - devicePropertyVisitorOp := newDevicePropVisitorOp(withVisitorName(devicePropertyTemperature), - withVisitorCollectCycle(collectCycle), - withVisitorReportCycle(reportCycle), - withVisitorConfig(deviceProtocolCustomized), - withProtocolName("test")) - deviceInstanceOp.device.Spec.PropertyVisitors = append(deviceInstanceOp.device.Spec.PropertyVisitors, devicePropertyVisitorOp.devicePropertyVisitor) - - return deviceInstanceOp.device -} diff --git a/cloud/test/integration/fixtures/devicemodel.go b/cloud/test/integration/fixtures/devicemodel.go deleted file mode 100644 index 77ee7e462..000000000 --- a/cloud/test/integration/fixtures/devicemodel.go +++ /dev/null @@ -1,158 +0,0 @@ -/* -Copyright 2019 The KubeEdge 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 fixtures - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "github.com/kubeedge/kubeedge/pkg/apis/devices/v1alpha2" -) - -type DevicePropertyOp struct { - deviceProperty v1alpha2.DeviceProperty -} - -type DevicePropertyOption func(*DevicePropertyOp) - -func withName(name string) DevicePropertyOption { - return func(op *DevicePropertyOp) { - op.deviceProperty.Name = name - } -} - -func withDescription(description string) DevicePropertyOption { - return func(op *DevicePropertyOp) { - op.deviceProperty.Description = description - } -} - -func withStringType(accessMode v1alpha2.PropertyAccessMode, defaultValue string) DevicePropertyOption { - return func(op *DevicePropertyOp) { - stringType := &v1alpha2.PropertyTypeString{ - DefaultValue: defaultValue, - } - stringType.AccessMode = accessMode - op.deviceProperty.Type = v1alpha2.PropertyType{ - String: stringType, - } - } -} - -func withIntType(accessMode v1alpha2.PropertyAccessMode, defaultValue int64, minimum int64, maximum int64, unit string) DevicePropertyOption { - return func(op *DevicePropertyOp) { - intType := &v1alpha2.PropertyTypeInt64{ - DefaultValue: defaultValue, - Minimum: minimum, - Maximum: maximum, - Unit: unit, - } - intType.AccessMode = accessMode - op.deviceProperty.Type = v1alpha2.PropertyType{ - Int: intType, - } - } -} - -func (op *DevicePropertyOp) applyDevicePropertyOpts(opts []DevicePropertyOption) { - for _, opt := range opts { - opt(op) - } -} - -func newDevicePropertyOp(opts ...DevicePropertyOption) *DevicePropertyOp { - op := &DevicePropertyOp{ - deviceProperty: v1alpha2.DeviceProperty{}, - } - op.applyDevicePropertyOpts(opts) - return op -} - -func newDeviceModel(name string, namespace string) *v1alpha2.DeviceModel { - spec := v1alpha2.DeviceModelSpec{} - deviceModel := &v1alpha2.DeviceModel{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - TypeMeta: metav1.TypeMeta{ - APIVersion: apiVersion, - Kind: deviceModelKind, - }, - Spec: spec, - } - return deviceModel -} - -func DeviceModelWithPropertyNoName(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withDescription(devicePropertyTemperatureDesc), - withStringType(v1alpha2.ReadOnly, "")) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - return deviceModel -} - -func DeviceModelWithPropertyNoType(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withName(devicePropertyTemperature), withDescription(devicePropertyTemperatureDesc)) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - return deviceModel -} - -func DeviceModelWithPropertyBadAccessMode(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withName(devicePropertyTemperature), withDescription(devicePropertyTemperatureDesc), - withStringType("", "")) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - - return deviceModel -} - -func NewDeviceModelBluetooth(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withName(devicePropertyTemperature), withDescription(devicePropertyTemperatureDesc), - withIntType(v1alpha2.ReadOnly, 0, minimum, maximum, devicePropertyUnit)) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - - return deviceModel -} - -func NewDeviceModelModbus(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withName(devicePropertyTemperature), withDescription(devicePropertyTemperatureDesc), - withIntType(v1alpha2.ReadOnly, 0, minimum, maximum, devicePropertyUnit)) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - - return deviceModel -} - -func NewDeviceModelOpcUA(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withName(devicePropertyTemperature), withDescription(devicePropertyTemperatureDesc), - withIntType(v1alpha2.ReadOnly, 0, minimum, maximum, devicePropertyUnit)) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - - return deviceModel -} - -func NewDeviceModelCustomized(name string, namespace string) *v1alpha2.DeviceModel { - deviceModel := newDeviceModel(name, namespace) - devicePropertyOp := newDevicePropertyOp(withName(devicePropertyTemperature), withDescription(devicePropertyTemperatureDesc), - withIntType(v1alpha2.ReadOnly, 0, minimum, maximum, devicePropertyUnit)) - deviceModel.Spec.Properties = append(deviceModel.Spec.Properties, devicePropertyOp.deviceProperty) - - return deviceModel -} |
