mirror of
https://github.com/rancher/os.git
synced 2025-07-18 17:11:04 +00:00
Add swap support in cloud config mounts
This commit is contained in:
parent
b22c075b95
commit
128c228ff5
@ -224,8 +224,16 @@ func executeCloudConfig() error {
|
|||||||
log.Errorf("Unable to mount %s: must specify exactly four arguments", configMount[1])
|
log.Errorf("Unable to mount %s: must specify exactly four arguments", configMount[1])
|
||||||
}
|
}
|
||||||
device := util.ResolveDevice(configMount[0])
|
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 {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
scripts/run
13
scripts/run
@ -64,6 +64,9 @@ while [ "$#" -gt 0 ]; do
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
--second-drive)
|
||||||
|
SECOND_DRIVE=1
|
||||||
|
;;
|
||||||
--arch)
|
--arch)
|
||||||
shift 1
|
shift 1
|
||||||
ARCH="$1"
|
ARCH="$1"
|
||||||
@ -132,12 +135,19 @@ fi
|
|||||||
if [ "$QEMU" == "1" ]; then
|
if [ "$QEMU" == "1" ]; then
|
||||||
|
|
||||||
HD=${BASE}/state/hd.img
|
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
|
if [ ! -e ${HD} ]; then
|
||||||
mkdir -p $(dirname ${HD})
|
mkdir -p $(dirname ${HD})
|
||||||
qemu-img create -f qcow2 -o size=10G ${HD}
|
qemu-img create -f qcow2 -o size=10G ${HD}
|
||||||
fi
|
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
|
CCROOT=${BUILD}/cloud-config
|
||||||
rm -rf ${CCROOT}
|
rm -rf ${CCROOT}
|
||||||
mkdir -p ${CCROOT}
|
mkdir -p ${CCROOT}
|
||||||
@ -170,6 +180,7 @@ if [ "$QEMU" == "1" ]; then
|
|||||||
-m 2048 \
|
-m 2048 \
|
||||||
${network["$ARCH"]} \
|
${network["$ARCH"]} \
|
||||||
$(eval "${hd["$ARCH"]} ${HD}") \
|
$(eval "${hd["$ARCH"]} ${HD}") \
|
||||||
|
${SECOND_DRIVE_ENABLE} \
|
||||||
-smp 1 \
|
-smp 1 \
|
||||||
-append "${KERNEL_ARGS}" \
|
-append "${KERNEL_ARGS}" \
|
||||||
-nographic \
|
-nographic \
|
||||||
|
5
tests/integration/assets/test_21/cloud-config.yml
Normal file
5
tests/integration/assets/test_21/cloud-config.yml
Normal 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
|
19
tests/integration/rostest/test_21_swap.py
Normal file
19
tests/integration/rostest/test_21_swap.py
Normal 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")
|
Loading…
Reference in New Issue
Block a user