From e1ab683e0f933b984b1974edfacf66e3ead379dd Mon Sep 17 00:00:00 2001 From: James Robson Date: Sat, 15 Aug 2015 18:38:47 +0100 Subject: [PATCH 1/3] add ode to handle libvirt hook files --- manifests/init.pp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 14be7a5..9a7d80c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,5 +1,3 @@ -# Class: libvirt -# # Install, enable and configure libvirt. # # Parameters: @@ -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': @@ -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) From 9a12a64e96e3fa12c7728cf5b54a6122f57b37af Mon Sep 17 00:00:00 2001 From: James Date: Sat, 5 Sep 2015 22:50:32 +0100 Subject: [PATCH 2/3] first test --- spec/acceptance/class_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index dd84ca7..6714150 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -62,4 +62,21 @@ 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 + end From ae2fd4080be368276960874e863467d5b8512770 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 10 Jan 2016 16:02:22 +0000 Subject: [PATCH 3/3] Add more basic tests --- spec/acceptance/class_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 6714150..5d18dce 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -79,4 +79,37 @@ class { 'libvirt': 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