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

func ApplyLabelToNode(apiserver, key, val string) error

func ChangeTwinValue

func ChangeTwinValue(updateMessage DeviceTwinUpdate, deviceID string) error

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

func CheckDeploymentPodDeleteState

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

func CleanUp(setupType string) error

func CompareConfigMaps

func CompareConfigMaps(configMap, expectedConfigMap v1.ConfigMap) bool

CompareConfigMaps is used to compare 2 config maps

func CompareTwin

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

CompareTwin is used to compare 2 device Twins

func CreateServiceObject

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

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

func DeleteSvc(svcname string) int

DeleteSvc function to delete service

func DeploySetup

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

func Err

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

function for Error log

func ExposeCloudService

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

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

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

func GetDevice(list *v1alpha1.DeviceList, getDeviceApi string, expectedDevice *v1alpha1.Device) ([]v1alpha1.Device, error)

GetDevice to get the device list

func GetDeviceModel

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

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

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

GetServicePort function to get the service port created for deployment.

func GetTwin

func GetTwin(updateMessage DeviceTwinUpdate, deviceID string) error

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

func HandleConfigmap

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

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

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

func IncorrectDeviceInstance() v1alpha1.Device

func IncorrectDeviceModel

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

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

MqttClientInit create mqtt client config

func MqttConnect

func MqttConnect() error

MqttConnect function felicitates the MQTT connection

func NewBluetoothDeviceInstance

func NewBluetoothDeviceInstance(nodeSelector string) v1alpha1.Device

func NewBluetoothDeviceModel

func NewBluetoothDeviceModel() v1alpha1.DeviceModel

func NewConfigMapBluetooth

func NewConfigMapBluetooth(nodeSelector string) v12.ConfigMap

func NewConfigMapLED

func NewConfigMapLED(nodeSelector string) v12.ConfigMap

func NewConfigMapModbus

func NewConfigMapModbus(nodeSelector string) v12.ConfigMap

func NewKubeClient

func NewKubeClient(apiserver string) *kubernetes.Clientset

NewKubeClient creates kube client from config

func NewLedDeviceInstance

func NewLedDeviceInstance(nodeSelector string) v1alpha1.Device

func NewLedDeviceModel

func NewLedDeviceModel() v1alpha1.DeviceModel

func NewModbusDeviceInstance

func NewModbusDeviceInstance(nodeSelector string) v1alpha1.Device

func NewModbusDeviceModel

func NewModbusDeviceModel() v1alpha1.DeviceModel

func OnTwinMessageReceived

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

func StartEdgeController() error

func StartEdgeCore

func StartEdgeCore() error

func StartEdgeSite

func StartEdgeSite() error

func TaintEdgeDeployedNode

func TaintEdgeDeployedNode(toTaint bool, taintHandler string) error

func TwinSubscribe

func TwinSubscribe(deviceID string)

subscribe function subscribes the device twin information through the MQTT broker

func UpdatedBluetoothDeviceInstance

func UpdatedBluetoothDeviceInstance(nodeSelector string) v1alpha1.Device

func UpdatedBluetoothDeviceModel

func UpdatedBluetoothDeviceModel() v1alpha1.DeviceModel

func UpdatedLedDeviceInstance

func UpdatedLedDeviceInstance(nodeSelector string) v1alpha1.Device

func UpdatedLedDeviceModel

func UpdatedLedDeviceModel() v1alpha1.DeviceModel

func UpdatedModbusDeviceInstance

func UpdatedModbusDeviceInstance(nodeSelector string) v1alpha1.Device

func UpdatedModbusDeviceModel

func UpdatedModbusDeviceModel() v1alpha1.DeviceModel

func VerifyDeleteDeployment

func VerifyDeleteDeployment(getDeploymentApi string) int

func WaitforPodsRunning

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

WaitforPodsRunning waits util all pods are in running status or timeout

Types

type BaseMessage

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

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

DeviceTwinResult device get result

var TwinResult DeviceTwinResult

type DeviceTwinUpdate

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

DeviceTwinUpdate the struct of device twin update

type MsgTwin

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

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

TestTimer represents a test timer

func (*TestTimer) Duration

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

Duration is used to calculate the duration

func (*TestTimer) End

func (testTimer *TestTimer) End()

End is used to end the test timer

func (*TestTimer) IsEnded

func (testTimer *TestTimer) IsEnded() bool

IsEnded represents if the test timer is ended

func (*TestTimer) PrintResult

func (testTimer *TestTimer) PrintResult()

PrintResult prints the result of the test timer

type TestTimerGroup

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

TestTimerGroup includes one or more test timers

func NewTestTimerGroup

func NewTestTimerGroup() *TestTimerGroup

NewTestTimerGroup creates a new test timer group

func (*TestTimerGroup) GetTestTimers

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

GetTestTimers returns test timers

func (*TestTimerGroup) NewTestTimer

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

NewTestTimer creates a new test timer

func (*TestTimerGroup) PrintResult

func (group *TestTimerGroup) PrintResult()

PrintResult prints the results of all test timers.

type Token

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

Token interface to validate the MQTT connection.

var TokenClient Token

type TwinValue

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

TwinValue the struct of twin value

type TwinVersion

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

TwinVersion twin version

type TypeMetadata

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

TypeMetadata the meta of value type

type ValueMetadata

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