dexter has uploaded this change for review.
restop.py, tryme_*.sh: improve log output and handling
The tryme scripts and the restop.py script produce lots of
distracting and difficult to read log output. Let's renovate
the scripts a bit so that the useful information is displayed
in a readable way.
Change-Id: I7fe40e7ed50354114e80cd96a5b40f3e579220e9
Related SYS#8100
Change-Id: Id257e7a541fc92386cecee5af3dad2077b62709c
---
M contrib/restop.py
M contrib/tryme_addEim.sh
M contrib/tryme_configureImmediateEnable.sh
M contrib/tryme_delete.sh
M contrib/tryme_deleteEim.sh
M contrib/tryme_disable.sh
M contrib/tryme_download.sh
M contrib/tryme_enable.sh
M contrib/tryme_euiccDataRequest.sh
M contrib/tryme_euicc_get_state.sh
M contrib/tryme_euicc_set_state.sh
M contrib/tryme_getRAT.sh
M contrib/tryme_listEim.sh
M contrib/tryme_listProfileInfo.sh
M contrib/tryme_lookup.sh
M contrib/tryme_updateEim.sh
16 files changed, 38 insertions(+), 39 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/onomondo-eim refs/changes/14/43014/1
diff --git a/contrib/restop.py b/contrib/restop.py
index 47c1953..9b43c89 100755
--- a/contrib/restop.py
+++ b/contrib/restop.py
@@ -8,8 +8,8 @@
import argparse
import json
import requests
-import erlang
import pprint
+import textwrap
DOWNLOAD_DEFAULT='{ "eidValue" : "89882119900000000000000000000005", "order" : {"activationCode" : "1$testsmdpplus1.example.com$OPxLD-UVRuC-jysPI-YkOwT"}}'
PSMO_DEFAULT='{ "eidValue" : "89882119900000000000000000000005", "order" : [{"psmo" : "enable", "iccid" : "98001032547698103285", "rollback" : false }]}'
@@ -37,53 +37,66 @@
def main(argv):
parser = argparse.ArgumentParser(prog='restop', description='utility to operate on the REST API of onomondo_eim')
parser.add_argument("-s", "--host", default="127.0.0.1:8080")
- parser.add_argument("-f", "--facility", default="download")
- parser.add_argument("-c", "--create", action='store_true', default=False)
- parser.add_argument("-l", "--lookup", action='store_true', default=False)
- parser.add_argument("-d", "--delete", action='store_true', default=False)
- parser.add_argument("-t", "--list", action='store_true', default=False)
- parser.add_argument("-r", "--resource-id")
- parser.add_argument("-j", "--json")
+ parser.add_argument("-f", "--facility", help="REST API facility", default="download")
+ parser.add_argument("-c", "--create", help="creata a new REST resource", action='store_true')
+ parser.add_argument("-l", "--lookup", help="lookup an existing REST resource", action='store_true')
+ parser.add_argument("-d", "--delete", help="delete a no longer needed REST resource", action='store_true')
+ parser.add_argument("-t", "--list", help="list all currently existing REST resources", action='store_true')
+ parser.add_argument("-r", "--resource-id", help="REST resource identifier")
+ parser.add_argument("-j", "--json", help="JSON input")
+ parser.add_argument("-e", "--erlang-debuginfo", help="decode and display erlang debug information", action='store_true')
args = parser.parse_args()
+ pp = pprint.PrettyPrinter()
if args.create:
print("create on: " + str(args.host), file=sys.stderr)
print(" facility: " + str(args.facility), file=sys.stderr)
if args.json:
- args_json = str(args.json)
+ args_json = json.loads(str(args.json))
else:
if args.facility == "download":
- args_json = DOWNLOAD_DEFAULT
+ args_json = json.loads(DOWNLOAD_DEFAULT)
elif args.facility == "psmo":
- args_json = PSMO_DEFAULT
- print(" json: " + args_json, file=sys.stderr)
- print("result:", file=sys.stderr)
- print(rest_create(args.host, args.facility, json.loads(args_json)))
+ args_json = json.loads(PSMO_DEFAULT)
+ args_json_pretty = pp.pformat(args_json)
+ print(" json: " + textwrap.indent(args_json_pretty, " " * 7)[7:], file=sys.stderr)
+ resource_url = rest_create(args.host, args.facility, args_json)
+ print(" resourceId: " + resource_url.rsplit('/')[-1], file=sys.stderr)
+ print(resource_url)
+
elif args.lookup:
print("lookup on: " + str(args.host), file=sys.stderr)
print(" facility: " + str(args.facility), file=sys.stderr)
print(" resourceId: " + str(args.resource_id), file=sys.stderr)
- result = rest_lookup(args.host, args.facility, args.resource_id)
- print(json.dumps(result))
- if 'debuginfo' in result:
- debuginfo_hexstr=result['debuginfo']
+ result_json = rest_lookup(args.host, args.facility, args.resource_id)
+ result_json_pretty = pp.pformat(result_json)
+ print(" json: " + textwrap.indent(result_json_pretty, " " * 7)[7:], file=sys.stderr)
+ if args.erlang_debuginfo and 'debuginfo' in result_json:
+ import erlang
+ debuginfo_hexstr=result_json['debuginfo']
debuginfo_bytes=h2b(debuginfo_hexstr)
debuginfo_term=erlang.binary_to_term(debuginfo_bytes)
- pp = pprint.PrettyPrinter(depth=4)
debuginfo_pretty = pp.pformat(debuginfo_term)
- print("decoded debuginfo: " + str(debuginfo_pretty), file=sys.stderr)
+ print(" debuginfo: " + textwrap.indent(debuginfo_pretty, " " * 12)[12:], file=sys.stderr)
+ print(json.dumps(result_json))
+
elif args.delete:
print("delete on: " + str(args.host), file=sys.stderr)
print(" facility: " + str(args.facility), file=sys.stderr)
print(" resourceId: " + str(args.resource_id), file=sys.stderr)
- print("result:", file=sys.stderr)
- print(json.dumps(rest_delete(args.host, args.facility, args.resource_id)))
+ result_json = rest_delete(args.host, args.facility, args.resource_id)
+ result_json_pretty = pp.pformat(result_json)
+ print(" json: " + textwrap.indent(result_json_pretty, " " * 7)[7:], file=sys.stderr)
+ print(json.dumps(result_json))
+
elif args.list:
print("list on: " + str(args.host), file=sys.stderr)
print(" facility: " + str(args.facility), file=sys.stderr)
- print("result:", file=sys.stderr)
- print(json.dumps(rest_list(args.host, args.facility)), file=sys.stderr)
+ result_json = rest_list(args.host, args.facility)
+ result_json_pretty = pp.pformat(result_json)
+ print(" json: " + textwrap.indent(result_json_pretty, " " * 7)[7:], file=sys.stderr)
+ print(json.dumps(result_json))
if __name__ == "__main__":
main(sys.argv[1:])
diff --git a/contrib/tryme_addEim.sh b/contrib/tryme_addEim.sh
index a504010..9bdee03 100755
--- a/contrib/tryme_addEim.sh
+++ b/contrib/tryme_addEim.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "eco" : [ { "addEim" : { "eimConfigurationData" : "3079800465494D32810E3132372E302E302E313A383030308301018401FFA55BA059301306072A8648CE3D020106082A8648CE3D03010703420004FE584A6F450459574AECA195D0299737F74C89BA2D36DF9286EC25D973037A0FBA70D14DF3E1F7D0A305E57B95B731C4DE218D2D7F9F22113ED5D18C2E3DDF1C" } } ] } }'
RC=`./restop.py -c -f eco -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_configureImmediateEnable.sh b/contrib/tryme_configureImmediateEnable.sh
index 9cf4fde..1d8233c 100755
--- a/contrib/tryme_configureImmediateEnable.sh
+++ b/contrib/tryme_configureImmediateEnable.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "psmo": [ { "configureImmediateEnable" : { "immediateEnableFlag" : true, "defaultSmdpAddress" : "testsmdpplus1.example.com" } } ] } }'
RC=`./restop.py -c -f psmo -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_delete.sh b/contrib/tryme_delete.sh
index bf1a9b2..b220838 100755
--- a/contrib/tryme_delete.sh
+++ b/contrib/tryme_delete.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "psmo" : [ { "delete" : { "iccid" : "'$ICCID'" } } ] } }'
RC=`./restop.py -c -f psmo -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_deleteEim.sh b/contrib/tryme_deleteEim.sh
index 8faf657..439e6fe 100755
--- a/contrib/tryme_deleteEim.sh
+++ b/contrib/tryme_deleteEim.sh
@@ -3,7 +3,6 @@
EIM_ID="eIM2"
JSON='{ "eidValue" : "'$EID'", "order" : { "eco" : [ { "deleteEim" : { "eimId" : "'$EIM_ID'" } } ] } }'
RC=`./restop.py -c -f eco -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_disable.sh b/contrib/tryme_disable.sh
index a45af94..f0d5de4 100755
--- a/contrib/tryme_disable.sh
+++ b/contrib/tryme_disable.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "psmo" : [ { "disable" : { "iccid" : "'$ICCID'" } } ] } }'
RC=`./restop.py -c -f psmo -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_download.sh b/contrib/tryme_download.sh
index 10725a2..09e6eb2 100755
--- a/contrib/tryme_download.sh
+++ b/contrib/tryme_download.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "download" : {"activationCode" : "'$AC'" } } }'
RC=`./restop.py -c -f download -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_enable.sh b/contrib/tryme_enable.sh
index ac08706..30a8c7f 100755
--- a/contrib/tryme_enable.sh
+++ b/contrib/tryme_enable.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "psmo": [ { "enable" : { "iccid" : "'$ICCID'", "rollback" : false } } ] } }'
RC=`./restop.py -c -f psmo -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_euiccDataRequest.sh b/contrib/tryme_euiccDataRequest.sh
index ba70a69..20d2fad 100755
--- a/contrib/tryme_euiccDataRequest.sh
+++ b/contrib/tryme_euiccDataRequest.sh
@@ -2,7 +2,6 @@
. ./tryme.cfg
JSON='{ "eidValue" : "'$EID'", "order" : { "edr" : { "tagList" : "81BF20BF228384A5A6A8A9A0" } } }'
RC=`./restop.py -c -f edr -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_euicc_get_state.sh b/contrib/tryme_euicc_get_state.sh
index dc96cf0..e7d8e7b 100755
--- a/contrib/tryme_euicc_get_state.sh
+++ b/contrib/tryme_euicc_get_state.sh
@@ -6,7 +6,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "euicc" : { "get" : [ '$STATES' ] } } }'
RC=`./restop.py -c -f euicc -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_euicc_set_state.sh b/contrib/tryme_euicc_set_state.sh
index 04d8c51..6911007 100755
--- a/contrib/tryme_euicc_set_state.sh
+++ b/contrib/tryme_euicc_set_state.sh
@@ -11,7 +11,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "euicc" : { "set" : '$STATES' } } }'
RC=`./restop.py -c -f euicc -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_getRAT.sh b/contrib/tryme_getRAT.sh
index fa61d51..e1a0160 100755
--- a/contrib/tryme_getRAT.sh
+++ b/contrib/tryme_getRAT.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "psmo" : [ { "getRAT" : { } } ] } }'
RC=`./restop.py -c -f psmo -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_listEim.sh b/contrib/tryme_listEim.sh
index 0d86787..47eb9e7 100755
--- a/contrib/tryme_listEim.sh
+++ b/contrib/tryme_listEim.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "eco" : [ { "listEim" : { } } ] } }'
RC=`./restop.py -c -f eco -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_listProfileInfo.sh b/contrib/tryme_listProfileInfo.sh
index 7d64b98..47209f7 100755
--- a/contrib/tryme_listProfileInfo.sh
+++ b/contrib/tryme_listProfileInfo.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "psmo" : [ { "listProfileInfo" : { } } ] } }'
RC=`./restop.py -c -f psmo -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
diff --git a/contrib/tryme_lookup.sh b/contrib/tryme_lookup.sh
index df8e129..5e49bb6 100755
--- a/contrib/tryme_lookup.sh
+++ b/contrib/tryme_lookup.sh
@@ -3,7 +3,7 @@
if [[ $# == 2 ]]; then
sleep 5
while true; do
- ./restop.py -l -f $1 -r $2
+ ./restop.py -l -f $1 -r $2 > /dev/null
sleep 5
done
else
diff --git a/contrib/tryme_updateEim.sh b/contrib/tryme_updateEim.sh
index 5d08398..faf34aa 100755
--- a/contrib/tryme_updateEim.sh
+++ b/contrib/tryme_updateEim.sh
@@ -3,7 +3,6 @@
JSON='{ "eidValue" : "'$EID'", "order" : { "eco" : [ { "updateEim" : { "eimConfigurationData" : "3017800465494D32810F3132372E302E302E34323A39303030" } } ] } }'
RC=`./restop.py -c -f eco -j "$JSON"`
-echo $RC
echo "---------------------------------------8<---------------------------------------"
RESOURCE_ID=`echo $RC | cut -d '/' -f 6`
To view, visit change 43014. To unsubscribe, or for help writing mail filters, visit settings.