utils

package
v1.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 4, 2021 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Overview

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.

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.

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.

Index

Constants

View Source
const (
	Namespace             = "default"
	DeviceETPrefix        = "$hw/events/device/"
	TwinETUpdateSuffix    = "/twin/update"
	TwinETGetSuffix       = "/twin/get"
	TwinETGetResultSuffix = "/twin/get/result"

	BlueTooth         = "bluetooth"
	ModBus            = "modbus"
	Led               = "led"
	IncorrectInstance = "incorrect-instance"
	Customized        = "customized"
)
View Source
const (
	RestType     = "rest"
	EventbusType = "eventbus"
)

Variables

View Source
var (
	ProtocolQuic      bool
	ProtocolWebsocket bool
)
View Source
var Client MQTT.Client
View Source
var ClientOpts *MQTT.ClientOptions

Functions

func ApplyLabelToNode added in v0.3.0

func ApplyLabelToNode(apiserver, key, val string) error

func ChangeTwinValue added in v1.0.0

func ChangeTwinValue(updateMessage DeviceTwinUpdate, deviceID string) error

ChangeTwinValue sends the updated twin value to the edge through the MQTT broker

func CheckDeploymentPodDeleteState added in v0.3.0

func CheckDeploymentPodDeleteState(apiserver string, podlist v1.PodList)

CheckDeploymentPodDeleteState function to check the Pod state

func CheckNodeDeleteStatus

func CheckNodeDeleteStatus(nodehandler, nodename string) int

CheckNodeDeleteStatus function to check node delete status

func CheckNodeReadyStatus

func CheckNodeReadyStatus(nodehandler, nodename string) string

CheckNodeReadyStatus function to get node status

func CheckPodDeleteState

func CheckPodDeleteState(apiserver string, podlist v1.PodList)

CheckPodDeleteState function to check the Pod state

func CheckPodRunningState

func CheckPodRunningState(apiserver string, podlist v1.PodList)

CheckPodRunningState function to check the Pod state

func CleanUp added in v1.0.0

func CleanUp(setupType string) error

func CompareConfigMaps added in v1.0.0

func CompareConfigMaps(configMap, expectedConfigMap v1.ConfigMap) bool

CompareConfigMaps is used to compare 2 config maps

func CompareDeviceProfileInConfigMaps added in v1.6.1

func CompareDeviceProfileInConfigMaps(configMap, expectedConfigMap v1.ConfigMap) bool

CompareConfigMaps is used to compare 2 device profile in config maps

func CompareTwin added in v1.0.0

func CompareTwin(deviceTwin map[string]*MsgTwin, expectedDeviceTwin map[string]*MsgTwin) bool

CompareTwin is used to compare 2 device Twins

func CreateServiceObject added in v0.3.0

func CreateServiceObject(name string) *v1.Service

CreateServiceObject function to create a servcice object

func DeRegisterNodeFromMaster

func DeRegisterNodeFromMaster(nodehandler, nodename string) error

DeRegisterNodeFromMaster function to deregister the node from master

func DeleteConfigmap added in v1.0.0

func DeleteConfigmap(apiConfigMap string) int

DeleteConfigmap function to delete configmaps

func DeleteDeployment

func DeleteDeployment(DeploymentAPI, deploymentname string) int

DeleteDeployment to delete deployment

func DeletePods

func DeletePods(apiserver string) (string, int)

DeletePods function to get the pod status and response code

func DeleteSvc added in v0.3.0

func DeleteSvc(svcname string) int

DeleteSvc function to delete service

func DeploySetup added in v1.0.0

func DeploySetup(ctx *TestContext, nodeName, setupType string) error

func Errorf added in v1.6.1

func Errorf(format string, args ...interface{})

function for Error log

func ExposeCloudService added in v0.3.0

func ExposeCloudService(name, serviceHandler string) error

ExposeCloudService function to expose the service for cloud deployment

