From: Andrew Grimberg Date: Wed, 11 Mar 2020 16:37:00 +0000 (-0700) Subject: Fix jq query testing if we got valid json X-Git-Tag: v0.52.0~4 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F63372%2F2;p=releng%2Fglobal-jjb.git Fix jq query testing if we got valid json 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 --- diff --git a/releasenotes/notes/fix_costing_jq_test-0d6954b3384ea99d.yaml b/releasenotes/notes/fix_costing_jq_test-0d6954b3384ea99d.yaml new file mode 100644 index 00000000..133b08be --- /dev/null +++ b/releasenotes/notes/fix_costing_jq_test-0d6954b3384ea99d.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Update jq validation of returned json blocks to work properly with jq v1.5. diff --git a/shell/job-cost.sh b/shell/job-cost.sh index a7dceea4..cb5f1a59 100644 --- a/shell/job-cost.sh +++ b/shell/job-cost.sh @@ -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