1
0
mirror of https://github.com/rancher/os.git synced 2025-07-16 16:11:03 +00:00

Add swap support in cloud config mounts

This commit is contained in:
Josh Curl 2016-06-22 21:49:57 -07:00
parent b22c075b95
commit 128c228ff5
No known key found for this signature in database
GPG Key ID: 82B504B9BCCFA677
4 changed files with 45 additions and 2 deletions

View File

@ -224,8 +224,16 @@ func executeCloudConfig() error {
log.Errorf("Unable to mount %s: must specify exactly four arguments", configMount[1])
}
device := util.ResolveDevice(configMount[0])
if configMount[2] == "swap" {
cmd := exec.Command("swapon", device)
err := cmd.Run()
if err != nil {
log.Errorf("Unable to swapon %s: %v", device, err)
}
continue
}
if err := mount.Mount(device, configMount[1], configMount[2], configMount[3]); err != nil {
log.Errorf("Unable to mount %s: %s", configMount[1], err)
log.Errorf("Unable to mount %s: %v", configMount[1], err)
}
}

View File

@ -64,6 +64,9 @@ while [ "$#" -gt 0 ]; do
exit 1
fi
;;
--second-drive)
SECOND_DRIVE=1
;;
--arch)
shift 1
ARCH="$1"
@ -132,12 +135,19 @@ fi
if [ "$QEMU" == "1" ]; then
HD=${BASE}/state/hd.img
[ "$FRESH" == "1" ] && rm -f ${HD} >/dev/null 2>&1 || :
HD2=${BASE}/state/hd2.img
[ "$FRESH" == "1" ] && rm -f ${HD} ${HD2} >/dev/null 2>&1 || :
if [ ! -e ${HD} ]; then
mkdir -p $(dirname ${HD})
qemu-img create -f qcow2 -o size=10G ${HD}
fi
if [ "$SECOND_DRIVE" == "1" ]; then
qemu-img create -f qcow2 -o size=10G ${HD2}
SECOND_DRIVE_ENABLE=$(eval "${hd["$ARCH"]} ${HD2}")
fi
CCROOT=${BUILD}/cloud-config
rm -rf ${CCROOT}
mkdir -p ${CCROOT}
@ -170,6 +180,7 @@ if [ "$QEMU" == "1" ]; then
-m 2048 \
${network["$ARCH"]} \
$(eval "${hd["$ARCH"]} ${HD}") \
${SECOND_DRIVE_ENABLE} \
-smp 1 \
-append "${KERNEL_ARGS}" \
-nographic \

View File

@ -0,0 +1,5 @@
#cloud-config
mounts:
- [ /dev/vdb, "", swap, "" ]
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF

View File

@ -0,0 +1,19 @@
import pytest
import rostest.util as u
from rostest.util import SSH
cloud_config_path = './tests/integration/assets/test_21/cloud-config.yml'
@pytest.fixture(scope="module")
def qemu(request):
q = u.run_qemu(request, run_args=['--second-drive', '--cloud-config',
cloud_config_path])
u.flush_out(q.stdout)
return q
def test_swap(qemu):
SSH(qemu).check_call("sudo mkswap /dev/vdb")
SSH(qemu).check_call("sudo cloud-init -execute")
SSH(qemu).check_call("cat /proc/swaps | grep /dev/vdb")