Add host_uuid to libvirtd.conf

Add host_uuid generated by uuidgen to libvirtd.conf

Change-Id: Ib060bff4b1f547b4db255969bc8cb3119a85ba6d
Closes-Bug: 1378962
This commit is contained in:
Oleksiy Molchanov 2014-10-29 13:20:18 +02:00
parent d93b9709af
commit 8bf30c41e9
3 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,11 @@
require 'facter'
Facter.add(:libvirt_uuid) do
setcode do
uuid_file_path = '/etc/libvirt/libvirt_uuid'
if File.file? uuid_file_path
File.read uuid_file_path
else
nil
end
end
end

View File

@ -21,11 +21,16 @@
# (optional) Migration flags to be set for block migration (string value) # (optional) Migration flags to be set for block migration (string value)
# Defaults to undef # Defaults to undef
# #
# [*override_uuid*]
# (optional) Set uuid not equal to output from dmidecode (boolean)
# Defaults to false
#
class nova::migration::libvirt( class nova::migration::libvirt(
$use_tls = false, $use_tls = false,
$auth = 'none', $auth = 'none',
$live_migration_flag = undef, $live_migration_flag = undef,
$block_migration_flag = undef, $block_migration_flag = undef,
$override_uuid = false,
){ ){
include ::nova::deps include ::nova::deps
@ -62,6 +67,26 @@ class nova::migration::libvirt(
File_line<| tag == 'libvirt-file_line' |> File_line<| tag == 'libvirt-file_line' |>
~> Service['libvirt'] ~> Service['libvirt']
if $override_uuid {
if ! $::libvirt_uuid {
$host_uuid = generate('/bin/cat', '/proc/sys/kernel/random/uuid')
file { '/etc/libvirt/libvirt_uuid':
content => $host_uuid
}
} else {
$host_uuid = $::libvirt_uuid
}
augeas { 'libvirt-conf-uuid':
context => '/files/etc/libvirt/libvirtd.conf',
changes => [
"set host_uuid ${host_uuid}",
],
notify => Service['libvirt'],
require => Package['libvirt'],
}
}
case $::osfamily { case $::osfamily {
'RedHat': { 'RedHat': {
file_line { '/etc/libvirt/libvirtd.conf listen_tls': file_line { '/etc/libvirt/libvirtd.conf listen_tls':

View File

@ -22,6 +22,14 @@ require 'spec_helper'
describe 'nova::migration::libvirt' do describe 'nova::migration::libvirt' do
generate = {}
before(:each) {
Puppet::Parser::Functions.newfunction(:generate, :type => :rvalue) {
|args| generate.call()
}
generate.stubs(:call).returns('0000-111-111')
}
let :pre_condition do let :pre_condition do
'include nova 'include nova
@ -38,6 +46,19 @@ describe 'nova::migration::libvirt' do
it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp').with(:line => "auth_tcp = \"none\"") } it { is_expected.to contain_file_line('/etc/libvirt/libvirtd.conf auth_tcp').with(:line => "auth_tcp = \"none\"") }
end end
context 'with override_uuid enabled' do
let :params do
{
:override_uuid => true,
}
end
it { is_expected.to contain_augeas('libvirt-conf-uuid').with({
:context => '/files/etc/libvirt/libvirtd.conf',
:changes => [ "set host_uuid 0000-111-111" ],
}).that_requires('Package[libvirt]').that_notifies('Service[libvirt]') }
end
context 'with tls enabled' do context 'with tls enabled' do
let :params do let :params do
{ {