Fix jq query testing if we got valid json 72/63372/2
authorAndrew Grimberg <agrimberg@linuxfoundation.org>
Wed, 11 Mar 2020 16:37:00 +0000 (09:37 -0700)
committerAndrew Grimberg <agrimberg@linuxfoundation.org>
Wed, 11 Mar 2020 17:06:04 +0000 (10:06 -0700)
While looking over cost data from OpenDaylight I noticed that we started
getting data that had unknown resources with 0 cost associated with it.
After digging in I found out that the job-cost.sh had been updated to
verify that the data received back was valid json.

Testing this out locally everything worked just fine, so I tested the
work flow on an instance in the build environment and found that the
version of jq on the systems throws an error if you try to redirect the
output without having a query, which is exactly what was being done for
the test for if we received a valid json block.

A little further testing showed me that changing the call to include a
query of '.' would just parse everything (as I expected) and that it
doesn't fail the test.

For further information this appears to be a bug in jq v1.5 which is
installed on the Centos7 systems but jq v1.6 which I have locally works
just fine.

Change-Id: Id1ffc4ce71903f62d56e62e6569975710294c630
Signed-off-by: Andrew Grimberg <agrimberg@linuxfoundation.org>
releasenotes/notes/fix_costing_jq_test-0d6954b3384ea99d.yaml [new file with mode: 0644]
shell/job-cost.sh

diff --git a/releasenotes/notes/fix_costing_jq_test-0d6954b3384ea99d.yaml b/releasenotes/notes/fix_costing_jq_test-0d6954b3384ea99d.yaml
new file mode 100644 (file)
index 0000000..133b08b
--- /dev/null
@@ -0,0 +1,4 @@
+---
+fixes:
+  - |
+    Update jq validation of returned json blocks to work properly with jq v1.5.
index a7dceea..cb5f1a5 100644 (file)
@@ -59,7 +59,7 @@ url="https://pricing.vexxhost.net/v1/pricing/$instance_type/cost?seconds=$uptime
 json_block=$(curl -s "$url")
 
 # check if JSON returned and can be parsed
-if jq <<< "$json_block" > /dev/null 2>&1; then
+if jq <<< "$json_block" > /dev/null 2>&1; then
     cost=$(jq .cost <<< "$json_block")
     resource=$(jq .resource <<< "$json_block" | tr -d '"')
 else