func Fatalf added in v1.6.1

func Fatalf(format string, args ...interface{})

Funciton to log Filure logs

func GenerateCerts added in v1.0.0

func GenerateCerts() error

GenerateCerts - Generates Cerificates for Edge and Cloud nodes copy to respective folders

func GenerateNodeReqBody

func GenerateNodeReqBody(nodeid, nodeselector string) (map[string]interface{}, error)

GenerateNodeReqBody function to generate the node request body

func GetConfigmap added in v0.3.0

func GetConfigmap(apiConfigMap string) (int, []byte)

GetConfigmap function to get configmaps for respective edgenodes

func GetDeployments

func GetDeployments(list *apps.DeploymentList, getDeploymentAPI string) error

GetDeployments to get the deployments list

func GetDevice added in v1.0.0

func GetDevice(list *v1alpha2.DeviceList, getDeviceAPI string, expectedDevice *v1alpha2.Device) ([]v1alpha2.Device, error)

GetDevice to get the device list

func GetDeviceModel added in v1.0.0

func GetDeviceModel(list *v1alpha2.DeviceModelList, getDeviceModelAPI string, expectedDeviceModel *v1alpha2.DeviceModel) ([]v1alpha2.DeviceModel, error)

GetDeviceModel to get the deviceModel list and verify whether the contents of the device model matches with what is expected

func GetNodes added in v0.3.0

func GetNodes(api string) v1.NodeList

GetNodes function to get configmaps for respective edgenodes

func GetPodState

func GetPodState(apiserver string) (string, int)

GetPodState function to get the pod status and response code

func GetPods

func GetPods(apiserver, label string) (v1.PodList, error)

GetPods function to get the pods from Edged

func GetRandomString

func GetRandomString(length int) string

function to Generate Random string

func GetRuleEndpointList added in v1.6.1

func GetRuleEndpointList(list *rulesv1.RuleEndpointList, getRuleEndpointAPI string, expectedRule *rulesv1.RuleEndpoint) ([]rulesv1.RuleEndpoint, error)

GetRuleEndpointList to get the rule endpoint list and verify whether the contents of the ruleendpoint matches with what is expected

func GetRuleList added in v1.6.1

func GetRuleList(list *rulesv1.RuleList, getRuleAPI string, expectedRule *rulesv1.Rule) ([]rulesv1.Rule, error)

GetRuleList to get the rule list and verify whether the contents of the rule matches with what is expected

func GetServicePort added in v0.3.0

func GetServicePort(cloudName, serviceHandler string) (int32, int32)

GetServicePort function to get the service port created for deployment.

func GetTwin added in v1.0.0

func GetTwin(updateMessage DeviceTwinUpdate, deviceID string) error

GetTwin function is used to get the device twin details from the edge

func HandleConfigmap added in v0.3.0

func HandleConfigmap(configName chan error, operation, confighandler string, IsEdgeCore bool)

HandleConfigmap function to create configmaps for respective edgenodes

func HandleDeployment

func HandleDeployment(IsCloudCore, IsEdgeCore bool, operation, apiserver, UID, ImageURL, nodeselector, configmapname string, replica int) bool

HandleDeployment to handle app deployment/delete deployment.

func HandleDeviceInstance added in v1.0.0

func HandleDeviceInstance(operation string, apiserver string, nodeSelector string, UID string, protocolType string) (bool, int)

HandleDeviceInstance to handle app deployment/delete using pod spec.

func HandleDeviceModel added in v1.0.0

func HandleDeviceModel(operation string, apiserver string, UID string, protocolType string) (bool, int)

HandleDeviceModel to handle app deployment/delete using pod spec.

func HandlePod

func HandlePod(operation string, apiserver string, UID string, pod *v1.Pod) bool

HandlePod to handle app deployment/delete using pod spec.

func HandleRule added in v1.6.1

func HandleRule(operation, apiserver, UID, sourceType, targetType string) (bool, int)

