Add nova::compute::libvirt::qemu class to configure limits

This change adds a class meant to configure the max_files and
max_processes limits in libvirt/qemu.conf, it uses augeas and supports
config cleanup.

Change-Id: I5fa423a4b212d14f6e9ff6a270931b569558b54e
This commit is contained in:
Giulio Fidente 2016-12-16 21:36:36 +01:00 committed by Emilien Macchi
parent 8ee6ab2918
commit 88a7bc8b20
3 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,55 @@
# == Class: nova::compute::libvirt::qemu
#
# Configures qemu limits for use by libvirt
#
# === Parameters:
#
# [*configure_qemu*]
# (optional) Whether or not configure qemu bits.
# Defaults to false.
#
# [*max_files*]
# (optional) Maximum number of opened files, per process.
# Defaults to 1024.
#
# [*max_processes*]
# (optional) Maximum number of processes that can be run by qemu user.
# Defaults to 4096.
#
class nova::compute::libvirt::qemu(
$configure_qemu = false,
$max_files = 1024,
$max_processes = 4096,
){
include ::nova::deps
require ::nova::compute::libvirt
Anchor['nova::config::begin']
-> Augeas<| tag == 'qemu-conf-augeas'|>
-> Anchor['nova::config::end']
Augeas<| tag == 'qemu-conf-augeas'|>
~> Service['libvirt']
if $configure_qemu {
augeas { 'qemu-conf-limits':
context => '/files/etc/libvirt/qemu.conf',
changes => [
"set max_files ${max_files}",
"set max_processes ${max_processes}",
],
tag => 'qemu-conf-augeas',
}
} else {
augeas { 'qemu-conf-limits':
context => '/files/etc/libvirt/qemu.conf',
changes => [
'rm max_files',
'rm max_processes',
],
tag => 'qemu-conf-augeas',
}
}
}

View File

@ -0,0 +1,5 @@
---
features:
- A new nova::compute::libvirt::qemu class has been added
with the initial purpose of configuring the max_files
and max_processes limits in qemu.conf

View File

@ -0,0 +1,66 @@
require 'spec_helper'
describe 'nova::compute::libvirt::qemu' do
let :pre_condition do
'include nova
include nova::compute
include nova::compute::libvirt'
end
shared_examples_for 'nova compute libvirt with qemu' do
context 'when not configuring qemu' do
let :params do
{
:configure_qemu => false
}
end
it { is_expected.to contain_augeas('qemu-conf-limits').with({
:context => '/files/etc/libvirt/qemu.conf',
:changes => [ "rm max_files", "rm max_processes" ],
}).that_notifies('Service[libvirt]') }
end
context 'when configuring qemu by default' do
let :params do
{
:configure_qemu => true
}
end
it { is_expected.to contain_augeas('qemu-conf-limits').with({
:context => '/files/etc/libvirt/qemu.conf',
:changes => [ "set max_files 1024", "set max_processes 4096" ],
:tag => 'qemu-conf-augeas',
}).that_notifies('Service[libvirt]') }
end
context 'when configuring qemu with overriden parameters' do
let :params do
{
:configure_qemu => true,
:max_files => 32768,
:max_processes => 131072,
}
end
it { is_expected.to contain_augeas('qemu-conf-limits').with({
:context => '/files/etc/libvirt/qemu.conf',
:changes => [ "set max_files 32768", "set max_processes 131072" ],
:tag => 'qemu-conf-augeas',
}).that_notifies('Service[libvirt]') }
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_configures 'nova compute libvirt with qemu'
end
end
end