installer: Prefer "cdrom" over "floppy"

Instead of using "floppy" as the way to perform unattended installations
for Windoes, let's prefer using "cdrom" instead.

The main reasons behind this change are:
- VMs using q35 may have floppy device disabled in some systems;
- We can drop mstools dependency;

Generating the ISO depends on genisofs, tho. However, it's not a big
deal as genisofs is already a virt-manager dependency.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
Fabiano Fidêncio
2019-06-07 12:00:56 +02:00
committed by Cole Robinson
parent 473f5c14d6
commit fd5bd5d90f
4 changed files with 33 additions and 30 deletions

View File

@@ -48,11 +48,6 @@ Requires: dconf
# no ambiguity.
Requires: vte291
# Those two dependencies are needed in order to support unattended
# installation for Windows guests.
Requires: dosfstools
Requires: mtools
# Weak dependencies for the common virt-manager usecase
Recommends: (libvirt-daemon-kvm or libvirt-daemon-qemu)
Recommends: libvirt-daemon-config-network

View File

@@ -6,11 +6,12 @@
import logging
import os
import shutil
import subprocess
import tempfile
def perform_floppy_injections(injections, scratchdir):
def perform_cdrom_injections(injections, scratchdir):
"""
Insert files into the root directory of a floppy
"""
@@ -20,17 +21,24 @@ def perform_floppy_injections(injections, scratchdir):
tempdir = tempfile.mkdtemp(dir=scratchdir)
os.chmod(tempdir, 0o775)
img = os.path.join(tempdir, "unattended.img")
tempfiles = []
iso = os.path.join(tempdir, "unattended.iso")
for filename in injections:
shutil.copy(filename, tempdir)
cmd = ["mkfs.msdos", "-C", img, "1440"]
tempfiles = os.listdir(tempdir)
cmd = ["mkisofs",
"-o", iso,
"-J",
"-input-charset", "utf8",
"-rational-rock",
tempdir]
logging.debug("Running mkisofs: %s", cmd)
output = subprocess.check_output(cmd)
logging.debug("cmd output: %s", output)
for filename in injections:
logging.debug("Copying %s to the floppy.", filename)
cmd = ["mcopy", "-i", img, filename, "::"]
output = subprocess.check_output(cmd)
logging.debug("cmd output: %s", output)
for f in tempfiles:
os.unlink(os.path.join(tempdir, f))
return img
return iso

View File

@@ -15,7 +15,7 @@ from .devices import DeviceDisk
from .domain import DomainOs
from .osdict import OSDB, OsMedia
from .installertreemedia import InstallerTreeMedia
from .floppyinject import perform_floppy_injections
from .cdrominject import perform_cdrom_injections
from . import unattended
from . import util
@@ -51,7 +51,7 @@ class Installer(object):
self._install_kernel = None
self._install_initrd = None
self._install_cdrom_device_added = False
self._install_floppy_device = False
self._unattended_install_cdrom_device = None
self._unattended_files = []
self._defaults_are_set = False
self._unattended_data = None
@@ -119,25 +119,25 @@ class Installer(object):
disk.sync_path_props()
break
def _add_install_floppy_device(self, guest, location):
if self._install_floppy_device:
def _add_unattended_install_cdrom_device(self, guest, location):
if self._unattended_install_cdrom_device:
return
dev = DeviceDisk(self.conn)
dev.device = dev.DEVICE_FLOPPY
dev.device = dev.DEVICE_CDROM
dev.path = location
dev.sync_path_props()
dev.validate()
dev.set_defaults(guest)
self._install_floppy_device = dev
guest.add_device(self._install_floppy_device)
self._unattended_install_cdrom_device = dev
guest.add_device(self._unattended_install_cdrom_device)
def _remove_install_floppy_device(self, guest):
def _remove_unattended_install_cdrom_device(self, guest):
dummy = guest
if not self._install_floppy_device:
if not self._unattended_install_cdrom_device:
return
self._install_floppy_device.path = None
self._install_floppy_device.sync_path_props()
self._unattended_install_cdrom_device.path = None
self._unattended_install_cdrom_device.sync_path_props()
def _cleanup_unattended_files(self):
dirs = []
@@ -236,10 +236,10 @@ class Installer(object):
logging.debug("Generated script contents:\n%s",
open(path).read())
floppy = perform_floppy_injections([path], util.get_cache_dir())
self._add_install_floppy_device(guest, floppy)
iso = perform_cdrom_injections([path], util.get_cache_dir())
self._add_unattended_install_cdrom_device(guest, iso)
self._unattended_files.extend([path, floppy])
self._unattended_files.extend([path, iso])
def _cleanup(self, guest):
if self._treemedia:
@@ -388,7 +388,7 @@ class Installer(object):
return ret
finally:
self._remove_install_cdrom_media(guest)
self._remove_install_floppy_device(guest)
self._remove_unattended_install_cdrom_device(guest)
self._finish_get_install_xml(guest, data)
def _build_xml(self, guest, meter):

View File

@@ -252,7 +252,7 @@ def prepare_install_script(guest, unattended_data, url=None, os_media=None):
# For all tree based installations we're going to perform initrd injection
# and install the systems via network.
injection_method = "floppy" if guest.osinfo.is_windows() else "initrd"
injection_method = "cdrom" if guest.osinfo.is_windows() else "initrd"
script.set_preferred_injection_method(injection_method)
installationsource = _get_installation_source(os_media)