HandleRule to handle rule.

func HandleRuleEndpoint added in v1.6.1

func HandleRuleEndpoint(operation string, apiserver string, UID string, endpointType string) (bool, int)

HandleRuleEndpoint to handle ruleendpoint.

func IncorrectDeviceInstance added in v1.0.0

func IncorrectDeviceInstance() v1alpha2.Device

func IncorrectDeviceModel added in v1.0.0

func IncorrectDeviceModel() v1alpha2.DeviceModel

func Infof added in v1.6.1

func Infof(format string, args ...interface{})

function for log level

func MapLabels

func MapLabels(ls map[string]string) string

MapLabels function add label selector

func MqttClientInit added in v1.0.0

func MqttClientInit(server, clientID, username, password string) *MQTT.ClientOptions

MqttClientInit create mqtt client config

func MqttConnect added in v1.0.0

func MqttConnect() error

MqttConnect function felicitates the MQTT connection

func NewBluetoothDeviceInstance added in v1.0.0

func NewBluetoothDeviceInstance(nodeSelector string) v1alpha2.Device

func NewBluetoothDeviceModel added in v1.0.0

func NewBluetoothDeviceModel() v1alpha2.DeviceModel

func NewConfigMapBluetooth added in v1.0.0

func NewConfigMapBluetooth(nodeSelector string) v12.ConfigMap

func NewConfigMapCustomized added in v1.6.1

func NewConfigMapCustomized(nodeSelector string) v12.ConfigMap

func NewConfigMapLED added in v1.0.0

func NewConfigMapLED(nodeSelector string) v12.ConfigMap

func NewConfigMapModbus added in v1.0.0

func NewConfigMapModbus(nodeSelector string) v12.ConfigMap

func NewCustomizedDeviceInstance added in v1.6.1

func NewCustomizedDeviceInstance(nodeSelector string) v1alpha2.Device

func NewCustomizedDeviceModel added in v1.6.1

func NewCustomizedDeviceModel() v1alpha2.DeviceModel

func NewEventbus2RestRule added in v1.6.1

func NewEventbus2RestRule() *rulesv1.Rule

func NewKubeClient added in v0.3.0

func NewKubeClient(kubeConfigPath string) *kubernetes.Clientset

NewKubeClient creates kube client from config

func NewLedDeviceInstance added in v1.0.0

func NewLedDeviceInstance(nodeSelector string) v1alpha2.Device

func NewLedDeviceModel added in v1.0.0

func NewLedDeviceModel() v1alpha2.DeviceModel

func NewMockInstance added in v1.6.1

func NewMockInstance(nodeSelector string) v1alpha2.Device

NewMockInstance create an instance for mock bluetooth device.

func NewModbusDeviceInstance added in v1.0.0

func NewModbusDeviceInstance(nodeSelector string) v1alpha2.Device

func NewModbusDeviceModel added in v1.0.0

func NewModbusDeviceModel() v1alpha2.DeviceModel

func NewPodObj added in v1.6.1

func NewPodObj(podName, imgURL, nodeselector string) *v1.Pod

func NewRest2EventbusRule added in v1.6.1

func NewRest2EventbusRule() *rulesv1.Rule

func NewRule added in v1.6.1

func NewRule(sourceType, targetType string) *rulesv1.Rule

func NewRuleEndpoint added in v1.6.1

func NewRuleEndpoint(endpointType string) *rulesv1.RuleEndpoint

func OnTwinMessageReceived added in v1.0.0

func OnTwinMessageReceived(client MQTT.Client, message MQTT.Message)

OnTwinMessageReceived callback function which is called when message is received

func PrintCombinedOutput

func PrintCombinedOutput(cmd *exec.Cmd) error

PrintCombinedOutput to show the os command injuction in combined format

func PrintTestcaseNameandStatus

func PrintTestcaseNameandStatus()

Function to print the test case name and status of execution

