summaryrefslogtreecommitdiff
path: root/bin
diff options
authorUbuntu <ubuntu@cert-jenkins-slave-1-201406-15260.maas>2022-03-01 14:10:36 +0000
committerUbuntu <ubuntu@cert-jenkins-slave-1-201406-15260.maas>2022-03-01 14:10:36 +0000
commita924f1bf73787b8a0bb2cee8c990768f59010600 (patch)
tree50f2b5009a013c97d8f2d8d4a20fc4008fa7d3cf /bin
parent4b243d446eac8d54819c297b4ed071dc5c8f31de (diff)
parente8cc344cbdc421f00435d70eb35b57d0e0760458 (diff)
Merge #415988 from ~rodsmith/plainbox-provider-checkbox:expand-maas-version-check
Add: Two new checks in maas-version-check.sh test
Diffstat (limited to 'bin')
-rwxr-xr-xbin/maas-version-check.sh66
1 files changed, 55 insertions, 11 deletions
diff --git a/bin/maas-version-check.sh b/bin/maas-version-check.sh
index 25e233f..7d97f0b 100755
--- a/bin/maas-version-check.sh
+++ b/bin/maas-version-check.sh
@@ -1,9 +1,10 @@
#!/bin/bash
-# Copyright (C) 2012-2019 Canonical Ltd.
+# Copyright (C) 2012-2022 Canonical Ltd.
# Authors
# Jeff Lane <jeff@ubuntu.com>
+# Rod Smith <rod.smith@canonical.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
@@ -18,14 +19,57 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
MAAS_FILE="/etc/installed-by-maas"
+DATASOURCE_FILE="/var/lib/cloud/instance/datasource"
+MAAS_DATASOURCE=""
+RETVAL="0"
-# Is the file there?
-if [ -s $MAAS_FILE ]; then
- maas_version=$(cat $MAAS_FILE)
- echo "$maas_version"
- exit 0
-else
- echo "ERROR: This system does not appear to have been installed by MAAS"
- echo "ERROR: " "$(ls -l $MAAS_FILE 2>&1)"
- exit 1
-fi
+# Find the MAAS data source, as recorded in cloud installer files
+get_maas_datasource() {
+ # Is the file there?
+ if [ -s $DATASOURCE_FILE ]; then
+ MAAS_DATASOURCE=$(cut -d "[" -f 2 $DATASOURCE_FILE | cut -d "]" -f 1)
+ echo "MAAS data source is $MAAS_DATASOURCE"
+ else
+ echo "ERROR: This system does not appear to have been installed by MAAS"
+ echo "ERROR: " "$(ls -l $DATASOURCE_FILE 2>&1)"
+ RETVAL="1"
+ fi
+}
+
+# Verify that the $MAAS_DATASOURCE points to a valid IP address.
+# Note: Function assumes that $MAAS_DATASOURCE is already set, as is
+# done by the get_maas_datasource() function.
+verify_maas_ip() {
+ if [[ $RETVAL == 0 ]]; then
+ MAAS_HOSTNAME=$(echo "$MAAS_DATASOURCE" | cut -d "/" -f 3 | cut -d ":" -f 1)
+ HOST_OUTPUT=$(host "$MAAS_HOSTNAME" | grep "has address")
+ status=$?
+ if [[ $status -eq 0 ]]; then
+ MAAS_IP=$(echo "$HOST_OUTPUT" | cut -d " " -f 4)
+ echo "MAAS server's IP address is $MAAS_IP"
+ else
+ echo "ERROR: Unable to determine MAAS server's IP address"
+ RETVAL=1
+ fi
+ fi
+}
+
+# Pull the MAAS version information from a file left here by the
+# Server Certification pre-seed file
+get_maas_version() {
+ # Is the file there?
+ if [ -s $MAAS_FILE ]; then
+ maas_version=$(cat $MAAS_FILE)
+ echo "MAAS version is $maas_version"
+ else
+ echo "ERROR: The MAAS version cannot be determined"
+ echo "ERROR: " "$(ls -l $MAAS_FILE 2>&1)"
+ RETVAL="1"
+ fi
+}
+
+get_maas_datasource
+verify_maas_ip
+get_maas_version
+
+exit $RETVAL