Merge "RTD Allow projects to change their default-version"
authorAric Gardner <agardner@linuxfoundation.org>
Mon, 16 Dec 2019 21:23:25 +0000 (21:23 +0000)
committerGerrit Code Review <gerrit@linuxfoundation.org>
Mon, 16 Dec 2019 21:23:25 +0000 (21:23 +0000)
jenkins-init-scripts/lf-env.sh
jjb/lf-macros.yaml
jjb/lf-openstack-heat.yaml
releasenotes/notes/get-job-cost-be3f4061e9cbdc90.yaml [new file with mode: 0644]
shell/gerrit-push-patch.sh
shell/job-cost.sh [new file with mode: 0644]
shell/openstack-stack-delete.sh [new file with mode: 0644]

index 37aaf7e..f0341f3 100644 (file)
@@ -218,10 +218,12 @@ function lf-git-validate-jira-urls()
         base_url=$(echo "$JIRA_URL" | awk -F'/' '{print $3}')
         jira_link=$(git rev-list --format=%B --max-count=1 HEAD | grep -io "http[s]*://$base_url/" || true)
         if [[ -n $jira_link ]]; then
-            lf-echo-error 'Remove JIRA URLs from commit message'
-            lf-echo-error 'Add jira references as: Issue: <JIRAKEY>-<ISSUE#>, instead of URLs'
+            lf-echo-stderr "${FUNCNAME[0]}(): ERROR: JIRA URL found in commit message"
+            lf-echo-stderr 'Add jira references as: Issue: <JIRAKEY>-<ISSUE#>, instead of URLs'
             return 1
         fi
+    else
+        echo "${FUNCNAME[0]}(): WARNING: JIRA_URL not set, continuing anyway"
     fi
     return 0
 }
