Skip to content

Commit 12cc3e5

Browse files
committed
fix: address PR review feedback (mfaferek93 + Copilot)
- Inject scripts: handle partial failures with per-call error tracking instead of aborting on first failure (inject-nan, inject-noise, inject-fault-scenario) - Add -sf flag to turtlebot3 POST calls (inject-localization-failure, reset-navigation) so HTTP errors are caught - Add exec_id format validation to lib/scripts-api.sh - Use proper if/else instead of && || to satisfy shellcheck SC2015
1 parent e2760ba commit 12cc3e5

6 files changed

Lines changed: 78 additions & 30 deletions

File tree

demos/sensor_diagnostics/container_scripts/compute-unit/inject-fault-scenario/script.bash

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,39 @@ GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
66
API_BASE="${GATEWAY_URL}/api/v1"
77

88
echo "Injecting composite fault scenario..."
9+
ERRORS=0
910

10-
curl -sf -X PUT "${API_BASE}/apps/lidar-sim/configurations/inject_nan" \
11-
-H "Content-Type: application/json" -d '{"value": true}'
12-
echo "lidar-sim: inject_nan=true"
11+
if curl -sf -X PUT "${API_BASE}/apps/lidar-sim/configurations/inject_nan" \
12+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
13+
echo "lidar-sim: inject_nan=true"
14+
else
15+
echo "FAIL: lidar-sim"; ERRORS=$((ERRORS + 1))
16+
fi
1317

14-
curl -sf -X PUT "${API_BASE}/apps/imu-sim/configurations/inject_nan" \
15-
-H "Content-Type: application/json" -d '{"value": true}'
16-
echo "imu-sim: inject_nan=true"
18+
if curl -sf -X PUT "${API_BASE}/apps/imu-sim/configurations/inject_nan" \
19+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
20+
echo "imu-sim: inject_nan=true"
21+
else
22+
echo "FAIL: imu-sim"; ERRORS=$((ERRORS + 1))
23+
fi
1724

18-
curl -sf -X PUT "${API_BASE}/apps/gps-sim/configurations/inject_nan" \
19-
-H "Content-Type: application/json" -d '{"value": true}'
20-
echo "gps-sim: inject_nan=true"
25+
if curl -sf -X PUT "${API_BASE}/apps/gps-sim/configurations/inject_nan" \
26+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
27+
echo "gps-sim: inject_nan=true"
28+
else
29+
echo "FAIL: gps-sim"; ERRORS=$((ERRORS + 1))
30+
fi
2131

22-
curl -sf -X PUT "${API_BASE}/apps/camera-sim/configurations/inject_black_frames" \
23-
-H "Content-Type: application/json" -d '{"value": true}'
24-
echo "camera-sim: inject_black_frames=true"
32+
if curl -sf -X PUT "${API_BASE}/apps/camera-sim/configurations/inject_black_frames" \
33+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
34+
echo "camera-sim: inject_black_frames=true"
35+
else
36+
echo "FAIL: camera-sim"; ERRORS=$((ERRORS + 1))
37+
fi
2538

39+
if [ $ERRORS -gt 0 ]; then
40+
echo "Composite injection partially failed: $ERRORS error(s)"
41+
exit 1
42+
fi
2643
echo "Composite fault scenario injected on all sensors"
2744
exit 0

demos/sensor_diagnostics/container_scripts/compute-unit/inject-nan/script.bash

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,32 @@ set -eu
55
GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
66
API_BASE="${GATEWAY_URL}/api/v1"
77

8-
curl -sf -X PUT "${API_BASE}/apps/lidar-sim/configurations/inject_nan" \
9-
-H "Content-Type: application/json" -d '{"value": true}'
10-
echo "lidar-sim: inject_nan=true"
8+
ERRORS=0
119

12-
curl -sf -X PUT "${API_BASE}/apps/imu-sim/configurations/inject_nan" \
13-
-H "Content-Type: application/json" -d '{"value": true}'
14-
echo "imu-sim: inject_nan=true"
10+
if curl -sf -X PUT "${API_BASE}/apps/lidar-sim/configurations/inject_nan" \
11+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
12+
echo "lidar-sim: inject_nan=true"
13+
else
14+
echo "FAIL: lidar-sim"; ERRORS=$((ERRORS + 1))
15+
fi
1516

16-
curl -sf -X PUT "${API_BASE}/apps/gps-sim/configurations/inject_nan" \
17-
-H "Content-Type: application/json" -d '{"value": true}'
18-
echo "gps-sim: inject_nan=true"
17+
if curl -sf -X PUT "${API_BASE}/apps/imu-sim/configurations/inject_nan" \
18+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
19+
echo "imu-sim: inject_nan=true"
20+
else
21+
echo "FAIL: imu-sim"; ERRORS=$((ERRORS + 1))
22+
fi
1923

