From 40345a6797bb76404481afb71f3be951d2637a90 Mon Sep 17 00:00:00 2001
From: Sergii Kipot <skipot@sipwise.com>
Date: Fri, 13 Jan 2017 14:17:57 +0100
Subject: [PATCH] TT#8883 Add puppet repeat dialog

Puppet often fails because puppet cert cleanup or something else forgotten
Normally we want to fix the issue and restart puppet without starting
whole installation from the beginning. Here repeat dialog added
to ask for puppet restart. For daily devops recovery tasks still have an
option to bypass this dialog and proceed to the end if 'nopuppetrepeat'
option is set.

Change-Id: I2a6498628c552aa65d5220c84ade6e12454b8f2d
---
 deployment.sh | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/deployment.sh b/deployment.sh
index 40ab803..3ac017c 100755
--- a/deployment.sh
+++ b/deployment.sh
@@ -2222,13 +2222,33 @@ puppet_install_from_git () {
 }
 
 puppet_install_from_puppet () {
-  echo "Running Puppet core deployment..."
-  grml-chroot $TARGET puppet agent --test --tags core,apt 2>&1 | tee -a /tmp/puppet.log
-  check_puppet_rc "${PIPESTATUS[0]}" "2"
-
-  echo "Running Puppet deployment..."
-  grml-chroot $TARGET puppet agent --test 2>&1 | tee -a /tmp/puppet.log
-  check_puppet_rc "${PIPESTATUS[0]}" "2"
+  local repeat=true
+
+  while $repeat ; do
+    echo "Running Puppet core deployment..."
+    grml-chroot $TARGET puppet agent --test --tags core,apt 2>&1 | tee -a /tmp/puppet.log
+    check_puppet_rc "${PIPESTATUS[0]}" "2"
+
+    echo "Running Puppet deployment..."
+    grml-chroot $TARGET puppet agent --test 2>&1 | tee -a /tmp/puppet.log
+    check_puppet_rc "${PIPESTATUS[0]}" "2"
+
+    if ! checkBootParam nopuppetrepeat && [ "$(get_deploy_status)" = "error" ] ; then
+      echo "Do you want to [r]epeat puppet run? (Press any other key to continue without repeating.)"
+      read a
+      case "$a" in
+        r)
+          echo "Repeating puppet run."
+          repeat=true
+          ;;
+        *)
+          echo "Continue without repeating puppet run."
+          repeat=false
+          ;;
+      esac
+      unset a
+    fi
+  done
 }
 
   set_deploy_status "puppet"