From 9e07a3f69a8f905b36db0b981885e25b0b3707fe Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 26 Sep 2019 19:01:58 +0900 Subject: [PATCH] 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 --- .../provider/virtlogd_config/ini_setting.rb | 22 +++ lib/puppet/type/virtlogd_config.rb | 46 ++++++ manifests/compute/libvirt/virtlogd.pp | 132 ++++++++++++++++++ manifests/compute/libvirt/virtlogd/config.pp | 30 ++++ .../libvirt-virtlogd-f4e2618a87fbab5a.yaml | 5 + .../nova_compute_libvirt_virtlogd_spec.rb | 71 ++++++++++ 6 files changed, 306 insertions(+) create mode 100644 lib/puppet/provider/virtlogd_config/ini_setting.rb create mode 100644 lib/puppet/type/virtlogd_config.rb create mode 100644 manifests/compute/libvirt/virtlogd.pp create mode 100644 manifests/compute/libvirt/virtlogd/config.pp create mode 100644 releasenotes/notes/libvirt-virtlogd-f4e2618a87fbab5a.yaml create mode 100644 spec/classes/nova_compute_libvirt_virtlogd_spec.rb diff --git a/lib/puppet/provider/virtlogd_config/ini_setting.rb b/lib/puppet/provider/virtlogd_config/ini_setting.rb new file mode 100644 index 000000000..9edf62689 --- /dev/null +++ b/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 diff --git a/lib/puppet/type/virtlogd_config.rb b/lib/puppet/type/virtlogd_config.rb new file mode 100644 index 000000000..167c93d40 --- /dev/null +++ b/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 diff --git a/manifests/compute/libvirt/virtlogd.pp b/manifests/compute/libvirt/virtlogd.pp new file mode 100644 index 000000000..4a05f2b66 --- /dev/null +++ b/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'] +} diff --git a/manifests/compute/libvirt/virtlogd/config.pp b/manifests/compute/libvirt/virtlogd/config.pp new file mode 100644 index 000000000..1e5af60e5 --- /dev/null +++ b/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) +} diff --git a/releasenotes/notes/libvirt-virtlogd-f4e2618a87fbab5a.yaml b/releasenotes/notes/libvirt-virtlogd-f4e2618a87fbab5a.yaml new file mode 100644 index 000000000..d6ab9c6cf --- /dev/null +++ b/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. diff --git a/spec/classes/nova_compute_libvirt_virtlogd_spec.rb b/spec/classes/nova_compute_libvirt_virtlogd_spec.rb new file mode 100644 index 000000000..96cc3ee3c --- /dev/null +++ b/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