@@ -250,12 +252,12 @@ function lf-git-validate-jira-urls()
 function lf-jjb-check-ascii()
 {
     if [[ ! -d "jjb" ]]; then
-        lf-echo-error "${FUNCNAME[0]}(): ERROR: missing jjb directory"
-        lf-echo-error "This function can only be run from top of global-jjb directory"
+        lf-echo-stderr "${FUNCNAME[0]}(): ERROR: missing jjb directory"
+        lf-echo-stderr "This function can only be run from top of global-jjb directory"
         return 1
     fi
     if LC_ALL=C grep -I -r '[^[:print:][:space:]]' jjb/; then
-        lf-echo-error "${FUNCNAME[0]}(): ERROR: Found YAML files containing non-printable characters."
+        lf-echo-stderr "${FUNCNAME[0]}(): ERROR: Found YAML files containing non-printable characters."
         return 1
     fi
     echo "${FUNCNAME[0]}(): INFO: All JJB YAML files contain only printable ASCII characters"
index 9411345..1c4e5f4 100644 (file)
@@ -78,6 +78,8 @@
           - ../shell/python-tools-install.sh
       - shell: !include-raw:
           - ../shell/sudo-logs.sh
+      - shell: !include-raw:
+          - ../shell/job-cost.sh
       - shell: !include-raw:
           - ../shell/logs-deploy.sh
       - shell: !include-raw:
index 4ca5e8f..0797e34 100644 (file)
@@ -36,8 +36,5 @@
                     files:
                       - file-id: clouds-yaml
                         target: "$HOME/.config/openstack/clouds.yaml"
-                - shell: |
-                    #!/bin/bash -l
-                    echo "Deleting $OS_STACK_NAME"
-                    lftools openstack --os-cloud "$OS_CLOUD" stack delete "$OS_STACK_NAME"
+                - shell: !include-raw-escape: ../shell/openstack-stack-delete.sh
           mark-unstable-if-failed: false
diff --git a/releasenotes/notes/get-job-cost-be3f4061e9cbdc90.yaml b/releasenotes/notes/get-job-cost-be3f4061e9cbdc90.yaml
new file mode 100644 (file)
index 0000000..b6c02f7
--- /dev/null
@@ -0,0 +1,19 @@
+---
+features:
+  - |
+    Generate Job cost information Each job it will archive a CSV file
+    (cost.csv). It will contain a single CSV record containing the following
+    fields: JobName , BuildNumber , Date , InstanceType , Uptime , Cost1 , Cost2
+    The Date field can be sorted as a string and is readable by your favorite
+    spreadsheet.
+    The Date/Time is GMT.
+    The Uptime is uptime of the build agent  (secs).
+    The Cost1 field is the cost($$) of the build node & Cost2 is cost associated
+    with the stack. If the job is not a Openstack job, then Cost2 is '0'.  The
+    project cost file will based on the year (cost-2019.csv).
+
+upgrade:
+  - |
+    The openstack-stack-delete.sh script installs the latest tagged version of
+    lftools and it uses that to get the stack cost. Any version of lftools >=
+    v0.29.0 will contain the required changes to get the stack cost.
index 62f8e9b..d0a77fe 100644 (file)
@@ -50,6 +50,7 @@ GERRIT_HOST="$(echo "$GERRIT_HOST" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
 GERRIT_TOPIC="$(echo "$GERRIT_TOPIC" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
 GERRIT_USER="$(echo "$GERRIT_USER" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
 REVIEWERS_EMAIL="$(echo "$REVIEWERS_EMAIL" | sed "s/^\([\"']\)\(.*\)\1\$/\2/g")"
+job=$JOB_NAME/$BUILD_NUMBER
 
 CHANGE_ID=$(ssh -p 29418 "$GERRIT_USER@$GERRIT_HOST" gerrit query \
                limit:1 owner:self is:open project:"$PROJECT" \
@@ -59,9 +60,9 @@ CHANGE_ID=$(ssh -p 29418 "$GERRIT_USER@$GERRIT_HOST" gerrit query \
                awk '{ print $2 }')
 
 if [ -z "$CHANGE_ID" ]; then
-   git commit -sm "$GERRIT_COMMIT_MESSAGE"
+   git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Job: ${job}"
 else
-   git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Change-Id: $CHANGE_ID"
+   git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Job: ${job}\nChange-Id: $CHANGE_ID"
 fi
 
 git status
diff --git a/shell/job-cost.sh b/shell/job-cost.sh
new file mode 100644 (file)
index 0000000..2264728
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> build-cost.sh"
+
+set -euf -o pipefail
+
+# shellcheck disable=SC1090
+source ~/lf-env.sh
+
+lf-activate-venv python-openstackclient
+
+if [[ -z ${JOB_NAME:-} ]]; then
+    lf-echo-error "Required Env Variable Unset/Empty: JOB_NAME"
+    exit 1
+fi
+
+# Get the cost of the Openstack agents. The 'stack-cost' file is created when
+# the 'lftools openstack stack cost' command is called from
+# 'openstack-stack-delete.sh' script. The 'stack-cost' file will only be created
+# if this is an openstack job.
+if [[ -f stack-cost ]]; then
+    echo "DEBUG: $(cat stack-cost)"
+    echo "INFO: Retrieving Stack Cost..."
+    if ! stack_cost=$(fgrep "total: " stack-cost | awk '{print $2}'); then
+        echo "ERROR: Unable to retrieve Stack Cost, continuing anyway"
+        stack_cost=0
+    fi
+else
+    echo "INFO: No Stack..."
+    stack_cost=0
+fi
+
+# Retrieve the current uptime (in seconds)
+uptime=$(cat /proc/uptime | awk '{print $1}')
+# Convert to integer by truncating fractional part' and round up by one
+((uptime=${uptime%\.*}+1))
+
+instance_type=$(curl -s http://169.254.169.254/latest/meta-data/instance-type)
+
+echo "INFO: Retrieving Pricing Info for: $instance_type"
+url="https://pricing.vexxhost.net/v1/pricing/$instance_type/cost?seconds=$uptime"
+jason_block=$(curl -s $url)
+
+cost=$(jq .cost <<< $jason_block)
+resource=$(jq .resource <<< $jason_block | tr -d '"')
+
+# Archive the cost date
+mkdir -p $WORKSPACE/archives/cost
+
+echo "INFO: Archiving Costs"
+
+# Set the timestamp in GMT
+# This format is readable by spreadsheet and is easily sortable
+date=$(TZ=GMT date +'%Y-%m-%d %H:%M:%S')
+
+cat << EOF > $WORKSPACE/archives/cost.csv
+$JOB_NAME,$BUILD_NUMBER,$date,$resource,$uptime,$cost,$stack_cost
+EOF
+
diff --git a/shell/openstack-stack-delete.sh b/shell/openstack-stack-delete.sh
new file mode 100644 (file)
index 0000000..6124c7e
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2019 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+echo "---> openstack-stack-delete.sh"
+
+set -eufo pipefail
+
+# shellcheck disable=SC1090
+source ~/lf-env.sh
+
+lf-activate-venv lftools[openstack] python-openstackclient
+
+echo "INFO: Retrieving stack cost for: $OS_STACK_NAME"
+if ! lftools openstack --os-cloud $OS_CLOUD stack cost $OS_STACK_NAME > stack-cost; then
+    echo "WARNING: Unable to get stack costs, continuing anyway"
+    echo "total: 0" > stack-cost
+else
+    echo "DEBUG: Successfully retrieved stack cost: $(cat stack-cost)"
+fi
+
+# Delete the stack even if the stack-cost script fails
+lftools openstack --os-cloud "$OS_CLOUD" stack delete "$OS_STACK_NAME" \
+    | echo "INFO: $(cat)"
+