requirements_rpm: Add epel-release, nbd
[fuel.git] / mcp / scripts / lib.sh
index 5a69609..2e14182 100644 (file)
@@ -49,18 +49,22 @@ function mount_image {
     fi
   done
   OPNFV_LOOP_DEV=$(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
   qemu-img resize "${image_dir}/${image}" 3G
   sudo qemu-nbd --connect="${OPNFV_NBD_DEV}" --aio=native --cache=none \
     "${image_dir}/${image}"
+  sudo kpartx -av "${OPNFV_NBD_DEV}"
   sleep 5 # /dev/nbdNp1 takes some time to come up
   # Hardcode partition index to 1, unlikely to change for Ubuntu UCA image
   if sudo growpart "${OPNFV_NBD_DEV}" 1; then
-    sudo e2fsck -yf "${OPNFV_NBD_DEV}p1" && sudo resize2fs "${OPNFV_NBD_DEV}p1"
+    sudo kpartx -u "${OPNFV_NBD_DEV}"
+    sudo e2fsck -yf "${OPNFV_MAP_DEV}"
+    sudo resize2fs "${OPNFV_MAP_DEV}"
   fi
   # grub-update does not like /dev/nbd*, so use a loop device to work around it
-  sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_NBD_DEV}p1"
+  sudo losetup "${OPNFV_LOOP_DEV}" "${OPNFV_MAP_DEV}"
   mkdir -p "${OPNFV_MNT_DIR}"
   sudo mount "${OPNFV_LOOP_DEV}" "${OPNFV_MNT_DIR}"
   sudo mount -t proc proc "${OPNFV_MNT_DIR}/proc"
@@ -141,14 +145,16 @@ function cleanup_mounts {
       sudo losetup -d "${OPNFV_LOOP_DEV}"
   fi
   if [ -n "${OPNFV_NBD_DEV}" ]; then
+    sudo kpartx -d "${OPNFV_NBD_DEV}" || true
     sudo qemu-nbd -d "${OPNFV_NBD_DEV}" || true
   fi
 }
 
 function cleanup_uefi {
   # Clean up Ubuntu boot entry if cfg01, kvm nodes online from previous deploy
-  # shellcheck disable=SC2086
-  ssh ${SSH_OPTS} "${SSH_SALT}" "sudo salt -C 'kvm* or cmp*' cmd.run \
+  local cmd_str="ssh ${SSH_OPTS} ${SSH_SALT}"
+  [ ! "$(hostname)" = 'cfg01' ] || cmd_str='eval'
+  ${cmd_str} "sudo salt -C 'kvm* or cmp*' cmd.run \
     \"which efibootmgr > /dev/null 2>&1 && \
     efibootmgr | grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | \
     xargs -I{} efibootmgr --delete-bootnum --bootnum {}; \
@@ -216,8 +222,7 @@ function create_networks {
   # create required networks, including constant "mcpcontrol"
   # FIXME(alav): since we renamed "pxe" to "mcpcontrol", we need to make sure
   # we delete the old "pxe" virtual network, or it would cause IP conflicts.
-  # FIXME(alav): The same applies for "fuel1" virsh network.
-  for net in "fuel1" "pxe" "mcpcontrol" "${vnode_networks[@]}"; do
+  for net in "pxe" "mcpcontrol" "${vnode_networks[@]}"; do
     if virsh net-info "${net}" >/dev/null 2>&1; then
       virsh net-destroy "${net}" || true
       virsh net-undefine "${net}"
@@ -251,8 +256,8 @@ function create_vms {
 
     # prepare network args
     net_args=" --network network=mcpcontrol,model=virtio"
-    if [ "${vnode_data[0]}" = "mas01" ]; then
-      # MaaS node's 3rd interface gets connected to PXE/Admin Bridge
+    if [ "${DEPLOY_TYPE:-}" = 'baremetal' ]; then
+      # 3rd interface gets connected to PXE/Admin Bridge (cfg01, mas01)
       vnode_networks[2]="${vnode_networks[0]}"
     fi
     for net in "${vnode_networks[@]:1}"; do