func PublishMqtt added in v1.6.1

func PublishMqtt(topic, message string) error

func RandomInt

func RandomInt(min, max int) int

func RegisterNodeToMaster

func RegisterNodeToMaster(UID, nodehandler, nodeselector string) error

RegisterNodeToMaster function to register node to master

func SendHTTPRequest added in v1.6.1

func SendHTTPRequest(method, reqAPI string) (*http.Response, error)

SendHTTPRequest Function to prepare the http req and send

func SendMsg added in v1.6.1

func SendMsg(url string, message []byte) (bool, int)

func StartCloudCore added in v1.6.1

func StartCloudCore() error

func StartEchoServer added in v1.6.1

func StartEchoServer() (string, error)

func StartEdgeCore added in v1.0.0

func StartEdgeCore(master, nodeName string) error

func StartEdgeSite added in v1.0.0

func StartEdgeSite() error

func SubscribeMqtt added in v1.6.1

func SubscribeMqtt(topic string) (string, error)

subscribe function subscribes the device twin information through the MQTT broker

func TaintEdgeDeployedNode added in v0.3.0

func TaintEdgeDeployedNode(toTaint bool, taintHandler string) error

func TwinSubscribe added in v1.0.0

func TwinSubscribe(deviceID string)

subscribe function subscribes the device twin information through the MQTT broker

func UpdatedBluetoothDeviceInstance added in v1.0.0

func UpdatedBluetoothDeviceInstance(nodeSelector string) v1alpha2.Device

func UpdatedBluetoothDeviceModel added in v1.0.0

func UpdatedBluetoothDeviceModel() v1alpha2.DeviceModel

func UpdatedConfigMapModbusForDataAndTwins added in v1.6.1

func UpdatedConfigMapModbusForDataAndTwins(nodeSelector string) v12.ConfigMap

func UpdatedLedDeviceInstance added in v1.0.0

func UpdatedLedDeviceInstance(nodeSelector string) v1alpha2.Device

func UpdatedLedDeviceModel added in v1.0.0

func UpdatedLedDeviceModel() v1alpha2.DeviceModel

func UpdatedModbusDeviceInstance added in v1.0.0

func UpdatedModbusDeviceInstance(nodeSelector string) v1alpha2.Device

func UpdatedModbusDeviceModel added in v1.0.0

func UpdatedModbusDeviceModel() v1alpha2.DeviceModel

func VerifyDeleteDeployment added in v0.3.0

func VerifyDeleteDeployment(getDeploymentAPI string) int

func WaitforPodsRunning added in v0.3.0

func WaitforPodsRunning(kubeConfigPath string, podlist v1.PodList, timout time.Duration)

WaitforPodsRunning waits util all pods are in running status or timeout

Types

type BaseMessage added in v1.0.0

type BaseMessage struct {
	EventID   string `json:"event_id"`
	Timestamp int64  `json:"timestamp"`
}

BaseMessage the base struct of event message

type Config

type Config struct {
	AppImageURL                    []string          `json:"image_url"`
	K8SMasterForKubeEdge           string            `json:"k8smasterforkubeedge"`
	Nodes                          map[string]vmSpec `json:"k8snodes"`
	NumOfNodes                     int               `json:"node_num"`
	ImageRepo                      string            `json:"imagerepo"`
	K8SMasterForProvisionEdgeNodes string            `json:"k8smasterforprovisionedgenodes"`
	CloudImageURL                  string            `json:"cloudimageurl"`
	EdgeImageURL                   string            `json:"edgeimageurl"`
	Namespace                      string            `json:"namespace"`
	ControllerStubPort             int               `json:"controllerstubport"`
	Protocol                       string            `json:"protocol"`
	DockerHubUserName              string            `json:"dockerhubusername"`
	DockerHubPassword              string            `json:"dockerhubpassword"`
	MqttEndpoint                   string            `json:"mqttendpoint"`
	KubeConfigPath                 string            `json:"kubeconfigpath"`
	Token                          string            `json:"token"`
}

