diff --git a/man/virt-install.rst b/man/virt-install.rst index 9cc43360..4b72788b 100644 --- a/man/virt-install.rst +++ b/man/virt-install.rst @@ -992,7 +992,29 @@ syntax as well: install media. Detection is presently only attempted for URL and CDROM installs, and is not 100% reliable. -By default, virt-install will use ``--os-variant detect=on``. +``require=on|off`` + If ``on``, virt-install errors if no OS value is set or detected. + + +Some interesting examples: + +``--os-variant detect=on,require=on`` + This tells virt-install to attempt detection from install media, + but explicitly fail if that does not succeed. This will ensure + your virt-install invocations don't fallback to a poorly performing + config + +``--os-variant detect=on,name=OSNAME`` + Attempt OS detection from install media, but if that fails, use + OSNAME as a fallback. + + +By default, virt-install will do ``--os-variant detect=on,name=generic``, +using the detected OS if found, and falling back to the stub ``generic`` +value otherwise, and printing a warning. + +If any manual ``--os-variant`` value is specified, the default is +all settings off or unset. Use the command "osinfo-query os" to get the list of the accepted OS variant names. diff --git a/tests/data/cli/compare/virt-install-os-detect-fail-fallback.xml b/tests/data/cli/compare/virt-install-os-detect-fail-fallback.xml new file mode 100644 index 00000000..1f4a45e7 --- /dev/null +++ b/tests/data/cli/compare/virt-install-os-detect-fail-fallback.xml @@ -0,0 +1,95 @@ + + win7 + 00000000-1111-2222-3333-444444444444 + + + + + + 65536 + 65536 + 2 + + hvm + + + + + + + + + + + + destroy + + + + + + /usr/bin/test-hv + + + + + + + + + + + + + + + + + + + win7 + 00000000-1111-2222-3333-444444444444 + + + + + + 65536 + 65536 + 2 + + hvm + + + + + + + + + + + + + + + + + /usr/bin/test-hv + + + + + + + + + + + + + + + + + diff --git a/tests/data/cli/compare/virt-install-os-detect-success-fallback.xml b/tests/data/cli/compare/virt-install-os-detect-success-fallback.xml new file mode 100644 index 00000000..8292e63a --- /dev/null +++ b/tests/data/cli/compare/virt-install-os-detect-success-fallback.xml @@ -0,0 +1,87 @@ + + rhel6.0 + 00000000-1111-2222-3333-444444444444 + + + + + + 65536 + 65536 + 2 + + hvm + /VIRTINST-TESTSUITE/vmlinuz + /VIRTINST-TESTSUITE/initrd.img + method=https://foobar.com + + + + + + destroy + + + + + + /usr/bin/test-hv + + + + + + + + + + + + + + + + + + + rhel6.0 + 00000000-1111-2222-3333-444444444444 + + + + + + 65536 + 65536 + 2 + + hvm + + + + + + + + + + + + /usr/bin/test-hv + + + + + + + + + + + + + + + + + diff --git a/tests/test_cli.py b/tests/test_cli.py index 76bf684e..120a1d60 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -869,7 +869,10 @@ c.add_compare("--cdrom http://example.com/path/to/some.iso", "cdrom-url") c.add_compare("--pxe --print-step all --os-variant none", "simple-pxe") # Diskless PXE install c.add_compare("--location ftp://example.com --os-variant auto", "fake-ftp") # fake ftp:// install using urlfetcher.py mocking c.add_compare("--location https://foobar.com --os-variant detect=no", "fake-http") # fake https:// install using urlfetcher.py mocking, but also hit --os-variant detect=no +c.add_compare("--location https://foobar.com --os-variant detect=yes,name=win7", "os-detect-success-fallback") # os detection succeeds, so fallback should be ignored +c.add_compare("--pxe --os-variant detect=yes,name=win7", "os-detect-fail-fallback") # os detection succeeds, so fallback should be ignored c.add_compare("--connect %(URI-KVM)s --install fedora26", "osinfo-url") # getting URL from osinfo +c.add_invalid("--pxe --os-variant detect=yes,require=yes", grep="An --os-variant is required") # No os-variant detected, but require=yes c.add_invalid("--pxe --virt-type bogus") # Bogus virt-type c.add_invalid("--pxe --arch bogus") # Bogus arch c.add_invalid("--livecd") # LiveCD with no media diff --git a/virtinst/cli.py b/virtinst/cli.py index 5a707301..2688661c 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -1795,6 +1795,7 @@ class OSVariantData(object): self._name = None self._id = None self._detect = False + self._require = False def set_compat_str(self, rawstr): if rawstr is None or rawstr == "auto": @@ -1822,6 +1823,8 @@ class OSVariantData(object): return self._detect is False or self._name == "generic" def is_detect(self): return self._detect + def is_require(self): + return self._require def get_name(self): return self._name @@ -1837,6 +1840,7 @@ class ParserOSVariant(VirtCLIParser): cls.add_arg("short-id", "_name") cls.add_arg("id", "_id") cls.add_arg("detect", "_detect", is_onoff=True) + cls.add_arg("require", "_require", is_onoff=True) def parse(self, inst): if "=" not in str(self.optstr): diff --git a/virtinst/virtinstall.py b/virtinst/virtinstall.py index 0e29cc68..6f14ce4c 100644 --- a/virtinst/virtinstall.py +++ b/virtinst/virtinstall.py @@ -530,20 +530,26 @@ def set_explicit_guest_options(options, guest): def installer_detect_distro(guest, installer, osdata): + os_set = False try: # OS name has to be set firstly whenever --os-variant is passed, # otherwise it won't be respected when the installer creates the # Distro Store. if osdata.get_name(): + os_set = True guest.set_os_name(osdata.get_name()) # This also validates the install location autodistro = installer.detect_distro(guest) if osdata.is_detect() and autodistro: + os_set = True guest.set_os_name(autodistro) except ValueError as e: fail(_("Error validating install location: %s") % str(e)) + if not os_set and osdata.is_require(): + fail(_("An --os-variant is required, but no value was set or detected.")) + def _build_options_guest(conn, options): guest = Guest(conn)