virt-install: Warn if mem less than OS recommended

And if mem is abnormally low, like it appears user tried to specify
GiB not MiB
This commit is contained in:
Cole Robinson 2019-06-14 11:24:10 -04:00
parent c37d6a7260
commit fbe388b26a
3 changed files with 32 additions and 3 deletions

View File

@ -795,7 +795,8 @@ c.add_invalid("--features smm=on --machine pc") # smm=on doesn't work for machi
c = vinst.add_category("nodisk-install", "--nographics --noautoconsole --nodisks")
c.add_valid("--hvm --cdrom %(EXISTIMG1)s") # Simple cdrom install
c.add_valid("--os-variant winxp --cdrom %(EXISTIMG1)s") # Windows (2 stage) install
c.add_valid("--pxe --ram 16", grep="Requested memory 16 MiB is abnormally low") # catch low memory error
c.add_valid("--os-variant winxp --ram 32 --cdrom %(EXISTIMG1)s", grep="32 MiB is less than the recommended 64 MiB") # Windows. Catch memory warning
c.add_valid("--pxe --virt-type test") # Explicit virt-type
c.add_valid("--arch i686 --pxe") # Explicitly fullvirt + arch
c.add_valid("--location location=%(TREEDIR)s") # Directory tree URL install

View File

@ -339,6 +339,23 @@ def _show_nographics_warnings(options, guest, installer):
return
def _show_memory_warnings(guest):
if not guest.currentMemory:
return
res = guest.osinfo.get_recommended_resources()
rammb = guest.currentMemory // 1024
minram = (res.get_minimum_ram(guest.os.arch) or 0)
if minram:
if (minram // 1024) > guest.currentMemory:
logging.warning(_("Requested memory %s MiB is less than the "
"recommended %s MiB for OS %s"), rammb,
minram // (1024 * 1024), guest.osinfo.name)
elif rammb < 17:
logging.warning(_("Requested memory %s MiB is abnormally low. "
"Were you trying to specify GiB?"), rammb)
def show_warnings(options, guest, installer, osdata):
if options.pxe and not supports_pxe(guest):
logging.warning(_("The guest's network configuration does not support "
@ -353,6 +370,7 @@ def show_warnings(options, guest, installer, osdata):
logging.warning(_("No operating system detected, VM performance may "
"suffer. Specify an OS with --os-variant for optimal results."))
_show_memory_warnings(guest)
_show_nographics_warnings(options, guest, installer)

View File

@ -307,6 +307,11 @@ class _OsResources:
if checkarch in resources and key in resources[checkarch]:
return resources[checkarch][key]
def _get_minimum_key(self, key, arch):
val = self._get_key(self._minimum, key, arch)
if val and val > 0:
return val
def _get_recommended_key(self, key, arch):
val = self._get_key(self._recommended, key, arch)
if val and val > 0:
@ -314,11 +319,16 @@ class _OsResources:
# If we are looking for a recommended value, but the OS
# DB only has minimum resources tracked, double the minimum
# value as an approximation at a 'recommended' value
val = self._get_key(self._minimum, key, arch)
if val and val > 0:
val = self._get_minimum_key(key, arch)
if val:
logging.debug("No recommended value found for key='%s', "
"using minimum=%s * 2", key, val)
return val * 2
return None
def get_minimum_ram(self, arch):
return self._get_minimum_key("ram", arch)
def get_recommended_ram(self, arch):
return self._get_recommended_key("ram", arch)