From: Anil Belur Date: Wed, 5 Aug 2020 09:21:09 +0000 (+1000) Subject: Capture instance metadata with job logs X-Git-Tag: v0.56.0~3 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=31a4b7fc00fe90494b6efb512ad0f1db02481ff3;p=releng%2Fglobal-jjb.git Capture instance metadata with job logs Capture instance metadata for the VM's. This data is useful while working with the cloud provider and debuging VM issues on the infrastructure. Issue: RELENG-3142 Change-Id: If54a6a02bf25f039c37fee2831f641ba662254a8 Signed-off-by: Anil Belur --- diff --git a/docs/jjb/lf-macros.rst b/docs/jjb/lf-macros.rst index f2169129..3df86ab2 100644 --- a/docs/jjb/lf-macros.rst +++ b/docs/jjb/lf-macros.rst @@ -44,6 +44,11 @@ Checks files for :licenses-allowed: Comma-separated list of allowed licenses. For example: Apache-2.0,EPL-1.0,MIT +lf-infra-capture-instance-metadata +---------------------------------- + +Capture instance metadata. + lf-infra-create-netrc --------------------- @@ -453,7 +458,8 @@ lf-infra-publish Provides basic lf-infra recommended publisher configurations which should be used in all job templates. This primary objective of this trigger is to -gather build logs and copy them to a log server. +gather package listing, instance metadata, sar reports, build logs and copy +them to a log server. lf-infra-publish-windows ------------------------ diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index 0db15aa5..b1875d2a 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -31,6 +31,12 @@ - shell: !include-raw-escape: - ../shell/license-check.sh +- builder: + name: lf-infra-capture-instance-metadata + builders: + - shell: !include-raw: + - ../shell/capture-instance-metadata.sh + - builder: name: lf-infra-create-netrc builders: @@ -655,6 +661,7 @@ build-steps: - lf-infra-sysstat - lf-infra-package-listing + - lf-infra-capture-instance-metadata - lf-infra-ship-logs mark-unstable-if-failed: true - workspace-cleanup: diff --git a/releasenotes/notes/capture-instance-metadata-50947457661350d0.yaml b/releasenotes/notes/capture-instance-metadata-50947457661350d0.yaml new file mode 100644 index 00000000..44c1cb7c --- /dev/null +++ b/releasenotes/notes/capture-instance-metadata-50947457661350d0.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Capture instance metadata for the VM's. This data is useful while working + with the cloud provider and debuging VM issues on the infrastructure. diff --git a/shell/capture-instance-metadata.sh b/shell/capture-instance-metadata.sh new file mode 100644 index 00000000..cb0081fd --- /dev/null +++ b/shell/capture-instance-metadata.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2020 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 "---> capture-instance-metadata.sh" + +# detect if we're in EC2 +if [ -z "${NOMAD_DC}" ]; then + echo "INFO: Running in Nomad, no metadata" + exit 0 +fi + +# detect if we're in AWS +if grep -qi amazon /sys/devices/virtual/dmi/id/bios_vendor ; then + echo "INFO: Running in AWS, not capturing instance metadata" + exit 0 +fi + +# Retrive OpenStack instace metadata APIs at this IP. +# The instance id and other metadata is useful for debugging VM. +echo "INFO: Running in OpenStack, capturing instance metadata" +curl -s http://169.254.169.254/openstack/latest/meta_data.json \ + | python -mjson.tool > "$WORKSPACE/archives/instance_meta_data.json"