From 6c9893663c0c354c6d8fd13d03aa3d177078477b Mon Sep 17 00:00:00 2001 From: Gerard Braad Date: Tue, 7 Feb 2017 00:13:46 +0800 Subject: [PATCH] Issue #96 Move swapon to mount function --- scripts/handle-user-data | 19 +++++++++++-------- tests/test.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/handle-user-data b/scripts/handle-user-data index 67dc03b..b2b0edb 100755 --- a/scripts/handle-user-data +++ b/scripts/handle-user-data @@ -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 @@ -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 @@ -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" @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/test.py b/tests/test.py index 3bb4ec0..0830ffd 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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"