utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 38 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"
)

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)

CheckPodDeleteState 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 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 Debug

func Debug(format string, data []byte, err error)

Function to log DEBUG logs

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 Err added in v1.0.0

func Err(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 Failf

func Failf(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) (error, map[string]interface{})

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 *v1alpha1.DeviceList, getDeviceApi string, expectedDevice *v1alpha1.Device) ([]v1alpha1.Device, error)

GetDevice to get the device list

func GetDeviceModel added in v1.0.0

func GetDeviceModel(list *v1alpha1.DeviceModelList, getDeviceModelApi string, expectedDeviceModel *v1alpha1.DeviceModel) ([]v1alpha1.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 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, ImageUrl, nodeselector string) bool

HandlePod to handle app deployment/delete using pod spec.

func IncorrectDeviceInstance added in v1.0.0

func IncorrectDeviceInstance() v1alpha1.Device

func IncorrectDeviceModel added in v1.0.0

func IncorrectDeviceModel() v1alpha1.DeviceModel

func Info

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

function for log level

func InfoV2

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

function for log level

func InfoV6

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

function for log level

func Logf

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

Function to generate INFO logs

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) v1alpha1.Device

func NewBluetoothDeviceModel added in v1.0.0

func NewBluetoothDeviceModel() v1alpha1.DeviceModel

func NewConfigMapBluetooth added in v1.0.0

func NewConfigMapBluetooth(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 NewKubeClient added in v0.3.0

func NewKubeClient(apiserver string) *kubernetes.Clientset

NewKubeClient creates kube client from config

func NewLedDeviceInstance added in v1.0.0

func NewLedDeviceInstance(nodeSelector string) v1alpha1.Device

func NewLedDeviceModel added in v1.0.0

func NewLedDeviceModel() v1alpha1.DeviceModel

func NewModbusDeviceInstance added in v1.0.0

func NewModbusDeviceInstance(nodeSelector string) v1alpha1.Device

func NewModbusDeviceModel added in v1.0.0

func NewModbusDeviceModel() v1alpha1.DeviceModel

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 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

func SendHttpRequest(method, reqApi string) (error, *http.Response)

SendHttpRequest Function to prepare the http req and send

func StartEdgeController added in v1.0.0

func StartEdgeController() error

func StartEdgeCore added in v1.0.0

func StartEdgeCore() error

func StartEdgeSite added in v1.0.0

func StartEdgeSite() error

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) v1alpha1.Device

func UpdatedBluetoothDeviceModel added in v1.0.0

func UpdatedBluetoothDeviceModel() v1alpha1.DeviceModel

func UpdatedLedDeviceInstance added in v1.0.0

func UpdatedLedDeviceInstance(nodeSelector string) v1alpha1.Device

func UpdatedLedDeviceModel added in v1.0.0

func UpdatedLedDeviceModel() v1alpha1.DeviceModel

func UpdatedModbusDeviceInstance added in v1.0.0

func UpdatedModbusDeviceInstance(nodeSelector string) v1alpha1.Device

func UpdatedModbusDeviceModel added in v1.0.0

func UpdatedModbusDeviceModel() v1alpha1.DeviceModel

func VerifyDeleteDeployment added in v0.3.0

func VerifyDeleteDeployment(getDeploymentApi string) int

func WaitforPodsRunning added in v0.3.0

func WaitforPodsRunning(apiserver 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"`
}

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