urldetect: Move treeinfo media checking into Treeinfo class
Rather than in the base Distro class. Simplifies things a bit
This commit is contained in:
parent
7dacc8502e
commit
b9e72b8609
|
@ -90,7 +90,7 @@ def _fetch_distro(distro):
|
|||
try:
|
||||
fetcher.prepareLocation()
|
||||
store = urldetect.getDistroStore(guest, fetcher)
|
||||
kernel, initrd, ignore = store.acquireKernel(guest)
|
||||
kernel, initrd, ignore = store.acquireKernel()
|
||||
cleanup.append(kernel)
|
||||
cleanup.append(initrd)
|
||||
distro.kernel = kernel
|
||||
|
|
|
@ -207,15 +207,15 @@ def _testURL(fetcher, testdata):
|
|||
|
||||
# Fetch boot iso
|
||||
if testdata.testbootiso:
|
||||
boot = hvmstore.acquireBootDisk(hvmguest)
|
||||
logging.debug("acquireBootDisk: %s", str(boot))
|
||||
boot = hvmstore.acquireBootISO()
|
||||
logging.debug("acquireBootISO: %s", str(boot))
|
||||
|
||||
if boot is not True:
|
||||
raise AssertionError("%s-%s: bootiso fetching failed" %
|
||||
(distname, arch))
|
||||
|
||||
# Fetch regular kernel
|
||||
kern = hvmstore.acquireKernel(hvmguest)
|
||||
kern = hvmstore.acquireKernel()
|
||||
logging.debug("acquireKernel (hvm): %s", str(kern))
|
||||
|
||||
if kern[0] is not True or kern[1] is not True:
|
||||
|
@ -224,7 +224,7 @@ def _testURL(fetcher, testdata):
|
|||
|
||||
# Fetch xen kernel
|
||||
if xenstore:
|
||||
kern = xenstore.acquireKernel(xenguest)
|
||||
kern = xenstore.acquireKernel()
|
||||
logging.debug("acquireKernel (xen): %s", str(kern))
|
||||
|
||||
if kern[0] is not True or kern[1] is not True:
|
||||
|
|
|
@ -108,13 +108,13 @@ class DistroInstaller(Installer):
|
|||
|
||||
def _prepare_cdrom_url(self, guest, fetcher):
|
||||
store = self._get_store(guest, fetcher)
|
||||
media = store.acquireBootDisk(guest)
|
||||
media = store.acquireBootISO()
|
||||
self._tmpfiles.append(media)
|
||||
return media
|
||||
|
||||
def _prepare_kernel_url(self, guest, fetcher):
|
||||
store = self._get_store(guest, fetcher)
|
||||
kernel, initrd, args = store.acquireKernel(guest)
|
||||
kernel, initrd, args = store.acquireKernel()
|
||||
self._tmpfiles.append(kernel)
|
||||
if initrd:
|
||||
self._tmpfiles.append(initrd)
|
||||
|
|
|
@ -246,37 +246,33 @@ class Distro(object):
|
|||
"""Determine if uri points to a tree of the store's distro"""
|
||||
raise NotImplementedError
|
||||
|
||||
def acquireKernel(self, guest):
|
||||
def acquireKernel(self):
|
||||
kernelpath = None
|
||||
initrdpath = None
|
||||
if self.treeinfo:
|
||||
try:
|
||||
kernelpath = self._getTreeinfoMedia("kernel")
|
||||
initrdpath = self._getTreeinfoMedia("initrd")
|
||||
except configparser.NoSectionError:
|
||||
pass
|
||||
|
||||
if not kernelpath or not initrdpath:
|
||||
paths = self._kernel_paths
|
||||
|
||||
for kpath, ipath in paths:
|
||||
if self.fetcher.hasFile(kpath) and self.fetcher.hasFile(ipath):
|
||||
kernelpath = kpath
|
||||
initrdpath = ipath
|
||||
for kpath, ipath in self._kernel_paths:
|
||||
if self.fetcher.hasFile(kpath) and self.fetcher.hasFile(ipath):
|
||||
kernelpath = kpath
|
||||
initrdpath = ipath
|
||||
break
|
||||
|
||||
if not kernelpath or not initrdpath:
|
||||
raise RuntimeError(_("Couldn't find kernel for "
|
||||
"%(distro)s tree.") %
|
||||
{"distro": self.PRETTY_NAME})
|
||||
|
||||
return self._kernelFetchHelper(guest, kernelpath, initrdpath)
|
||||
args = ""
|
||||
if not self.fetcher.location.startswith("/"):
|
||||
args += "%s=%s" % (self._get_method_arg(), self.fetcher.location)
|
||||
|
||||
def acquireBootDisk(self, guest):
|
||||
ignore = guest
|
||||
|
||||
if self.treeinfo:
|
||||
return self.fetcher.acquireFile(self._getTreeinfoMedia("boot.iso"))
|
||||
kernel = self.fetcher.acquireFile(kernelpath)
|
||||
try:
|
||||
initrd = self.fetcher.acquireFile(initrdpath)
|
||||
return kernel, initrd, args
|
||||
except Exception:
|
||||
os.unlink(kernel)
|
||||
raise
|
||||
|
||||
def acquireBootISO(self):
|
||||
for path in self._boot_iso_paths:
|
||||
if self.fetcher.hasFile(path):
|
||||
return self.fetcher.acquireFile(path)
|
||||
|
@ -304,14 +300,6 @@ class Distro(object):
|
|||
def _get_method_arg(self):
|
||||
return "method"
|
||||
|
||||
def _getTreeinfoMedia(self, mediaName):
|
||||
if self.type == "xen":
|
||||
t = "xen"
|
||||
else:
|
||||
t = self.treeinfo.get("general", "arch")
|
||||
|
||||
return self.treeinfo.get("images-%s" % t, mediaName)
|
||||
|
||||
def _fetchAndMatchRegex(self, filename, regex):
|
||||
# Fetch 'filename' and return True/False if it matches the regex
|
||||
try:
|
||||
|
@ -327,23 +315,6 @@ class Distro(object):
|
|||
self.__class__.__name__, filename)
|
||||
return False
|
||||
|
||||
def _kernelFetchHelper(self, guest, kernelpath, initrdpath):
|
||||
# Simple helper for fetching kernel + initrd and performing
|
||||
# cleanup if necessary
|
||||
ignore = guest
|
||||
kernel = self.fetcher.acquireFile(kernelpath)
|
||||
args = ''
|
||||
|
||||
if not self.fetcher.location.startswith("/"):
|
||||
args += "%s=%s" % (self._get_method_arg(), self.fetcher.location)
|
||||
|
||||
try:
|
||||
initrd = self.fetcher.acquireFile(initrdpath)
|
||||
return kernel, initrd, args
|
||||
except Exception:
|
||||
os.unlink(kernel)
|
||||
raise
|
||||
|
||||
|
||||
class GenericTreeinfoDistro(Distro):
|
||||
PRETTY_NAME = "Generic Treeinfo"
|
||||
|
@ -363,6 +334,31 @@ class GenericTreeinfoDistro(Distro):
|
|||
|
||||
self._detect_version()
|
||||
|
||||
if not self.treeinfo:
|
||||
return
|
||||
|
||||
self._kernel_paths = []
|
||||
self._boot_iso_paths = []
|
||||
|
||||
try:
|
||||
self._kernel_paths.append(
|
||||
(self._getTreeinfoMedia("kernel"),
|
||||
self._getTreeinfoMedia("initrd")))
|
||||
except Exception:
|
||||
logging.debug("Failed to parse treeinfo kernel/initrd",
|
||||
exc_info=True)
|
||||
|
||||
try:
|
||||
self._boot_iso_paths.append(self._getTreeinfoMedia("boot.iso"))
|
||||
except Exception:
|
||||
logging.debug("Failed to parse treeinfo boot.iso", exc_info=True)
|
||||
|
||||
def _getTreeinfoMedia(self, mediaName):
|
||||
image_type = self.treeinfo.get("general", "arch")
|
||||
if self.type == "xen":
|
||||
image_type = "xen"
|
||||
return self.treeinfo.get("images-%s" % image_type, mediaName)
|
||||
|
||||
def _detect_version(self):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue