From c20e78926b87274d8672e55722d30d56bf09aa6b Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Wed, 30 Jan 2019 17:07:36 -0500 Subject: [PATCH] installer: Drop check_location detect_distro does it all already nowadays, so there's no real reason to have a separate entry point. --- .../compare/virt-install-location-iso.xml | 38 +++++++++++++++++-- virt-install | 6 +-- virtinst/installer.py | 29 ++++++-------- virtinst/installertreemedia.py | 29 ++------------ 4 files changed, 53 insertions(+), 49 deletions(-) diff --git a/tests/cli-test-xml/compare/virt-install-location-iso.xml b/tests/cli-test-xml/compare/virt-install-location-iso.xml index d570a07e2..5bccab2a3 100644 --- a/tests/cli-test-xml/compare/virt-install-location-iso.xml +++ b/tests/cli-test-xml/compare/virt-install-location-iso.xml @@ -1,6 +1,11 @@ foobar 00000000-1111-2222-3333-444444444444 + + + + + 65536 65536 1 @@ -30,12 +35,12 @@ - + - + @@ -49,6 +54,13 @@ + + + + + + + @@ -59,11 +71,19 @@ + + /dev/urandom + foobar 00000000-1111-2222-3333-444444444444 + + + + + 65536 65536 1 @@ -91,10 +111,10 @@ - + - + @@ -108,6 +128,13 @@ + + + + + + + @@ -118,5 +145,8 @@ + + /dev/urandom + diff --git a/virt-install b/virt-install index 1984688b8..a228cd2d8 100755 --- a/virt-install +++ b/virt-install @@ -303,13 +303,13 @@ def convert_old_features(options): def set_distro_variant(options, guest, installer): distro = None try: - installer.check_location(guest) + # This also validates the install location + autodistro = installer.detect_distro(guest) if options.distro_variant == "auto": - distro = installer.detect_distro(guest) + distro = autodistro elif options.distro_variant != "none": distro = options.distro_variant - except ValueError as e: fail(_("Error validating install location: %s") % str(e)) diff --git a/virtinst/installer.py b/virtinst/installer.py index 8ada06ea7..34c7b3441 100644 --- a/virtinst/installer.py +++ b/virtinst/installer.py @@ -13,6 +13,7 @@ import libvirt from .devices import DeviceDisk from .domain import DomainOs +from .osdict import OSDB from .installertreemedia import InstallerTreeMedia from . import util @@ -244,15 +245,6 @@ class Installer(object): self._install_bootdev or self._treemedia) - def check_location(self, guest): - """ - Validate self.location seems to work. This will might hit the - network so we don't want to do it on demand. - """ - if self._treemedia: - return self._treemedia.check_location(guest) - return True - def detect_distro(self, guest): """ Attempt to detect the distro for the Installer's 'location'. If @@ -262,15 +254,18 @@ class Installer(object): :returns: distro variant string, or None """ ret = None - try: - if self._treemedia: - ret = self._treemedia.detect_distro(guest) - elif self.cdrom: - ret = InstallerTreeMedia.detect_iso_distro(guest, self.cdrom) + if self._treemedia: + ret = self._treemedia.detect_distro(guest) + elif self.cdrom: + if guest.conn.is_remote(): + logging.debug("Can't detect distro for cdrom " + "remote connection.") else: - logging.debug("No media for distro detection.") - except Exception: - logging.debug("Error attempting to detect distro.", exc_info=True) + osguess = OSDB.guess_os_by_iso(self.cdrom) + if osguess: + ret = osguess[0] + else: + logging.debug("No media for distro detection.") logging.debug("installer.detect_distro returned=%s", ret) return ret diff --git a/virtinst/installertreemedia.py b/virtinst/installertreemedia.py index 1331cb9f0..79bc2f291 100644 --- a/virtinst/installertreemedia.py +++ b/virtinst/installertreemedia.py @@ -13,9 +13,6 @@ from . import util from .devices import DeviceDisk from .initrdinject import perform_initrd_injections from .kernelupload import upload_kernel_initrd -from .osdict import OSDB - - # Enum of the various install media types we can have @@ -58,16 +55,6 @@ class InstallerTreeMedia(object): raise ValueError(_("Validating install media '%s' failed: %s") % (str(path), e)) - @staticmethod - def detect_iso_distro(guest, path): - if guest.conn.is_remote(): - logging.debug("Can't detect distro for media on " - "remote connection.") - return None - ret = OSDB.guess_os_by_iso(path) - if ret: - return ret[0] - def __init__(self, conn, location): self.conn = conn self.location = location @@ -87,6 +74,10 @@ class InstallerTreeMedia(object): elif _is_url(self.location): self._media_type = MEDIA_URL + if self.conn.is_remote() and not self._media_type == MEDIA_URL: + raise ValueError(_("Cannot access install tree on remote " + "connection: %s") % self.location) + if self._media_type == MEDIA_ISO: InstallerTreeMedia.validate_path(self.conn, self.location) @@ -163,19 +154,7 @@ class InstallerTreeMedia(object): if self._media_type in [MEDIA_ISO]: return self.location - def check_location(self, guest): - if self._media_type not in [MEDIA_URL]: - return True - - fetcher = self._get_fetcher(guest, None) - # This will throw an error for us - ignore = self._get_store(guest, fetcher) - return True - def detect_distro(self, guest): - if self._media_type in [MEDIA_ISO]: - return InstallerTreeMedia.detect_iso_distro(guest, self.location) - fetcher = self._get_fetcher(guest, None) store = self._get_store(guest, fetcher) return store.get_osdict_info()