Skip to content

Commit dbc450e

Browse files
fix(local): support mac bash for dummy bms (#30)
Signed-off-by: Frank Spitulski <fspitulski@nvidia.com>
1 parent 5c65740 commit dbc450e

3 files changed

Lines changed: 77 additions & 13 deletions

File tree

deploy/scripts/generate-nkeys.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ EOF
4545
cleanup() {
4646
local dir
4747

48+
if [ "${#TEMP_DIRS[@]}" -eq 0 ]; then
49+
return 0
50+
fi
51+
4852
for dir in "${TEMP_DIRS[@]}"; do
4953
if [ -n "${dir}" ] && [ -d "${dir}" ]; then
5054
rm -rf "${dir}"
@@ -173,6 +177,10 @@ validate_extra_account_tokens() {
173177
local token
174178
local seen_tokens=""
175179

180+
if [ "${#EXTRA_ACCOUNTS[@]}" -eq 0 ]; then
181+
return 0
182+
fi
183+
176184
for account_name in "${EXTRA_ACCOUNTS[@]}"; do
177185
token=$(extra_account_secret_token "${account_name}")
178186
case " ${seen_tokens} " in
@@ -521,9 +529,11 @@ main() {
521529
for cpc_id in "${CPC_IDS[@]}"; do
522530
generate_cluster "cpc-${cpc_id}"
523531
generate_cpc_leaf_outputs "${cpc_id}"
524-
for extra_account in "${EXTRA_ACCOUNTS[@]}"; do
525-
generate_extra_account_leaf_outputs "${extra_account}" "${cpc_id}"
526-
done
532+
if [ "${#EXTRA_ACCOUNTS[@]}" -gt 0 ]; then
533+
for extra_account in "${EXTRA_ACCOUNTS[@]}"; do
534+
generate_extra_account_leaf_outputs "${extra_account}" "${cpc_id}"
535+
done
536+
fi
527537
done
528538
fi
529539

local/infra/scripts/with-gateway-port-forwards.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ logs=()
2020

2121
cleanup() {
2222
local pid
23-
for pid in "${pids[@]}"; do
24-
if kill -0 "${pid}" >/dev/null 2>&1; then
25-
kill "${pid}" >/dev/null 2>&1 || true
26-
fi
27-
done
28-
wait >/dev/null 2>&1 || true
23+
if [ "${#pids[@]}" -gt 0 ]; then
24+
for pid in "${pids[@]}"; do
25+
if kill -0 "${pid}" >/dev/null 2>&1; then
26+
kill "${pid}" >/dev/null 2>&1 || true
27+
fi
28+
done
29+
wait >/dev/null 2>&1 || true
30+
fi
2931

3032
local log
31-
for log in "${logs[@]}"; do
32-
rm -f "${log}"
33-
done
33+
if [ "${#logs[@]}" -gt 0 ]; then
34+
for log in "${logs[@]}"; do
35+
rm -f "${log}"
36+
done
37+
fi
3438
}
3539

3640
trap cleanup EXIT
@@ -48,13 +52,15 @@ gateway_service() {
4852
wait_for_local_port() {
4953
local port="$1"
5054
local log="$2"
55+
local pid
5156

5257
for _ in {1..60}; do
5358
if nc -z 127.0.0.1 "${port}" >/dev/null 2>&1; then
5459
return 0
5560
fi
5661

57-
if ! kill -0 "${pids[-1]}" >/dev/null 2>&1; then
62+
pid="${pids[$((${#pids[@]} - 1))]}"
63+
if ! kill -0 "${pid}" >/dev/null 2>&1; then
5864
echo "ERROR: port-forward for local port ${port} exited before becoming ready" >&2
5965
cat "${log}" >&2
6066
return 1

local/mqtt-client/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,54 @@ your own sample or edit the sample for custom data.
179179

180180
From the repo root, run `make dummy-bms` after the local environment is
181181
deployed. For direct runs, pass the broker, CSV, and schema paths explicitly.
182+
Authentication options for real clients are covered in
183+
[authentication.md](../../docs/authentication.md); the local dummy-BMS target
184+
uses the no-auth example profile.
185+
186+
### Dummy BMS Scenario CSV
187+
188+
Scenario files must use exactly this header:
189+
190+
```csv
191+
offset,topic,payload
192+
```
193+
194+
Each row is one MQTT publish:
195+
196+
- `offset` is a Go duration such as `0s`, `500ms`, or `2m`. Offsets must be
197+
non-negative and non-decreasing because they are replayed relative to the
198+
start of each pass.
199+
- `topic` must be a concrete topic that matches a BMS AsyncAPI channel. For
200+
BMS-originated sample data, use
201+
`BMS/v1/PUB/{Value|Metadata}/{objectType}/{pointType}/{tagPath}`. For
202+
example, `BMS/v1/PUB/Metadata/Rack/RackPower/site-a/row-1/rack-1/power` and
203+
`BMS/v1/PUB/Value/Rack/RackPower/site-a/row-1/rack-1/power` are valid
204+
concrete topics. Empty segments and MQTT wildcards (`+`, `#`) are rejected.
205+
- `payload` must be JSON and must validate against the BMS AsyncAPI schema for
206+
the selected topic. Any topic parameter fields present in the payload must
207+
match the topic.
208+
- `{{timestamp_ms}}` in the payload is replaced at publish time with the current
209+
Unix timestamp in milliseconds.
210+
- `Metadata` topics are published retained. `Value` topics are live,
211+
non-retained publishes.
212+
213+
The command loops the scenario until interrupted. Add `--once` to publish one
214+
pass and exit:
215+
216+
```bash
217+
go run ./cmd/dummy-bms \
218+
--broker tcp://127.0.0.1:11883 \
219+
--csv examples/dsx_exemplar.csv \
220+
--schema ../../schema/schema/bms/bms.yaml \
221+
--once
222+
```
223+
224+
To verify messages while `make dummy-bms` is running, subscribe to the forwarded
225+
CSC broker from another terminal:
226+
227+
```bash
228+
mosquitto_sub -h 127.0.0.1 -p 11883 -t 'BMS/v1/PUB/#' -v
229+
```
182230

183231
## Development
184232

0 commit comments

Comments
 (0)