installer: Drop check_location

detect_distro does it all already nowadays, so there's no
real reason to have a separate entry point.
This commit is contained in:
Cole Robinson 2019-01-30 17:07:36 -05:00
parent 4b54b281b9
commit c20e78926b
4 changed files with 53 additions and 49 deletions

View File

@ -1,6 +1,11 @@
<domain type="kvm">
<name>foobar</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/fedora/17"/>
</libosinfo:libosinfo>
</metadata>
<memory>65536</memory>
<currentMemory>65536</currentMemory>
<vcpu>1</vcpu>
@ -30,12 +35,12 @@
<disk type="file" device="disk">
<driver name="qemu" type="qcow2"/>
<source file="/dev/default-pool/testvol1.img"/>
<target dev="hda" bus="ide"/>
<target dev="vda" bus="virtio"/>
</disk>
<disk type="file" device="cdrom">
<driver name="qemu"/>
<source file="/tmp/fake-fedora17-tree.iso"/>
<target dev="hdb" bus="ide"/>
<target dev="hda" bus="ide"/>
<readonly/>
</disk>
<controller type="usb" index="0" model="ich9-ehci1"/>
@ -49,6 +54,13 @@
<master startport="4"/>
</controller>
<console type="pty"/>
<channel type="unix">
<source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/>
</channel>
<channel type="spicevmc">
<target type="virtio" name="com.redhat.spice.0"/>
</channel>
<input type="tablet" bus="usb"/>
<graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
<image compression="off"/>
@ -59,11 +71,19 @@
</video>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>
<domain type="kvm">
<name>foobar</name>
<uuid>00000000-1111-2222-3333-444444444444</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/fedora/17"/>
</libosinfo:libosinfo>
</metadata>
<memory>65536</memory>
<currentMemory>65536</currentMemory>
<vcpu>1</vcpu>
@ -91,10 +111,10 @@
<disk type="file" device="disk">
<driver name="qemu" type="qcow2"/>
<source file="/dev/default-pool/testvol1.img"/>
<target dev="hda" bus="ide"/>
<target dev="vda" bus="virtio"/>
</disk>
<disk type="file" device="cdrom">
<target dev="hdb" bus="ide"/>
<target dev="hda" bus="ide"/>
<readonly/>
</disk>
<controller type="usb" index="0" model="ich9-ehci1"/>
@ -108,6 +128,13 @@
<master startport="4"/>
</controller>
<console type="pty"/>
<channel type="unix">
<source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/>
</channel>
<channel type="spicevmc">
<target type="virtio" name="com.redhat.spice.0"/>
</channel>
<input type="tablet" bus="usb"/>
<graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
<image compression="off"/>
@ -118,5 +145,8 @@
</video>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>

View File

@ -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))

View File

@ -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

View File

@ -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()