Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
client/tools/virt_disk.py | 6 +-
client/virt/tests/unattended_install.py | 24 +--
client/virt/utils_disk.py | 249 ++++++++++++++++++++++++++++++++
client/virt/virt_utils_disk.py | 249 --------------------------------
4 files changed, 264 insertions(+), 264 deletions(-)
create mode 100644 client/virt/utils_disk.py
delete mode 100644 client/virt/virt_utils_disk.py
diff --git a/client/tools/virt_disk.py b/client/tools/virt_disk.py
index 7606a62..932e134 100755
--- a/client/tools/virt_disk.py
+++ b/client/tools/virt_disk.py
@@ -10,7 +10,7 @@ disks just like they're created by the virt unattended test
installation.
import sys, optparse
import common
-from autotest.client.virt import virt_utils, virt_utils_disk
+from autotest.client.virt import virt_utils, utils_disk
class OptionParser(optparse.OptionParser):
@@ -73,11 +73,11 @@ class App:
def main(self):
self.parse_cmdline()
if self.options.floppy:
- self.disk = virt_utils_disk.FloppyDisk(self.image,
+ self.disk = utils_disk.FloppyDisk(self.image,
self.options.qemu_img,
self.options.temp)
elif self.options.cdrom:
- self.disk = virt_utils_disk.CdromDisk(self.image,
+ self.disk = utils_disk.CdromDisk(self.image,
self.options.temp)
for f in self.files:
diff --git a/client/virt/tests/unattended_install.py
b/client/virt/tests/unattended_install.py
index eb83324..77f16cb 100644
--- a/client/virt/tests/unattended_install.py
+++ b/client/virt/tests/unattended_install.py
@@ -3,7 +3,7 @@ import threading
import xml.dom.minidom
from autotest.client.shared import error, iso9660
from autotest.client import utils
-from autotest.client.virt import virt_vm, virt_utils, virt_utils_disk
+from autotest.client.virt import virt_vm, virt_utils, utils_disk
from autotest.client.virt import kvm_monitor, remote, syslog_server
from autotest.client.virt import http_server
@@ -79,7 +79,7 @@ class RemoteInstall(object):
"""
def __init__(self, path, ip, port, filename):
self.path = path
- virt_utils_disk.cleanup(self.path)
+ utils_disk.cleanup(self.path)
os.makedirs(self.path)
self.ip = ip
self.port = port
@@ -441,7 +441,7 @@ class UnattendedInstallConfig(object):
if self.unattended_file.endswith('.sif'):
dest_fname = 'winnt.sif'
setup_file = 'winnt.bat'
- boot_disk = virt_utils_disk.FloppyDisk(self.floppy,
+ boot_disk = utils_disk.FloppyDisk(self.floppy,
self.qemu_img_binary,
self.tmpdir)
answer_path = boot_disk.get_answer_file_path(dest_fname)
@@ -475,7 +475,7 @@ class UnattendedInstallConfig(object):
kernel_params)
self.params['kernel_params'] = ''
- boot_disk = virt_utils_disk.CdromInstallDisk(
+ boot_disk = utils_disk.CdromInstallDisk(
self.cdrom_unattended,
self.tmpdir,
self.cdrom_cd1_mount,
@@ -518,10 +518,10 @@ class UnattendedInstallConfig(object):
self.params['kernel_params'] = kernel_params
elif self.params.get('unattended_delivery_method') == 'cdrom':
- boot_disk = virt_utils_disk.CdromDisk(self.cdrom_unattended,
+ boot_disk = utils_disk.CdromDisk(self.cdrom_unattended,
self.tmpdir)
elif self.params.get('unattended_delivery_method') == 'floppy':
- boot_disk = virt_utils_disk.FloppyDisk(self.floppy,
+ boot_disk = utils_disk.FloppyDisk(self.floppy,
self.qemu_img_binary,
self.tmpdir)
else:
@@ -535,10 +535,10 @@ class UnattendedInstallConfig(object):
# SUSE autoyast install
dest_fname = "autoinst.xml"
if self.cdrom_unattended:
- boot_disk =
virt_utils_disk.CdromDisk(self.cdrom_unattended,
+ boot_disk = utils_disk.CdromDisk(self.cdrom_unattended,
self.tmpdir)
elif self.floppy:
- boot_disk = virt_utils_disk.FloppyDisk(self.floppy,
+ boot_disk = utils_disk.FloppyDisk(self.floppy,
self.qemu_img_binary,
self.tmpdir)
else:
@@ -550,7 +550,7 @@ class UnattendedInstallConfig(object):
else:
# Windows unattended install
dest_fname = "autounattend.xml"
- boot_disk = virt_utils_disk.FloppyDisk(self.floppy,
+ boot_disk = utils_disk.FloppyDisk(self.floppy,
self.qemu_img_binary,
self.tmpdir)
answer_path = boot_disk.get_answer_file_path(dest_fname)
@@ -610,7 +610,7 @@ class UnattendedInstallConfig(object):
if (self.params.get('unattended_delivery_method') !=
'integrated'):
i.close()
- virt_utils_disk.cleanup(self.cdrom_cd1_mount)
+ utils_disk.cleanup(self.cdrom_cd1_mount)
elif ((self.vm.driver_type == 'xen') and
(self.params.get('hvm_or_pv') == 'pv')):
logging.debug("starting unattended content web server")
@@ -703,7 +703,7 @@ class UnattendedInstallConfig(object):
os.path.basename(self.initrd),
self.image_path))
utils.run(initrd_fetch_cmd, verbose=DEBUG)
finally:
- virt_utils_disk.cleanup(self.nfs_mount)
+ utils_disk.cleanup(self.nfs_mount)
def setup_import(self):
@@ -844,7 +844,7 @@ def run_unattended_install(test, params, env):
_url_auto_content_server_thread_event.set()
_url_auto_content_server_thread.join(3)
_url_auto_content_server_thread = None
- virt_utils_disk.cleanup(unattended_install_config.cdrom_cd1_mount)
+ utils_disk.cleanup(unattended_install_config.cdrom_cd1_mount)
global _unattended_server_thread
global _unattended_server_thread_event
diff --git a/client/virt/utils_disk.py b/client/virt/utils_disk.py
new file mode 100644
index 0000000..6a573c5
--- /dev/null
+++ b/client/virt/utils_disk.py
@@ -0,0 +1,249 @@
+"""
+Virtualization test - Virtual disk related utility functions
+
+@copyright: Red Hat Inc.
+"""
+
+import os, glob, shutil, tempfile, logging, ConfigParser
+from autotest.client import utils
+from autotest.client.shared import error
+
+
+# Whether to print all shell commands called
+DEBUG = False
+
+
[email protected]_aware
+def cleanup(folder):
+ """
+ If folder is a mountpoint, do what is possible to unmount it. Afterwards,
+ try to remove it.
+
+ @param folder: Directory to be cleaned up.
+ """
+ error.context("cleaning up unattended install directory %s" % folder)
+ if os.path.ismount(folder):
+ utils.run('fuser -k %s' % folder, ignore_status=True, verbose=DEBUG)
+ utils.run('umount %s' % folder, verbose=DEBUG)
+ if os.path.isdir(folder):
+ shutil.rmtree(folder)
+
+
[email protected]_aware
+def clean_old_image(image):
+ """
+ Clean a leftover image file from previous processes. If it contains a
+ mounted file system, do the proper cleanup procedures.
+
+ @param image: Path to image to be cleaned up.
+ """
+ error.context("cleaning up old leftover image %s" % image)
+ if os.path.exists(image):
+ mtab = open('/etc/mtab', 'r')
+ mtab_contents = mtab.read()
+ mtab.close()
+ if image in mtab_contents:
+ utils.run('fuser -k %s' % image, ignore_status=True, verbose=DEBUG)
+ utils.run('umount %s' % image, verbose=DEBUG)
+ os.remove(image)
+
+
+class Disk(object):
+ """
+ Abstract class for Disk objects, with the common methods implemented.
+ """
+ def __init__(self):
+ self.path = None
+
+
+ def get_answer_file_path(self, filename):
+ return os.path.join(self.mount, filename)
+
+
+ def copy_to(self, src):
+ logging.debug("Copying %s to disk image mount", src)
+ dst = os.path.join(self.mount, os.path.basename(src))
+ if os.path.isdir(src):
+ shutil.copytree(src, dst)
+ elif os.path.isfile(src):
+ shutil.copyfile(src, dst)
+
+
+ def close(self):
+ os.chmod(self.path, 0755)
+ cleanup(self.mount)
+ logging.debug("Disk %s successfuly set", self.path)
+
+
+class FloppyDisk(Disk):
+ """
+ Represents a 1.44 MB floppy disk. We can copy files to it, and setup it in
+ convenient ways.
+ """
+ @error.context_aware
+ def __init__(self, path, qemu_img_binary, tmpdir):
+ error.context("Creating unattended install floppy image %s" % path)
+ self.tmpdir = tmpdir
+ self.mount = tempfile.mkdtemp(prefix='floppy_', dir=self.tmpdir)
+ self.virtio_mount = None
+ self.path = path
+ clean_old_image(path)
+ if not os.path.isdir(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+
+ try:
+ c_cmd = '%s create -f raw %s 1440k' % (qemu_img_binary, path)
+ utils.run(c_cmd, verbose=DEBUG)
+ f_cmd = 'mkfs.msdos -s 1 %s' % path
+ utils.run(f_cmd, verbose=DEBUG)
+ m_cmd = 'mount -o loop,rw %s %s' % (path, self.mount)
+ utils.run(m_cmd, verbose=DEBUG)
+ except error.CmdError, e:
+ logging.error("Error during floppy initialization: %s" % e)
+ cleanup(self.mount)
+ raise
+
+
+ def _copy_virtio_drivers(self, virtio_floppy):
+ """
+ Copy the virtio drivers on the virtio floppy to the install floppy.
+
+ 1) Mount the floppy containing the viostor drivers
+ 2) Copy its contents to the root of the install floppy
+ """
+ virtio_mount = tempfile.mkdtemp(prefix='virtio_floppy_',
+ dir=self.tmpdir)
+
+ pwd = os.getcwd()
+ try:
+ m_cmd = 'mount -o loop,ro %s %s' % (virtio_floppy, virtio_mount)
+ utils.run(m_cmd, verbose=DEBUG)
+ os.chdir(virtio_mount)
+ path_list = glob.glob('*')
+ for path in path_list:
+ self.copy_to(path)
+ finally:
+ os.chdir(pwd)
+ cleanup(virtio_mount)
+
+
+ def setup_virtio_win2003(self, virtio_floppy, virtio_oemsetup_id):
+ """
+ Setup the install floppy with the virtio storage drivers, win2003
style.
+
+ Win2003 and WinXP depend on the file txtsetup.oem file to install
+ the virtio drivers from the floppy, which is a .ini file.
+ Process:
+
+ 1) Copy the virtio drivers on the virtio floppy to the install floppy
+ 2) Parse the ini file with config parser
+ 3) Modify the identifier of the default session that is going to be
+ executed on the config parser object
+ 4) Re-write the config file to the disk
+ """
+ self._copy_virtio_drivers(virtio_floppy)
+ txtsetup_oem = os.path.join(self.mount, 'txtsetup.oem')
+ if not os.path.isfile(txtsetup_oem):
+ raise IOError('File txtsetup.oem not found on the install '
+ 'floppy. Please verify if your floppy virtio '
+ 'driver image has this file')
+ parser = ConfigParser.ConfigParser()
+ parser.read(txtsetup_oem)
+ if not parser.has_section('Defaults'):
+ raise ValueError('File txtsetup.oem does not have the session '
+ '"Defaults". Please check txtsetup.oem')
+ default_driver = parser.get('Defaults', 'SCSI')
+ if default_driver != virtio_oemsetup_id:
+ parser.set('Defaults', 'SCSI', virtio_oemsetup_id)
+ fp = open(txtsetup_oem, 'w')
+ parser.write(fp)
+ fp.close()
+
+
+ def setup_virtio_win2008(self, virtio_floppy):
+ """
+ Setup the install floppy with the virtio storage drivers, win2008
style.
+
+ Win2008, Vista and 7 require people to point out the path to the
drivers
+ on the unattended file, so we just need to copy the drivers to the
+ driver floppy disk. Important to note that it's possible to specify
+ drivers from a CDROM, so the floppy driver copy is optional.
+ Process:
+
+ 1) Copy the virtio drivers on the virtio floppy to the install floppy,
+ if there is one available
+ """
+ if os.path.isfile(virtio_floppy):
+ self._copy_virtio_drivers(virtio_floppy)
+ else:
+ logging.debug("No virtio floppy present, not needed for this OS
anyway")
+
+
+class CdromDisk(Disk):
+ """
+ Represents a CDROM disk that we can master according to our needs.
+ """
+ def __init__(self, path, tmpdir):
+ self.mount = tempfile.mkdtemp(prefix='cdrom_unattended_', dir=tmpdir)
+ self.path = path
+ clean_old_image(path)
+ if not os.path.isdir(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+
+
+ @error.context_aware
+ def close(self):
+ error.context("Creating unattended install CD image %s" % self.path)
+ g_cmd = ('mkisofs -o %s -max-iso9660-filenames '
+ '-relaxed-filenames -D --input-charset iso8859-1 '
+ '%s' % (self.path, self.mount))
+ utils.run(g_cmd, verbose=DEBUG)
+
+ os.chmod(self.path, 0755)
+ cleanup(self.mount)
+ logging.debug("unattended install CD image %s successfuly created",
+ self.path)
+
+
+class CdromInstallDisk(Disk):
+ """
+ Represents a install CDROM disk that we can master according to our needs.
+ """
+ def __init__(self, path, tmpdir, source_cdrom, extra_params):
+ self.mount = tempfile.mkdtemp(prefix='cdrom_unattended_', dir=tmpdir)
+ self.path = path
+ self.extra_params = extra_params
+ self.source_cdrom = source_cdrom
+ cleanup(path)
+ if not os.path.isdir(os.path.dirname(path)):
+ os.makedirs(os.path.dirname(path))
+ cp_cmd = ('cp -r %s/isolinux/ %s/' % (source_cdrom, self.mount))
+ listdir = os.listdir(self.source_cdrom)
+ for i in listdir:
+ if i == 'isolinux':
+ continue
+ os.symlink(os.path.join(self.source_cdrom, i),
+ os.path.join(self.mount, i))
+ utils.run(cp_cmd)
+
+
+ def get_answer_file_path(self, filename):
+ return os.path.join(self.mount, 'isolinux', filename)
+
+
+ @error.context_aware
+ def close(self):
+ error.context("Creating unattended install CD image %s" % self.path)
+ f = open(os.path.join(self.mount, 'isolinux', 'isolinux.cfg'), 'w')
+ f.write('default /isolinux/vmlinuz append initrd=/isolinux/initrd.img '
+ '%s\n' % self.extra_params)
+ f.close()
+ m_cmd = ('mkisofs -o %s -b isolinux/isolinux.bin -c isolinux/boot.cat '
+ '-no-emul-boot -boot-load-size 4 -boot-info-table -f -R -J '
+ '-V -T %s' % (self.path, self.mount))
+ utils.run(m_cmd)
+ os.chmod(self.path, 0755)
+ cleanup(self.mount)
+ cleanup(self.source_cdrom)
+ logging.debug("unattended install CD image %s successfully created",
+ self.path)
diff --git a/client/virt/virt_utils_disk.py b/client/virt/virt_utils_disk.py
deleted file mode 100644
index 6a573c5..0000000
--- a/client/virt/virt_utils_disk.py
+++ /dev/null
@@ -1,249 +0,0 @@
-"""
-Virtualization test - Virtual disk related utility functions
-
-@copyright: Red Hat Inc.
-"""
-
-import os, glob, shutil, tempfile, logging, ConfigParser
-from autotest.client import utils
-from autotest.client.shared import error
-
-
-# Whether to print all shell commands called
-DEBUG = False
-
-
[email protected]_aware
-def cleanup(folder):
- """
- If folder is a mountpoint, do what is possible to unmount it. Afterwards,
- try to remove it.
-
- @param folder: Directory to be cleaned up.
- """
- error.context("cleaning up unattended install directory %s" % folder)
- if os.path.ismount(folder):
- utils.run('fuser -k %s' % folder, ignore_status=True, verbose=DEBUG)
- utils.run('umount %s' % folder, verbose=DEBUG)
- if os.path.isdir(folder):
- shutil.rmtree(folder)
-
-
[email protected]_aware
-def clean_old_image(image):
- """
- Clean a leftover image file from previous processes. If it contains a
- mounted file system, do the proper cleanup procedures.
-
- @param image: Path to image to be cleaned up.
- """
- error.context("cleaning up old leftover image %s" % image)
- if os.path.exists(image):
- mtab = open('/etc/mtab', 'r')
- mtab_contents = mtab.read()
- mtab.close()
- if image in mtab_contents:
- utils.run('fuser -k %s' % image, ignore_status=True, verbose=DEBUG)
- utils.run('umount %s' % image, verbose=DEBUG)
- os.remove(image)
-
-
-class Disk(object):
- """
- Abstract class for Disk objects, with the common methods implemented.
- """
- def __init__(self):
- self.path = None
-
-
- def get_answer_file_path(self, filename):
- return os.path.join(self.mount, filename)
-
-
- def copy_to(self, src):
- logging.debug("Copying %s to disk image mount", src)
- dst = os.path.join(self.mount, os.path.basename(src))
- if os.path.isdir(src):
- shutil.copytree(src, dst)
- elif os.path.isfile(src):
- shutil.copyfile(src, dst)
-
-
- def close(self):
- os.chmod(self.path, 0755)
- cleanup(self.mount)
- logging.debug("Disk %s successfuly set", self.path)
-
-
-class FloppyDisk(Disk):
- """
- Represents a 1.44 MB floppy disk. We can copy files to it, and setup it in
- convenient ways.
- """
- @error.context_aware
- def __init__(self, path, qemu_img_binary, tmpdir):
- error.context("Creating unattended install floppy image %s" % path)
- self.tmpdir = tmpdir
- self.mount = tempfile.mkdtemp(prefix='floppy_', dir=self.tmpdir)
- self.virtio_mount = None
- self.path = path
- clean_old_image(path)
- if not os.path.isdir(os.path.dirname(path)):
- os.makedirs(os.path.dirname(path))
-
- try:
- c_cmd = '%s create -f raw %s 1440k' % (qemu_img_binary, path)
- utils.run(c_cmd, verbose=DEBUG)
- f_cmd = 'mkfs.msdos -s 1 %s' % path
- utils.run(f_cmd, verbose=DEBUG)
- m_cmd = 'mount -o loop,rw %s %s' % (path, self.mount)
- utils.run(m_cmd, verbose=DEBUG)
- except error.CmdError, e:
- logging.error("Error during floppy initialization: %s" % e)
- cleanup(self.mount)
- raise
-
-
- def _copy_virtio_drivers(self, virtio_floppy):
- """
- Copy the virtio drivers on the virtio floppy to the install floppy.
-
- 1) Mount the floppy containing the viostor drivers
- 2) Copy its contents to the root of the install floppy
- """
- virtio_mount = tempfile.mkdtemp(prefix='virtio_floppy_',
- dir=self.tmpdir)
-
- pwd = os.getcwd()
- try:
- m_cmd = 'mount -o loop,ro %s %s' % (virtio_floppy, virtio_mount)
- utils.run(m_cmd, verbose=DEBUG)
- os.chdir(virtio_mount)
- path_list = glob.glob('*')
- for path in path_list:
- self.copy_to(path)
- finally:
- os.chdir(pwd)
- cleanup(virtio_mount)
-
-
- def setup_virtio_win2003(self, virtio_floppy, virtio_oemsetup_id):
- """
- Setup the install floppy with the virtio storage drivers, win2003
style.
-
- Win2003 and WinXP depend on the file txtsetup.oem file to install
- the virtio drivers from the floppy, which is a .ini file.
- Process:
-
- 1) Copy the virtio drivers on the virtio floppy to the install floppy
- 2) Parse the ini file with config parser
- 3) Modify the identifier of the default session that is going to be
- executed on the config parser object
- 4) Re-write the config file to the disk
- """
- self._copy_virtio_drivers(virtio_floppy)
- txtsetup_oem = os.path.join(self.mount, 'txtsetup.oem')
- if not os.path.isfile(txtsetup_oem):
- raise IOError('File txtsetup.oem not found on the install '
- 'floppy. Please verify if your floppy virtio '
- 'driver image has this file')
- parser = ConfigParser.ConfigParser()
- parser.read(txtsetup_oem)
- if not parser.has_section('Defaults'):
- raise ValueError('File txtsetup.oem does not have the session '
- '"Defaults". Please check txtsetup.oem')
- default_driver = parser.get('Defaults', 'SCSI')
- if default_driver != virtio_oemsetup_id:
- parser.set('Defaults', 'SCSI', virtio_oemsetup_id)
- fp = open(txtsetup_oem, 'w')
- parser.write(fp)
- fp.close()
-
-
- def setup_virtio_win2008(self, virtio_floppy):
- """
- Setup the install floppy with the virtio storage drivers, win2008
style.
-
- Win2008, Vista and 7 require people to point out the path to the
drivers
- on the unattended file, so we just need to copy the drivers to the
- driver floppy disk. Important to note that it's possible to specify
- drivers from a CDROM, so the floppy driver copy is optional.
- Process:
-
- 1) Copy the virtio drivers on the virtio floppy to the install floppy,
- if there is one available
- """
- if os.path.isfile(virtio_floppy):
- self._copy_virtio_drivers(virtio_floppy)
- else:
- logging.debug("No virtio floppy present, not needed for this OS
anyway")
-
-
-class CdromDisk(Disk):
- """
- Represents a CDROM disk that we can master according to our needs.
- """
- def __init__(self, path, tmpdir):
- self.mount = tempfile.mkdtemp(prefix='cdrom_unattended_', dir=tmpdir)
- self.path = path
- clean_old_image(path)
- if not os.path.isdir(os.path.dirname(path)):
- os.makedirs(os.path.dirname(path))
-
-
- @error.context_aware
- def close(self):
- error.context("Creating unattended install CD image %s" % self.path)
- g_cmd = ('mkisofs -o %s -max-iso9660-filenames '
- '-relaxed-filenames -D --input-charset iso8859-1 '
- '%s' % (self.path, self.mount))
- utils.run(g_cmd, verbose=DEBUG)
-
- os.chmod(self.path, 0755)
- cleanup(self.mount)
- logging.debug("unattended install CD image %s successfuly created",
- self.path)
-
-
-class CdromInstallDisk(Disk):
- """
- Represents a install CDROM disk that we can master according to our needs.
- """
- def __init__(self, path, tmpdir, source_cdrom, extra_params):
- self.mount = tempfile.mkdtemp(prefix='cdrom_unattended_', dir=tmpdir)
- self.path = path
- self.extra_params = extra_params
- self.source_cdrom = source_cdrom
- cleanup(path)
- if not os.path.isdir(os.path.dirname(path)):
- os.makedirs(os.path.dirname(path))
- cp_cmd = ('cp -r %s/isolinux/ %s/' % (source_cdrom, self.mount))
- listdir = os.listdir(self.source_cdrom)
- for i in listdir:
- if i == 'isolinux':
- continue
- os.symlink(os.path.join(self.source_cdrom, i),
- os.path.join(self.mount, i))
- utils.run(cp_cmd)
-
-
- def get_answer_file_path(self, filename):
- return os.path.join(self.mount, 'isolinux', filename)
-
-
- @error.context_aware
- def close(self):
- error.context("Creating unattended install CD image %s" % self.path)
- f = open(os.path.join(self.mount, 'isolinux', 'isolinux.cfg'), 'w')
- f.write('default /isolinux/vmlinuz append initrd=/isolinux/initrd.img '
- '%s\n' % self.extra_params)
- f.close()
- m_cmd = ('mkisofs -o %s -b isolinux/isolinux.bin -c isolinux/boot.cat '
- '-no-emul-boot -boot-load-size 4 -boot-info-table -f -R -J '
- '-V -T %s' % (self.path, self.mount))
- utils.run(m_cmd)
- os.chmod(self.path, 0755)
- cleanup(self.mount)
- cleanup(self.source_cdrom)
- logging.debug("unattended install CD image %s successfully created",
- self.path)
--
1.7.11.2
_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel