summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2019-01-29 16:05:27 -0500
committerCole Robinson <crobinso@redhat.com>2019-02-03 12:05:18 -0500
commit9995ebc86bdc93bdd18536dbb317a447ced56e35 (patch)
tree9708f569b419a52b3145a35ab8cdd5adfc596aa1
parente2edcc559d46fe16e30b2218279433db76b60ce8 (diff)
downloadvirt-manager-9995ebc86bdc93bdd18536dbb317a447ced56e35.tar.gz
urldetect: Kill acquireKernel
Decompose it into a helper to probe for available kernel paths, but leave the actual file fetching up to the installer class
-rw-r--r--tests/test_urls.ini8
-rw-r--r--tests/test_urls.py24
-rw-r--r--virtinst/installertreemedia.py12
-rw-r--r--virtinst/urldetect.py56
4 files changed, 39 insertions, 61 deletions
diff --git a/tests/test_urls.ini b/tests/test_urls.ini
index c9e887dc..09430589 100644
--- a/tests/test_urls.ini
+++ b/tests/test_urls.ini
@@ -12,7 +12,7 @@
[fedora-old]
url = https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/14/Fedora/x86_64/os/
distro = fedora14
-kernelarg = method=
+kernelarg = method
[fedora-old-i686]
url = https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/14/Fedora/i386/os/
distro = fedora14
@@ -33,7 +33,7 @@ distro = fedora27
url = http://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/Server/x86_64/os/
distro = fedora-unknown
testxen = 1
-kernelarg = inst.repo=
+kernelarg = inst.repo
@@ -100,14 +100,14 @@ distro = opensuse13.2
[opensuseleap-42.3]
url = http://download.opensuse.org/distribution/leap/42.3/repo/oss/
distro = opensuse42.3
-kernelarg = install=
+kernelarg = install
# opensuse tumbleweed (rolling distro)
# Test for xen for full coverage
[opensusetumbleweed]
url = http://download.opensuse.org/tumbleweed/repo/oss/
distro = opensusetumbleweed
testxen = 1
-kernelarg = install=
+kernelarg = install
diff --git a/tests/test_urls.py b/tests/test_urls.py
index 055d0c8c..65ec9680 100644
--- a/tests/test_urls.py
+++ b/tests/test_urls.py
@@ -174,40 +174,26 @@ def _testURL(fetcher, testdata):
(s.get_osdict_info(), detectdistro,
distname, fetcher.location, testdata.distroclass))
- # Do this only after the distro detection, since we actually need
- # to fetch files for that part
- def fakeAcquireFile(filename):
- logging.debug("Fake acquiring %s", filename)
- if not fetcher.hasFile(filename):
- return False
- return filename
- fetcher.acquireFile = fakeAcquireFile
-
# Fetch regular kernel
- kernel, initrd, kernelargs = hvmstore.acquireKernel()
- if kernel is False or initrd is False:
- AssertionError("%s-%s: hvm kernel fetching failed" %
- (distname, arch))
-
+ kernel, initrd = hvmstore.check_kernel_paths()
+ dummy = initrd
if testdata.kernelregex and not re.match(testdata.kernelregex, kernel):
raise AssertionError("kernel=%s but testdata.kernelregex='%s'" %
(kernel, testdata.kernelregex))
+ kernelargs = hvmstore.get_kernel_url_arg()
if testdata.kernelarg == "None":
if bool(kernelargs):
raise AssertionError("kernelargs='%s' but testdata.kernelarg='%s'"
% (kernelargs, testdata.kernelarg))
elif testdata.kernelarg:
- if not kernelargs.startswith(testdata.kernelarg):
+ if not kernelargs == testdata.kernelarg:
raise AssertionError("kernelargs='%s' but testdata.kernelarg='%s'"
% (kernelargs, testdata.kernelarg))
# Fetch xen kernel
if xenstore:
- kernel, initrd, kernelargs = xenstore.acquireKernel()
- if kernel is False or initrd is False:
- raise AssertionError("%s-%s: xen kernel fetching failed" %
- (distname, arch))
+ xenstore.check_kernel_paths()
def _fetchWrapper(url, cb):
diff --git a/virtinst/installertreemedia.py b/virtinst/installertreemedia.py
index aa0978e9..9887d41b 100644
--- a/virtinst/installertreemedia.py
+++ b/virtinst/installertreemedia.py
@@ -113,10 +113,16 @@ class InstallerTreeMedia(object):
def _prepare_kernel_url(self, guest, fetcher):
store = self._get_store(guest, fetcher)
- kernel, initrd, args = store.acquireKernel()
+ kernelpath, initrdpath = store.check_kernel_paths()
+
+ kernel = fetcher.acquireFile(kernelpath)
self._tmpfiles.append(kernel)
- if initrd:
- self._tmpfiles.append(initrd)
+ initrd = fetcher.acquireFile(initrdpath)
+ self._tmpfiles.append(initrd)
+
+ args = ""
+ if not self.location.startswith("/") and store.get_kernel_url_arg():
+ args += "%s=%s" % (store.get_kernel_url_arg(), self.location)
perform_initrd_injections(initrd,
self.initrd_injections,
diff --git a/virtinst/urldetect.py b/virtinst/urldetect.py
index c1a1081c..6987c3a4 100644
--- a/virtinst/urldetect.py
+++ b/virtinst/urldetect.py
@@ -6,7 +6,6 @@
import configparser
import logging
-import os
import re
from .osdict import OSDB
@@ -326,10 +325,6 @@ class Distro(object):
self._set_manual_kernel_paths()
- @classmethod
- def is_valid(cls, cache):
- raise NotImplementedError
-
def _set_manual_kernel_paths(self):
"""
If kernel/initrd path could not be determined from a source
@@ -338,31 +333,29 @@ class Distro(object):
"""
pass
- def acquireKernel(self):
- kernelpath = None
- initrdpath = None
- for kpath, ipath in self._kernel_paths:
- if self.fetcher.hasFile(kpath) and self.fetcher.hasFile(ipath):
- kernelpath = kpath
- initrdpath = ipath
- break
+ def _detect_version(self):
+ """
+ Hook for subclasses to detect media os variant.
+ """
+ logging.debug("%s does not implement any osdict detection", self)
+ return None
- if not kernelpath or not initrdpath:
- raise RuntimeError(_("Couldn't find kernel for "
- "%(distro)s tree.") %
- {"distro": self.PRETTY_NAME})
- args = ""
- if not self.uri.startswith("/") and self._get_kernel_url_arg():
- args += "%s=%s" % (self._get_kernel_url_arg(), self.uri)
+ ##############
+ # Public API #
+ ##############
- kernel = self.fetcher.acquireFile(kernelpath)
- try:
- initrd = self.fetcher.acquireFile(initrdpath)
- return kernel, initrd, args
- except Exception:
- os.unlink(kernel)
- raise
+ @classmethod
+ def is_valid(cls, cache):
+ raise NotImplementedError
+
+ def check_kernel_paths(self):
+ for kpath, ipath in self._kernel_paths:
+ if self.fetcher.hasFile(kpath) and self.fetcher.hasFile(ipath):
+ return kpath, ipath
+ raise RuntimeError(_("Couldn't find kernel for "
+ "%(distro)s tree.") %
+ {"distro": self.PRETTY_NAME})
def get_osdict_info(self):
"""
@@ -370,14 +363,7 @@ class Distro(object):
"""
return self._os_variant
- def _detect_version(self):
- """
- Hook for subclasses to detect media os variant.
- """
- logging.debug("%s does not implement any osdict detection", self)
- return None
-
- def _get_kernel_url_arg(self):
+ def get_kernel_url_arg(self):
"""
Kernel argument name the distro's installer uses to reference
a network source, possibly bypassing some installer prompts