Browse Source

Add support to configure virtlogd

Add a new class nova::compute::libvirt::virtlogd to manage virtlogd
configuration, which is located in /etc/libvirt/virtlogd.conf.

Change-Id: Iddfec9557ac93935744aa96b813eb54bda876deb
changes/24/685024/20
Takashi Kajinami 2 years ago
parent
commit
9e07a3f69a
  1. 22
      lib/puppet/provider/virtlogd_config/ini_setting.rb
  2. 46
      lib/puppet/type/virtlogd_config.rb
  3. 132
      manifests/compute/libvirt/virtlogd.pp
  4. 30
      manifests/compute/libvirt/virtlogd/config.pp
  5. 5
      releasenotes/notes/libvirt-virtlogd-f4e2618a87fbab5a.yaml
  6. 71
      spec/classes/nova_compute_libvirt_virtlogd_spec.rb

22
lib/puppet/provider/virtlogd_config/ini_setting.rb

@ -0,0 +1,22 @@
Puppet::Type.type(:virtlogd_config).provide(
:ini_setting,
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do
def section
''
end
def setting
resource[:name]
end
def separator
'='
end
def self.file_path
'/etc/libvirt/virtlogd.conf'
end
end

46
lib/puppet/type/virtlogd_config.rb

@ -0,0 +1,46 @@
Puppet::Type.newtype(:virtlogd_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'setting name to manage from virtlogd.conf'
newvalues(/\S+/)
end
newproperty(:value) do
desc 'The value of the setting to be defined.'
munge do |value|
value = value.to_s.strip
value
end
def is_to_s( currentvalue )
if resource.secret?
return '[old secret redacted]'
else
return currentvalue
end
end
def should_to_s( newvalue )
if resource.secret?
return '[new secret redacted]'
else
return newvalue
end
end
end
newparam(:secret, :boolean => true) do
desc 'Whether to hide the value from Puppet logs. Defaults to `false`.'
newvalues(:true, :false)
defaultto false
end
autorequire(:package) do
'libvirt-daemon'
end
end

132
manifests/compute/libvirt/virtlogd.pp

@ -0,0 +1,132 @@
# == Class: nova::compute::libvirt::virtlogd
#
# virtlogd configuration
#
# === Parameters:
#
# [*log_level*]
# Defines a log level to filter log outputs.
# Defaults to undef
#
# [*log_filters*]
# Defines a log filter to select a different logging level for
# for a given category log outputs.
# Defaults to undef
#
# [*log_outputs*]
# (optional) Defines log outputs, as specified in
# https://libvirt.org/logging.html
# Defaults to undef
#
# [*max_clients*]
# The maximum number of concurrent client connections to allow
# on primary socket.
# Defaults to undef
#
# [*admin_max_clients*]
# The maximum number of concurrent client connections to allow
# on administrative socket.
# Defaults to undef
#
# [*max_size*]
# Maximum file size before rolling over.
# Defaults to undef
#
# [*max_backups*]
# Maximum nuber of backup files to keep.
# Defaults to undef
#
class nova::compute::libvirt::virtlogd (
$log_level = undef,
$log_filters = undef,
$log_outputs = undef,
$max_clients = undef,
$admin_max_clients = undef,
$max_size = undef,
$max_backups = undef,
) {
include nova::deps
require ::nova::compute::libvirt
if $log_level {
virtlogd_config {
'log_level': value => $log_level;
}
}
else {
virtlogd_config {
'log_level': ensure => 'absent';
}
}
if $log_filters {
virtlogd_config {
'log_filters': value => "\"${log_filters}\"";
}
}
else {
virtlogd_config {
'log_filters': ensure => 'absent';
}
}
if $log_outputs {
virtlogd_config {
'log_outputs': value => "\"${log_outputs}\"";
}
}
else {
virtlogd_config {
'log_outputs': ensure => 'absent';
}
}
if $max_clients {
virtlogd_config {
'max_clients': value => $max_clients;
}
}
else {
virtlogd_config {
'max_clients': ensure => 'absent';
}
}
if $admin_max_clients {
virtlogd_config {
'admin_max_clients': value => $admin_max_clients;
}
}
else {
virtlogd_config {
'admin_max_clients': ensure => 'absent';
}
}
if $max_size {
virtlogd_config {
'max_size': value => $max_size;
}
}
else {
virtlogd_config {
'max_size': ensure => 'absent';
}
}
if $max_backups {
virtlogd_config {
'max_backups': value => $max_backups;
}
}
else {
virtlogd_config {
'max_backups': ensure => 'absent';
}
}
Anchor['nova::config::begin']
-> Virtlogd_config<||>
-> Anchor['nova::config::end']
}

30
manifests/compute/libvirt/virtlogd/config.pp

@ -0,0 +1,30 @@
# == Class: nova::compute::libvirt::virtlogd::config
#
# This class is used to manage arbitrary virtlogd configurations.
#
# === Parameters
#
# [*virtlogd_config*]
# (optional) Allow configuration of arbitrary libvirtd configurations.
# The value is an hash of virtlogd_config resources. Example:
# { 'foo' => { value => 'fooValue'},
# 'bar' => { value => 'barValue'}
# }
# In yaml format, Example:
# virtlogd_config:
# foo:
# value: fooValue
# bar:
# value: barValue
#
# NOTE: The configuration MUST NOT be already handled by this module
# or Puppet catalog compilation will fail with duplicate resources.
#
class nova::compute::libvirt::virtlogd::config (
$virtlogd_config = {},
) {
validate_legacy(Hash, 'validate_hash', $virtlogd_config)
create_resources('virtlogd_config', $virtlogd_config)
}

5
releasenotes/notes/libvirt-virtlogd-f4e2618a87fbab5a.yaml

@ -0,0 +1,5 @@
---
features:
- |
A new nova::compute::libvirt::virtlogd class has been added to manage
virtlogd configration.

71
spec/classes/nova_compute_libvirt_virtlogd_spec.rb

@ -0,0 +1,71 @@
# Unit tests for nova::compute::libvirt::virtlogd class
#
require 'spec_helper'
describe 'nova::compute::libvirt::virtlogd' do
let :pre_condition do
<<-eos
include nova
include nova::compute
include nova::compute::libvirt
eos
end
shared_examples_for 'nova-compute-libvirt-virtlogd' do
context 'with default parameters' do
let :params do
{}
end
it { is_expected.to contain_class('nova::deps')}
it { is_expected.to contain_class('nova::compute::libvirt::virtlogd')}
it { is_expected.to contain_virtlogd_config('log_level').with_ensure('absent')}
it { is_expected.to contain_virtlogd_config('log_outputs').with_ensure('absent')}
it { is_expected.to contain_virtlogd_config('log_filters').with_ensure('absent')}
it { is_expected.to contain_virtlogd_config('max_clients').with_ensure('absent')}
it { is_expected.to contain_virtlogd_config('admin_max_clients').with_ensure('absent')}
it { is_expected.to contain_virtlogd_config('max_size').with_ensure('absent')}
it { is_expected.to contain_virtlogd_config('max_backups').with_ensure('absent')}
end
context 'with specified parameters' do
let :params do
{ :log_level => 3,
:log_outputs => '3:syslog',
:log_filters => '1:logging 4:object 4:json 4:event 1:util',
:max_clients => 1024,
:admin_max_clients => 5,
:max_size => 2097152,
:max_backups => 3,
}
end
it { is_expected.to contain_class('nova::deps')}
it { is_expected.to contain_class('nova::compute::libvirt::virtlogd')}
it { is_expected.to contain_virtlogd_config('log_level').with_value(params[:log_level])}
it { is_expected.to contain_virtlogd_config('log_outputs').with_value("\"#{params[:log_outputs]}\"")}
it { is_expected.to contain_virtlogd_config('log_filters').with_value("\"#{params[:log_filters]}\"")}
it { is_expected.to contain_virtlogd_config('max_clients').with_value(params[:max_clients])}
it { is_expected.to contain_virtlogd_config('admin_max_clients').with_value(params[:admin_max_clients])}
it { is_expected.to contain_virtlogd_config('max_size').with_value(params[:max_size])}
it { is_expected.to contain_virtlogd_config('max_backups').with_value(params[:max_backups])}
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-virtlogd'
end
end
end
Loading…
Cancel
Save