Skip to content

Commit

Permalink
Issue #96 Move swapon to mount function
Browse files Browse the repository at this point in the history
  • Loading branch information
gbraad authored and hferentschik committed Feb 17, 2017
1 parent d8d5a14 commit 6c98936
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
19 changes: 11 additions & 8 deletions scripts/handle-user-data
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ LABEL=boot2docker-data
MAGIC="boot2docker, please format-me"
UNPARTITIONED_HD=/dev/sda

# Function to mount the data partition
mount_data_partition() {
# Function to mount partitions
mount_partitions() {
PARTNAME=`echo "$BOOT2DOCKER_DATA" | sed 's/.*\///'`
echo "mount p:$PARTNAME ..."
mkdir -p /mnt/$PARTNAME
Expand All @@ -17,6 +17,10 @@ mount_data_partition() {
mount $BOOT2DOCKER_DATA /mnt/$PARTNAME
fi

# Activate swap partition
echo "activate swap ..."
swapon "${UNPARTITIONED_HD}2"

# Just in case, the links will fail if not
umount -f /var/lib/docker || true
rm -rf /var/lib/docker /var/lib/boot2docker /etc/docker /var/lib/minishift
Expand Down Expand Up @@ -52,7 +56,7 @@ mount_data_partition() {
}

# Function to partion and format the data disk
prepare_data_partion() {
prepare_partions() {
# Create the partition, format it and then mount it
echo "NEW boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use"

Expand All @@ -71,7 +75,7 @@ prepare_data_partion() {
sleep 0.5
done

# Activate the swap partition
# Prepare the swap partition
mkswap "${UNPARTITIONED_HD}2"

# Add the data partition
Expand All @@ -87,7 +91,6 @@ prepare_data_partion() {

BOOT2DOCKER_DATA=`echo "${UNPARTITIONED_HD}1"`
mkfs.ext4 -i 8192 -L $LABEL $BOOT2DOCKER_DATA
swapon "${UNPARTITIONED_HD}2"
}

# Function to extract userdata.tar containing the ssh keys into the home directory /home/docker
Expand All @@ -113,7 +116,7 @@ echo 'PATH=$PATH:/sbin' >> /home/docker/.bashrc
# userdata.tar. Remember, /home/docker is not persistent
BOOT2DOCKER_DATA=`blkid -o device -l -t LABEL=$LABEL`
if [ -n "$BOOT2DOCKER_DATA" ]; then
mount_data_partition
mount_partitions
handle_user_data
exit 0
fi
Expand All @@ -124,7 +127,7 @@ if [ "$HEADER" = "$MAGIC" ]; then
# Read /userdata.tar with ssh keys and place it temporarily under /
dd if=/dev/sda of=/userdata.tar bs=1 count=4096 2>/dev/null

prepare_data_partion
mount_data_partition
prepare_partions
mount_partitions
handle_user_data
fi
11 changes: 11 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ def test_stopping_vm(self):
self.assertEqual(0, process.returncode)
self.assertEqual('Stopped', output.rstrip())

def test_swapspace(self):
''' Test if swap space is available on restart '''
cmd = self.bin_dir + "minishift start"
self.execute_test({ 'cmd': cmd })

# Check swap space
cmd = self.bin_dir + "minishift ssh \"echo `free | tail -n 1 | awk '{print $2}'`\""
self.log.info("Executing command : %s" % cmd)
output = self.execute_test({ 'cmd': cmd })
self.assertNotEqual(0, output)

def test_delete_vm(self):
''' Test removing machine '''
cmd = self.bin_dir + "minishift delete"
Expand Down

0 comments on commit 6c98936

Please sign in to comment.