From 2035bc1dab3407f9d3b726f6b87cfe26c6d7e6f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Wed, 30 Nov 2011 17:00:17 +0000 Subject: [PATCH] Bug#898257 abstract out disk image access methods Rather than providing two mutually exlusive image access methods (loop and qemu-nbd), try each in turn. This is to prepare for a follow up patch which will add libguestfs as a method to try. * nova/virt/mount.py: A new Mount class to abstract the devce allocation, partition mapping and file sys mounting, for each access type. * nova/virt/disk/loop.py: A specialization of the base Mount class to provide loop back mounting support. * nova/virt/disk/nbd.py: A specialization of the base Mount class to provide qemu-nbd mounting support. * nova/virt/disk/api.py: A new file containing the nova.virt.disk module interface. (img_handlers): A new list of access methods to try, with the order being honored. (_DiskImage): An internal helper class that uses the plugin classes above, to provide the operations available on a disk image file. When mounting, iterate over each access method until one succeeds. If a hint is provided about a CoW format image, the list of methods to try will be reduced accordingly. Note expected errors are no longer raised as exceptions during mounting. Instead, on failure to mount an image, errors are collated and raised. Interveining errors are logged in debug mode for successful mounts. * nova/virt/libvirt/connection.py: Adjust the function parameter names to be more general, rather than referencing specific implementations like 'nbd' and 'tune2fs'. Simplify the destroy_container() by storing and passing back a reference to the _DiskImage object, which has the necessary state to unmount. * nova/utils.py (trycmd): A helper function to both deal with, commands that issue ignorable warnings to stderr, and commands that EXIT_SUCCESS while issuing errors to stderr. nova/virt/xenapi/vm_utils.py: Adjust for the moved virt.disk package Change-Id: If3a4b1c8f4e2f2e7300a21071340dcc839cb36d7 --- Authors | 1 + nova/rootwrap/compute.py | 39 ++++++++++++++++++-------------------- nova/tests/test_libvirt.py | 2 +- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Authors b/Authors index d92663df..b09a4bdd 100644 --- a/Authors +++ b/Authors @@ -112,6 +112,7 @@ Naveed Massjouni Nikolay Sokolov Nirmal Ranganathan Ollie Leahy +Pádraig Brady Paul Voccio Renuka Apte Ricardo Carrillo Cruz diff --git a/nova/rootwrap/compute.py b/nova/rootwrap/compute.py index cd8521d0..cd971e0d 100755 --- a/nova/rootwrap/compute.py +++ b/nova/rootwrap/compute.py @@ -19,53 +19,50 @@ from nova.rootwrap.filters import CommandFilter, DnsmasqFilter filters = [ - # nova/virt/disk.py: 'kpartx', '-a', device - # nova/virt/disk.py: 'kpartx', '-d', device + # nova/virt/disk/mount.py: 'kpartx', '-a', device + # nova/virt/disk/mount.py: 'kpartx', '-d', device CommandFilter("/sbin/kpartx", "root"), - # nova/virt/disk.py: 'tune2fs', '-c', 0, '-i', 0, mapped_device + # nova/virt/disk/mount.py: 'tune2fs', '-c', 0, '-i', 0, mapped_device # nova/virt/xenapi/vm_utils.py: "tune2fs", "-O ^has_journal", part_path # nova/virt/xenapi/vm_utils.py: "tune2fs", "-j", partition_path CommandFilter("/sbin/tune2fs", "root"), - # nova/virt/disk.py: 'mount', mapped_device, tmpdir - # nova/virt/disk.py: 'mount', device, container_dir - # nova/virt/disk.py: 'mount' + # nova/virt/disk/mount.py: 'mount', mapped_device, mount_dir # nova/virt/xenapi/vm_utils.py: 'mount', '-t', 'ext2,ext3,ext4,reiserfs'.. CommandFilter("/bin/mount", "root"), - # nova/virt/disk.py: 'umount', mapped_device - # nova/virt/disk.py: 'umount', container_dir + # nova/virt/disk/mount.py: 'umount', mapped_device # nova/virt/xenapi/vm_utils.py: 'umount', dev_path CommandFilter("/bin/umount", "root"), - # nova/virt/disk.py: 'qemu-nbd', '-c', device, image - # nova/virt/disk.py: 'qemu-nbd', '-d', device + # nova/virt/disk/nbd.py: 'qemu-nbd', '-c', device, image + # nova/virt/disk/nbd.py: 'qemu-nbd', '-d', device CommandFilter("/usr/bin/qemu-nbd", "root"), - # nova/virt/disk.py: 'losetup', '--find', '--show', image - # nova/virt/disk.py: 'losetup', '--detach', device + # nova/virt/disk/loop.py: 'losetup', '--find', '--show', image + # nova/virt/disk/loop.py: 'losetup', '--detach', device CommandFilter("/sbin/losetup", "root"), - # nova/virt/disk.py: 'tee', metadata_path - # nova/virt/disk.py: 'tee', '-a', keyfile - # nova/virt/disk.py: 'tee', netfile + # nova/virt/disk/api.py: 'tee', metadata_path + # nova/virt/disk/api.py: 'tee', '-a', keyfile + # nova/virt/disk/api.py: 'tee', netfile CommandFilter("/usr/bin/tee", "root"), - # nova/virt/disk.py: 'mkdir', '-p', sshdir - # nova/virt/disk.py: 'mkdir', '-p', netdir + # nova/virt/disk/api.py: 'mkdir', '-p', sshdir + # nova/virt/disk/api.py: 'mkdir', '-p', netdir CommandFilter("/bin/mkdir", "root"), - # nova/virt/disk.py: 'chown', 'root', sshdir - # nova/virt/disk.py: 'chown', 'root:root', netdir + # nova/virt/disk/api.py: 'chown', 'root', sshdir + # nova/virt/disk/api.py: 'chown', 'root:root', netdir # nova/virt/libvirt/connection.py: 'chown', os.getuid(), console_log # nova/virt/libvirt/connection.py: 'chown', os.getuid(), console_log # nova/virt/libvirt/connection.py: 'chown', 'root', basepath('disk') # nova/virt/xenapi/vm_utils.py: 'chown', os.getuid(), dev_path CommandFilter("/bin/chown", "root"), - # nova/virt/disk.py: 'chmod', '700', sshdir - # nova/virt/disk.py: 'chmod', 755, netdir + # nova/virt/disk/api.py: 'chmod', '700', sshdir + # nova/virt/disk/api.py: 'chmod', 755, netdir CommandFilter("/bin/chmod", "root"), # nova/virt/libvirt/vif.py: 'ip', 'tuntap', 'add', dev, 'mode', 'tap' diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index ebe487d0..92a14ee2 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -36,7 +36,7 @@ from nova import utils from nova.api.ec2 import cloud from nova.compute import power_state from nova.compute import vm_states -from nova.virt import disk +from nova.virt.disk import api as disk from nova.virt import images from nova.virt import driver from nova.virt.libvirt import connection