← Back to team overview

canonical-hw-cert team mailing list archive

[Merge] ~rodsmith/maas-cert-server:add-disk-space-checks into maas-cert-server:master

 

Rod Smith has proposed merging ~rodsmith/maas-cert-server:add-disk-space-checks into maas-cert-server:master.

Commit message:
Added disk space checks to lxc-setup and maniacs-setup scripts

Requested reviews:
  hardware-certification-users (hardware-certification)

For more details, see:
https://code.launchpad.net/~rodsmith/maas-cert-server/+git/maas-cert-server/+merge/437965

Added an identical function, disk_space_check(), to both scripts, and called it twice in maniacs-setup (for the main installation and for mirroring the APT archive) and once in lxc-setup. Added control code around each call so that the scripts do reasonable things: Warn the user about inadequate space when installing MAAS in maniacs-setup and give the option to ignore the warning or proceed; terminate the APT mirroring operation in maniacs-setup; and terminate the LXC setup in lxc-setup.

The space limits are based on the observed sizes of the MAAS setup on weavile, the observed size of an APT mirror operation, and the size of the LXC container image created by lxc-setup.
-- 
Your team hardware-certification-users is requested to review the proposed merge of ~rodsmith/maas-cert-server:add-disk-space-checks into maas-cert-server:master.
diff --git a/debian/changelog b/debian/changelog
index 4c040cc..e7cd82e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,10 +1,16 @@
+maas-cert-server (0.7.4-0ppa1) jammy; urgency=medium
+
+  * Add disk space checks to maniacs-setup and lxc-setup scripts.
+
+ -- Rod Smith <rod.smith@xxxxxxxxxxxxx>  Mon, 27 Feb 2023 15:10:47 -0500
+
 maas-cert-server (0.7.3-0ppa1) jammy; urgency=medium
 
   * Fixed bug in maniacs-setup that caused it to fail if there
     was no user with a UID of 1000 on the computer.
   * Adjusted maniacs-setup to work with MAAS 3.3.0.
 
- -- Rod Smith <rodsmith@xxxxxxxxxxxxxxxxxxxxx>  Thu, 23 Feb 2023 17:10:13 -0500
+ -- Rod Smith <rod.smith@xxxxxxxxxxxxx>  Thu, 23 Feb 2023 17:10:13 -0500
 
 maas-cert-server (0.7.2-0ppa1) jammy; urgency=medium
 
diff --git a/usr/sbin/lxc-setup b/usr/sbin/lxc-setup
index a5f3494..67e8afa 100755
--- a/usr/sbin/lxc-setup
+++ b/usr/sbin/lxc-setup
@@ -129,6 +129,35 @@ get_yn() {
     done
 }
 