config.json decode struct

func LoadConfig

func LoadConfig() Config

get config.json path

type DeviceTwinResult added in v1.0.0

type DeviceTwinResult struct {
	BaseMessage
	Twin map[string]*MsgTwin `json:"twin"`
}

DeviceTwinResult device get result

var TwinResult DeviceTwinResult

type DeviceTwinUpdate added in v1.0.0

type DeviceTwinUpdate struct {
	BaseMessage
	Twin map[string]*MsgTwin `json:"twin"`
}

DeviceTwinUpdate the struct of device twin update

type MsgTwin added in v1.0.0

type MsgTwin struct {
	Expected        *TwinValue    `json:"expected,omitempty"`
	Actual          *TwinValue    `json:"actual,omitempty"`
	Optional        *bool         `json:"optional,omitempty"`
	Metadata        *TypeMetadata `json:"metadata,omitempty"`
	ExpectedVersion *TwinVersion  `json:"expected_version,omitempty"`
	ActualVersion   *TwinVersion  `json:"actual_version,omitempty"`
}

MsgTwin the struct of device twin

type TestContext

type TestContext struct {
	Cfg Config
}

Test context struct

func NewTestContext

func NewTestContext(cfg Config) *TestContext

NewTestContext function to build testcontext with provided config.

type TestTimer added in v0.3.0

type TestTimer struct {
	Name      string
	StartTime time.Time
	EndTime   time.Time
}

TestTimer represents a test timer

func (*TestTimer) Duration added in v0.3.0

func (testTimer *TestTimer) Duration() time.Duration

Duration is used to calculate the duration

func (*TestTimer) End added in v0.3.0

func (testTimer *TestTimer) End()

End is used to end the test timer

func (*TestTimer) IsEnded added in v0.3.0

func (testTimer *TestTimer) IsEnded() bool

IsEnded represents if the test timer is ended

func (*TestTimer) PrintResult added in v0.3.0

func (testTimer *TestTimer) PrintResult()

PrintResult prints the result of the test timer

type TestTimerGroup added in v0.3.0

type TestTimerGroup struct {
	// contains filtered or unexported fields
}

TestTimerGroup includes one or more test timers

func NewTestTimerGroup added in v0.3.0

func NewTestTimerGroup() *TestTimerGroup

NewTestTimerGroup creates a new test timer group

func (*TestTimerGroup) GetTestTimers added in v0.3.0

func (group *TestTimerGroup) GetTestTimers() []*TestTimer

GetTestTimers returns test timers

func (*TestTimerGroup) NewTestTimer added in v0.3.0

func (group *TestTimerGroup) NewTestTimer(name string) *TestTimer

NewTestTimer creates a new test timer

func (*TestTimerGroup) PrintResult added in v0.3.0

func (group *TestTimerGroup) PrintResult()

PrintResult prints the results of all test timers.

type Token added in v1.0.0

type Token interface {
	Wait() bool
	WaitTimeout(time.Duration) bool
	Error() error
}

Token interface to validate the MQTT connection.

var TokenClient Token

type TwinValue added in v1.0.0

type TwinValue struct {
	Value    *string        `json:"value,omitempty"`
	Metadata *ValueMetadata `json:"metadata,omitempty"`
}

TwinValue the struct of twin value

type TwinVersion added in v1.0.0

type TwinVersion struct {
	CloudVersion int64 `json:"cloud"`
	EdgeVersion  int64 `json:"edge"`
}

TwinVersion twin version

type TypeMetadata added in v1.0.0

type TypeMetadata struct {
	Type string `json:"type,omitempty"`
}

TypeMetadata the meta of value type

type ValueMetadata added in v1.0.0

type ValueMetadata struct {
	Timestamp int64 `json:"timestamp,omitempty"`
}

ValueMetadata the meta of value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL