Merge "Set the default CPU mode to 'host-model' for Libvirt KVM/QEMU guests"
This commit is contained in:
commit
b576a1846c
@ -608,6 +608,52 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.assertEquals(cfg.devices[3].target_dev, 'vdd')
|
||||
|
||||
def test_get_guest_cpu_config_none(self):
|
||||
self.flags(libvirt_cpu_mode="none")
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
_fake_network_info(self.stubs, 1),
|
||||
None, None)
|
||||
self.assertEquals(conf.cpu, None)
|
||||
|
||||
def test_get_guest_cpu_config_default_kvm(self):
|
||||
self.flags(libvirt_type="kvm",
|
||||
libvirt_cpu_mode=None)
|
||||
|
||||
def get_lib_version_stub(self):
|
||||
return (0 * 1000 * 1000) + (9 * 1000) + 11
|
||||
|
||||
self.stubs.Set(libvirt.virConnect,
|
||||
"getLibVersion",
|
||||
get_lib_version_stub)
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
_fake_network_info(self.stubs, 1),
|
||||
None, None)
|
||||
self.assertEquals(type(conf.cpu),
|
||||
config.LibvirtConfigGuestCPU)
|
||||
self.assertEquals(conf.cpu.mode, "host-model")
|
||||
self.assertEquals(conf.cpu.model, None)
|
||||
|
||||
def test_get_guest_cpu_config_default_uml(self):
|
||||
self.flags(libvirt_type="uml",
|
||||
libvirt_cpu_mode=None)
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
conf = conn.get_guest_config(instance_ref,
|
||||
_fake_network_info(self.stubs, 1),
|
||||
None, None)
|
||||
self.assertEquals(conf.cpu, None)
|
||||
|
||||
def test_get_guest_cpu_config_default_lxc(self):
|
||||
self.flags(libvirt_type="lxc",
|
||||
libvirt_cpu_mode=None)
|
||||
|
||||
conn = libvirt_driver.LibvirtDriver(True)
|
||||
instance_ref = db.instance_create(self.context, self.test_instance)
|
||||
|
||||
|
@ -168,9 +168,11 @@ libvirt_opts = [
|
||||
cfg.StrOpt('libvirt_cpu_mode',
|
||||
default=None,
|
||||
help='Set to "host-model" to clone the host CPU feature flags; '
|
||||
'to "host-passthrough" to use the host CPU model '
|
||||
'exactly; or to "custom" to use a named CPU model. Only '
|
||||
'has effect if libvirt_type="kvm|qemu"'),
|
||||
'to "host-passthrough" to use the host CPU model exactly; '
|
||||
'to "custom" to use a named CPU model; '
|
||||
'to "none" to not set any CPU model. '
|
||||
'If libvirt_type="kvm|qemu", it will default to '
|
||||
'"host-model", otherwise it will default to "none"'),
|
||||
cfg.StrOpt('libvirt_cpu_model',
|
||||
default=None,
|
||||
help='Set to a named libvirt CPU model (see names listed '
|
||||
@ -1504,6 +1506,12 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
model = FLAGS.libvirt_cpu_model
|
||||
|
||||
if mode is None:
|
||||
if FLAGS.libvirt_type == "kvm" or FLAGS.libvirt_type == "qemu":
|
||||
mode = "host-model"
|
||||
else:
|
||||
mode = "none"
|
||||
|
||||
if mode == "none":
|
||||
return None
|
||||
|
||||
if FLAGS.libvirt_type != "kvm" and FLAGS.libvirt_type != "qemu":
|
||||
|
Loading…
Reference in New Issue
Block a user