+# Check available disk space and warn user if the space is insufficient.
+# It also sets the SUFFICIENT_DISK_SPACE variable to "1" (if the space
+# is greater than or equal to that specified) or "0" (if not). It's up
+# to the calling function to decide what to do.
+# Input options:
+#  $1 - Directory to check
+#  $2 - Space required to pass the check, in GiB
+disk_space_check() {
+    local check_dir
+    check_dir="$1"
+    local target_size
+    target_size="$2"
+    local measured_size
+
+    SUFFICIENT_DISK_SPACE=1
+    if [[ $# -ge 2 ]] ; then
+        measured_size=$(df -B 1073741824 "$check_dir" --output=avail / | tail -n 1)
+        if [[ "$measured_size" -lt "$target_size" ]] ; then
+            SUFFICIENT_DISK_SPACE=0
+            echo "* ERROR: Inadequate disk space!"
+            echo "* Available disk space: $measured_size GiB"
+            echo "* Required disk space: $target_size GiB"
+        fi
+    else
+        echo "* Improper call to disk_space_check()! Terminating!"
+        exit 1
+    fi
+} # disk_space_check()
+
 get_device_name() {
     # $1 = descriptive string ("internal" or "external")
     # $2 = device to exclude
@@ -477,6 +506,19 @@ fi
 sudo modprobe zfs
 
 get_params "$@"
+
+# Check to see if we have at least 140 GiB of free disk space....
+disk_space_check "/" "140"
+if [[ "$SUFFICIENT_DISK_SPACE" -eq 0 ]] ; then
+    echo "*"
+    echo "* The LXC container requires at least 128 GiB of disk space, so this script"
+    echo "* Requires at least 140 GiB (to give a little extra space)."
+    echo "*"
+    echo "* Terminating setup!"
+    echo "*"
+    exit 1
+fi
+
 setup_progress_tracker
 
 if [[ $CONFIGURE_NETWORK == "1" ]] || [[ $DO_IT_ALL == "1" ]] ; then
diff --git a/usr/sbin/maniacs-setup b/usr/sbin/maniacs-setup
index adef490..a8c84bd 100755
--- a/usr/sbin/maniacs-setup
+++ b/usr/sbin/maniacs-setup
@@ -206,6 +206,35 @@ setup_progress_tracker() {
     fi
 }
 
+# Check available disk space and warn user if the space is insufficient.
+# It also sets the SUFFICIENT_DISK_SPACE variable to "1" (if the space
+# is greater than or equal to that specified) or "0" (if not). It's up
+# to the calling function to decide what to do.
+# Input options:
+#  $1 - Directory to check
+#  $2 - Space required to pass the check, in GiB
+disk_space_check() {
+    local check_dir
+    check_dir="$1"
+    local target_size
+    target_size="$2"
+    local measured_size
+
+    SUFFICIENT_DISK_SPACE=1
+    if [[ $# -ge 2 ]] ; then
+        measured_size=$(df -B 1073741824 "$check_dir" --output=avail / | tail -n 1)
+        if [[ "$measured_size" -lt "$target_size" ]] ; then
+            SUFFICIENT_DISK_SPACE=0
+            echo "* ERROR: Inadequate disk space!"
+            echo "* Available disk space: $measured_size GiB"
+            echo "* Required disk space: $target_size GiB"
+        fi
+    else
+        echo "* Improper call to disk_space_check()! Terminating!"
+        exit 1
+    fi
+} # disk_space_check()
+
 setup_network_addresses() {
     local internal_with_route
     internal_with_route=$(route | grep default | grep $INTERNAL_NET) || true
@@ -527,7 +556,7 @@ mirror_archive() {
     echo "* Mirroring an archive site is necessary if you'll be doing testing while"
     echo "* disconnected from the Internet, and is desirable if your test site has"
     echo "* poor Internet connectivity. Performing the mirroring operation takes"
-    echo "* time and disk space, though -- about 150 GiB per release mirrored."
+    echo "* time and disk space, though -- about 250 GiB per release mirrored."
     echo "* To defer this task, respond 'N' to the following question."
     echo "*"
     if [[ -d /srv/mirror && -d /srv/skel && -d /srv/var ]]; then
@@ -610,6 +639,19 @@ mirror_archive() {
                 fi
             fi
         done
+        local total_mirror_space
+        # On a recent test, mirroring 20.04 and 22.04 chewed up 370 GiB of disk
+        # space (185 GiB each). Bump that up to 250 GiB per release for safety....
+        ((total_mirror_space=i*250))
+        disk_space_check "$ARCHIVE_MIRROR" "$total_mirror_space"
+        if [[ $SUFFICIENT_DISK_SPACE -eq 0 ]] ; then
+            echo "*"
+            echo "* Inadequate disk space to mirror the requested archives!"
+            echo "* Terminating the mirror operation, but you may try again later by running"
+            echo "* this script with the -m (or --mirror-archives) option."
+            echo "*"
+            return
+        fi
         for release in "${releases[@]}" ; do
             # NOTE: Must mirror both amd64 and i386 because some 32-bit packages
             # get installed on 64-bit systems; src is needed because default
@@ -1178,6 +1220,21 @@ if [ $DO_IT_ALL == 0 ] ; then
         setup_flat_storage
     fi
 else
+    # Check to see if we have at least 50 GiB of free disk space....
+    disk_space_check "/" "50"
+    if [[ "$SUFFICIENT_DISK_SPACE" -eq 0 ]] ; then
+        echo "*"
+        echo "* Although MAAS can install with much less disk space, its databases"
+        echo "* and downloaded images expand, making installation with less than"
+        echo "* 50 GiB of available space inadvisable."
+        echo "*"
+        get_yn "* Do you want to override this restriction" "N"
+        if [ "$YN" == "N" ] ; then
+            echo "*"
+            echo "* Terminating!"
+            exit 1
+        fi
+    fi
     setup_network_addresses
     if [ "$USE_SNAPS" == 1 ]; then
         setup_postgresql

Follow ups