From 44f406cbb141c28a33aae936baa6c0d90c844060 Mon Sep 17 00:00:00 2001 From: Trevor Bramwell Date: Wed, 27 Jan 2021 12:05:06 -0800 Subject: [PATCH] Skip Job Cost Calulations on Non-Cloud Platforms When 'job-cost.sh' is ran on a VM not initialized with cloud-init, or running in OpenStack, attempts to read '/run/cloud-init/result.json' will fail causing the job to become unsable. This change adds a check for any relevant files to the beginning of 'job-cost.sh' in order to skip the calculation on VMs not running on either AWS or OpenStack. Change-Id: I878adee1ba3ceeffa574a1b1c7ae103811344123 Signed-off-by: Trevor Bramwell --- releasenotes/notes/fix-job-cost-18fd129b9713c5dd.yaml | 5 +++++ shell/job-cost.sh | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 releasenotes/notes/fix-job-cost-18fd129b9713c5dd.yaml diff --git a/releasenotes/notes/fix-job-cost-18fd129b9713c5dd.yaml b/releasenotes/notes/fix-job-cost-18fd129b9713c5dd.yaml new file mode 100644 index 00000000..6af989be --- /dev/null +++ b/releasenotes/notes/fix-job-cost-18fd129b9713c5dd.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixes an bug with 'job-cost.sh' that would cause builds to be marked + as unstable if not run on AWS or OpenStack. diff --git a/shell/job-cost.sh b/shell/job-cost.sh index 595b342e..dde31298 100644 --- a/shell/job-cost.sh +++ b/shell/job-cost.sh @@ -15,6 +15,13 @@ set -euf -o pipefail # shellcheck disable=SC1090 source ~/lf-env.sh +if [[ ! -f /run/cloud-init/result.json && ! -f stack-cost ]]; then + # Don't attempt to calculate job cost as build is not running in a + # cloud environment + echo "INFO: Skipping job cost calculation" + exit 0 +fi + # AWS job cost not supported, exit cloudtype="$(jq -r .v1.datasource /run/cloud-init/result.json)" if [[ $cloudtype == "DataSourceEc2Local" ]]; then -- 2.16.6