diff --git a/manifests/compute/libvirt.pp b/manifests/compute/libvirt.pp index c63963027..260e01c85 100644 --- a/manifests/compute/libvirt.pp +++ b/manifests/compute/libvirt.pp @@ -97,6 +97,13 @@ # (optional) Compute driver. # Defaults to 'libvirt.LibvirtDriver' # +# [*manage_libvirt_services*] +# (optional) Whether or not deploy Libvirt services. +# In the case of micro-services, set it to False and use +# nova::compute::libvirt::services + hiera to select what +# you actually want to deploy. +# Defaults to true for backward compatibility. +# # DEPRECATED # # [*remove_unused_kernels*] @@ -126,6 +133,7 @@ class nova::compute::libvirt ( $virtlock_service_name = $::nova::params::virtlock_service_name, $virtlog_service_name = $::nova::params::virtlog_service_name, $compute_driver = 'libvirt.LibvirtDriver', + $manage_libvirt_services = true, # Deprecated $remove_unused_kernels = undef, ) inherits nova::params { @@ -133,8 +141,6 @@ class nova::compute::libvirt ( include ::nova::deps include ::nova::params - Service['libvirt'] -> Service['nova-compute'] - # libvirt_cpu_mode has different defaults depending on hypervisor. if !$libvirt_cpu_mode { case $libvirt_virt_type { @@ -156,75 +162,35 @@ class nova::compute::libvirt ( } } - if($::osfamily == 'RedHat' and $::operatingsystem != 'Fedora') { - service { 'messagebus': - ensure => running, - enable => true, - name => $::nova::params::messagebus_service_name, - provider => $::nova::params::special_service_provider, - - } - Package['libvirt'] -> Service['messagebus'] -> Service['libvirt'] - } - if $migration_support { if $vncserver_listen != '0.0.0.0' and $vncserver_listen != '::0' { fail('For migration support to work, you MUST set vncserver_listen to \'0.0.0.0\' or \'::0\'') } else { + # TODO(emilien): explode ::nova::migration::libvirt to select what bits we want to configure + # and allow micro services between libvirt & nova-compute. include ::nova::migration::libvirt } } - if $::osfamily == 'RedHat' { - package { 'libvirt-nwfilter': - ensure => present, - name => $::nova::params::libvirt_nwfilter_package_name, - before => Service['libvirt'], - tag => ['openstack', 'nova-support-package'], - } - case $libvirt_virt_type { - 'qemu': { - $libvirt_package_name_real = "${::nova::params::libvirt_daemon_package_prefix}kvm" - } - default: { - $libvirt_package_name_real = "${::nova::params::libvirt_daemon_package_prefix}${libvirt_virt_type}" - } - } - } else { - $libvirt_package_name_real = $::nova::params::libvirt_package_name - } - - package { 'libvirt': - ensure => present, - name => $libvirt_package_name_real, - tag => ['openstack', 'nova-support-package'], - } - - service { 'libvirt' : - ensure => running, - enable => true, - name => $libvirt_service_name, - provider => $::nova::params::special_service_provider, - require => Package['libvirt'], - } - - if $virtlock_service_name { - service { 'virtlockd': - ensure => running, - enable => true, - name => $virtlock_service_name, - provider => $::nova::params::special_service_provider, - require => Package['libvirt'] - } - } - - if $virtlog_service_name { - service { 'virtlogd': - ensure => running, - enable => true, - name => $virtlog_service_name, - provider => $::nova::params::special_service_provider, - require => Package['libvirt'] + # manage_libvirt_services is here for backward compatibility to support + # deployments that do not include nova::compute::libvirt::services + # + # If you're using hiera: + # - set nova::compute::libvirt::manage_libvirt_services to false + # - include ::nova::compute::libvirt::services in your composition layer + # - select which services you want to deploy with + # ::nova::compute::libvirt::services:* parameters. + # + # If you're not using hiera: + # - set nova::compute::libvirt::manage_libvirt_services to true (default). + # - select which services you want to deploy with + # ::nova::compute::libvirt::*_service_name parameters. + if $manage_libvirt_services { + class { '::nova::compute::libvirt::services': + libvirt_service_name => $libvirt_service_name, + virtlock_service_name => $virtlock_service_name, + virtlog_service_name => $virtlog_service_name, + libvirt_virt_type => $libvirt_virt_type, } } diff --git a/manifests/compute/libvirt/services.pp b/manifests/compute/libvirt/services.pp new file mode 100644 index 000000000..77b58bc25 --- /dev/null +++ b/manifests/compute/libvirt/services.pp @@ -0,0 +1,105 @@ +# == Class: nova::compute::libvirt::services +# +# Install and manage libvirt services. +# +# === Parameters: +# +# [*libvirt_service_name*] +# (optional) libvirt service name. +# Defaults to $::nova::params::libvirt_service_name +# +# [*virtlock_service_name*] +# (optional) virtlock service name. +# Defaults to $::nova::params::virtlock_service_name +# +# [*virtlog_service_name*] +# (optional) virtlog service name. +# Defaults to $::nova::params::virtlog_service_name +# +# [*libvirt_virt_type*] +# (optional) Libvirt domain type. Options are: kvm, lxc, qemu, uml, xen +# Defaults to 'kvm' +# +class nova::compute::libvirt::services ( + $libvirt_service_name = $::nova::params::libvirt_service_name, + $virtlock_service_name = $::nova::params::virtlock_service_name, + $virtlog_service_name = $::nova::params::virtlog_service_name, + $libvirt_virt_type = 'kvm', +) inherits nova::params { + + include ::nova::deps + include ::nova::params + + if $libvirt_service_name { + # messagebus + if($::osfamily == 'RedHat' and $::operatingsystem != 'Fedora') { + service { 'messagebus': + ensure => running, + enable => true, + name => $::nova::params::messagebus_service_name, + provider => $::nova::params::special_service_provider, + + } + Package['libvirt'] -> Service['messagebus'] -> Service['libvirt'] + } + + # libvirt-nwfilter + if $::osfamily == 'RedHat' { + package { 'libvirt-nwfilter': + ensure => present, + name => $::nova::params::libvirt_nwfilter_package_name, + before => Service['libvirt'], + tag => ['openstack', 'nova-support-package'], + } + case $libvirt_virt_type { + 'qemu': { + $libvirt_package_name_real = "${::nova::params::libvirt_daemon_package_prefix}kvm" + } + default: { + $libvirt_package_name_real = "${::nova::params::libvirt_daemon_package_prefix}${libvirt_virt_type}" + } + } + } else { + $libvirt_package_name_real = $::nova::params::libvirt_package_name + } + + # libvirt + package { 'libvirt': + ensure => present, + name => $libvirt_package_name_real, + tag => ['openstack', 'nova-support-package'], + } + service { 'libvirt' : + ensure => running, + enable => true, + name => $libvirt_service_name, + provider => $::nova::params::special_service_provider, + require => Package['libvirt'], + } + + # when nova-compute & libvirt run together + Service['libvirt'] -> Service<| title == 'nova-compute'|> + } + + + if $virtlock_service_name { + service { 'virtlockd': + ensure => running, + enable => true, + name => $virtlock_service_name, + provider => $::nova::params::special_service_provider, + require => Package['libvirt'] + } + } + + if $virtlog_service_name { + service { 'virtlogd': + ensure => running, + enable => true, + name => $virtlog_service_name, + provider => $::nova::params::special_service_provider, + require => Package['libvirt'] + } + } + +} diff --git a/releasenotes/notes/libvit_micro_service-ba1cd4ad8bda4e0d.yaml b/releasenotes/notes/libvit_micro_service-ba1cd4ad8bda4e0d.yaml new file mode 100644 index 000000000..f58e2b4c0 --- /dev/null +++ b/releasenotes/notes/libvit_micro_service-ba1cd4ad8bda4e0d.yaml @@ -0,0 +1,7 @@ +--- +features: + - Enable puppet-nova to deploy micro-services where libvirt & nova-compute + are separated. With a new class, nova::compute::libvirt::services, we're now + able to manage libvirt packages & services outside nova-compute. + This class is included by default in nova::compute::libvirt for backward + compatibility but can be disabled if you deploy compute services on containers. diff --git a/spec/classes/nova_compute_libvirt_services_spec.rb b/spec/classes/nova_compute_libvirt_services_spec.rb new file mode 100644 index 000000000..5e74f0569 --- /dev/null +++ b/spec/classes/nova_compute_libvirt_services_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe 'nova::compute::libvirt::services' do + + shared_examples_for 'nova compute libvirt services' do + + context 'with default parameters' do + it 'deploys libvirt packages and services' do + is_expected.to contain_package('libvirt') + is_expected.to contain_service('libvirt') + end + end + + context 'with overridden parameters' do + let :params do + { :libvirt_service_name => false } + end + + it 'disable libvirt service' do + is_expected.not_to contain_package('libvirt') + is_expected.not_to contain_service('libvirt') + end + 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 services' + end + end +end diff --git a/spec/classes/nova_compute_libvirt_spec.rb b/spec/classes/nova_compute_libvirt_spec.rb index 40b684c3e..dde10f5b2 100644 --- a/spec/classes/nova_compute_libvirt_spec.rb +++ b/spec/classes/nova_compute_libvirt_spec.rb @@ -175,6 +175,21 @@ describe 'nova::compute::libvirt' do end end + + describe 'when manage_libvirt_services is set to false' do + context 'without libvirt packages & services' do + let :params do + { :manage_libvirt_services => false } + end + + it { is_expected.not_to contain_package('libvirt') } + it { is_expected.not_to contain_service('libvirt') } + it { is_expected.not_to contain_package('libvirt-nwfilter') } + it { is_expected.not_to contain_service('messagebus') } + it { is_expected.not_to contain_service('virtlockd') } + it { is_expected.not_to contain_service('virtlogd') } + end + end end @@ -303,6 +318,21 @@ describe 'nova::compute::libvirt' do end end + describe 'when manage_libvirt_services is set to false' do + context 'without libvirt packages & services' do + let :params do + { :manage_libvirt_services => false } + end + + it { is_expected.not_to contain_package('libvirt') } + it { is_expected.not_to contain_service('libvirt') } + it { is_expected.not_to contain_package('libvirt-nwfilter') } + it { is_expected.not_to contain_service('messagebus') } + it { is_expected.not_to contain_service('virtlockd') } + it { is_expected.not_to contain_service('virtlogd') } + end + end + describe 'with default parameters on Fedora' do before do facts.merge!({ :operatingsystem => 'Fedora', :osfamily => 'RedHat' })