From 92ae0f1077e4c5916d99777b032aaf0840e7ab93 Mon Sep 17 00:00:00 2001 From: "Chung Chih, Hung" Date: Tue, 20 Oct 2015 12:41:46 +0000 Subject: [PATCH] libvirt - Add log if libguestfs can't read host kernel Host's kernel only allows a root user to have read/write permission in ubuntu. If compute-service didn't have read permission then libguestfs will launch image fail. In libguestfs offical FAQ site had point out this issue, following is the link http://libguestfs.org/guestfs-faq.1.html#binaries It had suggested users to change host's kernel permission. But this action should be handled by other patch. Here only give a hint what's going wrong. Change-Id: I36c93610831e2935d46f7ee37f95619fe6dc1481 Related-Bug: 1413142 Closes-Bug: 1491216 --- nova/exception.py | 4 ++++ nova/tests/unit/virt/disk/vfs/test_guestfs.py | 18 ++++++++++++++++++ nova/virt/disk/vfs/guestfs.py | 3 +++ 3 files changed, 25 insertions(+) diff --git a/nova/exception.py b/nova/exception.py index 4676e6a61a96..a42750214593 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -2107,6 +2107,10 @@ class UnsupportedHostCPUControlPolicy(Invalid): msg_fmt = _("Requested CPU control policy not supported by host") +class LibguestfsCannotReadKernel(Invalid): + msg_fmt = _("Libguestfs does not have permission to read host kernel.") + + class RealtimePolicyNotSupported(Invalid): msg_fmt = _("Realtime policy not supported by hypervisor") diff --git a/nova/tests/unit/virt/disk/vfs/test_guestfs.py b/nova/tests/unit/virt/disk/vfs/test_guestfs.py index 938a90160e87..7b59536b596d 100644 --- a/nova/tests/unit/virt/disk/vfs/test_guestfs.py +++ b/nova/tests/unit/virt/disk/vfs/test_guestfs.py @@ -310,3 +310,21 @@ class VirtDiskVFSGuestFSTest(test.NoDBTestCase): vfs = vfsimpl.VFSGuestFS(self.qcowfile) vfs.setup(mount=False) self.assertFalse(setup_os.called) + + @mock.patch('os.access') + @mock.patch('os.uname', return_value=('Linux', '', 'kernel_name')) + def test_appliance_setup_inspect_capabilties_fail_with_ubuntu(self, + mock_uname, + mock_access): + # In ubuntu os will default host kernel as 600 permission + m = mock.MagicMock() + m.launch.side_effect = Exception + vfs = vfsimpl.VFSGuestFS(self.qcowfile) + with mock.patch('eventlet.tpool.Proxy', return_value=m): + self.assertRaises(exception.LibguestfsCannotReadKernel, + vfs.inspect_capabilities) + m.add_drive.assert_called_once_with('/dev/null') + m.launch.assert_called_once_with() + mock_access.assert_called_once_with('/boot/vmlinuz-kernel_name', + mock.ANY) + mock_uname.assert_called_once_with() diff --git a/nova/virt/disk/vfs/guestfs.py b/nova/virt/disk/vfs/guestfs.py index 884b48db9cbc..2e4e58550eb0 100644 --- a/nova/virt/disk/vfs/guestfs.py +++ b/nova/virt/disk/vfs/guestfs.py @@ -13,6 +13,7 @@ # under the License. from eventlet import tpool +import os from oslo_log import log as logging from oslo_utils import importutils import six @@ -78,6 +79,8 @@ class VFSGuestFS(vfs.VFS): g.add_drive("/dev/null") # sic g.launch() except Exception as e: + if os.access("/boot/vmlinuz-%s" % os.uname()[2], os.R_OK): + raise exception.LibguestfsCannotReadKernel() raise exception.NovaException( _("libguestfs installed but not usable (%s)") % e)