24+
if curl -sf -X PUT "${API_BASE}/apps/gps-sim/configurations/inject_nan" \
25+
-H "Content-Type: application/json" -d '{"value": true}' > /dev/null 2>&1; then
26+
echo "gps-sim: inject_nan=true"
27+
else
28+
echo "FAIL: gps-sim"; ERRORS=$((ERRORS + 1))
29+
fi
30+
31+
if [ $ERRORS -gt 0 ]; then
32+
echo "NaN injection partially failed: $ERRORS error(s)"
33+
exit 1
34+
fi
2035
echo "NaN injection enabled on lidar-sim, imu-sim, gps-sim"
2136
exit 0

demos/sensor_diagnostics/container_scripts/compute-unit/inject-noise/script.bash

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@ set -eu
55
GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
66
API_BASE="${GATEWAY_URL}/api/v1"
77

8-
curl -sf -X PUT "${API_BASE}/apps/lidar-sim/configurations/noise_stddev" \
9-
-H "Content-Type: application/json" -d '{"value": 0.5}'
10-
echo "lidar-sim: noise_stddev=0.5"
8+
ERRORS=0
119

12-
curl -sf -X PUT "${API_BASE}/apps/camera-sim/configurations/noise_level" \
13-
-H "Content-Type: application/json" -d '{"value": 0.3}'
14-
echo "camera-sim: noise_level=0.3"
10+
if curl -sf -X PUT "${API_BASE}/apps/lidar-sim/configurations/noise_stddev" \
11+
-H "Content-Type: application/json" -d '{"value": 0.5}' > /dev/null 2>&1; then
12+
echo "lidar-sim: noise_stddev=0.5"
13+
else
14+
echo "FAIL: lidar-sim"; ERRORS=$((ERRORS + 1))
15+
fi
1516

17+
if curl -sf -X PUT "${API_BASE}/apps/camera-sim/configurations/noise_level" \
18+
-H "Content-Type: application/json" -d '{"value": 0.3}' > /dev/null 2>&1; then
19+
echo "camera-sim: noise_level=0.3"
20+
else
21+
echo "FAIL: camera-sim"; ERRORS=$((ERRORS + 1))
22+
fi
23+
24+
if [ $ERRORS -gt 0 ]; then
25+
echo "Noise injection partially failed: $ERRORS error(s)"
26+
exit 1
27+
fi
1628
echo "High noise injected on lidar-sim and camera-sim"
1729
exit 0

demos/turtlebot3_integration/container_scripts/nav2-stack/inject-localization-failure/script.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GATEWAY_URL="${GATEWAY_URL:-http://localhost:8080}"
66
API_BASE="${GATEWAY_URL}/api/v1"
77

88
echo "Reinitializing AMCL global localization (scatters particles)..."
9-
curl -s -X POST "${API_BASE}/apps/amcl/operations/reinitialize_global_localization/executions" \
9+
curl -sf -X POST "${API_BASE}/apps/amcl/operations/reinitialize_global_localization/executions" \
1010
-H "Content-Type: application/json" \
1111
-d '{}'
1212

@@ -15,7 +15,7 @@ echo "Waiting for particles to scatter..."
1515
sleep 2
1616

1717
echo "Sending navigation goal with high localization uncertainty..."
18-
curl -s -X POST "${API_BASE}/apps/bt-navigator/operations/navigate_to_pose/executions" \
18+
curl -sf -X POST "${API_BASE}/apps/bt-navigator/operations/navigate_to_pose/executions" \
1919
-H "Content-Type: application/json" \
2020
-d '{
2121
"goal": {

demos/turtlebot3_integration/container_scripts/nav2-stack/reset-navigation/script.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fi
2020

2121
echo ""
2222
echo "Resetting AMCL global localization..."
23-
curl -s -X POST "${API_BASE}/apps/amcl/operations/reinitialize_global_localization/executions" \
23+
curl -sf -X POST "${API_BASE}/apps/amcl/operations/reinitialize_global_localization/executions" \
2424
-H "Content-Type: application/json" \
2525
-d '{}'
2626

lib/scripts-api.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ execute_script() {
5959
echo "$result" | jq '.' 2>/dev/null || echo "$result"
6060
exit 1
6161
fi
62+
if [[ ! "$exec_id" =~ ^[a-zA-Z0-9_-]+$ ]]; then
63+
echo "Unexpected execution ID format: $exec_id"
64+
exit 1
65+
fi
6266

6367
echo "Execution started: $exec_id"
6468

0 commit comments

Comments
 (0)