Merge "Discover computes after they are registered"
[fuel.git] / mcp / scripts / lib.sh
index 5be4c55..ce5db25 100644 (file)
@@ -38,10 +38,11 @@ function get_base_image {
 function __kernel_modules {
   # Load mandatory kernel modules: loop, nbd
   local image_dir=$1
-  sudo modprobe loop
+  test -e /dev/loop-control || sudo modprobe loop
   if sudo modprobe nbd max_part=8 || sudo modprobe -f nbd max_part=8; then
     return 0
   fi
+  if [ -e /dev/nbd0 ]; then return 0; fi  # nbd might be inbuilt
   # CentOS (or RHEL family in general) do not provide 'nbd' out of the box
   echo "[WARN] 'nbd' kernel module cannot be loaded!"
   if [ ! -e /etc/redhat-release ]; then
@@ -120,7 +121,7 @@ function mount_image {
       break
     fi
   done
-  OPNFV_LOOP_DEV=$(losetup -f)
+  OPNFV_LOOP_DEV=$(sudo losetup -f)
   OPNFV_MAP_DEV=/dev/mapper/$(basename "${OPNFV_NBD_DEV}")p1
   export OPNFV_MNT_DIR OPNFV_LOOP_DEV
   [ -n "${OPNFV_NBD_DEV}" ] && [ -n "${OPNFV_LOOP_DEV}" ] || exit 1
@@ -213,7 +214,7 @@ function cleanup_mounts {
     fi
   fi
   if [ -n "${OPNFV_LOOP_DEV}" ] && \
-    losetup "${OPNFV_LOOP_DEV}" 1>&2 > /dev/null; then
+    sudo losetup "${OPNFV_LOOP_DEV}" 1>&2 > /dev/null; then
       sudo losetup -d "${OPNFV_LOOP_DEV}"
   fi
   if [ -n "${OPNFV_NBD_DEV}" ]; then
@@ -225,6 +226,7 @@ function cleanup_mounts {
 function cleanup_uefi {
   # Clean up Ubuntu boot entry if cfg01, kvm nodes online from previous deploy
   local cmd_str="ssh ${SSH_OPTS} ${SSH_SALT}"
+  ping -c 1 -w 1 "${SALT_MASTER}" || return 0
   [ ! "$(hostname)" = 'cfg01' ] || cmd_str='eval'
   ${cmd_str} "sudo salt -C 'kvm* or cmp*' cmd.run \
     \"which efibootmgr > /dev/null 2>&1 && \