Merge "libvirt - Add log if libguestfs can't read host kernel"

This commit is contained in:
Jenkins 2016-05-09 10:53:20 +00:00 committed by Gerrit Code Review
commit 93797372c2
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)