Tim Landscheidt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/235642

Change subject: labs_lvm: Only run extend-instance-vol when needed
......................................................................

labs_lvm: Only run extend-instance-vol when needed

Currently, labs_lvm::volume calls extend-instance-vol in each Puppet
run, making logs unnecessarily noisy.  This change runs
extend-instance-vol only if it would not be a no-op.

It does this by depending the call on that "extend-instance-vol --test
$mountat $size" does /not/ succeed and building that logic into
extend-instance-vol, i. e. if "extend-instance-vol $mountat $size"
would fail because one of its tests fails, it is run (to not hide the
error from the user), and only if all the tests succeed and lvextend
would fail because the volume is already of the intended size,
"extend-instance-vol --test" succeeds, thus /not/ running the non-test
extend-instance-vol.

Ideally, this whole cascade of shell scripts and defined types would
be replaced by a custom Puppet type in Ruby that could be written more
straightforward, but ceterum censeo changing file systems inside a
running system is bad and should be done at the OpenStack level
instead.

Bug: T109933
Change-Id: Ie58720d12a8e94d1c5b6a71aa71160e3f499cabc
---
M modules/labs_lvm/files/extend-instance-vol
M modules/labs_lvm/manifests/extend.pp
2 files changed, 29 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/42/235642/1

diff --git a/modules/labs_lvm/files/extend-instance-vol 
b/modules/labs_lvm/files/extend-instance-vol
index d87255b..3feb219 100755
--- a/modules/labs_lvm/files/extend-instance-vol
+++ b/modules/labs_lvm/files/extend-instance-vol
@@ -1,4 +1,15 @@
-#! /bin/bash
+#!/bin/bash
+
+# If we are called with --test as the first parameter, this means that
+# we change nothing on disk, but indicate with an exit status other
+# than 0 that we would have changed anything and with an exit status
+# of 0 that this call would have been a no-op.
+if [ "x$1" = "x--test" ]; then
+  dryrun=1
+  shift
+else
+  dryrun=0
+fi
 
 mount="$1"; shift
 size="$1"; shift
@@ -24,13 +35,26 @@
 fi
 
 if /sbin/lvextend -t $sopt "$volume" >/dev/null 2>&1; then
+  if [ $dryrun -ne 0 ]; then
+    exit 1
+  fi
   /sbin/lvextend -r $sopt "$volume"
   exit
 else
-  if [ "$?" -eq 5 ]; then
+  lvextend_exitcode=$?
+  if [ $lvextend_exitcode -eq 5 ]; then
     echo "$0: no space left to grow $mount to $size" >&2
     exit 2
   fi
+  # This is the only case when --test should succeed: All the tests
+  # above have passed and lvextend wouldn't do anything because the
+  # partition is already of the requested size.
+  if [ $lvextend_exitcode -eq 3 ] && [ $dryrun -ne 0 ]; then
+    exit 0
+  fi
+  if [ $dryrun -ne 0 ]; then
+    exit 1
+  else
+    exit 0
+  fi
 fi
-
-exit 0
diff --git a/modules/labs_lvm/manifests/extend.pp 
b/modules/labs_lvm/manifests/extend.pp
index 4d729b0..d330c9c 100644
--- a/modules/labs_lvm/manifests/extend.pp
+++ b/modules/labs_lvm/manifests/extend.pp
@@ -15,7 +15,6 @@
 # Sample Usage:
 #   labs_lvm::extend { '/srv': size => '8G' }
 #
-
 define labs_lvm::extend(
     $mountat    = $title,
     $mountowner = 'root',
@@ -23,12 +22,10 @@
     $mountmode  = '755',
     $size       = '100%FREE',
 ) {
-
     exec { "extend-vd-${mountat}":
         logoutput => 'on_failure',
         require   => File['/usr/local/sbin/extend-instance-vol'],
         command   => "/usr/local/sbin/extend-instance-vol '${mountat}' 
'${size}'",
+        unless    => "/usr/local/sbin/extend-instance-vol --test '${mountat}' 
'${size}'",
     }
-
 }
-

-- 
To view, visit https://gerrit.wikimedia.org/r/235642
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie58720d12a8e94d1c5b6a71aa71160e3f499cabc
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Tim Landscheidt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to