Skip to content

Commit 1609634

Browse files
authored
Merge pull request #3682 from rina23q/improve/3646/improve-diag-plugins
chore: improve diag-plugins and add system tests
2 parents 861730a + a7b70ba commit 1609634

File tree

5 files changed

+120
-19
lines changed

5 files changed

+120
-19
lines changed

configuration/contrib/diag-plugins/01_tedge.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -e
33

44
OUTPUT_DIR=""
5+
TEDGE_CONFIG_DIR=${TEDGE_CONFIG_DIR:-/etc/tedge}
56
COMMAND=""
67

78
# Parse arguments
@@ -11,6 +12,10 @@ while [ $# -gt 0 ]; do
1112
OUTPUT_DIR="$2"
1213
shift 2
1314
;;
15+
--config-dir)
16+
TEDGE_CONFIG_DIR="$2"
17+
shift 2
18+
;;
1419
collect)
1520
COMMAND="collect"
1621
shift
@@ -46,6 +51,17 @@ collect() {
4651
collect_logs "tedge-mapper-${cloud}"
4752
fi
4853
done
54+
55+
# Collectd mapper log
56+
if systemctl list-unit-files tedge-mapper-collectd.service >/dev/null 2>&1; then
57+
collect_logs tedge-mapper-collectd
58+
fi
59+
60+
# Copy tedge.toml
61+
cp "$TEDGE_CONFIG_DIR"/tedge.toml "$OUTPUT_DIR"/tedge.toml
62+
63+
# tedge config list
64+
tedge config list --all > "$OUTPUT_DIR"/tedge-config-list.log
4965
}
5066

5167
# Execute the specified command

configuration/contrib/diag-plugins/06_internal.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
OUTPUT_DIR=""
5-
CONFIG_DIR=${TEDGE_CONFIG_DIR:-/etc/tedge}
5+
TEDGE_CONFIG_DIR=${TEDGE_CONFIG_DIR:-/etc/tedge}
66
COMMAND=""
77

88
# Parse arguments
@@ -13,7 +13,7 @@ while [ $# -gt 0 ]; do
1313
shift 2
1414
;;
1515
--config-dir)
16-
CONFIG_DIR="$2"
16+
TEDGE_CONFIG_DIR="$2"
1717
shift 2
1818
;;
1919
collect)
@@ -33,10 +33,10 @@ if [ -n "$OUTPUT_DIR" ] && [ ! -d "$OUTPUT_DIR" ]; then
3333
fi
3434

