Add functionality to manage /etc/sysconfig/libvirt-guests
If resume_guests_state_on_host_boot is set in nova.conf also libvirt-guests need to be configured in the right way to shutdown running instances on a compute reboot. Closes-bug: 1778216 Change-Id: I2766cdd66ff17756daaf1a75ad516a7af6eebddc
This commit is contained in:
parent
ccd0ee93ff
commit
df325e8f6d
97
manifests/compute/libvirt_guests.pp
Normal file
97
manifests/compute/libvirt_guests.pp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
# == Class: nova::compute::libvirt_guests
|
||||||
|
#
|
||||||
|
# manages configuration for starting running instances when compute node
|
||||||
|
# gets rebooted.
|
||||||
|
#
|
||||||
|
# === Parameters:
|
||||||
|
#
|
||||||
|
# [*enabled*]
|
||||||
|
# (optional) Whether the libvirt-guests service will be run
|
||||||
|
# Defaults to false
|
||||||
|
#
|
||||||
|
# [*package_ensure*]
|
||||||
|
# (optional) The state of libvirt packages
|
||||||
|
# Defaults to 'present'
|
||||||
|
#
|
||||||
|
# [*on_boot*]
|
||||||
|
# (optional) libvirt-guests parameter - action taken on host boot
|
||||||
|
# - start all guests which were running on shutdown are started on boot
|
||||||
|
# regardless on their autostart settings
|
||||||
|
# - ignore libvirt-guests init script won't start any guest on boot, however,
|
||||||
|
# guests marked as autostart will still be automatically started by
|
||||||
|
# libvirtd
|
||||||
|
# Defaults to 'ignore'
|
||||||
|
#
|
||||||
|
# [*on_shutdown*]
|
||||||
|
# (optional) libvirt-guests parameter - action taken on host shutdown
|
||||||
|
# - suspend all running guests are suspended using virsh managedsave
|
||||||
|
# - shutdown all running guests are asked to shutdown. Please be careful with
|
||||||
|
# this settings since there is no way to distinguish between a
|
||||||
|
# guest which is stuck or ignores shutdown requests and a guest
|
||||||
|
# which just needs a long time to shutdown. When setting
|
||||||
|
# ON_SHUTDOWN=shutdown, you must also set SHUTDOWN_TIMEOUT to a
|
||||||
|
# value suitable for your guests.
|
||||||
|
# Defaults to 'shutdown'
|
||||||
|
#
|
||||||
|
# [*shutdown_timeout*]
|
||||||
|
# (optional) Number of seconds we're willing to wait for a guest to shut
|
||||||
|
# down. If parallel shutdown is enabled, this timeout applies as a timeout
|
||||||
|
# for shutting down all guests on a single URI defined in the variable URIS.
|
||||||
|
# If this is 0, then there is no time out (use with caution, as guests might
|
||||||
|
# not respond to a shutdown request). The default value is 300 seconds
|
||||||
|
# (5 minutes).
|
||||||
|
# Defaults to 300.
|
||||||
|
#
|
||||||
|
class nova::compute::libvirt_guests (
|
||||||
|
$enabled = false,
|
||||||
|
$package_ensure = 'present',
|
||||||
|
$shutdown_timeout = '300',
|
||||||
|
$on_boot = 'ignore',
|
||||||
|
$on_shutdown = 'shutdown',
|
||||||
|
) {
|
||||||
|
include ::nova::params
|
||||||
|
include ::nova::deps
|
||||||
|
|
||||||
|
Anchor['nova::config::begin']
|
||||||
|
-> File_line<| tag == 'libvirt-guests-file_line'|>
|
||||||
|
-> Anchor['nova::config::end']
|
||||||
|
|
||||||
|
File_line<| tag == 'libvirt-guests-file_line' |>
|
||||||
|
~> Service['libvirt-guests']
|
||||||
|
|
||||||
|
case $::osfamily {
|
||||||
|
'RedHat': {
|
||||||
|
file_line { '/etc/sysconfig/libvirt-guests ON_BOOT':
|
||||||
|
path => '/etc/sysconfig/libvirt-guests',
|
||||||
|
line => "ON_BOOT=${on_boot}",
|
||||||
|
match => '^#?ON_BOOT=.*',
|
||||||
|
tag => 'libvirt-guests-file_line',
|
||||||
|
}
|
||||||
|
|
||||||
|
file_line { '/etc/sysconfig/libvirt-guests ON_SHUTDOWN':
|
||||||
|
path => '/etc/sysconfig/libvirt-guests',
|
||||||
|
line => "ON_SHUTDOWN=${on_shutdown}",
|
||||||
|
match => '^#?ON_SHUTDOWN=.*',
|
||||||
|
tag => 'libvirt-guests-file_line',
|
||||||
|
}
|
||||||
|
|
||||||
|
file_line { '/etc/sysconfig/libvirt-guests SHUTDOWN_TIMEOUT':
|
||||||
|
path => '/etc/sysconfig/libvirt-guests',
|
||||||
|
line => "SHUTDOWN_TIMEOUT=${shutdown_timeout}",
|
||||||
|
match => '^#?SHUTDOWN_TIMEOUT=.*',
|
||||||
|
tag => 'libvirt-guests-file_line',
|
||||||
|
}
|
||||||
|
|
||||||
|
nova::generic_service { 'libvirt-guests':
|
||||||
|
enabled => $enabled,
|
||||||
|
manage_service => $enabled,
|
||||||
|
package_name => $::nova::params::libvirt_guests_package_name,
|
||||||
|
service_name => $::nova::params::libvirt_guests_service_name,
|
||||||
|
ensure_package => $package_ensure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
warning("Unsupported osfamily: ${::osfamily}, make sure you are configuring this yourself")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ class nova::params {
|
|||||||
$consoleauth_package_name = 'openstack-nova-console'
|
$consoleauth_package_name = 'openstack-nova-console'
|
||||||
$doc_package_name = 'openstack-nova-doc'
|
$doc_package_name = 'openstack-nova-doc'
|
||||||
$libvirt_package_name = 'libvirt'
|
$libvirt_package_name = 'libvirt'
|
||||||
|
$libvirt_guests_package_name = 'libvirt-client'
|
||||||
$libvirt_daemon_package_prefix = 'libvirt-daemon-'
|
$libvirt_daemon_package_prefix = 'libvirt-daemon-'
|
||||||
$libvirt_nwfilter_package_name = 'libvirt-daemon-config-nwfilter'
|
$libvirt_nwfilter_package_name = 'libvirt-daemon-config-nwfilter'
|
||||||
$network_package_name = 'openstack-nova-network'
|
$network_package_name = 'openstack-nova-network'
|
||||||
@ -42,6 +43,7 @@ class nova::params {
|
|||||||
$consoleauth_service_name = 'openstack-nova-consoleauth'
|
$consoleauth_service_name = 'openstack-nova-consoleauth'
|
||||||
$placement_service_name = 'httpd'
|
$placement_service_name = 'httpd'
|
||||||
$libvirt_service_name = 'libvirtd'
|
$libvirt_service_name = 'libvirtd'
|
||||||
|
$libvirt_guests_service_name = 'libvirt-guests'
|
||||||
$virtlock_service_name = 'virtlockd'
|
$virtlock_service_name = 'virtlockd'
|
||||||
$virtlog_service_name = undef
|
$virtlog_service_name = undef
|
||||||
$network_service_name = 'openstack-nova-network'
|
$network_service_name = 'openstack-nova-network'
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Adds nova::compute::libvirt_guests to manage /etc/sysconfig/libvirt-guests
|
||||||
|
to configure libvirt-guests for compute reboot and handle running instance
|
||||||
|
properly.
|
||||||
|
|
75
spec/classes/nova_compute_libvirt_guests_spec.rb
Normal file
75
spec/classes/nova_compute_libvirt_guests_spec.rb
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require 'puppet/util/package'
|
||||||
|
describe 'nova::compute::libvirt_guests' do
|
||||||
|
|
||||||
|
let :pre_condition do
|
||||||
|
"include nova\ninclude nova::compute"
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples 'redhat-nova-compute-libvirt-guests' do
|
||||||
|
before do
|
||||||
|
facts.merge!({ :operatingsystem => 'RedHat', :osfamily => 'RedHat',
|
||||||
|
:operatingsystemrelease => 6.5,
|
||||||
|
:operatingsystemmajrelease => '6' })
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with default parameters' do
|
||||||
|
|
||||||
|
it { is_expected.to contain_class('nova::params')}
|
||||||
|
|
||||||
|
it { is_expected.not_to contain_package('libvirt-client') }
|
||||||
|
it { is_expected.not_to contain_service('libvirt-guests') }
|
||||||
|
|
||||||
|
describe 'on rhel 7' do
|
||||||
|
before do
|
||||||
|
facts.merge!({
|
||||||
|
:operatingsystemrelease => 7.0,
|
||||||
|
:operatingsystemmajrelease => '7'
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to contain_service('libvirt-guests')}
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with params' do
|
||||||
|
let :params do
|
||||||
|
{ :enabled => true,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to contain_file_line('/etc/sysconfig/libvirt-guests ON_BOOT').with(:line => 'ON_BOOT=ignore') }
|
||||||
|
it { is_expected.to contain_file_line('/etc/sysconfig/libvirt-guests ON_SHUTDOWN').with(:line => "ON_SHUTDOWN=shutdown") }
|
||||||
|
it { is_expected.to contain_file_line('/etc/sysconfig/libvirt-guests SHUTDOWN_TIMEOUT').with(:line => "SHUTDOWN_TIMEOUT=300") }
|
||||||
|
|
||||||
|
it { is_expected.to contain_package('libvirt-guests').with(
|
||||||
|
:name => 'libvirt-client',
|
||||||
|
:ensure => 'present'
|
||||||
|
) }
|
||||||
|
|
||||||
|
it { is_expected.to contain_service('libvirt-guests').with(
|
||||||
|
:name => 'libvirt-guests',
|
||||||
|
:enable => true,
|
||||||
|
:ensure => 'running',
|
||||||
|
)}
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
on_supported_os({
|
||||||
|
:supported_os => OSDefaults.get_supported_os
|
||||||
|
}).each do |os,facts|
|
||||||
|
context "on #{os}" do
|
||||||
|
|
||||||
|
case [:osfamily]
|
||||||
|
when 'RedHat'
|
||||||
|
let (:facts) do
|
||||||
|
facts.merge!(OSDefaults.get_facts({ :os_package_type => 'rpm' }))
|
||||||
|
end
|
||||||
|
it_behaves_like 'redhat-nova-compute-libvirt-guests'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user