guestfs: Don't report exception if there's read access to kernel

Commit 92ae0f1 ("libvirt - Add log if libguestfs can't read host
kernel") reworks the logic of handling access to Kernel for libguestfs.
In doing that, it erroneously raises an exception when libguestfs is
_able_ to access the Kernel.

Fix it by reporting exception only when libguestfs does _not_ have
read access to the Kernel.

This was first tried by Kevin Zhao here
Ic6802650cb8f93e0d02c51e9014eb85a7e71f6fe, but is abandoned for some
reason.

This also adds a little more direction on what to do to fix this error.

Related-Bug: #1646002

Change-Id: Id6b4108e4e4af7c98b3e1bd9de3a09ad057e7b92
This commit is contained in:
Kashyap Chamarthy 2016-11-23 18:26:33 +01:00 committed by Sean Dague
parent 8f3d9c9b5d
commit e604946018
2 changed files with 6 additions and 2 deletions

View File

@ -320,6 +320,7 @@ class VirtDiskVFSGuestFSTest(test.NoDBTestCase):
m = mock.MagicMock()
m.launch.side_effect = Exception
vfs = vfsimpl.VFSGuestFS(self.qcowfile)
mock_access.return_value = False
with mock.patch('eventlet.tpool.Proxy', return_value=m):
self.assertRaises(exception.LibguestfsCannotReadKernel,
vfs.inspect_capabilities)

View File

@ -80,8 +80,11 @@ 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()
kernel_file = "/boot/vmlinuz-%s" % os.uname()[2]
if not os.access(kernel_file, os.R_OK):
raise exception.LibguestfsCannotReadKernel(
_("Please change permissions on %s to 0x644")
% kernel_file)
raise exception.NovaException(
_("libguestfs installed but not usable (%s)") % e)