Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Probes nested virtualization on additional environments. #10

Merged
merged 2 commits into from
Nov 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 108 additions & 21 deletions utils/custom_devstack_setup_1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,123 @@ else
exit 1
fi

if test "${OS_NAME}" = "centos"; then
#
# Checks if nested virtualization is enabled
#
probe_kvm_intel_nested() {
if test -f "/sys/module/kvm_intel/parameters/nested"; then
IS_YN=$(cat /sys/module/kvm_intel/parameters/nested)
if test "${IS_YN}" = "Y" -o "${IS_YN}" = "1" ; then
echo "[OK] kvm_intel nested is 1 or Y:${IS_YN}"
return 0
else
echo "[NO] kvm_intel nested is not 1 nor Y:${IS_YN}"
fi
else
echo "[NO] /sys/module/kvm_intel/parameters/nested doesn't exist"
fi
echo "[NO] kvm_intel nested is currently not supported"
return 1
}

#
# Adds nested=1 to kvm_intel module if nested = 0
#
probe_kvm_intel () {

probe_kvm_intel_nested
if test "${?}" -eq 1; then
echo "[NO] Try to reload the module because kvm_intel nested is currently not supported."
else
echo "[OK] kvm_intel nested is already supported."
return 0
fi

# Adds 'options kvm_intel nested=y' to dist.conf to enable it permanently.
# See https://docs.openstack.org/devstack/latest/guides/devstack-with-nested-kvm.html
grep "options kvm_intel nested=y" /etc/modprobe.d/dist.conf >/dev/null 2>&1
if test "${?}" -ne 0; then
echo 'options kvm_intel nested=y' | sudo tee -a /etc/modprobe.d/dist.conf
else
echo 'options kvm_intel nested=y already exists in /etc/modprobe.d/dist.conf'
fi

# try to re-load the module
sudo modprobe -r kvm_intel
sudo modprobe -a kvm_intel 1>/dev/null 2>&1
if test "$?" != "0"; then
echo "[NO] kvm_intel module is not supported"
return 1
fi
lsmod | grep kvm_intel
if test "$?" != "0"; then
echo "[NO] kvm_intel module not found"
exit 1
else
echo "DEBUG grep kvm_intel"
return 1
fi

echo "sudo rmmod kvm_intel"
sudo rmmod kvm_intel
echo 'options kvm_intel nested=y' | sudo tee /etc/modprobe.d/dist.conf
echo "sudo modprobe kvm_intel"
sudo modprobe kvm_intel
echo "sudo lsmod | grep kvm_intel"

if test -f "/sys/module/kvm_intel/parameters/nested"; then
IS_YN=$(cat /sys/module/kvm_intel/parameters/nested)
if test "${IS_YN}" != "Y" -a "${IS_YN}" != "1" ; then
echo "[NO] nested should be Y. IS_YN is ${IS_YN}"
exit 1
# Checks if nested is featured
probe_kvm_intel_nested
if test "${?}" -eq 1; then
echo "[NO] kvm_intel nested is not supported"
return 1
fi
echo "[OK] kvm_intel nested is currently supported"
return 0
}

probe_kvm_amd() {
lscpu | grep -E "^Vendor ID:(\s+)AuthenticAMD$" >/dev/null 2>&1
if test "$?" = "0"; then
lscpu | grep -E "^Hypervisor vendor:(\s+)KVM$" >/dev/null 2>&1
if test "$?" = "0"; then
lscpu | grep -E "^Virtualization type:(\s+)full$" >/dev/null 2>&1
if test "$?" = "0"; then
echo "[OK] Full virtualization supported"
return 0
fi
fi
fi
return 1
}

probe_kvm_azure() {
echo "lscpu | grep -E '^Hypervisor vendor:(\s+)Microsoft$'" >/dev/null 2>&1
lscpu | grep -E "^Hypervisor vendor:(\s+)Microsoft$" >/dev/null 2>&1
if test "$?" = "0"; then
echo "[OK] Full virtualization supported"
return 0
fi
return 1
}

probe_nested_virtualization_enabled() {
probe_kvm_intel
if test "$?" -eq 0; then
echo "[OK] kvm_intel supports nested virtualization"
return 0
fi
probe_kvm_amd
if test "$?" -eq 0; then
echo "[OK] kvm supports nested virtualization"
return 0
fi
probe_kvm_azure
if test "$?" -eq 0; then
echo "[OK] kvm supports nested virtualization"
return 0
fi
return 1
}

if test "${OS_NAME}" = "centos"; then
# Enables Nested Virtualization of some kernel module
probe_nested_virtualization_enabled
if test "${?}" -eq 0; then
echo "[OK] nested virtualization is enabled"
else
echo '[NO] no /sys/module/kvm_intel/parameters/nested exists'
echo "[NO] nested virtualization is not enabled"
exit 1
fi

echo "sudo dnf install -y python36-devel"
sudo dnf install -y python36-devel

Expand All @@ -92,9 +182,6 @@ if test -x "${SRCDIR}/custom_internal_devstack_setup_1.sh"; then
/bin/sh ${SRCDIR}/custom_internal_devstack_setup_1.sh
fi

echo "reboot"
sudo reboot

exit 0

#
Expand Down