From ccd73e7270ace0c3edca51935f0b807587db4118 Mon Sep 17 00:00:00 2001 From: Kris Moore Date: Mon, 8 Feb 2016 13:12:06 -0500 Subject: [PATCH] Update the various lpreserver API backends, to use new CLI syntax, and uppdate README with further information about testing --- README.md | 24 +++++++++++++++++++-- src/server/library/sysadm-lifepreserver.cpp | 12 +++++------ tests/api-test.sh | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 32ea295..cc96dde 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ Official repo for PC-BSD's sysadm middleware WebSocket & REST server -This middleware acts as the core for controlling a PC-BSD or FreeBSD system either locally or remotely via WebSockets or REST. +This middleware acts as the core for controlling a PC-BSD or FreeBSD +system either locally or remotely via WebSockets or REST. ### Required Qt Modules @@ -39,7 +40,9 @@ https://api.pcbsd.org ### Contributing new API calls -Adding new API calls to the middleware is very straight-forward, simply add a new function which accepts JSON in, and returns JSON, then connect it to the backend. +Adding new API calls to the middleware is very straight-forward, simply +add a new function which accepts JSON in, and returns JSON, then connect +it to the backend. Example: https://github.com/pcbsd/sysadm/commit/4d3b590f460d301b9376a063f9407dabfd7c9c66 @@ -51,3 +54,20 @@ Adding a new API class requires tweaking a few more files than a new API call on Example: https://github.com/pcbsd/sysadm/commit/1ba65b33880e2298ade3e5cc4f2718aa6112e44f +### Testing new API calls / classes + +Before committing or sending a pull request, you'll need to run our +"api-test.sh" script and confirm it works properly. To do so, first add +your new call and restart the websocket server. Next do the following: + +``` +% cd sysadm/tests +% ./api-test.sh +``` + +The api-test script will prompt you to enter username, password, and some +information about which class / API call to run. When that is done, and you +have verified the functionality of your new call you should add the output +of the test script (either from copy-n-paste, or from the file /tmp/api-response) +to your commit. (This will allow us to document the new call / class) + diff --git a/src/server/library/sysadm-lifepreserver.cpp b/src/server/library/sysadm-lifepreserver.cpp index 0884fdb..d495b02 100644 --- a/src/server/library/sysadm-lifepreserver.cpp +++ b/src/server/library/sysadm-lifepreserver.cpp @@ -127,7 +127,7 @@ QJsonObject LifePreserver::initReplication(QJsonObject jsin) { QJsonObject LifePreserver::listCron() { QJsonObject retObject; - QStringList output = General::RunCommand("lpreserver listcron").split("\n"); + QStringList output = General::RunCommand("lpreserver cronsnap list").split("\n"); QList snaps; // Parse the output @@ -254,7 +254,7 @@ QJsonObject LifePreserver::listSnap(QJsonObject jsin) { return retObject; } - QStringList output = General::RunCommand("lpreserver listsnap " + pool ).split("\n"); + QStringList output = General::RunCommand("lpreserver snapshot list " + pool ).split("\n"); QList snaps; QStringList snapitems; QRegExp sep("\\s+"); @@ -350,7 +350,7 @@ QJsonObject LifePreserver::removeSnapshot(QJsonObject jsin) { } QStringList output; - output = General::RunCommand("lpreserver rmsnap " + dataset + " " + snap).split("\n"); + output = General::RunCommand("lpreserver snapshot remove " + dataset + " " + snap).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) @@ -426,7 +426,7 @@ QJsonObject LifePreserver::revertSnapshot(QJsonObject jsin) { } QStringList output; - output = General::RunCommand("lpreserver revertsnap " + dataset + " " + snap).split("\n"); + output = General::RunCommand("lpreserver snapshot revert " + dataset + " " + snap).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) @@ -589,9 +589,9 @@ QJsonObject LifePreserver::scheduleSnapshot(QJsonObject jsin) { QStringList output; if ( frequency == "none" ) - output = General::RunCommand("lpreserver cronsnap " + pool + " stop " ).split("\n"); + output = General::RunCommand("lpreserver cronsnap stop " + pool ).split("\n"); else - output = General::RunCommand("lpreserver cronsnap " + pool + " start " + frequency + " " + keep ).split("\n"); + output = General::RunCommand("lpreserver cronsnap start " + pool + " " + frequency + " " + keep ).split("\n"); // Check for any errors for ( int i = 0; i < output.size(); i++) diff --git a/tests/api-test.sh b/tests/api-test.sh index c290493..ccf7b8a 100755 --- a/tests/api-test.sh +++ b/tests/api-test.sh @@ -132,6 +132,7 @@ fi # Now check the response via WebSockets export NODE_TLS_REJECT_UNAUTHORIZED=0 +rm $ofile >/dev/null 2>/dev/null ofile="/tmp/api-response" echo "" > $ofile @@ -149,4 +150,3 @@ echo "" | tee -a $ofile echo "Response:" | tee -a $ofile echo "-------------------------------" | tee -a $ofile echo "{ \"namespace\":\"${APITESTNAMESPACE}\", \"name\":\"${APITESTCLASS}\", \"id\":\"fooid\", \"args\":${APITESTPAYLOAD} }" | node sendwebsocket.js "$APITESTUSER" "$APITESTPASS" | tee -a $ofile -rm $ofile