Merge "Exposes new ksm config directive."

This commit is contained in:
Jenkins 2017-03-10 17:21:43 +00:00 committed by Gerrit Code Review
commit a0c736680d
4 changed files with 73 additions and 6 deletions

View File

@ -226,18 +226,18 @@ options:
type: string type: string
default: default:
description: | description: |
Set to 'host-model' to clone the host CPU feature flags; to Set to 'host-model' to clone the host CPU feature flags; to
'host-passthrough' to use the host CPU model exactly; to 'custom' 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 use a named CPU model; to 'none' to not set any CPU model. If
virt_type='kvm|qemu', it will default to 'host-model', otherwise it will virt_type='kvm|qemu', it will default to 'host-model', otherwise it will
default to 'none'. Defaults to 'host-passthrough' for ppc64el, ppc64le default to 'none'. Defaults to 'host-passthrough' for ppc64el, ppc64le
if no value is set. if no value is set.
cpu-model: cpu-model:
type: string type: string
default: default:
description: | description: |
Set to a named libvirt CPU model (see names listed in Set to a named libvirt CPU model (see names listed in
/usr/share/libvirt/cpu_map.xml). Only has effect if cpu_mode='custom' and /usr/share/libvirt/cpu_map.xml). Only has effect if cpu_mode='custom' and
virt_type='kvm|qemu'. virt_type='kvm|qemu'.
# Storage configuration options # Storage configuration options
libvirt-image-backend: libvirt-image-backend:
@ -308,6 +308,13 @@ options:
For a systemd system (wily and later) the prefered approach is to enable For a systemd system (wily and later) the prefered approach is to enable
hugepages via kernel parameters set in MAAS and systemd will mount them hugepages via kernel parameters set in MAAS and systemd will mount them
automatically. automatically.
ksm:
type: string
default: "AUTO"
description: |
Set to 1 to enable KSM, 0 to disable KSM, and AUTO to use default settings.
Please note that the AUTO value works for qemu 2.2+ (> Kilo), older
releases will be set to 1 as default.
action-managed-upgrade: action-managed-upgrade:
type: boolean type: boolean
default: False default: False

View File

