2024-02-29 20:03:12 +01:00
|
|
|
#!/usr/bin/env bash
|
2017-08-10 17:58:01 +02:00
|
|
|
#
|
|
|
|
# Integration test for remote API
|
|
|
|
#
|
2022-03-15 09:18:01 -04:00
|
|
|
# Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2017-08-10 17:58:01 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
set -e
|
2017-08-10 17:58:01 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
DIR=$(mktemp -d)
|
|
|
|
pushd ${DIR}
|
2017-08-10 17:58:01 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
function finish {
|
2024-02-29 21:54:10 +01:00
|
|
|
popd
|
|
|
|
rm -rf ${DIR}
|
2021-08-10 10:12:48 -04:00
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
|
|
|
|
cat > base.json <<EOF
|
2021-09-22 13:30:26 +02:00
|
|
|
{
|
2024-02-29 21:54:10 +01:00
|
|
|
"http": {
|
|
|
|
"port": 8080
|
|
|
|
}
|
2021-09-22 13:30:26 +02:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
cat > local.json <<EOF
|
2017-08-10 17:58:01 +02:00
|
|
|
{
|
2024-02-29 21:54:10 +01:00
|
|
|
"http": {
|
|
|
|
"port": 8080
|
|
|
|
},
|
|
|
|
"nodes": {
|
|
|
|
"node1": {
|
|
|
|
"type" : "socket",
|
|
|
|
"format": "csv",
|
2024-02-29 20:03:12 +01:00
|
|
|
|
2024-02-29 21:54:10 +01:00
|
|
|
"in": {
|
|
|
|
"address" : "*:12000"
|
|
|
|
},
|
|
|
|
"out": {
|
|
|
|
"address": "127.0.0.1:12001"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"paths": [
|
|
|
|
{
|
|
|
|
"in": "node1",
|
|
|
|
"out": "node1",
|
|
|
|
"hooks": [
|
|
|
|
{ "type": "print" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-08-10 17:58:01 +02:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2018-12-02 03:57:40 +01:00
|
|
|
# Start with base configuration
|
2021-08-10 10:12:48 -04:00
|
|
|
villas node base.json &
|
2017-08-10 17:58:01 +02:00
|
|
|
|
|
|
|
# Wait for node to complete init
|
2018-12-02 03:57:40 +01:00
|
|
|
sleep 1
|
2017-08-10 17:58:01 +02:00
|
|
|
|
|
|
|
# Restart with configuration
|
2021-08-10 10:12:48 -04:00
|
|
|
curl -sX POST --data '{ "config": "local.json" }' http://localhost:8080/api/v2/restart
|
2017-08-10 17:58:01 +02:00
|
|
|
|
|
|
|
# Wait for node to complete init
|
2018-12-02 03:57:40 +01:00
|
|
|
sleep 2
|
2017-08-10 17:58:01 +02:00
|
|
|
|
|
|
|
# Fetch config via API
|
2021-08-10 10:12:48 -04:00
|
|
|
curl -s http://localhost:8080/api/v2/config > fetched.json
|
2017-08-10 17:58:01 +02:00
|
|
|
|
|
|
|
# Shutdown VILLASnode
|
2021-08-10 10:12:48 -04:00
|
|
|
kill %%
|
|
|
|
wait %%
|
2017-08-10 17:58:01 +02:00
|
|
|
|
|
|
|
# Compare local config with the fetched one
|
2021-08-10 10:12:48 -04:00
|
|
|
diff -u <(jq -S . < fetched.json) <(jq -S . < local.json)
|