Skip to content

Commit

Permalink
Lwm2m without security (#1022)
Browse files Browse the repository at this point in the history
* lwm2m without security update

* modify lwm2m without security completedly

* add sleep command in azure-pipelines

* push for go test

* fix space in azure-pipelines

* push for go test

* update script

* update shell script to python script

* back to shell

* back to shell

* back to shell

* update azure-pipelines

* update shell
  • Loading branch information
beingStrongeryqqq authored Oct 23, 2024
1 parent 68559a6 commit cb458e6
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
37 changes: 37 additions & 0 deletions azure-pipelines/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,43 @@ stages:
kubectl delete -f $(System.DefaultWorkingDirectory)/examples/deviceshifu/demo_device/edgedevice-opcua/mock-device
displayName: "Shifu demo device OPCUA E2E test"
- job: kind_e2e_test_lwm2m_without_security
steps:
- task: GoTool@0
inputs:
version: $(goVersion)
- script: |
tag=`cat version.txt` && echo "##vso[task.setvariable variable=tag]$tag"
displayName: Set the tag name as an environment variable
- script: |
make buildx-build-image-shifu-controller
displayName: build edgehub/shifu-controller
- script: |
make buildx-build-image-deviceshifu-http-lwm2m
displayName: build edgehub/deviceshifu-http-lwm2m
- script: |
set -e
kind --version
kind delete cluster && kind create cluster
kind load docker-image edgehub/shifu-controller:$(tag)
kind load docker-image edgehub/deviceshifu-http-lwm2m:$(tag)
kubectl version
kubectl apply -f $(System.DefaultWorkingDirectory)/pkg/k8s/crd/install/shifu_install.yml
kubectl wait --for=condition=Available deploy/shifu-crd-controller-manager -n shifu-crd-system --timeout=150s
displayName: "setup Kind cluster and install Shifu"
- script: |
set -e
kubectl run nginx --image=nginx -n deviceshifu
kubectl apply -f $(System.DefaultWorkingDirectory)/examples/lwM2MDeviceshifuWithoutSecurity/lwM2M
kubectl wait --for=condition=Available deploy/deviceshifu-lwm2m-deployment -n deviceshifu --timeout=150s
kubectl wait --for=condition=Ready pod/nginx -n deviceshifu --timeout=150s
kubectl apply -f $(System.DefaultWorkingDirectory)/examples/lwM2MDeviceshifuWithoutSecurity/mockdevice
kubectl wait --for=condition=available --timeout=150s deployment/leshan-client -n deviceshifu
bash $(System.DefaultWorkingDirectory)/examples/deviceshifu/mockdevice/lwM2M/checkoutput.sh
kubectl delete -R -f $(System.DefaultWorkingDirectory)/examples/lwM2MDeviceshifuWithoutSecurity
displayName: "Shifu demo device lwM2M E2E test"
- job: kind_e2e_test_socket
steps:
- task: GoTool@0
Expand Down
60 changes: 60 additions & 0 deletions examples/deviceshifu/mockdevice/lwM2M/checkoutput.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Default value to write to the mock device
writeData=88.8

# Get the pod name of deviceshifu
pod_name=$(kubectl get pods -n deviceshifu -l app=deviceshifu-lwm2m-deployment -o jsonpath='{.items[0].metadata.name}')

if [ -z "$pod_name" ]; then
echo "No deviceshifu-lwm2m pod found. Exiting..."
exit 1
fi

# Function to retrieve value from the LwM2M server
get_value() {
kubectl exec -n deviceshifu nginx -- curl --connect-timeout 5 deviceshifu-lwm2m.deviceshifu.svc.cluster.local/float_value
}

# Attempt to get the value with retries
for i in {1..5}; do
out=$(get_value)

# Remove any whitespace and newline characters
out=$(echo "$out" | tr -d '\r\n')

# Output the status
echo "Received value: $out"

# Check if the server response indicates an error
if [[ $out != "Error on reading object" ]]; then
break
fi

echo "Device is unhealthy. Attempting to reconnect... ($i/5)"
sleep 3
done

if [[ $out == "Error on reading object" ]]; then
echo "Device is still unhealthy after 5 attempts. Exiting..."
kubectl logs -n deviceshifu $pod_name
exit 1
fi

# Use deviceshifu to write data to the mock device with retry settings
kubectl exec -n deviceshifu nginx -- curl --retry 5 --retry-delay 3 --max-time 15 --connect-timeout 5 -X PUT deviceshifu-lwm2m.deviceshifu.svc.cluster.local/float_value -d $writeData

# Retrieve the value again after writing to verify if it was successful
out=$(get_value)

# Remove any whitespace and newline characters
out=$(echo "$out" | tr -d '\r\n')

# Check if the modification was successful
if awk "BEGIN {exit !($out == $writeData)}"; then
echo "Modification successful"
exit 0
else
echo "Modification failed, expected: $writeData, got: $out"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: deviceshifu-lwm2m
namespace: deviceshifu
data:
driverProperties: |
driverSku: LwM2M Device
driverImage: lwm2m-device:v0.0.1
leshanConfig: |
serverUrl: coap://leshan-service.deviceshifu.svc.cluster.local:5683
instructions: |
instructions:
float_value:
protocolPropertyList:
ObjectId: /3442/0/130
EnableObserve: false
reset:
protocolPropertyList:
ObjectId: /3303/0/5605
EnableObserve: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: deviceshifu-lwm2m-deployment
name: deviceshifu-lwm2m-deployment
namespace: deviceshifu
spec:
replicas: 1
selector:
matchLabels:
app: deviceshifu-lwm2m-deployment
template:
metadata:
labels:
app: deviceshifu-lwm2m-deployment
spec:
containers:
- image: edgehub/deviceshifu-http-lwm2m:nightly
name: deviceshifu-lwm2m
ports:
- containerPort: 8080
volumeMounts:
- name: deviceshifu-config
mountPath: "/etc/edgedevice/config"
readOnly: true
env:
- name: EDGEDEVICE_NAME
value: "edgedevice-lwm2m"
- name: EDGEDEVICE_NAMESPACE
value: "devices"
- name: LOG_LEVEL
value: debug
volumes:
- name: deviceshifu-config
configMap:
name: deviceshifu-lwm2m
serviceAccountName: edgedevice-sa
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: deviceshifu-lwm2m-deployment
name: deviceshifu-lwm2m
namespace: deviceshifu
spec:
ports:
- name: deviceshifu
port: 80
protocol: TCP
nodePort: 30080
targetPort: 8080
- name: lwm2mserver-coap
port: 5683
protocol: UDP
nodePort: 30000
targetPort: 5683
selector:
app: deviceshifu-lwm2m-deployment
type: NodePort
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: shifu.edgenesis.io/v1alpha1
kind: EdgeDevice
metadata:
name: edgedevice-lwm2m
namespace: devices
spec:
sku: "LwM2M Device"
connection: Ethernet
protocol: LwM2M
protocolSettings:
LwM2MSetting:
endpointName: leshan-client
securityMode: None
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: leshan-client
namespace: deviceshifu
labels:
app: leshan-client
spec:
replicas: 1
selector:
matchLabels:
app: leshan-client
template:
metadata:
labels:
app: leshan-client
spec:
containers:
- name: leshan-client
image: edgenesis/lwm2m-demo-leshan-client:nightly
command: ["java", "-jar", "leshan-client-demo-2.0.0-SNAPSHOT-jar-with-dependencies.jar", "-u", "coap://deviceshifu-lwm2m.deviceshifu.svc.cluster.local:5683", "-n", "leshan-client"]
restartPolicy: Always

0 comments on commit cb458e6

Please sign in to comment.