@ -33,6 +33,7 @@ from charmhelpers.core.hookenv import (
related_units, related_units,
service_name, service_name,
ERROR, ERROR,
INFO,
) )
from charmhelpers.contrib.openstack.utils import ( from charmhelpers.contrib.openstack.utils import (
get_os_version_package, get_os_version_package,
@ -191,6 +192,16 @@ class NovaComputeLibvirtContext(context.OSContextGenerator):
else: else:
ctxt['kvm_hugepages'] = 0 ctxt['kvm_hugepages'] = 0
if config('ksm') in ("1", "0",):
ctxt['ksm'] = config('ksm')
else:
if release < 'kilo':
log("KSM set to 1 by default on openstack releases < kilo",
level=INFO)
ctxt['ksm'] = "1"
else:
ctxt['ksm'] = "AUTO"
if config('pci-passthrough-whitelist'): if config('pci-passthrough-whitelist'):
ctxt['pci_passthrough_whitelist'] = \ ctxt['pci_passthrough_whitelist'] = \
config('pci-passthrough-whitelist') config('pci-passthrough-whitelist')

View File

@ -2,5 +2,15 @@
# [ WARNING ] # [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten. # Configuration file maintained by Juju. Local changes may be overwritten.
############################################################################### ###############################################################################
# Set to 1 to enable KSM, 0 to disable KSM, and AUTO to use default settings.
# After changing this setting restart the qemu-kvm service.
KSM_ENABLED={{ ksm }}
SLEEP_MILLISECS=200
# To load the vhost_net module, which in some cases can speed up
# network performance, set VHOST_NET_ENABLED to 1.
VHOST_NET_ENABLED=0
# Set this to 1 if you want hugepages to be available to kvm under
# /run/hugepages/kvm
KVM_HUGEPAGES={{ kvm_hugepages }} KVM_HUGEPAGES={{ kvm_hugepages }}

View File

@ -76,6 +76,7 @@ class NovaComputeContextTests(CharmTestCase):
def setUp(self): def setUp(self):
super(NovaComputeContextTests, self).setUp(context, TO_PATCH) super(NovaComputeContextTests, self).setUp(context, TO_PATCH)
self.os_release.return_value = 'kilo'
self.relation_get.side_effect = self.test_relation.get self.relation_get.side_effect = self.test_relation.get
self.config.side_effect = self.test_config.get self.config.side_effect = self.test_config.get
self.log.side_effect = fake_log self.log.side_effect = fake_log
@ -202,6 +203,7 @@ class NovaComputeContextTests(CharmTestCase):
{'libvirtd_opts': '', {'libvirtd_opts': '',
'libvirt_user': 'libvirt', 'libvirt_user': 'libvirt',
'arch': platform.machine(), 'arch': platform.machine(),
'ksm': 'AUTO',
'kvm_hugepages': 0, 'kvm_hugepages': 0,
'listen_tls': 0, 'listen_tls': 0,
'host_uuid': self.host_uuid, 'host_uuid': self.host_uuid,
@ -216,6 +218,7 @@ class NovaComputeContextTests(CharmTestCase):
{'libvirtd_opts': '-d', {'libvirtd_opts': '-d',
'libvirt_user': 'libvirtd', 'libvirt_user': 'libvirtd',
'arch': platform.machine(), 'arch': platform.machine(),
'ksm': 'AUTO',
'kvm_hugepages': 0, 'kvm_hugepages': 0,
'listen_tls': 0, 'listen_tls': 0,
'host_uuid': self.host_uuid, 'host_uuid': self.host_uuid,
@ -230,6 +233,7 @@ class NovaComputeContextTests(CharmTestCase):
{'libvirtd_opts': '-d -l', {'libvirtd_opts': '-d -l',
'libvirt_user': 'libvirtd', 'libvirt_user': 'libvirtd',
'arch': platform.machine(), 'arch': platform.machine(),
'ksm': 'AUTO',
'kvm_hugepages': 0, 'kvm_hugepages': 0,
'listen_tls': 0, 'listen_tls': 0,
'host_uuid': self.host_uuid, 'host_uuid': self.host_uuid,
@ -245,6 +249,7 @@ class NovaComputeContextTests(CharmTestCase):
'libvirt_user': 'libvirtd', 'libvirt_user': 'libvirtd',
'disk_cachemodes': 'file=unsafe,block=none', 'disk_cachemodes': 'file=unsafe,block=none',
'arch': platform.machine(), 'arch': platform.machine(),
'ksm': 'AUTO',
'kvm_hugepages': 0, 'kvm_hugepages': 0,
'listen_tls': 0, 'listen_tls': 0,
'host_uuid': self.host_uuid, 'host_uuid': self.host_uuid,
@ -260,6 +265,7 @@ class NovaComputeContextTests(CharmTestCase):
'libvirt_user': 'libvirtd', 'libvirt_user': 'libvirtd',
'arch': platform.machine(), 'arch': platform.machine(),
'hugepages': True, 'hugepages': True,
'ksm': 'AUTO',
'kvm_hugepages': 1, 'kvm_hugepages': 1,
'listen_tls': 0, 'listen_tls': 0,
'host_uuid': self.host_uuid, 'host_uuid': self.host_uuid,
@ -342,6 +348,7 @@ class NovaComputeContextTests(CharmTestCase):
{'libvirtd_opts': '-d', {'libvirtd_opts': '-d',
'libvirt_user': 'libvirtd', 'libvirt_user': 'libvirtd',
'arch': platform.machine(), 'arch': platform.machine(),
'ksm': 'AUTO',
'hugepages': True, 'hugepages': True,
'kvm_hugepages': 1, 'kvm_hugepages': 1,
'listen_tls': 0, 'listen_tls': 0,
@ -350,6 +357,38 @@ class NovaComputeContextTests(CharmTestCase):
'vcpu_pin_set': '^0^2', 'vcpu_pin_set': '^0^2',
'pci_passthrough_whitelist': 'mypcidevices'}, libvirt()) 'pci_passthrough_whitelist': 'mypcidevices'}, libvirt())
def test_ksm_configs(self):
self.test_config.set('ksm', '1')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == '1')
self.test_config.set('ksm', '0')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == '0')
self.test_config.set('ksm', 'AUTO')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == 'AUTO')
self.test_config.set('ksm', '')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == 'AUTO')
self.os_release.return_value = 'ocata'
self.test_config.set('ksm', 'AUTO')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == 'AUTO')
self.os_release.return_value = 'kilo'
self.test_config.set('ksm', 'AUTO')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == 'AUTO')
self.os_release.return_value = 'cactus'
self.test_config.set('ksm', 'AUTO')
libvirt = context.NovaComputeLibvirtContext()
self.assertTrue(libvirt()['ksm'] == '1')
@patch.object(context.uuid, 'uuid4') @patch.object(context.uuid, 'uuid4')
def test_libvirt_cpu_mode_default(self, mock_uuid): def test_libvirt_cpu_mode_default(self, mock_uuid):
libvirt = context.NovaComputeLibvirtContext() libvirt = context.NovaComputeLibvirtContext()