diff --git a/cmd/cloudinit/cloudinit.go b/cmd/cloudinit/cloudinit.go index 23f3c510..8e3ccb71 100644 --- a/cmd/cloudinit/cloudinit.go +++ b/cmd/cloudinit/cloudinit.go @@ -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) } } diff --git a/scripts/run b/scripts/run index 01086b41..9e615cc3 100755 --- a/scripts/run +++ b/scripts/run @@ -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 \ diff --git a/tests/integration/assets/test_21/cloud-config.yml b/tests/integration/assets/test_21/cloud-config.yml new file mode 100644 index 00000000..94fc33a0 --- /dev/null +++ b/tests/integration/assets/test_21/cloud-config.yml @@ -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 diff --git a/tests/integration/rostest/test_21_swap.py b/tests/integration/rostest/test_21_swap.py new file mode 100644 index 00000000..9b1f9d40 --- /dev/null +++ b/tests/integration/rostest/test_21_swap.py @@ -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")