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
This commit is contained in:
Chung Chih, Hung 2015-10-20 12:41:46 +00:00
parent 0315d46766
commit 92ae0f1077
3 changed files with 25 additions and 0 deletions

View File

@ -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")

View File

@ -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()

View File

@ -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)