Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Class: libvirt
#
# Install, enable and configure libvirt.
#
# Parameters:
Expand Down Expand Up @@ -60,6 +58,13 @@
$sasl2_qemu_mech_list = undef,
$sasl2_qemu_keytab = undef,
$sasl2_qemu_auxprop_plugin = undef,
# libvirt hooks
$daemon_hook_content = undef,
$daemon_hook_source = undef,
$qemu_hook_content = undef,
$qemu_hook_source = undef,
$network_hook_content = undef,
$network_hook_source = undef,
) inherits ::libvirt::params {

package { 'libvirt':
Expand Down Expand Up @@ -156,6 +161,37 @@
}
}

if $daemon_hook_content and $daemon_hook_source {
fail('daemon_hook_content and daemon_hook_source cannot be used together')
} elsif $daemon_hook_content or $daemon_hook_source {
file { '/etc/libvirt/hooks/daemon':
ensure => present,
source => $daemon_hook_source,
content => $daemon_hook_content,
mode => '0755'
}
}
if $qemu_hook_content and $qemu_hook_source {
fail('qemu_hook_content and qemu_hook_source cannot be used together')
} elsif $daemon_hook_content or $daemon_hook_source {
file { '/etc/libvirt/hooks/qemu':
ensure => present,
source => $qemu_hook_source,
content => $qemu_hook_content,
mode => '0755'
}
}
if $network_hook_content and $network_hook_source {
fail('network_hook_content and network_hook_source cannot be used together')
} elsif $network_hook_content or $network_hook_source {
file { '/etc/libvirt/hooks/network':
ensure => present,
source => $network_hook_source,
content => $network_hook_content,
mode => '0755'
}
}

# Create Optional networks
create_resources(libvirt::network, $networks, $networks_defaults)

Expand Down
50 changes: 50 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,54 @@ class { 'libvirt':
end
end

context 'with network hook' do
it 'should work with no errors' do
pp = <<-EOS
class { 'libvirt':
network_hook_content => "this is a test"
}
EOS
# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe file("/etc/libvirt/hooks/network") do
it { should contain 'this is a test' }
end
end

context 'with qemu hook' do
it 'should work with no errors' do
pp = <<-EOS
class { 'libvirt':
qemu_hook_content => "this is a test"
}
EOS
# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe file("/etc/libvirt/hooks/qemu") do
it { should contain 'this is a test' }
end
end

context 'with daemon hook' do
it 'should work with no errors' do
pp = <<-EOS
class { 'libvirt':
daemon_hook_content => "this is a test"
}
EOS
# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
end

describe file("/etc/libvirt/hooks/daemon") do
it { should contain 'this is a test' }
end
end
end