3535
entity_store() {
36-
if [ -f "$CONFIG_DIR"/.agent/entity_store.jsonl ]; then
37-
cp "$CONFIG_DIR"/.agent/entity_store.jsonl "$OUTPUT_DIR"/
38-
elif [ -f "$CONFIG_DIR"/.tedge-mapper-c8y/entity_store.jsonl ]; then
39-
cp "$CONFIG_DIR"/.tedge-mapper-c8y/entity_store.jsonl "$OUTPUT_DIR"/
36+
if [ -f "$TEDGE_CONFIG_DIR"/.agent/entity_store.jsonl ]; then
37+
cp "$TEDGE_CONFIG_DIR"/.agent/entity_store.jsonl "$OUTPUT_DIR"/
38+
elif [ -f "$TEDGE_CONFIG_DIR"/.tedge-mapper-c8y/entity_store.jsonl ]; then
39+
cp "$TEDGE_CONFIG_DIR"/.tedge-mapper-c8y/entity_store.jsonl "$OUTPUT_DIR"/
4040
else
4141
echo "entity_store.jsonl not found" >&2
4242
fi

configuration/contrib/diag-plugins/07_mosquitto.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ if [ -n "$OUTPUT_DIR" ] && [ ! -d "$OUTPUT_DIR" ]; then
2828
fi
2929

3030
mosquitto_journal() {
31-
if command -V journalctl >/dev/null 2>&1; then
32-
journalctl -u "mosquitto" -n 1000 --no-pager > "$OUTPUT_DIR/mosquitto-journal.log" 2>&1 ||:
33-
fi
31+
journalctl -u "mosquitto" -n 1000 --no-pager > "$OUTPUT_DIR/mosquitto-journal.log" 2>&1 ||:
3432
}
3533

3634
mosquitto_log() {
@@ -42,17 +40,16 @@ mosquitto_log() {
4240
}
4341

4442
collect() {
45-
if [ "$(tedge config get mqtt.bridge.built_in)" = "false" ]; then
46-
if command -V mosquitto > /dev/null 2>&1; then
43+
if command -V mosquitto > /dev/null 2>&1; then
44+
if command -V journalctl >/dev/null 2>&1; then
4745
mosquitto_journal
48-
mosquitto_log
49-
else
50-
echo "mosquitto not found" >&2
5146
fi
47+
mosquitto_log
5248
else
53-
# built-in bridge is used, hence this plugin should be skipped
54-
exit 2
55-
fi
49+
echo "mosquitto not found" >&2
50+
# this plugin is not applicable when mosquitto doesn't exist
51+
exit 2
52+
fi
5653
}
5754

5855
case "$COMMAND" in

tests/RobotFramework/tests/tedge/diag/00_template.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -e
66
# ./00_template.sh collect --output-dir /tmp --config-dir /etc/tedge/diag-plugins
77

88
OUTPUT_DIR=""
9-
CONFIG_DIR=${TEDGE_CONFIG_DIR:-/etc/tedge}
9+
TEDGE_CONFIG_DIR=${TEDGE_CONFIG_DIR:-/etc/tedge}
1010
COMMAND=""
1111

1212
# Parse arguments
@@ -18,7 +18,7 @@ while [ $# -gt 0 ]; do
1818
;;
1919
--config-dir)
2020
# shellcheck disable=SC2034
21-
CONFIG_DIR="$2"
21+
TEDGE_CONFIG_DIR="$2"
2222
shift 2
2323
;;
2424
collect)
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
*** Settings ***
2+
Library String
3+
Library ThinEdgeIO
4+
5+
Suite Setup Custom Suite Setup
6+
Suite Teardown Get Suite Logs
7+
8+
Test Tags theme:troubleshooting theme:cli theme:plugins
9+
10+
11+
*** Test Cases ***
12+
01_tedge
13+
${log_names}= Create List
14+
... output.log
15+
... tedge-agent.log
16+
... tedge-mapper-c8y.log
17+
... tedge-mapper-collectd.log
18+
... tedge-config-list.log
19+
... tedge.toml
20+
FOR ${log_name} IN @{log_names}
21+
File Size Is Not Zero ${log_name}
22+
END
23+
24+
Log Should Contain tedge-agent.log Starting tedge-agent.service
25+
Log Should Contain tedge-mapper-c8y.log Starting tedge-mapper-c8y.service
26+
Log Should Contain tedge-mapper-collectd.log Starting tedge-mapper-collectd.service
27+
Log Should Contain tedge-config-list.log c8y.url
28+
Execute Command diff /etc/tedge/tedge.toml /results/test/01_tedge/tedge.toml
29+
30+
02_os
31+
File Size Is Not Zero output.log
32+
Log Should Contain output.log Linux
33+
34+
03_mqtt
35+
${log_names}= Create List
36+
... output.log
37+
... tedge-mqtt-sub.log
38+
... tedge-mqtt-sub-retained-only.log
39+
FOR ${log_name} IN @{log_names}
40+
File Size Is Not Zero ${log_name}
41+
END
42+
Log Should Contain tedge-mqtt-sub.log [te/device/main///cmd/restart] {}
43+
Log Should Contain tedge-mqtt-sub-retained-only.log [te/device/main///twin/type] "thin-edge.io"
44+
45+
04_workflow
46+
File Size Is Not Zero output.log
47+
Execute Command diff -qr /var/log/tedge/agent/workflow-* /results/test/04_workflow/workflow-*
48+
49+
05_entities
50+
File Size Is Not Zero output.log
51+
Log Should Contain output.log "@topic-id": "device/main//"
52+
53+
06_internal
54+
${log_names}= Create List
55+
... output.log
56+
... entity_store.jsonl
57+
FOR ${log_name} IN @{log_names}
58+
File Size Is Not Zero ${log_name}
59+
END
60+
Execute Command diff /etc/tedge/.agent/entity_store.jsonl /results/test/06_internal/entity_store.jsonl
61+
62+
07_mosquitto
63+
${log_names}= Create List
64+
... output.log
65+
... mosquitto.log
66+
... mosquitto-journal.log
67+
FOR ${log_name} IN @{log_names}
68+
File Size Is Not Zero ${log_name}
69+
END
70+
Execute Command diff /var/log/mosquitto/mosquitto.log /results/test/07_mosquitto/mosquitto.log
71+
Log Should Contain mosquitto-journal.log Starting mosquitto.service
72+
73+
74+
*** Keywords ***
75+
File Size Is Not Zero
76+
[Arguments] ${filename}
77+
Execute Command test -s /results/test/${TEST NAME}/${filename}
78+
79+
Log Should Contain
80+
[Arguments] ${filename} ${string}
81+
${content}= Execute Command cat /results/test/${TEST NAME}/${filename}
82+
Should Contain ${content} ${string}
83+
84+
Custom Suite Setup
85+
Setup
86+
Execute Command mkdir -p /results
87+
Start Service tedge-mapper-collectd
88+
Execute Command tedge diag collect --keep-dir --output-dir /results --name test

0 commit comments

Comments
 (0)