Fix make_swap on rackspace

Rackspace is now providing a partition table on /dev/xvde1, so check
to see if a filesystem exists, and if now, delete it and rebuild.

Import our logic from devstack-gate role to fix swap issues too.

Change-Id: I81571489cab121159f48a9437a24388696db331c
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2017-09-11 14:42:19 -04:00
parent dddf50888c
commit c3f3e627ea
No known key found for this signature in database
GPG Key ID: 611A80832067AF38

View File

@ -23,15 +23,30 @@ if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then
fi fi
# Avoid using config drive device for swap # Avoid using config drive device for swap
if [ -n "$DEV" ] && ! blkid | grep $DEV ; then if [ -n "$DEV" ] && ! blkid | grep $DEV | grep TYPE ; then
MEMKB=`grep MemTotal /proc/meminfo | awk '{print $2; }'` MEMKB=`grep MemTotal /proc/meminfo | awk '{print $2; }'`
# Use the nearest power of two in MB as the swap size. # Use the nearest power of two in MB as the swap size.
# This ensures that the partitions below are aligned properly. # This ensures that the partitions below are aligned properly.
MEM=`python -c "import math ; print 2**int(round(math.log($MEMKB/1024, 2)))"` MEM=`python -c "import math ; print 2**int(round(math.log($MEMKB/1024, 2)))"`
umount ${DEV} if mount | grep ${DEV} > /dev/null; then
parted ${DEV} --script -- mklabel msdos echo "*** ${DEV} appears to already be mounted"
parted ${DEV} --script -- mkpart primary linux-swap 1 ${MEM} echo "*** ${DEV} unmounting and reformating"
parted ${DEV} --script -- mkpart primary ext2 ${MEM} -1 umount ${DEV}
fi
parted ${DEV} --script -- \
mklabel msdos \
mkpart primary linux-swap 1 ${MEM} \
mkpart primary ext2 ${MEM} -1
sync
# We are only interested in scanning $DEV, not all block devices
sudo partprobe ${DEV}
# The device partitions might not show up immediately, make sure
# they are ready and available for use
udevadm settle --timeout=0 || echo "Block device not ready yet. Waiting for up to 10 seconds for it to be ready"
udevadm settle --timeout=10 --exit-if-exists=${DEV}1
udevadm settle --timeout=10 --exit-if-exists=${DEV}2
mkswap ${DEV}1 mkswap ${DEV}1
mkfs.ext4 ${DEV}2 mkfs.ext4 ${DEV}2
swapon ${DEV}1 swapon ${DEV}1