Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX 3001_mqtt_alarms removing dependency on external MQTT broker #4638

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
image: eclipse-mosquitto:1.6.15
ports:
- 1883:1883
volumes:
- ./test/functionalTest/mosquitto_conf_for_tests.conf:/mosquitto/config/mosquitto.conf
- ./test/functionalTest/mosquitto_passwd:/mosquitto/config/passwd

mosquitto-extra:
# Needed by MQTT notification tests (multi broker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ brokerStart CB 0 IPv4 -logSummary 5
--SHELL--

#
# FIXME: this test relies on an external service (mqtt.flespi.io) which we don't control
# It would be better to use a MQTT broker running by us (docker?)
# This test requires a MQTT broker with authentication enabled. This may help:
#
# sudo cp /path/to/test/functionalTest/mosquitto_conf_for_tests.conf /etc/mosquitto/conf.d/local.conf
# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1
# sudo chmod 640 /etc/mosquitto/passwd
# sudo chown root:mosquitto /etc/mosquitto/passwd
#
# 01. Sleep 6 and see 0-0 raised and 0-0 released
# 02. Create MQTT sub with wrong user/pass
Expand Down Expand Up @@ -67,8 +71,8 @@ payload='{
},
"notification": {
"mqtt": {
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user",
"url": "mqtt://localhost:1883",
"user": "user_noexist",
"passwd": "xxxx",
"topic": "sub1"
}
Expand Down Expand Up @@ -118,8 +122,8 @@ echo "========================================"
payload='{
"notification": {
"mqtt": {
"url": "mqtt://mqtt.flespi.io:1883",
"user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ",
"url": "mqtt://localhost:1883",
"user": "user1",
"passwd": "xxxx",
"topic": "sub1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ brokerStart CB 0 IPV4
--SHELL--

#
# FIXME: this test relies on an external service (mqtt.flespi.io) which we don't control
# It would be better to use a MQTT broker running by us (docker?)
# Given the MQTT broker is a remote system in the Internet, we have to wait at some points
# so subscription status and logs get consolidated before checking it
# This test requires a MQTT broker with authentication enabled. This may help:
#
# sudo cp /path/to/test/functionalTest/mosquitto_conf_for_tests.conf /etc/mosquitto/conf.d/local.conf
# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1
# sudo chmod 640 /etc/mosquitto/passwd
# sudo chown root:mosquitto /etc/mosquitto/passwd
#
# 01. Create MQTT sub with wrong user/pass
# 02. Upsert to trigger first MQTT notification, which fails and raises alarm
Expand All @@ -59,8 +61,8 @@ payload='{
},
"notification": {
"mqtt": {
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user",
"url": "mqtt://localhost:1883",
"user": "user_noexist",
"passwd": "xxxx",
"topic": "sub1"
}
Expand Down Expand Up @@ -125,8 +127,8 @@ echo "========================================"
payload='{
"notification": {
"mqtt": {
"url": "mqtt://mqtt.flespi.io:1883",
"user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ",
"url": "mqtt://localhost:1883",
"user": "user1",
"passwd": "xxxx",
"topic": "sub1"
}
Expand Down Expand Up @@ -193,7 +195,7 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 482
Content-Length: 485

[
{
Expand All @@ -210,8 +212,8 @@ Content-Length: 482
"qos": 0,
"retain": false,
"topic": "sub1",
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user"
"url": "mqtt://localhost:1883",
"user": "user_noexist"
},
"onlyChangedAttrs": false,
"timesSent": 1
Expand Down Expand Up @@ -248,7 +250,7 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 482
Content-Length: 485

[
{
Expand All @@ -265,8 +267,8 @@ Content-Length: 482
"qos": 0,
"retain": false,
"topic": "sub1",
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user"
"url": "mqtt://localhost:1883",
"user": "user_noexist"
},
"onlyChangedAttrs": false,
"timesSent": 2
Expand Down Expand Up @@ -311,7 +313,7 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 566
Content-Length: 502

[
{
Expand All @@ -328,8 +330,8 @@ Content-Length: 566
"qos": 0,
"retain": false,
"topic": "sub1",
"url": "mqtt://mqtt.flespi.io:1883",
"user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ"
"url": "mqtt://localhost:1883",
"user": "user1"
},
"onlyChangedAttrs": false,
"timesSent": 3
Expand All @@ -354,16 +356,16 @@ Content-Length: 566
09. Check logs and see 1 raised alarm and 1 released alarm
==========================================================
#SORT_START
Request received: POST /v2/subscriptions, request payload (181 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "user", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201
Request received: POST /v2/subscriptions, request payload (184 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201
Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204
Raising alarm MqttConnectionError mqtt.flespi.io:1883: Connection Refused: bad user name or password.
Raising alarm MqttConnectionError localhost:1883: Connection Refused: not authorised.
Request received: GET /v2/subscriptions, response code: 200
Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204
Request received: GET /v2/subscriptions, response code: 200
Request received: PATCH /v2/subscriptions/SUB_ID, request payload (182 bytes): { "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204
Request received: PATCH /v2/subscriptions/SUB_ID, request payload (118 bytes): { "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user1", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204
Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204
Releasing alarm MqttConnectionError mqtt.flespi.io:1883
MQTT Notif delivered (subId: SUB_ID): broker: mqtt.flespi.io:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]}
Releasing alarm MqttConnectionError localhost:1883
MQTT Notif delivered (subId: SUB_ID): broker: localhost:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]}
Request received: GET /v2/subscriptions, response code: 200
#SORT_END

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ brokerStart CB 0 IPV4 -relogAlarms
--SHELL--

#
# FIXME: this test relies on an external service (mqtt.flespi.io) which we don't control
# It would be better to use a MQTT broker running by us (docker?)
# Given the MQTT broker is a remote system in the Internet, we have to wait at some points
# so subscription status and logs get consolidated before checking it
# This test requires a MQTT broker with authentication enabled. This may help:
#
# sudo cp /path/to/test/functionalTest/mosquitto_conf_for_tests.conf /etc/mosquitto/conf.d/local.conf
# sudo mosquitto_passwd -c /etc/mosquitto/passwd user1
# sudo chmod 640 /etc/mosquitto/passwd
# sudo chown root:mosquitto /etc/mosquitto/passwd
#
# 01. Create MQTT sub with wrong user/pass
# 02. Upsert to trigger first MQTT notification, which fails and raises alarm
Expand All @@ -59,8 +61,8 @@ payload='{
},
"notification": {
"mqtt": {
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user",
"url": "mqtt://localhost:1883",
"user": "user_noexist",
"passwd": "xxxx",
"topic": "sub1"
}
Expand Down Expand Up @@ -125,8 +127,8 @@ echo "========================================"
payload='{
"notification": {
"mqtt": {
"url": "mqtt://mqtt.flespi.io:1883",
"user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ",
"url": "mqtt://localhost:1883",
"user": "user1",
"passwd": "xxxx",
"topic": "sub1"
}
Expand Down Expand Up @@ -193,7 +195,7 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 482
Content-Length: 485

[
{
Expand All @@ -210,8 +212,8 @@ Content-Length: 482
"qos": 0,
"retain": false,
"topic": "sub1",
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user"
"url": "mqtt://localhost:1883",
"user": "user_noexist"
},
"onlyChangedAttrs": false,
"timesSent": 1
Expand Down Expand Up @@ -248,7 +250,7 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 482
Content-Length: 485

[
{
Expand All @@ -265,8 +267,8 @@ Content-Length: 482
"qos": 0,
"retain": false,
"topic": "sub1",
"url": "mqtt://mqtt.flespi.io:1883",
"user": "user"
"url": "mqtt://localhost:1883",
"user": "user_noexist"
},
"onlyChangedAttrs": false,
"timesSent": 2
Expand Down Expand Up @@ -311,7 +313,7 @@ HTTP/1.1 200 OK
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 566
Content-Length: 502

[
{
Expand All @@ -328,8 +330,8 @@ Content-Length: 566
"qos": 0,
"retain": false,
"topic": "sub1",
"url": "mqtt://mqtt.flespi.io:1883",
"user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ"
"url": "mqtt://localhost:1883",
"user": "user1"
},
"onlyChangedAttrs": false,
"timesSent": 3
Expand All @@ -354,17 +356,17 @@ Content-Length: 566
09. Check logs and see 1 raised alarm, 1 repeat alarm and 1 released alarm
==========================================================================
#SORT_START
Request received: POST /v2/subscriptions, request payload (181 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "user", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201
Request received: POST /v2/subscriptions, request payload (184 bytes): { "subject": { "entities": [ { "id": "E", "type": "T" } ] }, "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user_noexist", "passwd": "xxxx", "topic": "sub1" } } }, response code: 201
Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204
Raising alarm MqttConnectionError mqtt.flespi.io:1883: Connection Refused: bad user name or password.
Raising alarm MqttConnectionError localhost:1883: Connection Refused: not authorised.
Request received: GET /v2/subscriptions, response code: 200
Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204
Request received: GET /v2/subscriptions, response code: 200
Repeated MqttConnectionError mqtt.flespi.io:1883: Connection Refused: bad user name or password.
Request received: PATCH /v2/subscriptions/SUB_ID, request payload (182 bytes): { "notification": { "mqtt": { "url": "mqtt://mqtt.flespi.io:1883", "user": "SeY7oD5XPa1UENBiOLPHqWXmj4r4OZHu4tsgWn1AmTkQuMW6lCDCmqMvi1oURVfJ", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204
Repeated MqttConnectionError localhost:1883: Connection Refused: not authorised.
Request received: PATCH /v2/subscriptions/SUB_ID, request payload (118 bytes): { "notification": { "mqtt": { "url": "mqtt://localhost:1883", "user": "user1", "passwd": "xxxx", "topic": "sub1" } } }, response code: 204
Request received: POST /v2/entities?options=forcedUpdate,upsert, request payload (64 bytes): { "id": "E", "type": "T", "A": { "value": 1, "type": "Float" } }, response code: 204
Releasing alarm MqttConnectionError mqtt.flespi.io:1883
MQTT Notif delivered (subId: SUB_ID): broker: mqtt.flespi.io:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]}
Releasing alarm MqttConnectionError localhost:1883
MQTT Notif delivered (subId: SUB_ID): broker: localhost:1883, topic: sub1, payload (121 bytes): {"subscriptionId":"SUB_ID","data":[{"id":"E","type":"T","A":{"type":"Float","value":1,"metadata":{}}}]}
Request received: GET /v2/subscriptions, response code: 200
#SORT_END

Expand Down
2 changes: 2 additions & 0 deletions test/functionalTest/mosquitto_conf_for_tests.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
password_file /etc/mosquitto/passwd
allow_anonymous true
1 change: 1 addition & 0 deletions test/functionalTest/mosquitto_passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
user1:$7$101$eqgU7wUvh4Y3VQAm$ovEPI43qOwAskK5M+OFmNJAoXtLRx5GI2tBjTX4AOf3ZTB79IRv1CMgbHrPnKY+/K/RKMm2i/XFp9syteeOCvg==
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing dangerous here :) This is just the codification of "xxxx"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTC (informative)

Loading