utils

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: Apache-2.0 Imports: 40 Imported by: 6

Documentation

Index

Constants

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

	ModBus            = "modbus"
	IncorrectInstance = "incorrect-instance"
	IncorrectModel    = "incorrect-model"
)

Variables

View Source
var CRDTestTimerGroup = NewTestTimerGroup()
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 CallServicebus added in v1.9.0

func CallServicebus() (response string, err 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 CheckDeviceExists added in v1.13.0

func CheckDeviceExists(deviceList []v1beta1.Device, expectedDevice *v1beta1.Device) error

func CheckDeviceModelExists added in v1.13.0

func CheckDeviceModelExists(deviceModels []v1beta1.DeviceModel, expectedDeviceModel *v1beta1.DeviceModel) error

CheckDeviceModelExists verify whether the contents of the device model matches with what is expected

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(c clientset.Interface, podList *v1.PodList)

CheckPodDeleteState check whether the given pod list is deleted successfully

func CheckRuleExists added in v1.13.0

func CheckRuleExists(rules []rulesv1.Rule, expectedRule *rulesv1.Rule) error

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 CopyFlags added in v1.11.0

func CopyFlags(source *flag.FlagSet, target *flag.FlagSet)

func CreateDeployment added in v1.13.0

func CreateDeployment(c clientset.Interface, deployment *apps.Deployment) (*apps.Deployment, error)

func CreatePod added in v1.13.0

func CreatePod(c clientset.Interface, pod *v1.Pod) (*v1.Pod, error)

func CreateStatefulSet added in v1.12.0

func CreateStatefulSet(c clientset.Interface, statefulSet *apps.StatefulSet) (*apps.StatefulSet, error)

func DeRegisterNodeFromMaster

func DeRegisterNodeFromMaster(nodehandler, nodename string) error

DeRegisterNodeFromMaster function to deregister the node from master

func DeleteConfigMap added in v1.13.0

func DeleteConfigMap(client clientset.Interface, ns, name string) error

func DeleteDeployment

func DeleteDeployment(c clientset.Interface, ns, name string) error

DeleteDeployment to delete deployment

func DeletePod added in v1.12.0

func DeletePod(c clientset.Interface, ns, name string) error

func DeleteStatefulSet added in v1.12.0

func DeleteStatefulSet(c clientset.Interface, ns, name string) error

DeleteStatefulSet to delete statefulSet

func Errorf added in v1.1.0

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

Errorf for Error log

func Fatalf added in v1.1.0

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

Fatalf log Failure logs

func GenerateNodeReqBody

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

GenerateNodeReqBody function to generate the node request body

func GetDeployment added in v1.13.0

func GetDeployment(c clientset.Interface, ns, name string) (*apps.Deployment, error)

func GetNodes added in v0.3.0

func GetNodes(api string) v1.NodeList

GetNodes function to get configmaps for respective edgenodes

func GetPod added in v1.13.0

func GetPod(c clientset.Interface, ns, name string) (*v1.Pod, error)

func GetPods

func GetPods(c clientset.Interface, ns string, labelSelector labels.Selector, fieldSelector fields.Selector) (*v1.PodList, error)

func GetRandomString

func GetRandomString(length int) string

function to Generate Random string

func GetStatefulSet added in v1.12.0

func GetStatefulSet(c clientset.Interface, ns, name string) (*apps.StatefulSet, error)

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

func HandleDeviceInstance(c edgeclientset.Interface, operation string, nodeName string, UID string, protocolType string) error

HandleDeviceInstance to handle app deployment/delete using pod spec.

func HandleDeviceModel added in v1.0.0

func HandleDeviceModel(c edgeclientset.Interface, operation string, UID string, protocolType string) error

HandleDeviceModel to handle DeviceModel operation to apiserver.

func HandleRule added in v1.6.0

func HandleRule(c edgeclientset.Interface, operation, UID string, sourceType, targetType rulesv1.RuleEndpointTypeDef) error

HandleRule to handle rule.

func HandleRuleEndpoint added in v1.6.0

func HandleRuleEndpoint(c edgeclientset.Interface, operation string, UID string, endpointType rulesv1.RuleEndpointTypeDef) error

HandleRuleEndpoint to handle ruleendpoint.

func IncorrectDeviceInstance added in v1.0.0

func IncorrectDeviceInstance() v1beta1.Device

func IncorrectDeviceModel added in v1.0.0

func IncorrectDeviceModel() v1beta1.DeviceModel

func Infof added in v1.1.0

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

Infof for log level

func ListDevice added in v1.13.0

func ListDevice(c edgeclientset.Interface, ns string) ([]v1beta1.Device, error)

func ListDeviceModel added in v1.13.0

func ListDeviceModel(c edgeclientset.Interface, ns string) ([]v1beta1.DeviceModel, error)

func ListRule added in v1.13.0

func ListRule(c edgeclientset.Interface, ns string) ([]rulesv1.Rule, error)

func ListRuleEndpoint added in v1.13.0

func ListRuleEndpoint(c edgeclientset.Interface, ns string) ([]rulesv1.RuleEndpoint, error)

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 NewDeployment added in v1.13.0

func NewDeployment(name, imgURL string, replicas int32) *apps.Deployment

func NewEventbus2RestRule added in v1.6.0

func NewEventbus2RestRule() *rulesv1.Rule

func NewKubeClient added in v0.3.0

func NewKubeClient(kubeConfigPath string) clientset.Interface

NewKubeClient creates kube client from config

func NewKubeEdgeClient added in v1.13.0

func NewKubeEdgeClient(kubeConfigPath string) edgeclientset.Interface

NewKubeEdgeClient creates kubeEdge CRD client from config

func NewModbusDeviceInstance added in v1.0.0

func NewModbusDeviceInstance(nodeName string) v1beta1.Device

func NewModbusDeviceModel added in v1.0.0

func NewModbusDeviceModel() v1beta1.DeviceModel

func NewPod added in v1.13.0

func NewPod(podName, imgURL string) *v1.Pod

func NewRest2EventbusRule added in v1.6.0

func NewRest2EventbusRule() *rulesv1.Rule

func NewRest2ServicebusRule added in v1.7.0

func NewRest2ServicebusRule() *rulesv1.Rule

func NewRule added in v1.6.0

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

func NewRuleEndpoint added in v1.6.0

func NewRuleEndpoint(endpointType rulesv1.RuleEndpointTypeDef) *rulesv1.RuleEndpoint

func NewServicebus2Rest added in v1.9.0

func NewServicebus2Rest() *rulesv1.Rule

func NewTestStatefulSet added in v1.12.0

func NewTestStatefulSet(name, imgURL string, replicas int32) *apps.StatefulSet

NewTestStatefulSet create statefulSet for test

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 PrintTestcaseNameandStatus

func PrintTestcaseNameandStatus()

PrintTestcaseNameandStatus print the test case name and status of execution

func PublishMqtt added in v1.6.0

func PublishMqtt(topic, message string) error

func RegisterFlags added in v1.11.0

func RegisterFlags(flags *flag.FlagSet)

func RegisterNodeToMaster

func RegisterNodeToMaster(UID, nodehandler, nodeselector string) error

RegisterNodeToMaster function to register node to master

func SendHTTPRequest added in v1.4.0

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

SendHTTPRequest Function to prepare the http req and send

func SendMsg added in v1.6.0

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

func StartEchoServer added in v1.6.0

func StartEchoServer() (string, error)

func SubscribeMqtt added in v1.6.0

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

func UpdatedModbusDeviceInstance(nodeName string) v1beta1.Device

func UpdatedModbusDeviceModel added in v1.0.0

func UpdatedModbusDeviceModel() v1beta1.DeviceModel

func WaitForPodsRunning added in v1.13.0

func WaitForPodsRunning(c clientset.Interface, podList *v1.PodList, timeout time.Duration)

WaitForPodsRunning waits util all pods are in running status or timeout

func WaitForPodsToDisappear added in v1.12.0

func WaitForPodsToDisappear(c clientset.Interface, ns string, label labels.Selector, interval, timeout time.Duration) error

func WaitForStatusReplicas added in v1.12.0

func WaitForStatusReplicas(c clientset.Interface, ss *apps.StatefulSet, expectedReplicas int32)

WaitForStatusReplicas waits for the ss.Status.Replicas to be equal to expectedReplicas

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"`
	NumOfNodes                     int      `json:"node_num"`
	K8SMasterForProvisionEdgeNodes string   `json:"k8smasterforprovisionedgenodes"`
	CloudImageURL                  string   `json:"cloudimageurl"`
	EdgeImageURL                   string   `json:"edgeimageurl"`
	ControllerStubPort             int      `json:"controllerstubport"`
	Protocol                       string   `json:"protocol"`
	TestDevice                     bool
}

Config 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 ServicebusResponse added in v1.9.0

type ServicebusResponse struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Body string `json:"body"`
}

type TestContext

type TestContext struct {
	Cfg Config
}

TestContext 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