Capture instance metadata with job logs 22/64922/3
authorAnil Belur <abelur@linuxfoundation.org>
Wed, 5 Aug 2020 09:21:09 +0000 (19:21 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Fri, 7 Aug 2020 05:57:09 +0000 (15:57 +1000)
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 <abelur@linuxfoundation.org>
docs/jjb/lf-macros.rst
jjb/lf-macros.yaml
releasenotes/notes/capture-instance-metadata-50947457661350d0.yaml [new file with mode: 0644]
shell/capture-instance-metadata.sh [new file with mode: 0644]

index f216912..3df86ab 100644 (file)
@@ -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
 ------------------------
index 0db15aa..b1875d2 100644 (file)
       - 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:
               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 (file)
index 0000000..44c1cb7
--- /dev/null
@@ -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 (file)
index 0000000..cb0081f
--- /dev/null
@@ -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"