From e6511fd5f463c10789fae56cbdcce4d7056e8536 Mon Sep 17 00:00:00 2001 From: Benedikt Braunger Date: Wed, 23 Sep 2020 13:08:22 +0200 Subject: [PATCH] added possibility to config defined types via hiera --- manifests/storage.pp | 47 +++++++++++++++--- spec/classes/storage_spec.rb | 94 ++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 8 deletions(-) diff --git a/manifests/storage.pp b/manifests/storage.pp index 3608dd4..5c72c3b 100644 --- a/manifests/storage.pp +++ b/manifests/storage.pp @@ -5,14 +5,19 @@ # This class will be automatically included when a resource is defined. # It is not intended to be used directly by external resources like node definitions or other modules. class bareos::storage( - $manage_service = $::bareos::manage_service, - $manage_package = $::bareos::manage_package, - $package_name = $::bareos::storage_package_name, - $package_ensure = $::bareos::package_ensure, - $service_name = $::bareos::storage_service_name, - $service_ensure = $::bareos::service_ensure, - $service_enable = $::bareos::service_enable, - $config_dir = "${::bareos::config_dir}/bareos-sd.d" + $manage_service = $::bareos::manage_service, + $manage_package = $::bareos::manage_package, + $package_name = $::bareos::storage_package_name, + $package_ensure = $::bareos::package_ensure, + $service_name = $::bareos::storage_service_name, + $service_ensure = $::bareos::service_ensure, + $service_enable = $::bareos::service_enable, + $config_dir = "${::bareos::config_dir}/bareos-sd.d", + Hash $autochangers = {}, + Has$devices = {}, + Has$directors = {}, + Has$messages = {}, + Has$ndmps = {}, ) inherits ::bareos { include ::bareos::storage::storage @@ -54,4 +59,30 @@ notify => Service[$service_name], tag => ['bareos', 'bareos_storage'], } + + $autochangers.each |String $resource, Hash $attributes| { + bareos::storage::autochanger { $resource: + * => $attributes; + } + } + $devices.each |String $resource, Hash $attributes| { + bareos::storage::device { $resource: + * => $attributes; + } + } + $directors.each |String $resource, Hash $attributes| { + bareos::storage::director { $resource: + * => $attributes; + } + } + $messages.each |String $resource, Hash $attributes| { + bareos::storage::message { $resource: + * => $attributes; + } + } + $ndmps.each |String $resource, Hash $attributes| { + bareos::storage::ndmp { $resource: + * => $attributes; + } + } } diff --git a/spec/classes/storage_spec.rb b/spec/classes/storage_spec.rb index 25ff9b3..2547f94 100644 --- a/spec/classes/storage_spec.rb +++ b/spec/classes/storage_spec.rb @@ -4,4 +4,98 @@ it { is_expected.to compile } it { is_expected.to contain_class('bareos') } end + + context 'with autochangers => { test: { changer_command => "foo", changer_device => "/dev/foo", device => "dev01" }}}' do + let(:params) do + { + autochangers: { + test: { + changer_command: "foo", + changer_device: "/dev/foo", + device: "dev01", + } + } + } + end + it { is_expected.to compile } + it do + is_expected.to contain_bareos__storage__autochanger('test') + .with_changer_command('foo') + .with_changer_device('/dev/foo') + .with_device('dev01'), + end + end + + context 'with devices => { test: { archive_device => "/mnt/test", media_type => "file" }}}' do + let(:params) do + { + devices: { + test: { + archive_device: "/mnt/test", + media_type: "file", + } + } + } + end + it { is_expected.to compile } + it do + is_expected.to contain_bareos__storage__device('test') + .with_archive_device('/mnt/test'), + .with_media_type('file'), + end + end + + context 'with directors => { test: { password => "foobar" }}}' do + let(:params) do + { + directors: { + test: { + password: "foobar", + } + } + } + end + it { is_expected.to compile } + it do + is_expected.to contain_bareos__storage__director('test') + .with_password('foobar'), + end + end + + context 'with messages => { test: { description => "test" }}}' do + let(:params) do + { + messages: { + test: { + description: "test", + } + } + } + end + it { is_expected.to compile } + it do + is_expected.to contain_bareos__storage__message('test') + .with_description('test'), + end + end + + context 'with ndmps => { test: { username => "test", password => "foobar" }}}' do + let(:params) do + { + ndmps: { + test: { + username: "test", + password: "foobar", + } + } + } + end + it { is_expected.to compile } + it do + is_expected.to contain_bareos__storage__ndmp('test') + .with_username('test'), + .with_password('password'), + end + end + end