From bae82edaa98852031f0e0cd435077808d3bd711a Mon Sep 17 00:00:00 2001 From: Richard Hillmann Date: Mon, 14 Aug 2017 13:51:30 +0200 Subject: [PATCH 1/2] Fix client name conf file. Update readme and improve metadata requires. --- README.md | 16 ++++++++-------- manifests/client/client.pp | 2 +- metadata.json | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d58d597..c977702 100644 --- a/README.md +++ b/README.md @@ -8,18 +8,18 @@ 1. [Description](#description) 1. [Setup requirements](#setup-requirements) 1. [Reference](#reference) - * [Bareos common](#class-bareos) - * [Client/Filedaemon](#client-filedaemon) - * [Console (bconsole)](#console) - * [Director](#director) - * [Monitor (Tray)](#monitor) - * [Storage](#storage) - * [Web UI](#webui) + 1. [Bareos common](#class-bareos) + 1. [Client/Filedaemon](#clientfiledaemon) + 1. [Console (bconsole)](#console) + 1. [Director](#director) + 1. [Monitor (Tray)](#monitor) + 1. [Storage](#storage) + 1. [Web UI](#webui) 1. [Limitations - OS compatibility, etc.](#limitations) ## Description -Bareos is a 100% open source fork of the backup project from bacula.org. +[Bareos](http://bareos.org/) is a 100% open source fork of the backup project from bacula.org. This puppet module configures and manage all aspects of an complex bareos installation. Unfortunately backups cannot be handled on an standard way, so this module tends to be flexible as possible. It is recommend to make familiar with the [documentation](http://doc.bareos.org/master/html/bareos-manual-main-reference.html) of the configuration. diff --git a/manifests/client/client.pp b/manifests/client/client.pp index 0d5db50..5cda3d1 100644 --- a/manifests/client/client.pp +++ b/manifests/client/client.pp @@ -451,7 +451,7 @@ $_require_res_messages = undef } - file { "${::bareos::client::config_dir}/${_resource_dir}/${name}.conf": + file { "${::bareos::client::config_dir}/${_resource_dir}/${name_client}.conf": ensure => $ensure, mode => $::bareos::file_mode, owner => $::bareos::file_owner, diff --git a/metadata.json b/metadata.json index adb769b..7a31024 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "project0-bareos", - "version": "0.1.0", + "version": "CHANGE_ME", "author": "Richard Hillmann ", "summary": "Manage and configure a Bareos installation", "license": "Apache-2.0", @@ -9,9 +9,9 @@ "issues_url": "https://github.com/project0/puppet-bareos/issues", "tags": ["bareos", "backup"], "dependencies": [ - {"name": "puppetlabs/stdlib","version_requirement":">= 4.0.0"}, - {"name": "puppetlabs/apt", "version_requirement": ">=2.0.0"}, - {"name": "puppetlabs/concat", "version_requirement": ">=2.0.0"} + {"name": "puppetlabs/stdlib","version_requirement":">= 4.0.0 < 5.0.0"}, + {"name": "puppetlabs/apt", "version_requirement": ">=2.0.0 < 5.0.0"}, + {"name": "puppetlabs/concat", "version_requirement": ">=2.0.0 < 5.0.0"} ], "requirements": [ { From e7a1aa24888a7ad655d3f0afa424afdc23406ca5 Mon Sep 17 00:00:00 2001 From: Richard Hillmann Date: Tue, 15 Aug 2017 11:45:43 +0200 Subject: [PATCH 2/2] Improve bareos type checking, fix bugs and add specs. * Fix dependencie cycle on multiple catalog definitions * Fix some bareos type checking * Add missing bareos types to bareos_settings function and remove them from manifests * Add specs for all bareos resources, with helper. * Remove unneeded aliases fd-* from director::client define --- .travis.yml | 2 - .../parser/functions/bareos_settings.rb | 24 ++- manifests/client/client.pp | 2 +- manifests/client/director.pp | 2 +- manifests/director.pp | 6 + manifests/director/catalog.pp | 9 +- manifests/director/client.pp | 37 +--- manifests/director/counter.pp | 9 + manifests/director/director.pp | 2 +- manifests/director/job.pp | 32 +--- manifests/director/jobdefs.pp | 30 +-- manifests/director/pool.pp | 7 +- manifests/director/storage.pp | 37 +--- manifests/monitor/storage.pp | 4 +- manifests/storage/device.pp | 10 +- manifests/storage/ndmp.pp | 5 +- manifests/webui/director.pp | 2 +- metadata.json | 2 +- spec/classes/client_client_spec.rb | 84 +++++++++ spec/classes/director_director_spec.rb | 86 +++++++++ spec/classes/storage_storage_spec.rb | 89 +++++++++ spec/defines/client/client_director_spec.rb | 62 +++++++ spec/defines/client/client_messages_spec.rb | 50 +++++ spec/defines/console/console_console_spec.rb | 55 ++++++ spec/defines/console/console_director_spec.rb | 53 ++++++ spec/defines/director/director_catalog.rb | 63 +++++++ spec/defines/director/director_client_spec.rb | 88 +++++++++ .../defines/director/director_console_spec.rb | 77 ++++++++ .../defines/director/director_counter_spec.rb | 49 +++++ .../defines/director/director_fileset_spec.rb | 39 ++++ spec/defines/director/director_job_spec.rb | 173 ++++++++++++++++++ .../defines/director/director_jobdefs_spec.rb | 155 ++++++++++++++++ .../director/director_messages_spec.rb | 50 +++++ spec/defines/director/director_pool_spec.rb | 86 +++++++++ .../defines/director/director_profile_spec.rb | 45 +++++ .../director/director_schedule_spec.rb | 37 ++++ .../defines/director/director_storage_spec.rb | 92 ++++++++++ spec/defines/monitor/monitor_client_spec.rb | 46 +++++ spec/defines/monitor/monitor_director_spec.rb | 44 +++++ spec/defines/monitor/monitor_monitor_spec.rb | 47 +++++ spec/defines/monitor/monitor_storage_spec.rb | 48 +++++ .../storage/storage_autochanger_spec.rb | 68 +++++++ spec/defines/storage/storage_device_spec.rb | 106 +++++++++++ spec/defines/storage/storage_director_spec.rb | 61 ++++++ spec/defines/storage/storage_messages_spec.rb | 50 +++++ spec/defines/storage/storage_ndmp_spec.rb | 50 +++++ spec/functions/bareos_settings_spec.rb | 153 +++++++++++++++- spec/settings_helper.rb | 116 ++++++++++++ spec/spec_helper.rb | 2 + 49 files changed, 2285 insertions(+), 161 deletions(-) create mode 100644 spec/classes/client_client_spec.rb create mode 100644 spec/classes/director_director_spec.rb create mode 100644 spec/classes/storage_storage_spec.rb create mode 100644 spec/defines/client/client_director_spec.rb create mode 100644 spec/defines/client/client_messages_spec.rb create mode 100644 spec/defines/console/console_console_spec.rb create mode 100644 spec/defines/console/console_director_spec.rb create mode 100644 spec/defines/director/director_catalog.rb create mode 100644 spec/defines/director/director_client_spec.rb create mode 100644 spec/defines/director/director_console_spec.rb create mode 100644 spec/defines/director/director_counter_spec.rb create mode 100644 spec/defines/director/director_fileset_spec.rb create mode 100644 spec/defines/director/director_job_spec.rb create mode 100644 spec/defines/director/director_jobdefs_spec.rb create mode 100644 spec/defines/director/director_messages_spec.rb create mode 100644 spec/defines/director/director_pool_spec.rb create mode 100644 spec/defines/director/director_profile_spec.rb create mode 100644 spec/defines/director/director_schedule_spec.rb create mode 100644 spec/defines/director/director_storage_spec.rb create mode 100644 spec/defines/monitor/monitor_client_spec.rb create mode 100644 spec/defines/monitor/monitor_director_spec.rb create mode 100644 spec/defines/monitor/monitor_monitor_spec.rb create mode 100644 spec/defines/monitor/monitor_storage_spec.rb create mode 100644 spec/defines/storage/storage_autochanger_spec.rb create mode 100644 spec/defines/storage/storage_device_spec.rb create mode 100644 spec/defines/storage/storage_director_spec.rb create mode 100644 spec/defines/storage/storage_messages_spec.rb create mode 100644 spec/defines/storage/storage_ndmp_spec.rb create mode 100644 spec/settings_helper.rb diff --git a/.travis.yml b/.travis.yml index 3e8a2fa..69e79ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -59,5 +59,3 @@ matrix: env: PUPPET_GEM_VERSION="~> 4.4.0" STRICT_VARIABLES=yes - rvm: 2.4 env: PUPPET_GEM_VERSION="~> 4.6.0" STRICT_VARIABLES=yes - - rvm: 2.4 - env: PUPPET_GEM_VERSION="~> 5.0.1" STRICT_VARIABLES=yes diff --git a/lib/puppet/parser/functions/bareos_settings.rb b/lib/puppet/parser/functions/bareos_settings.rb index 8e10923..1abce38 100644 --- a/lib/puppet/parser/functions/bareos_settings.rb +++ b/lib/puppet/parser/functions/bareos_settings.rb @@ -51,7 +51,7 @@ module Puppet::Parser::Functions when 'acl', 'messages', 'type', 'string_noquote', 'schedule_run_command' raise 'Value need to be an string' unless value.is_a?(String) # type md5password is missleading, it is an plain password and not md5 hashed - when 'audit-command', 'runscript_short', 'autopassword', 'md5password', 'directory', 'string', 'strname', 'address', 'device', 'plugin_names' + when 'audit_command', 'runscript_short', 'autopassword', 'md5password', 'directory', 'string', 'strname', 'address', 'device', 'plugin_names' # array quote = true raise 'Value need to be an string' unless value.is_a?(String) @@ -69,11 +69,31 @@ module Puppet::Parser::Functions when 'include_exclude_item', 'runscript', 'hash' raise 'Please specify as Hash' unless value.is_a?(Hash) when 'backup_level' - value_in_array = %w[full incremental differential virtualfull] + value_in_array = %w[full incremental differential virtualfull initcatalog catalog volumetocatalog disktocatalog] when 'io_direction' value_in_array = %w[in out both] when 'action_on_purge' value_in_array = %w[truncate] + when 'encryption_cipher' + value_in_array = %w[aes128 aes192 aes256 camellia128 camellia192 camellia256 aes128hmacsha1 aes256hmacsha1 blowfish] + when 'auth_type' + value_in_array = %w[clear md5] + when 'auth_protocol_type', 'protocol_type' + value_in_array = %w[native ndmp] + when 'pooltype' + value_in_array = %w[backup archive cloned migration copy save scratch] + when 'label' + value_in_array = %w[ansi ibm bareos] + when 'migration_type' + value_in_array = %w[smallestvolume oldestvolume client volume job sqlquery pooloccupancy pooltime pooluncopiedjobs] + when 'job_type' + value_in_array = %w[backup restore verify admin migrate copy consolidate] + when 'replace_option' + value_in_array = %w[always ifnewer ifolder never] + when 'device_type' + value_in_array = %w[tape file fifo gfapi rados] + when 'compression_algorithm' + value_in_array = %w[gzip lzo lzfast lz4 lz4hc] else raise "Invalid setting type '#{type}'" end diff --git a/manifests/client/client.pp b/manifests/client/client.pp index 5cda3d1..99ae422 100644 --- a/manifests/client/client.pp +++ b/manifests/client/client.pp @@ -393,7 +393,7 @@ } if $ensure == 'present' { - $_require_res_messages = $messages ? { undef => undef, default => Bareos::Director::Messages[$messages] } + $_require_res_messages = $messages ? { undef => undef, default => Bareos::Client::Messages[$messages] } $_require_resource = delete_undef_values([ $_require_res_messages, diff --git a/manifests/client/director.pp b/manifests/client/director.pp index e59803b..e638693 100644 --- a/manifests/client/director.pp +++ b/manifests/client/director.pp @@ -199,12 +199,12 @@ if $ensure == 'present' { $_settings = bareos_settings( [$name, 'Name', 'name', true], + [$description, 'Description', 'string', false], [$address, 'Address', 'string', false], [$allowed_job_command, 'Allowed Job Command', 'string_list', false], [$allowed_script_dir, 'Allowed Script Dir', 'directory_list', false], [$connection_from_client_to_director, 'Connection From Client To Director', 'boolean', false], [$connection_from_director_to_client, 'Connection From Director To Client', 'boolean', false], - [$description, 'Description', 'string', false], [$maximum_bandwidth_per_job, 'Maximum Bandwidth Per Job', 'speed', false], [$monitor, 'Monitor', 'boolean', false], [$password, 'Password', 'md5password', true], diff --git a/manifests/director.pp b/manifests/director.pp index b9be039..c3dbe1d 100644 --- a/manifests/director.pp +++ b/manifests/director.pp @@ -59,4 +59,10 @@ require => Package[$package_name], notify => Service[$service_name], } + + File <| |> -> exec { 'bareos director init catalog': + command => '/usr/lib/bareos/scripts/create_bareos_database && /usr/lib/bareos/scripts/make_bareos_tables && /usr/lib/bareos/scripts/grant_bareos_privileges', + notify => Service[$::bareos::director::service_name], + refreshonly => true, + } } diff --git a/manifests/director/catalog.pp b/manifests/director/catalog.pp index 15df843..9a6070c 100644 --- a/manifests/director/catalog.pp +++ b/manifests/director/catalog.pp @@ -178,7 +178,6 @@ ) } - $_exec_create = "bareos catalog create database ${title}" file { "${::bareos::director::config_dir}/${_resource_dir}/${name}.conf": ensure => $ensure, mode => $::bareos::file_mode, @@ -187,13 +186,7 @@ content => template('bareos/resource.erb'), notify => [ Service[$::bareos::director::service_name], - Exec[$_exec_create], + Exec['bareos director init catalog'], ] } - # execute after all config files are written - File <| |> -> exec { $_exec_create: - command => '/usr/lib/bareos/scripts/create_bareos_database && /usr/lib/bareos/scripts/make_bareos_tables && /usr/lib/bareos/scripts/grant_bareos_privileges', - notify => Service[$::bareos::director::service_name], - refreshonly => true, - } } diff --git a/manifests/director/client.pp b/manifests/director/client.pp index bca6659..2ee14f5 100644 --- a/manifests/director/client.pp +++ b/manifests/director/client.pp @@ -63,27 +63,6 @@ # Bareos Default: true # Required: false # -# [*fd_address*] -# Fd Address: Alias for Address. -# -# Bareos Datatype: string -# Bareos Default: Not set -# Required: false -# -# [*fd_password*] -# Fd Password -# -# Bareos Datatype: autopassword -# Bareos Default: Not set -# Required: false -# -# [*fd_port*] -# Fd Port -# -# Bareos Datatype: pint32 -# Bareos Default: 9102 -# Required: false -# # [*file_retention*] # File Retention # @@ -305,9 +284,6 @@ $connection_from_director_to_client = undef, $description = undef, $enabled = undef, - $fd_address = undef, - $fd_password = undef, - $fd_port = undef, $file_retention = undef, $hard_quota = undef, $heartbeat_interval = undef, @@ -355,25 +331,16 @@ $_require_res_catalog, ]) - unless $auth_type == undef or (downcase($auth_type) in [ 'Clear', 'md5' ]) { - fail('Invalid value for auth_type') - } - unless $protocol == undef or (downcase($protocol) in [ 'native', 'ndmp' ]) { - fail('Invalid value for protocol') - } $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], [$address, 'Address', 'string', true], - [$auth_type, 'Auth Type', 'type', false], + [$auth_type, 'Auth Type', 'auth_type', false], [$auto_prune, 'Auto Prune', 'boolean', false], [$catalog, 'Catalog', 'res', false], [$connection_from_client_to_director, 'Connection From Client To Director', 'boolean', false], [$connection_from_director_to_client, 'Connection From Director To Client', 'boolean', false], [$enabled, 'Enabled', 'boolean', false], - [$fd_address, 'Fd Address', 'string', false], - [$fd_password, 'Fd Password', 'autopassword', false], - [$fd_port, 'Fd Port', 'pint32', false], [$file_retention, 'File Retention', 'time', false], [$hard_quota, 'Hard Quota', 'size64', false], [$heartbeat_interval, 'Heartbeat Interval', 'time', false], @@ -386,7 +353,7 @@ [$passive, 'Passive', 'boolean', false], [$password, 'Password', 'autopassword', true], [$port, 'Port', 'pint32', false], - [$protocol, 'Protocol', 'type', false], + [$protocol, 'Protocol', 'auth_protocol_type', false], [$quota_include_failed_jobs, 'Quota Include Failed Jobs', 'boolean', false], [$soft_quota, 'Soft Quota', 'size64', false], [$soft_quota_grace_period, 'Soft Quota Grace Period', 'time', false], diff --git a/manifests/director/counter.pp b/manifests/director/counter.pp index 1a725a1..1be39fa 100644 --- a/manifests/director/counter.pp +++ b/manifests/director/counter.pp @@ -59,6 +59,12 @@ } if $ensure == 'present' { + $_require_res_catalog = $catalog ? { undef => undef, default => Bareos::Director::Catalog[$catalog] } + + $_require_resource = delete_undef_values([ + $_require_res_catalog, + ]) + $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], @@ -67,6 +73,8 @@ [$minimum, 'Minimum', 'int32', false], [$wrap_counter, 'Wrap Counter', 'res', false] ) + } else { + $_require_resource = undef } file { "${::bareos::director::config_dir}/${_resource_dir}/${name}.conf": @@ -76,5 +84,6 @@ group => $::bareos::file_group, content => template('bareos/resource.erb'), notify => Service[$::bareos::director::service_name], + require => $_require_resource, } } diff --git a/manifests/director/director.pp b/manifests/director/director.pp index 27eb54e..165d198 100644 --- a/manifests/director/director.pp +++ b/manifests/director/director.pp @@ -371,7 +371,7 @@ $omit_defaults = undef, $optimize_for_size = undef, $optimize_for_speed = undef, - $password = 'set', + $password = 'PleaseChangeMe', $pid_directory = undef, $plugin_directory = undef, $plugin_names = undef, diff --git a/manifests/director/job.pp b/manifests/director/job.pp index c0a1d25..594a7a8 100644 --- a/manifests/director/job.pp +++ b/manifests/director/job.pp @@ -566,13 +566,6 @@ # Bareos Default: Not set # Required: true # -# [*verify_job*] -# Verify Job -# -# Bareos Datatype: res -# Bareos Default: Not set -# Required: false -# # [*virtual_full_backup_pool*] # Virtual Full Backup Pool # @@ -682,7 +675,6 @@ $storage = undef, $strip_prefix = undef, $type = undef, - $verify_job = undef, $virtual_full_backup_pool = undef, $where = undef, $write_bootstrap = undef, @@ -711,7 +703,7 @@ $_require_res_client = $client ? { undef => undef, default => Bareos::Director::Client[$client] } $_require_res_file_set = $file_set ? { undef => undef, default => Bareos::Director::Fileset[$file_set] } # note: verify_job is an alias to job_to_verify - $_jobs = delete_undef_values([$base, $job_to_verify, $verify_job]) + $_jobs = delete_undef_values([$base, $job_to_verify]) $_require_res_jobs = empty($_jobs) ? { false => Bareos::Director::Job[$_jobs], default => undef } $_require_res_job_defs = $job_defs ? { undef => undef, default => Bareos::Director::Jobdefs[$job_defs] } $_require_res_message = $messages ? { undef => undef, default => Bareos::Director::Messages[$messages] } @@ -733,19 +725,6 @@ $_require_res_storage, ]) - unless $level == undef or (downcase($level) in [ 'full', 'incremental', 'differential', 'virtualfull', 'initcatalog', 'catalog', 'volumetocatalog', 'disktocatalog' ]) { - fail("Invalid value for level: ${level}") - } - unless $protocol == undef or (downcase($protocol) in [ 'native', 'ndmp' ]) { - fail('Invalid value for protocol') - } - unless $selection_type == undef or (downcase($selection_type) in [ 'smallestvolume', 'oldestvolume', 'client', 'volume', 'job', 'sqlquery', 'pooloccupancy', 'pooltime', 'pooluncopiedjobs' ]) { - fail('Invalid value for selection_type') - } - unless $type == undef or (downcase($type) in [ 'backup', 'restore', 'verify', 'admin', 'migrate', 'copy', 'consolidate' ]) { - fail("Invalid value for type: ${type}") - } - $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], @@ -782,7 +761,7 @@ [$incremental_max_runtime, 'Incremental Max Runtime', 'time', false], [$job_defs, 'Job Defs', 'res', false], [$job_to_verify, 'Job To Verify', 'res', false], - [$level, 'Level', 'type', false], + [$level, 'Level', 'backup_level', false], [$max_concurrent_copies, 'Max Concurrent Copies', 'pint32', false], [$max_diff_interval, 'Max Diff Interval', 'time', false], [$max_full_consolidations, 'Max Full Consolidations', 'pint32', false], @@ -800,7 +779,7 @@ [$prefer_mounted_volumes, 'Prefer Mounted Volumes', 'boolean', false], [$prefix_links, 'Prefix Links', 'boolean', false], [$priority, 'Priority', 'pint32', false], - [$protocol, 'Protocol', 'type', false], + [$protocol, 'Protocol', 'protocol_type', false], [$prune_files, 'Prune Files', 'boolean', false], [$prune_jobs, 'Prune Jobs', 'boolean', false], [$prune_volumes, 'Prune Volumes', 'boolean', false], @@ -820,14 +799,13 @@ [$schedule_res, 'Schedule', 'res', false], [$sd_plugin_options, 'Sd Plugin Options', 'string_list', false], [$selection_pattern, 'Selection Pattern', 'string', false], - [$selection_type, 'Selection Type', 'type', false], + [$selection_type, 'Selection Type', 'migration_type', false], [$spool_attributes, 'Spool Attributes', 'boolean', false], [$spool_data, 'Spool Data', 'boolean', false], [$spool_size, 'Spool Size', 'size64', false], [$storage, 'Storage', 'resource_list', false], [$strip_prefix, 'Strip Prefix', 'string', false], - [$type, 'Type', 'type', $_require_res], - [$verify_job, 'Verify Job', 'res', false], + [$type, 'Type', 'job_type', $_require_res], [$virtual_full_backup_pool, 'Virtual Full Backup Pool', 'res', false], [$where, 'Where', 'directory', false], [$write_bootstrap, 'Write Bootstrap', 'directory', false], diff --git a/manifests/director/jobdefs.pp b/manifests/director/jobdefs.pp index f4ad424..05e4bae 100644 --- a/manifests/director/jobdefs.pp +++ b/manifests/director/jobdefs.pp @@ -565,13 +565,6 @@ # Bareos Default: Not set # Required: true # -# [*verify_job*] -# Verify Job -# -# Bareos Datatype: res -# Bareos Default: Not set -# Required: false -# # [*virtual_full_backup_pool*] # Virtual Full Backup Pool # @@ -681,7 +674,6 @@ $storage = undef, $strip_prefix = undef, $type = undef, - $verify_job = undef, $virtual_full_backup_pool = undef, $where = undef, $write_bootstrap = undef, @@ -702,7 +694,7 @@ $_require_res_client = $client ? { undef => undef, default => Bareos::Director::Client[$client] } $_require_res_file_set = $file_set ? { undef => undef, default => Bareos::Director::Fileset[$file_set] } # note: verify_job is an alias to job_to_verify - $_jobs = delete_undef_values([$base, $job_to_verify, $verify_job]) + $_jobs = delete_undef_values([$base, $job_to_verify]) $_require_res_jobs = empty($_jobs) ? { false => Bareos::Director::Job[$_jobs], default => undef } $_require_res_job_defs = $job_defs ? { undef => undef, default => Bareos::Director::Jobdefs[$job_defs] } $_require_res_message = $messages ? { undef => undef, default => Bareos::Director::Messages[$messages] } @@ -724,19 +716,6 @@ $_require_res_storage, ]) - unless $level == undef or (downcase($level) in [ 'full', 'incremental', 'differential', 'virtualfull', 'initcatalog', 'catalog', 'volumetocatalog', 'disktocatalog' ]) { - fail("Invalid value for level: ${level}") - } - unless $protocol == undef or (downcase($protocol) in [ 'native', 'ndmp' ]) { - fail('Invalid value for protocol') - } - unless $selection_type == undef or (downcase($selection_type) in [ 'smallestvolume', 'oldestvolume', 'client', 'volume', 'job', 'sqlquery', 'pooloccupancy', 'pooltime', 'pooluncopiedjobs' ]) { - fail('Invalid value for selection_type') - } - unless $type == undef or (downcase($type) in [ 'backup', 'restore', 'verify', 'admin', 'migrate', 'copy', 'consolidate' ]) { - fail("Invalid value for type: ${type}") - } - $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], @@ -791,7 +770,7 @@ [$prefer_mounted_volumes, 'Prefer Mounted Volumes', 'boolean', false], [$prefix_links, 'Prefix Links', 'boolean', false], [$priority, 'Priority', 'pint32', false], - [$protocol, 'Protocol', 'type', false], + [$protocol, 'Protocol', 'protocol_type', false], [$prune_files, 'Prune Files', 'boolean', false], [$prune_jobs, 'Prune Jobs', 'boolean', false], [$prune_volumes, 'Prune Volumes', 'boolean', false], @@ -811,14 +790,13 @@ [$schedule_res, 'Schedule', 'res', false], [$sd_plugin_options, 'Sd Plugin Options', 'string_list', false], [$selection_pattern, 'Selection Pattern', 'string', false], - [$selection_type, 'Selection Type', 'type', false], + [$selection_type, 'Selection Type', 'migration_type', false], [$spool_attributes, 'Spool Attributes', 'boolean', false], [$spool_data, 'Spool Data', 'boolean', false], [$spool_size, 'Spool Size', 'size64', false], [$storage, 'Storage', 'resource_list', false], [$strip_prefix, 'Strip Prefix', 'string', false], - [$type, 'Type', 'type', false], - [$verify_job, 'Verify Job', 'res', false], + [$type, 'Type', 'job_type', false], [$virtual_full_backup_pool, 'Virtual Full Backup Pool', 'res', false], [$where, 'Where', 'directory', false], [$write_bootstrap, 'Write Bootstrap', 'directory', false], diff --git a/manifests/director/pool.pp b/manifests/director/pool.pp index 013e2c6..4c17193 100644 --- a/manifests/director/pool.pp +++ b/manifests/director/pool.pp @@ -274,7 +274,7 @@ $_require_res_catalog = $catalog ? { undef => undef, default => Bareos::Director::Catalog[$catalog] } # check all configured pools $_pools = delete_undef_values([$next_pool, $recycle_pool, $scratch_pool]) - $_require_res_pools = empty($_pools) ? { false => Bareos::Director::Job[$_pools], default => undef } + $_require_res_pools = empty($_pools) ? { false => Bareos::Director::Pool[$_pools], default => undef } $_require_res_storage = $storage ? { undef => undef, default => Bareos::Director::Storage[$storage]} $_require_resource = delete_undef_values([ @@ -283,9 +283,6 @@ $_require_res_storage, ]) - unless $pool_type == undef or $pool_type in [ 'Backup', 'Archive', 'Cloned', 'Migration', 'Copy', 'Save', 'Scratch' ] { - fail("Invalid value for pool_type: ${pool_type}") - } $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], @@ -308,7 +305,7 @@ [$migration_time, 'Migration Time', 'time', false], [$minimum_block_size, 'Minimum Block Size', 'pint32', false], [$next_pool, 'Next Pool', 'res', false], - [$pool_type, 'Pool Type', 'type', false], + [$pool_type, 'Pool Type', 'pooltype', false], [$purge_oldest_volume, 'Purge Oldest Volume', 'boolean', false], [$recycle, 'Recycle', 'boolean', false], [$recycle_current_volume, 'Recycle Current Volume', 'boolean', false], diff --git a/manifests/director/storage.pp b/manifests/director/storage.pp index 0bf9f00..5283546 100644 --- a/manifests/director/storage.pp +++ b/manifests/director/storage.pp @@ -139,27 +139,6 @@ # Bareos Default: Native # Required: false # -# [*sd_address*] -# Sd Address: Alias for Address. -# -# Bareos Datatype: string -# Bareos Default: Not set -# Required: false -# -# [*sd_password*] -# Sd Password: Alias for Password. -# -# Bareos Datatype: autopassword -# Bareos Default: Not set -# Required: false -# -# [*sd_port*] -# Sd Port: Alias for Port. -# -# Bareos Datatype: pint32 -# Bareos Default: 9103 -# Required: false -# # [*tape_device*] # Tape Device # @@ -281,9 +260,6 @@ $password = undef, $port = undef, $protocol = undef, - $sd_address = undef, - $sd_password = undef, - $sd_port = undef, $tape_device = undef, $tls_allowed_cn = undef, $tls_authenticate = undef, @@ -315,18 +291,12 @@ $_require_res_storage, ]) - unless $auth_type == undef or $auth_type in [ undef ] { - fail('Invalid value for auth_type') - } - unless $protocol == undef or $protocol in [ undef ] { - fail('Invalid value for protocol') - } $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], [$address, 'Address', 'string', true], [$allow_compression, 'Allow Compression', 'boolean', false], - [$auth_type, 'Auth Type', 'type', false], + [$auth_type, 'Auth Type', 'auth_type', false], [$auto_changer, 'Auto Changer', 'boolean', false], [$cache_status_interval, 'Cache Status Interval', 'time', false], [$changer_device, 'Changer Device', 'strname', false], @@ -341,10 +311,7 @@ [$paired_storage, 'Paired Storage', 'res', false], [$password, 'Password', 'autopassword', true], [$port, 'Port', 'pint32', false], - [$protocol, 'Protocol', 'type', false], - [$sd_address, 'Sd Address', 'string', false], - [$sd_password, 'Sd Password', 'autopassword', false], - [$sd_port, 'Sd Port', 'pint32', false], + [$protocol, 'Protocol', 'auth_protocol_type', false], [$tape_device, 'Tape Device', 'string_list', false], [$tls_allowed_cn, 'Tls Allowed Cn', 'string_list', false], [$tls_authenticate, 'Tls Authenticate', 'boolean', false], diff --git a/manifests/monitor/storage.pp b/manifests/monitor/storage.pp index 5c26486..8f012ed 100644 --- a/manifests/monitor/storage.pp +++ b/manifests/monitor/storage.pp @@ -80,8 +80,8 @@ [$address, 'Address', 'string', true], [$enable_ssl, 'Enable Ssl', 'boolean', false], [$password, 'Password', 'md5password', true], - [$sd_address, 'Sd Address', 'string', false], - [$sd_password, 'Sd Password', 'md5password', false], + [$sd_address, 'Sd Address', 'string', false], # alias? undocumented + [$sd_password, 'Sd Password', 'md5password', false], # alias? undocumented [$sd_port, 'Sd Port', 'pint32', false] ) } diff --git a/manifests/storage/device.pp b/manifests/storage/device.pp index 6838ac5..4603c11 100644 --- a/manifests/storage/device.pp +++ b/manifests/storage/device.pp @@ -508,12 +508,6 @@ } if $ensure == 'present' { - unless $device_type == undef or (downcase($device_type) in [ 'tape', 'file', 'fifo', 'gfapi', 'rados' ]) { - fail("Invalid value for device_type: ${device_type}") - } - unless $auto_deflate_algorithm == undef or (downcase($auto_deflate_algorithm) in [ 'gzip', 'lzo', 'lzfast', 'lz4', 'lz4hc' ]) { - fail("Invalid value for auto_deflate_algorithm: ${auto_deflate_algorithm}") - } $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], @@ -521,7 +515,7 @@ [$always_open, 'Always Open', 'bit', false], [$archive_device, 'Archive Device', 'strname', true], [$auto_deflate, 'Auto Deflate', 'io_direction', false], - [$auto_deflate_algorithm, 'Auto Deflate Algorithm', 'type', false], + [$auto_deflate_algorithm, 'Auto Deflate Algorithm', 'compression_algorithm', false], [$auto_deflate_level, 'Auto Deflate Level', 'pint16', false], [$auto_inflate, 'Auto Inflate', 'io_direction', false], [$auto_select, 'Auto Select', 'boolean', false], @@ -538,7 +532,7 @@ [$close_on_poll, 'Close On Poll', 'bit', false], [$collect_statistics, 'Collect Statistics', 'boolean', false], [$device_options, 'Device Options', 'string', false], - [$device_type, 'Device Type', 'type', false], + [$device_type, 'Device Type', 'device_type', false], [$diagnostic_device, 'Diagnostic Device', 'strname', false], [$drive_crypto_enabled, 'Drive Crypto Enabled', 'boolean', false], [$drive_index, 'Drive Index', 'pint16', false], diff --git a/manifests/storage/ndmp.pp b/manifests/storage/ndmp.pp index 5779398..763597c 100644 --- a/manifests/storage/ndmp.pp +++ b/manifests/storage/ndmp.pp @@ -60,13 +60,10 @@ } if $ensure == 'present' { - unless $auth_type == undef or downcase($auth_type) in [ 'none', 'clear', 'md5' ] { - fail("Invalid value for auth_type: ${auth_type}") - } $_settings = bareos_settings( [$name, 'Name', 'name', true], [$description, 'Description', 'string', false], - [$auth_type, 'Auth Type', 'type', false], + [$auth_type, 'Auth Type', 'auth_type', false], [$log_level, 'Log Level', 'pint32', false], [$password, 'Password', 'autopassword', true], [$username, 'Username', 'string', true] diff --git a/manifests/webui/director.pp b/manifests/webui/director.pp index 4a09a8c..ce38a5e 100644 --- a/manifests/webui/director.pp +++ b/manifests/webui/director.pp @@ -51,7 +51,7 @@ [$enabled, 'Enabled', 'bit', true], [$name, 'Dir Name', 'res', true] ) - concat::fragment{ 'bareos-fd.conf initial': + concat::fragment{ "bareos webui director ${title}": target => "${::bareos::webui::config_dir}/directors.ini", content => template('bareos/webui_directors.erb'), notify => Service[$::bareos::webui::service_name], diff --git a/metadata.json b/metadata.json index 7a31024..18a8c5c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "project0-bareos", - "version": "CHANGE_ME", + "version": "0.0.0", "author": "Richard Hillmann ", "summary": "Manage and configure a Bareos installation", "license": "Apache-2.0", diff --git a/spec/classes/client_client_spec.rb b/spec/classes/client_client_spec.rb new file mode 100644 index 0000000..7e2e5b8 --- /dev/null +++ b/spec/classes/client_client_spec.rb @@ -0,0 +1,84 @@ +require 'spec_helper' + +describe 'bareos::client::client' do + filename = '/etc/bareos/bareos-fd.d/client/bareos-fd.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::client') } + it { is_expected.to contain_file(filename).with_content(%r{^Client \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "bareos-fd"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Client') + res.param('name_client', 'Name', 'name').param_val('name_client', 'bareos-fd', '"bareos-fd"'). + param('description', 'Description', 'string'). + param('absolute_job_timeout', 'Absolute Job Timeout', 'pint32'). + param('allow_bandwidth_bursting', 'Allow Bandwidth Bursting', 'boolean'). + param('allowed_job_command', 'Allowed Job Command', 'string_list'). + param('allowed_script_dir', 'Allowed Script Dir', 'directory_list'). + param('always_use_lmdb', 'Always Use Lmdb', 'boolean'). + param('compatible', 'Compatible', 'boolean'). + param('fd_address', 'Fd Address', 'address'). + param('fd_addresses', 'Fd Addresses', 'addresses'). + param('fd_port', 'Fd Port', 'port'). + param('fd_source_address', 'Fd Source Address', 'address'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('lmdb_threshold', 'Lmdb Threshold', 'pint32'). + param('log_timestamp_format', 'Log Timestamp Format', 'string'). + param('maximum_bandwidth_per_job', 'Maximum Bandwidth Per Job', 'speed'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('maximum_connections', 'Maximum Connections', 'pint32'). + param('maximum_network_buffer_size', 'Maximum Network Buffer Size', 'pint32'). + param('messages', 'Messages', 'res'). + param('pid_directory', 'Pid Directory', 'directory'). + param('pki_cipher', 'Pki Cipher', 'encryption_cipher'). + param('pki_encryption', 'Pki Encryption', 'boolean'). + param('pki_key_pair', 'Pki Key Pair', 'directory'). + param('pki_master_key', 'Pki Master Key', 'directory_list'). + param('pki_signatures', 'Pki Signatures', 'boolean'). + param('pki_signer', 'Pki Signer', 'directory_list'). + param('plugin_directory', 'Plugin Directory', 'directory'). + param('plugin_names', 'Plugin Names', 'plugin_names'). + param('scripts_directory', 'Scripts Directory', 'directory'). + param('sd_connect_timeout', 'Sd Connect Timeout', 'time'). + param('secure_erase_command', 'Secure Erase Command', 'string'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean'). + param('ver_id', 'Ver Id', 'string'). + param('working_directory', 'Working Directory', 'directory') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::client::messages { "name":} + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-fd]'). + that_requires('Bareos::Client::Messages[name]') + end + end + + context 'ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/classes/director_director_spec.rb b/spec/classes/director_director_spec.rb new file mode 100644 index 0000000..0d46ada --- /dev/null +++ b/spec/classes/director_director_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +describe 'bareos::director::director' do + filename = '/etc/bareos/bareos-dir.d/director/bareos-dir.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Director \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "bareos-dir"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Director') + res.param('name_director', 'Name', 'name').param_val('name_director', 'bareos-dir', '"bareos-dir"'). + param('description', 'Description', 'string'). + param('absolute_job_timeout', 'Absolute Job Timeout', 'pint32'). + param('audit_events', 'Audit Events', 'audit_command_list'). + param('auditing', 'Auditing', 'boolean'). + param('backend_directory', 'Backend Directory', 'directory_list'). + param('dir_address', 'Dir Address', 'address'). + param('dir_addresses', 'Dir Addresses', 'addresses'). + param('dir_port', 'Dir Port', 'port'). + param('dir_source_address', 'Dir Source Address', 'address'). + param('fd_connect_timeout', 'Fd Connect Timeout', 'time'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('key_encryption_key', 'Key Encryption Key', 'autopassword'). + param('log_timestamp_format', 'Log Timestamp Format', 'string'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('maximum_connections', 'Maximum Connections', 'pint32'). + param('maximum_console_connections', 'Maximum Console Connections', 'pint32'). + param('messages', 'Messages', 'res'). + param('ndmp_log_level', 'Ndmp Log Level', 'pint32'). + param('ndmp_snooping', 'Ndmp Snooping', 'boolean'). + param('omit_defaults', 'Omit Defaults', 'boolean'). + param('optimize_for_size', 'Optimize For Size', 'boolean'). + param('optimize_for_speed', 'Optimize For Speed', 'boolean'). + param('password', 'Password', 'autopassword'). + param('pid_directory', 'Pid Directory', 'directory'). + param('plugin_directory', 'Plugin Directory', 'directory'). + param('plugin_names', 'Plugin Names', 'plugin_names'). + param('query_file', 'Query File', 'directory'). + param('scripts_directory', 'Scripts Directory', 'directory'). + param('sd_connect_timeout', 'Sd Connect Timeout', 'time'). + param('secure_erase_command', 'Secure Erase Command', 'string'). + param('statistics_collect_interval', 'Statistics Collect Interval', 'pint32'). + param('statistics_retention', 'Statistics Retention', 'time'). + param('subscriptions', 'Subscriptions', 'pint32'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean'). + param('ver_id', 'Ver Id', 'string'). + param('working_directory', 'Working Directory', 'directory') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::messages { "name":} + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Messages[name]') + end + end + + context 'ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/classes/storage_storage_spec.rb b/spec/classes/storage_storage_spec.rb new file mode 100644 index 0000000..8badd9a --- /dev/null +++ b/spec/classes/storage_storage_spec.rb @@ -0,0 +1,89 @@ +require 'spec_helper' + +describe 'bareos::storage::storage' do + filename = '/etc/bareos/bareos-sd.d/storage/bareos-sd.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::storage') } + it { is_expected.to contain_file(filename).with_content(%r{^Storage \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "bareos-sd"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Storage') + res.param('name_storage', 'Name', 'name').param_val('name_storage', 'bareos-sd', '"bareos-sd"'). + param('absolute_job_timeout', 'Absolute Job Timeout', 'pint32'). + param('allow_bandwidth_bursting', 'Allow Bandwidth Bursting', 'boolean'). + param('auto_x_flate_on_replication', 'Auto X Flate On Replication', 'boolean'). + param('backend_directory', 'Backend Directory', 'directory_list'). + param('client_connect_wait', 'Client Connect Wait', 'time'). + param('collect_device_statistics', 'Collect Device Statistics', 'boolean'). + param('collect_job_statistics', 'Collect Job Statistics', 'boolean'). + param('compatible', 'Compatible', 'boolean'). + param('device_reserve_by_media_type', 'Device Reserve By Media Type', 'boolean'). + param('fd_connect_timeout', 'Fd Connect Timeout', 'time'). + param('file_device_concurrent_read', 'File Device Concurrent Read', 'boolean'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('log_timestamp_format', 'Log Timestamp Format', 'string'). + param('maximum_bandwidth_per_job', 'Maximum Bandwidth Per Job', 'speed'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('maximum_connections', 'Maximum Connections', 'pint32'). + param('maximum_network_buffer_size', 'Maximum Network Buffer Size', 'pint32'). + param('messages', 'Messages', 'res'). + param('ndmp_address', 'Ndmp Address', 'address'). + param('ndmp_addresses', 'Ndmp Addresses', 'addresses'). + param('ndmp_enable', 'Ndmp Enable', 'boolean'). + param('ndmp_log_level', 'Ndmp Log Level', 'pint32'). + param('ndmp_port', 'Ndmp Port', 'port'). + param('ndmp_snooping', 'Ndmp Snooping', 'boolean'). + param('pid_directory', 'Pid Directory', 'directory'). + param('plugin_directory', 'Plugin Directory', 'directory'). + param('plugin_names', 'Plugin Names', 'plugin_names'). + param('scripts_directory', 'Scripts Directory', 'directory'). + param('sd_address', 'Sd Address', 'address'). + param('sd_addresses', 'Sd Addresses', 'addresses'). + param('sd_connect_timeout', 'Sd Connect Timeout', 'time'). + param('sd_port', 'Sd Port', 'port'). + param('sd_source_address', 'Sd Source Address', 'address'). + param('secure_erase_command', 'Secure Erase Command', 'string'). + param('statistics_collect_interval', 'Statistics Collect Interval', 'pint32'). + param('sub_sys_directory', 'Sub Sys Directory', 'directory'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean'). + param('ver_id', 'Ver Id', 'string'). + param('working_directory', 'Working Directory', 'directory') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::storage::messages { "name":} + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-sd]'). + that_requires('Bareos::Storage::Messages[name]') + end + end + + context 'ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/client/client_director_spec.rb b/spec/defines/client/client_director_spec.rb new file mode 100644 index 0000000..300974c --- /dev/null +++ b/spec/defines/client/client_director_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe 'bareos::client::director' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-fd.d/director/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) { { 'password' => 'password' } } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::client') } + it { is_expected.to contain_file(filename).with_content(%r{^Director \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Director') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('allowed_job_command', 'Allowed Job Command', 'string_list'). + param('allowed_script_dir', 'Allowed Script Dir', 'directory_list'). + param('connection_from_client_to_director', 'Connection From Client To Director', 'boolean'). + param('connection_from_director_to_client', 'Connection From Director To Client', 'boolean'). + param('maximum_bandwidth_per_job', 'Maximum Bandwidth Per Job', 'speed'). + param('monitor', 'Monitor', 'boolean'). + param('password', 'Password', 'md5password'). + param('port', 'Port', 'pint32'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-fd]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/client/client_messages_spec.rb b/spec/defines/client/client_messages_spec.rb new file mode 100644 index 0000000..693e3c1 --- /dev/null +++ b/spec/defines/client/client_messages_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'bareos::client::messages' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-fd.d/messages/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::client') } + it { is_expected.to contain_file(filename).with_content(%r{^Messages \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Messages') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('append', 'Append', 'messages_list'). + param('catalog', 'Catalog', 'messages_list'). + param('console', 'Console', 'messages_list'). + param('director', 'Director', 'messages_list'). + param('file', 'File', 'messages_list'). + param('mail', 'Mail', 'messages_list'). + param('mail_command', 'Mail Command', 'string'). + param('mail_on_error', 'Mail On Error', 'messages_list'). + param('mail_on_success', 'Mail On Success', 'messages_list'). + param('operator', 'Operator', 'messages_list'). + param('operator_command', 'Operator Command', 'string'). + param('stderr', 'Stderr', 'messages_list'). + param('stdout', 'Stdout', 'messages_list'). + param('syslog', 'Syslog', 'messages_list'). + param('timestamp_format', 'Timestamp Format', 'string') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-fd]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/console/console_console_spec.rb b/spec/defines/console/console_console_spec.rb new file mode 100644 index 0000000..90a644b --- /dev/null +++ b/spec/defines/console/console_console_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe 'bareos::console::console' do + let(:title) { 'name' } + + filename = '/etc/bareos/bconsole.d/console/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) { { 'password' => 'password' } } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::console') } + it { is_expected.to contain_file(filename).with_content(%r{^Console \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Console') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('director', 'Director', 'string'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('history_file', 'History File', 'directory'). + param('history_length', 'History Length', 'pint32'). + param('password', 'Password', 'md5password'). + param('rc_file', 'Rc File', 'directory'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/console/console_director_spec.rb b/spec/defines/console/console_director_spec.rb new file mode 100644 index 0000000..69a3831 --- /dev/null +++ b/spec/defines/console/console_director_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'bareos::console::director' do + let(:title) { 'name' } + + filename = '/etc/bareos/bconsole.d/director/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) { { 'password' => 'password' } } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::console') } + it { is_expected.to contain_file(filename).with_content(%r{^Director \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Director') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('dir_port', 'Dir Port', 'pint32'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('password', 'Password', 'md5password'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_catalog.rb b/spec/defines/director/director_catalog.rb new file mode 100644 index 0000000..a7ddc1e --- /dev/null +++ b/spec/defines/director/director_catalog.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe 'bareos::director::catalog' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/catalog/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'db_driver' => 'mysql', + 'db_name' => 'catalogdb' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Catalog \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Catalog') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('db_address', 'Db Address', 'string'). + param('db_driver', 'Db Driver', 'string'). + param('db_name', 'Db Name', 'string'). + param('db_password', 'Db Password', 'autopassword'). + param('db_port', 'Db Port', 'pint32'). + param('db_socket', 'Db Socket', 'string'). + param('db_user', 'Db User', 'string'). + param('disable_batch_insert', 'Disable Batch Insert', 'boolean'). + param('exit_on_fatal', 'Exit On Fatal', 'boolean'). + param('idle_timeout', 'Idle Timeout', 'pint32'). + param('inc_connections', 'Inc Connections', 'pint32'). + param('max_connections', 'Max Connections', 'pint32'). + param('min_connections', 'Min Connections', 'pint32'). + param('multiple_connections', 'Multiple Connections', 'bit'). + param('reconnect', 'Reconnect', 'boolean'). + param('validate_timeout', 'Validate Timeout', 'pint32') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_notifies('Exec[bareos director init catalog]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_client_spec.rb b/spec/defines/director/director_client_spec.rb new file mode 100644 index 0000000..5b6f0f1 --- /dev/null +++ b/spec/defines/director/director_client_spec.rb @@ -0,0 +1,88 @@ +require 'spec_helper' + +describe 'bareos::director::client' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/client/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) { { 'password' => 'password', 'address' => '127.0.0.1' } } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Client \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Client') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('auth_type', 'Auth Type', 'auth_type'). + param('auto_prune', 'Auto Prune', 'boolean'). + param('catalog', 'Catalog', 'res'). + param('connection_from_client_to_director', 'Connection From Client To Director', 'boolean'). + param('connection_from_director_to_client', 'Connection From Director To Client', 'boolean'). + param('enabled', 'Enabled', 'boolean'). + param('file_retention', 'File Retention', 'time'). + param('hard_quota', 'Hard Quota', 'size64'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('job_retention', 'Job Retention', 'time'). + param('maximum_bandwidth_per_job', 'Maximum Bandwidth Per Job', 'speed'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('ndmp_block_size', 'Ndmp Block Size', 'pint32'). + param('ndmp_log_level', 'Ndmp Log Level', 'pint32'). + param('ndmp_use_lmdb', 'Ndmp Use Lmdb', 'boolean'). + param('passive', 'Passive', 'boolean'). + param('password', 'Password', 'autopassword'). + param('port', 'Port', 'pint32'). + param('protocol', 'Protocol', 'auth_protocol_type'). + param('quota_include_failed_jobs', 'Quota Include Failed Jobs', 'boolean'). + param('soft_quota', 'Soft Quota', 'size64'). + param('soft_quota_grace_period', 'Soft Quota Grace Period', 'time'). + param('strict_quotas', 'Strict Quotas', 'boolean'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean'). + param('username', 'Username', 'string') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::catalog { "name": + db_driver => "sqlite3", + db_name => "test", + } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Catalog[name]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_console_spec.rb b/spec/defines/director/director_console_spec.rb new file mode 100644 index 0000000..098ea0d --- /dev/null +++ b/spec/defines/director/director_console_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper' + +describe 'bareos::director::console' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/console/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'password' => 'pw' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Console \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Console') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('catalog_acl', 'Catalog ACL', 'acl'). + param('client_acl', 'Client ACL', 'acl'). + param('command_acl', 'Command ACL', 'acl'). + param('file_set_acl', 'File Set ACL', 'acl'). + param('job_acl', 'Job ACL', 'acl'). + param('password', 'Password', 'autopassword'). + param('plugin_options_acl', 'Plugin Options ACL', 'acl'). + param('pool_acl', 'Pool ACL', 'acl'). + param('profile', 'Profile', 'resource_list'). + param('run_acl', 'Run ACL', 'acl'). + param('schedule_acl', 'Schedule ACL', 'acl'). + param('storage_acl', 'Storage ACL', 'acl'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean'). + param('where_acl', 'Where ACL', 'acl') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::profile { "name": } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Profile[name]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_counter_spec.rb b/spec/defines/director/director_counter_spec.rb new file mode 100644 index 0000000..f018360 --- /dev/null +++ b/spec/defines/director/director_counter_spec.rb @@ -0,0 +1,49 @@ +require 'spec_helper' + +describe 'bareos::director::counter' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/counter/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Counter \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Counter') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('catalog', 'Catalog', 'res'). + param('maximum', 'Maximum', 'pint32'). + param('minimum', 'Minimum', 'int32'). + param('wrap_counter', 'Wrap Counter', 'res') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::catalog { "name": + db_driver => "sqlite3", + db_name => "test", + } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Catalog[name]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_fileset_spec.rb b/spec/defines/director/director_fileset_spec.rb new file mode 100644 index 0000000..4443c7c --- /dev/null +++ b/spec/defines/director/director_fileset_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'bareos::director::fileset' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/fileset/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^FileSet \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('FileSet') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('enable_vss', 'Enable VSS', 'boolean'). + param('exclude', 'Exclude', 'include_exclude_item'). + param('ignore_file_set_changes', 'Ignore File Set Changes', 'boolean'). + param('include', 'Include', 'include_exclude_item') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_job_spec.rb b/spec/defines/director/director_job_spec.rb new file mode 100644 index 0000000..fe6c9da --- /dev/null +++ b/spec/defines/director/director_job_spec.rb @@ -0,0 +1,173 @@ +require 'spec_helper' + +describe 'bareos::director::job' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/job/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'messages' => 'name', + 'pool' => 'name', + 'type' => 'backup' + } + end + let(:pre_condition) do + ' + bareos::director::pool { "name": } + bareos::director::messages { "name": } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Job \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Job') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('accurate', 'Accurate', 'boolean'). + param('add_prefix', 'Add Prefix', 'string'). + param('add_suffix', 'Add Suffix', 'string'). + param('allow_duplicate_jobs', 'Allow Duplicate Jobs', 'boolean'). + param('allow_higher_duplicates', 'Allow Higher Duplicates', 'boolean'). + param('allow_mixed_priority', 'Allow Mixed Priority', 'boolean'). + param('always_incremental', 'Always Incremental', 'boolean'). + param('always_incremental_job_retention', 'Always Incremental Job Retention', 'time'). + param('always_incremental_keep_number', 'Always Incremental Keep Number', 'pint32'). + param('always_incremental_max_full_age', 'Always Incremental Max Full Age', 'time'). + param('backup_format', 'Backup Format', 'string'). + param('base', 'Base', 'resource_list').param_val('base', 'name2', '"name2"'). + param('bootstrap', 'Bootstrap', 'directory'). + param('cancel_lower_level_duplicates', 'Cancel Lower Level Duplicates', 'boolean'). + param('cancel_queued_duplicates', 'Cancel Queued Duplicates', 'boolean'). + param('cancel_running_duplicates', 'Cancel Running Duplicates', 'boolean'). + param('catalog', 'Catalog', 'res'). + param('client', 'Client', 'res'). + param('client_run_after_job', 'Client Run After Job', 'runscript_short'). + param('client_run_before_job', 'Client Run Before Job', 'runscript_short'). + param('differential_backup_pool', 'Differential Backup Pool', 'res'). + param('differential_max_runtime', 'Differential Max Runtime', 'time'). + param('dir_plugin_options', 'Dir Plugin Options', 'string_list'). + param('enabled', 'Enabled', 'boolean'). + param('fd_plugin_options', 'Fd Plugin Options', 'string_list'). + param('file_history_size', 'File History Size', 'size64'). + param('file_set', 'File Set', 'res'). + param('full_backup_pool', 'Full Backup Pool', 'res'). + param('full_max_runtime', 'Full Max Runtime', 'time'). + param('incremental_backup_pool', 'Incremental Backup Pool', 'res'). + param('incremental_max_runtime', 'Incremental Max Runtime', 'time'). + param('job_defs', 'Job Defs', 'res'). + param('job_to_verify', 'Job To Verify', 'res').param_val('job_to_verify', 'name2', '"name2"'). + param('level', 'Level', 'backup_level'). + param('max_concurrent_copies', 'Max Concurrent Copies', 'pint32'). + param('max_diff_interval', 'Max Diff Interval', 'time'). + param('max_full_consolidations', 'Max Full Consolidations', 'pint32'). + param('max_full_interval', 'Max Full Interval', 'time'). + param('max_run_sched_time', 'Max Run Sched Time', 'time'). + param('max_run_time', 'Max Run Time', 'time'). + param('max_start_delay', 'Max Start Delay', 'time'). + param('max_virtual_full_interval', 'Max Virtual Full Interval', 'time'). + param('max_wait_time', 'Max Wait Time', 'time'). + param('maximum_bandwidth', 'Maximum Bandwidth', 'speed'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('messages', 'Messages', 'res'). + param('next_pool', 'Next Pool', 'res'). + param('pool', 'Pool', 'res'). + param('prefer_mounted_volumes', 'Prefer Mounted Volumes', 'boolean'). + param('prefix_links', 'Prefix Links', 'boolean'). + param('priority', 'Priority', 'pint32'). + param('protocol', 'Protocol', 'protocol_type'). + param('prune_files', 'Prune Files', 'boolean'). + param('prune_jobs', 'Prune Jobs', 'boolean'). + param('prune_volumes', 'Prune Volumes', 'boolean'). + param('purge_migration_job', 'Purge Migration Job', 'boolean'). + param('regex_where', 'Regex Where', 'string'). + param('replace', 'Replace', 'replace_option'). + param('rerun_failed_levels', 'Rerun Failed Levels', 'boolean'). + param('reschedule_interval', 'Reschedule Interval', 'time'). + param('reschedule_on_error', 'Reschedule On Error', 'boolean'). + param('reschedule_times', 'Reschedule Times', 'pint32'). + param('run', 'Run', 'string_list'). + param('run_after_failed_job', 'Run After Failed Job', 'runscript_short'). + param('run_after_job', 'Run After Job', 'runscript_short'). + param('run_before_job', 'Run Before Job', 'runscript_short'). + param('run_script', 'Run Script', 'runscript'). + param('save_file_history', 'Save File History', 'boolean'). + param('schedule_res', 'Schedule', 'res'). + param('sd_plugin_options', 'Sd Plugin Options', 'string_list'). + param('selection_pattern', 'Selection Pattern', 'string'). + param('selection_type', 'Selection Type', 'migration_type'). + param('spool_attributes', 'Spool Attributes', 'boolean'). + param('spool_data', 'Spool Data', 'boolean'). + param('spool_size', 'Spool Size', 'size64'). + param('storage', 'Storage', 'resource_list'). + param('strip_prefix', 'Strip Prefix', 'string'). + param('type', 'Type', 'job_type'). + param('virtual_full_backup_pool', 'Virtual Full Backup Pool', 'res'). + param('where', 'Where', 'directory'). + param('write_bootstrap', 'Write Bootstrap', 'directory'). + param('write_verify_list', 'Write Verify List', 'directory') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::pool { "name": } + bareos::director::catalog { "name": + db_driver => "sqlite3", + db_name => "test", + } + bareos::director::storage { "name": + address => "127.0.0.1", + device => "Device", + media_type => "File", + password => "pw", + } + bareos::director::client { "name": + address => "127.0.0.1", + password => "pw", + } + bareos::director::fileset { "name": } + bareos::director::schedule { "name": } + bareos::director::messages { "name": } + bareos::director::job { "name2": + messages => "name", + pool => "name", + type => "backup", + } + bareos::director::jobdefs { "name": } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Catalog[name]'). + that_requires('Bareos::Director::Storage[name]'). + that_requires('Bareos::Director::Schedule[name]'). + that_requires('Bareos::Director::Messages[name]'). + that_requires('Bareos::Director::Client[name]'). + that_requires('Bareos::Director::Fileset[name]'). + that_requires('Bareos::Director::Job[name2]'). + that_requires('Bareos::Director::Jobdefs[name]'). + that_requires('Bareos::Director::Pool[name]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_jobdefs_spec.rb b/spec/defines/director/director_jobdefs_spec.rb new file mode 100644 index 0000000..80197a3 --- /dev/null +++ b/spec/defines/director/director_jobdefs_spec.rb @@ -0,0 +1,155 @@ +require 'spec_helper' + +describe 'bareos::director::jobdefs' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/jobdefs/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^JobDefs \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('JobDefs') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('accurate', 'Accurate', 'boolean'). + param('add_prefix', 'Add Prefix', 'string'). + param('add_suffix', 'Add Suffix', 'string'). + param('allow_duplicate_jobs', 'Allow Duplicate Jobs', 'boolean'). + param('allow_higher_duplicates', 'Allow Higher Duplicates', 'boolean'). + param('allow_mixed_priority', 'Allow Mixed Priority', 'boolean'). + param('always_incremental', 'Always Incremental', 'boolean'). + param('always_incremental_job_retention', 'Always Incremental Job Retention', 'time'). + param('always_incremental_keep_number', 'Always Incremental Keep Number', 'pint32'). + param('always_incremental_max_full_age', 'Always Incremental Max Full Age', 'time'). + param('backup_format', 'Backup Format', 'string'). + param('base', 'Base', 'resource_list').param_val('base', 'name2', '"name2"'). + param('bootstrap', 'Bootstrap', 'directory'). + param('cancel_lower_level_duplicates', 'Cancel Lower Level Duplicates', 'boolean'). + param('cancel_queued_duplicates', 'Cancel Queued Duplicates', 'boolean'). + param('cancel_running_duplicates', 'Cancel Running Duplicates', 'boolean'). + param('catalog', 'Catalog', 'res'). + param('client', 'Client', 'res'). + param('client_run_after_job', 'Client Run After Job', 'runscript_short'). + param('client_run_before_job', 'Client Run Before Job', 'runscript_short'). + param('differential_backup_pool', 'Differential Backup Pool', 'res'). + param('differential_max_runtime', 'Differential Max Runtime', 'time'). + param('dir_plugin_options', 'Dir Plugin Options', 'string_list'). + param('enabled', 'Enabled', 'boolean'). + param('fd_plugin_options', 'Fd Plugin Options', 'string_list'). + param('file_history_size', 'File History Size', 'size64'). + param('file_set', 'File Set', 'res'). + param('full_backup_pool', 'Full Backup Pool', 'res'). + param('full_max_runtime', 'Full Max Runtime', 'time'). + param('incremental_backup_pool', 'Incremental Backup Pool', 'res'). + param('incremental_max_runtime', 'Incremental Max Runtime', 'time'). + param('job_defs', 'Job Defs', 'res').param_val('job_defs', 'name2', '"name2"'). + param('job_to_verify', 'Job To Verify', 'res').param_val('job_to_verify', 'name2', '"name2"'). + param('level', 'Level', 'backup_level'). + param('max_concurrent_copies', 'Max Concurrent Copies', 'pint32'). + param('max_diff_interval', 'Max Diff Interval', 'time'). + param('max_full_consolidations', 'Max Full Consolidations', 'pint32'). + param('max_full_interval', 'Max Full Interval', 'time'). + param('max_run_sched_time', 'Max Run Sched Time', 'time'). + param('max_run_time', 'Max Run Time', 'time'). + param('max_start_delay', 'Max Start Delay', 'time'). + param('max_virtual_full_interval', 'Max Virtual Full Interval', 'time'). + param('max_wait_time', 'Max Wait Time', 'time'). + param('maximum_bandwidth', 'Maximum Bandwidth', 'speed'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('messages', 'Messages', 'res'). + param('next_pool', 'Next Pool', 'res'). + param('pool', 'Pool', 'res'). + param('prefer_mounted_volumes', 'Prefer Mounted Volumes', 'boolean'). + param('prefix_links', 'Prefix Links', 'boolean'). + param('priority', 'Priority', 'pint32'). + param('protocol', 'Protocol', 'protocol_type'). + param('prune_files', 'Prune Files', 'boolean'). + param('prune_jobs', 'Prune Jobs', 'boolean'). + param('prune_volumes', 'Prune Volumes', 'boolean'). + param('purge_migration_job', 'Purge Migration Job', 'boolean'). + param('regex_where', 'Regex Where', 'string'). + param('replace', 'Replace', 'replace_option'). + param('rerun_failed_levels', 'Rerun Failed Levels', 'boolean'). + param('reschedule_interval', 'Reschedule Interval', 'time'). + param('reschedule_on_error', 'Reschedule On Error', 'boolean'). + param('reschedule_times', 'Reschedule Times', 'pint32'). + param('run', 'Run', 'string_list'). + param('run_after_failed_job', 'Run After Failed Job', 'runscript_short'). + param('run_after_job', 'Run After Job', 'runscript_short'). + param('run_before_job', 'Run Before Job', 'runscript_short'). + param('run_script', 'Run Script', 'runscript'). + param('save_file_history', 'Save File History', 'boolean'). + param('schedule_res', 'Schedule', 'res'). + param('sd_plugin_options', 'Sd Plugin Options', 'string_list'). + param('selection_pattern', 'Selection Pattern', 'string'). + param('selection_type', 'Selection Type', 'migration_type'). + param('spool_attributes', 'Spool Attributes', 'boolean'). + param('spool_data', 'Spool Data', 'boolean'). + param('spool_size', 'Spool Size', 'size64'). + param('storage', 'Storage', 'resource_list'). + param('strip_prefix', 'Strip Prefix', 'string'). + param('type', 'Type', 'job_type'). + param('virtual_full_backup_pool', 'Virtual Full Backup Pool', 'res'). + param('where', 'Where', 'directory'). + param('write_bootstrap', 'Write Bootstrap', 'directory'). + param('write_verify_list', 'Write Verify List', 'directory') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::pool { "name": } + bareos::director::catalog { "name": + db_driver => "sqlite3", + db_name => "test", + } + bareos::director::storage { "name": + address => "127.0.0.1", + device => "Device", + media_type => "File", + password => "pw", + } + bareos::director::client { "name": + address => "127.0.0.1", + password => "pw", + } + bareos::director::fileset { "name": } + bareos::director::schedule { "name": } + bareos::director::messages { "name": } + bareos::director::job { "name2": + messages => "name", + pool => "name", + type => "backup", + } + bareos::director::jobdefs { "name2": } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Catalog[name]'). + that_requires('Bareos::Director::Storage[name]'). + that_requires('Bareos::Director::Schedule[name]'). + that_requires('Bareos::Director::Messages[name]'). + that_requires('Bareos::Director::Client[name]'). + that_requires('Bareos::Director::Fileset[name]'). + that_requires('Bareos::Director::Job[name2]'). + that_requires('Bareos::Director::Jobdefs[name2]'). + that_requires('Bareos::Director::Pool[name]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_messages_spec.rb b/spec/defines/director/director_messages_spec.rb new file mode 100644 index 0000000..3a2f855 --- /dev/null +++ b/spec/defines/director/director_messages_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'bareos::director::messages' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/messages/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Messages \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Messages') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('append', 'Append', 'messages_list'). + param('catalog', 'Catalog', 'messages_list'). + param('console', 'Console', 'messages_list'). + param('director', 'Director', 'messages_list'). + param('file', 'File', 'messages_list'). + param('mail', 'Mail', 'messages_list'). + param('mail_command', 'Mail Command', 'string'). + param('mail_on_error', 'Mail On Error', 'messages_list'). + param('mail_on_success', 'Mail On Success', 'messages_list'). + param('operator', 'Operator', 'messages_list'). + param('operator_command', 'Operator Command', 'string'). + param('stderr', 'Stderr', 'messages_list'). + param('stdout', 'Stdout', 'messages_list'). + param('syslog', 'Syslog', 'messages_list'). + param('timestamp_format', 'Timestamp Format', 'string') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_pool_spec.rb b/spec/defines/director/director_pool_spec.rb new file mode 100644 index 0000000..89b969e --- /dev/null +++ b/spec/defines/director/director_pool_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +describe 'bareos::director::pool' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/pool/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Pool \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Pool') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('action_on_purge', 'Action On Purge', 'action_on_purge'). + param('auto_prune', 'Auto Prune', 'boolean'). + param('catalog', 'Catalog', 'res'). + param('catalog_files', 'Catalog Files', 'boolean'). + param('cleaning_prefix', 'Cleaning Prefix', 'strname'). + param('file_retention', 'File Retention', 'time'). + param('job_retention', 'Job Retention', 'time'). + param('label_format', 'Label Format', 'strname'). + param('label_type', 'Label Type', 'label'). + param('maximum_block_size', 'Maximum Block Size', 'pint32'). + param('maximum_volume_bytes', 'Maximum Volume Bytes', 'size64'). + param('maximum_volume_files', 'Maximum Volume Files', 'pint32'). + param('maximum_volume_jobs', 'Maximum Volume Jobs', 'pint32'). + param('maximum_volumes', 'Maximum Volumes', 'pint32'). + param('migration_high_bytes', 'Migration High Bytes', 'size64'). + param('migration_low_bytes', 'Migration Low Bytes', 'size64'). + param('migration_time', 'Migration Time', 'time'). + param('minimum_block_size', 'Minimum Block Size', 'pint32'). + param('next_pool', 'Next Pool', 'res').param_val('next_pool', 'next_pool', '"next_pool"'). + param('pool_type', 'Pool Type', 'pooltype'). + param('purge_oldest_volume', 'Purge Oldest Volume', 'boolean'). + param('recycle', 'Recycle', 'boolean'). + param('recycle_current_volume', 'Recycle Current Volume', 'boolean'). + param('recycle_oldest_volume', 'Recycle Oldest Volume', 'boolean'). + param('recycle_pool', 'Recycle Pool', 'res').param_val('recycle_pool', 'recycle_pool', '"recycle_pool"'). + param('scratch_pool', 'Scratch Pool', 'res').param_val('scratch_pool', 'scratch_pool', '"scratch_pool"'). + param('storage', 'Storage', 'resource_list'). + param('use_catalog', 'Use Catalog', 'boolean'). + param('volume_retention', 'Volume Retention', 'time'). + param('volume_use_duration', 'Volume Use Duration', 'time') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::pool { ["next_pool", "recycle_pool", "scratch_pool"]: } + bareos::director::catalog { "name": + db_driver => "sqlite3", + db_name => "test", + } + bareos::director::storage { "name": + address => "127.0.0.1", + device => "Device", + media_type => "File", + password => "pw", + } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Catalog[name]'). + that_requires('Bareos::Director::Storage[name]'). + that_requires('Bareos::Director::Pool[next_pool]'). + that_requires('Bareos::Director::Pool[recycle_pool]'). + that_requires('Bareos::Director::Pool[scratch_pool]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_profile_spec.rb b/spec/defines/director/director_profile_spec.rb new file mode 100644 index 0000000..e6b7284 --- /dev/null +++ b/spec/defines/director/director_profile_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe 'bareos::director::profile' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/profile/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Profile \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Profile') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('catalog_acl', 'Catalog ACL', 'acl'). + param('client_acl', 'Client ACL', 'acl'). + param('command_acl', 'Command ACL', 'acl'). + param('file_set_acl', 'File Set ACL', 'acl'). + param('job_acl', 'Job ACL', 'acl'). + param('plugin_options_acl', 'Plugin Options ACL', 'acl'). + param('pool_acl', 'Pool ACL', 'acl'). + param('schedule_acl', 'Schedule ACL', 'acl'). + param('storage_acl', 'Storage ACL', 'acl'). + param('where_acl', 'Where ACL', 'acl') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_schedule_spec.rb b/spec/defines/director/director_schedule_spec.rb new file mode 100644 index 0000000..e759326 --- /dev/null +++ b/spec/defines/director/director_schedule_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper' + +describe 'bareos::director::schedule' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/schedule/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Schedule \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Schedule') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('enabled', 'Enabled', 'boolean'). + param('run', 'Run', 'schedule_run_command_list') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/director/director_storage_spec.rb b/spec/defines/director/director_storage_spec.rb new file mode 100644 index 0000000..5b3f762 --- /dev/null +++ b/spec/defines/director/director_storage_spec.rb @@ -0,0 +1,92 @@ +require 'spec_helper' + +describe 'bareos::director::storage' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-dir.d/storage/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'address' => '127.0.0.1', + 'device' => 'Device', + 'media_type' => 'File', + 'password' => 'pw' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::director') } + it { is_expected.to contain_file(filename).with_content(%r{^Storage \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Storage') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('allow_compression', 'Allow Compression', 'boolean'). + param('auth_type', 'Auth Type', 'auth_type'). + param('auto_changer', 'Auto Changer', 'boolean'). + param('cache_status_interval', 'Cache Status Interval', 'time'). + param('changer_device', 'Changer Device', 'strname'). + param('collect_statistics', 'Collect Statistics', 'boolean'). + param('device', 'Device', 'resource_list'). + param('enabled', 'Enabled', 'boolean'). + param('heartbeat_interval', 'Heartbeat Interval', 'time'). + param('maximum_bandwidth_per_job', 'Maximum Bandwidth Per Job', 'speed'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('maximum_concurrent_read_jobs', 'Maximum Concurrent Read Jobs', 'pint32'). + param('media_type', 'Media Type', 'strname'). + param('paired_storage', 'Paired Storage', 'res').param_val('paired_storage', 'name2', '"name2"'). + param('password', 'Password', 'autopassword'). + param('port', 'Port', 'pint32'). + param('protocol', 'Protocol', 'auth_protocol_type'). + param('tape_device', 'Tape Device', 'string_list'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean'). + param('username', 'Username', 'string') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::director::storage { "name2": + address => "127.0.0.1", + device => "Device", + media_type => "File", + password => "pw", + } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-dir]'). + that_requires('Bareos::Director::Storage[name2]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/monitor/monitor_client_spec.rb b/spec/defines/monitor/monitor_client_spec.rb new file mode 100644 index 0000000..eba4eb3 --- /dev/null +++ b/spec/defines/monitor/monitor_client_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'bareos::monitor::client' do + let(:title) { 'name' } + + filename = '/etc/bareos/tray-monitor.d/client/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'password' => 'password', + 'address' => 'localhost' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::monitor') } + it { is_expected.to contain_file(filename).with_content(%r{^Client \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Client') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('enable_ssl', 'Enable Ssl', 'boolean'). + param('fd_port', 'Fd Port', 'pint32'). + param('password', 'Password', 'md5password') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/monitor/monitor_director_spec.rb b/spec/defines/monitor/monitor_director_spec.rb new file mode 100644 index 0000000..aa2ea76 --- /dev/null +++ b/spec/defines/monitor/monitor_director_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' + +describe 'bareos::monitor::director' do + let(:title) { 'name' } + + filename = '/etc/bareos/tray-monitor.d/director/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'address' => 'localhost' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::monitor') } + it { is_expected.to contain_file(filename).with_content(%r{^Director \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Director') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('dir_port', 'Dir Port', 'pint32'). + param('enable_ssl', 'Enable Ssl', 'boolean') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/monitor/monitor_monitor_spec.rb b/spec/defines/monitor/monitor_monitor_spec.rb new file mode 100644 index 0000000..f85fdfa --- /dev/null +++ b/spec/defines/monitor/monitor_monitor_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe 'bareos::monitor::monitor' do + let(:title) { 'name' } + + filename = '/etc/bareos/tray-monitor.d/monitor/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'password' => 'password' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::monitor') } + it { is_expected.to contain_file(filename).with_content(%r{^Monitor \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Monitor') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('dir_connect_timeout', 'Dir Connect Timeout', 'time'). + param('fd_connect_timeout', 'Fd Connect Timeout', 'time'). + param('password', 'Password', 'md5password'). + param('refresh_interval', 'Refresh Interval', 'time'). + param('require_ssl', 'Require Ssl', 'boolean'). + param('sd_connect_timeout', 'Sd Connect Timeout', 'time') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/monitor/monitor_storage_spec.rb b/spec/defines/monitor/monitor_storage_spec.rb new file mode 100644 index 0000000..ede9537 --- /dev/null +++ b/spec/defines/monitor/monitor_storage_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe 'bareos::monitor::storage' do + let(:title) { 'name' } + + filename = '/etc/bareos/tray-monitor.d/storage/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'password' => 'password', + 'address' => 'localhost' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::monitor') } + it { is_expected.to contain_file(filename).with_content(%r{^Storage \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Storage') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('address', 'Address', 'string'). + param('enable_ssl', 'Enable Ssl', 'boolean'). + param('password', 'Password', 'md5password'). + param('sd_address', 'Sd Address', 'string'). + param('sd_password', 'Sd Password', 'md5password'). + param('sd_port', 'Sd Port', 'pint32') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/storage/storage_autochanger_spec.rb b/spec/defines/storage/storage_autochanger_spec.rb new file mode 100644 index 0000000..e770d2d --- /dev/null +++ b/spec/defines/storage/storage_autochanger_spec.rb @@ -0,0 +1,68 @@ +require 'spec_helper' + +describe 'bareos::storage::autochanger' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-sd.d/autochanger/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'changer_command' => '/bin/command', + 'changer_device' => '/dev/tape', + 'device' => 'name' + } + end + let(:pre_condition) do + ' + bareos::storage::device { "name": + archive_device => "/dev/tape", + media_type => "DLT7000" + } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::storage') } + it { is_expected.to contain_file(filename).with_content(%r{^Autochanger \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Autochanger') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('changer_command', 'Changer Command', 'strname'). + param('changer_device', 'Changer Device', 'strname'). + param('device', 'Device', 'resource_list') + + let(:params) { res.params } + # required resources + let(:pre_condition) do + ' + bareos::storage::device { "name": + archive_device => "/dev/tape", + media_type => "DLT7000" + } + ' + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-sd]'). + that_requires('Bareos::Storage::Device[name]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/storage/storage_device_spec.rb b/spec/defines/storage/storage_device_spec.rb new file mode 100644 index 0000000..9ef1ded --- /dev/null +++ b/spec/defines/storage/storage_device_spec.rb @@ -0,0 +1,106 @@ +require 'spec_helper' + +describe 'bareos::storage::device' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-sd.d/device/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'archive_device' => '/dev/tape', + 'media_type' => 'DLT7000' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::storage') } + it { is_expected.to contain_file(filename).with_content(%r{^Device \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Device') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('alert_command', 'Alert Command', 'strname'). + param('always_open', 'Always Open', 'bit'). + param('archive_device', 'Archive Device', 'strname'). + param('auto_deflate', 'Auto Deflate', 'io_direction'). + param('auto_deflate_algorithm', 'Auto Deflate Algorithm', 'compression_algorithm'). + param('auto_deflate_level', 'Auto Deflate Level', 'pint16'). + param('auto_inflate', 'Auto Inflate', 'io_direction'). + param('auto_select', 'Auto Select', 'boolean'). + param('autochanger', 'Autochanger', 'bit'). + param('automatic_mount', 'Automatic Mount', 'bit'). + param('backward_space_file', 'Backward Space File', 'bit'). + param('backward_space_record', 'Backward Space Record', 'bit'). + param('block_checksum', 'Block Checksum', 'bit'). + param('block_positioning', 'Block Positioning', 'bit'). + param('bsf_at_eom', 'Bsf At Eom', 'bit'). + param('changer_command', 'Changer Command', 'strname'). + param('changer_device', 'Changer Device', 'strname'). + param('check_labels', 'Check Labels', 'bit'). + param('close_on_poll', 'Close On Poll', 'bit'). + param('collect_statistics', 'Collect Statistics', 'boolean'). + param('device_options', 'Device Options', 'string'). + param('device_type', 'Device Type', 'device_type'). + param('diagnostic_device', 'Diagnostic Device', 'strname'). + param('drive_crypto_enabled', 'Drive Crypto Enabled', 'boolean'). + param('drive_index', 'Drive Index', 'pint16'). + param('drive_tape_alert_enabled', 'Drive Tape Alert Enabled', 'boolean'). + param('fast_forward_space_file', 'Fast Forward Space File', 'bit'). + param('forward_space_file', 'Forward Space File', 'bit'). + param('forward_space_record', 'Forward Space Record', 'bit'). + param('hardware_end_of_file', 'Hardware End Of File', 'bit'). + param('hardware_end_of_medium', 'Hardware End Of Medium', 'bit'). + param('label_block_size', 'Label Block Size', 'pint32'). + param('label_media', 'Label Media', 'bit'). + param('label_type', 'Label Type', 'label'). + param('maximum_block_size', 'Maximum Block Size', 'max_blocksize'). + param('maximum_changer_wait', 'Maximum Changer Wait', 'time'). + param('maximum_concurrent_jobs', 'Maximum Concurrent Jobs', 'pint32'). + param('maximum_file_size', 'Maximum File Size', 'size64'). + param('maximum_job_spool_size', 'Maximum Job Spool Size', 'size64'). + param('maximum_network_buffer_size', 'Maximum Network Buffer Size', 'pint32'). + param('maximum_open_volumes', 'Maximum Open Volumes', 'pint32'). + param('maximum_open_wait', 'Maximum Open Wait', 'time'). + param('maximum_rewind_wait', 'Maximum Rewind Wait', 'time'). + param('maximum_spool_size', 'Maximum Spool Size', 'size64'). + param('media_type', 'Media Type', 'strname'). + param('minimum_block_size', 'Minimum Block Size', 'pint32'). + param('mount_command', 'Mount Command', 'strname'). + param('mount_point', 'Mount Point', 'strname'). + param('no_rewind_on_close', 'No Rewind On Close', 'boolean'). + param('offline_on_unmount', 'Offline On Unmount', 'bit'). + param('query_crypto_status', 'Query Crypto Status', 'boolean'). + param('random_access', 'Random Access', 'bit'). + param('removable_media', 'Removable Media', 'bit'). + param('requires_mount', 'Requires Mount', 'bit'). + param('spool_directory', 'Spool Directory', 'directory'). + param('two_eof', 'Two Eof', 'bit'). + param('unmount_command', 'Unmount Command', 'strname'). + param('use_mtiocget', 'Use Mtiocget', 'bit'). + param('volume_capacity', 'Volume Capacity', 'size64'). + param('volume_poll_interval', 'Volume Poll Interval', 'time') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-sd]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/storage/storage_director_spec.rb b/spec/defines/storage/storage_director_spec.rb new file mode 100644 index 0000000..0577e0e --- /dev/null +++ b/spec/defines/storage/storage_director_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe 'bareos::storage::director' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-sd.d/director/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'password' => 'pw' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::storage') } + it { is_expected.to contain_file(filename).with_content(%r{^Director \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Director') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('key_encryption_key', 'Key Encryption Key', 'autopassword'). + param('maximum_bandwidth_per_job', 'Maximum Bandwidth Per Job', 'speed'). + param('monitor', 'Monitor', 'boolean'). + param('password', 'Password', 'autopassword'). + param('tls_allowed_cn', 'Tls Allowed Cn', 'string_list'). + param('tls_authenticate', 'Tls Authenticate', 'boolean'). + param('tls_ca_certificate_dir', 'Tls Ca Certificate Dir', 'directory'). + param('tls_ca_certificate_file', 'Tls Ca Certificate File', 'directory'). + param('tls_certificate', 'Tls Certificate', 'directory'). + param('tls_certificate_revocation_list', 'Tls Certificate Revocation List', 'directory'). + param('tls_cipher_list', 'Tls Cipher List', 'string'). + param('tls_dh_file', 'Tls Dh File', 'directory'). + param('tls_enable', 'Tls Enable', 'boolean'). + param('tls_key', 'Tls Key', 'directory'). + param('tls_require', 'Tls Require', 'boolean'). + param('tls_verify_peer', 'Tls Verify Peer', 'boolean') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-sd]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/storage/storage_messages_spec.rb b/spec/defines/storage/storage_messages_spec.rb new file mode 100644 index 0000000..f37cc42 --- /dev/null +++ b/spec/defines/storage/storage_messages_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'bareos::storage::messages' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-sd.d/messages/name.conf' + + context 'with default values for all parameters' do + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::storage') } + it { is_expected.to contain_file(filename).with_content(%r{^Messages \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Messages') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('append', 'Append', 'messages_list'). + param('catalog', 'Catalog', 'messages_list'). + param('console', 'Console', 'messages_list'). + param('director', 'Director', 'messages_list'). + param('file', 'File', 'messages_list'). + param('mail', 'Mail', 'messages_list'). + param('mail_command', 'Mail Command', 'string'). + param('mail_on_error', 'Mail On Error', 'messages_list'). + param('mail_on_success', 'Mail On Success', 'messages_list'). + param('operator', 'Operator', 'messages_list'). + param('operator_command', 'Operator Command', 'string'). + param('stderr', 'Stderr', 'messages_list'). + param('stdout', 'Stdout', 'messages_list'). + param('syslog', 'Syslog', 'messages_list'). + param('timestamp_format', 'Timestamp Format', 'string') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-sd]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/defines/storage/storage_ndmp_spec.rb b/spec/defines/storage/storage_ndmp_spec.rb new file mode 100644 index 0000000..0201383 --- /dev/null +++ b/spec/defines/storage/storage_ndmp_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +describe 'bareos::storage::ndmp' do + let(:title) { 'name' } + + filename = '/etc/bareos/bareos-sd.d/ndmp/name.conf' + + context 'with default values for all parameters will fail' do + it { is_expected.to compile.and_raise_error(%r{.*}) } + end + + context 'with required values' do + let(:params) do + { + 'username' => 'user', + 'password' => 'pw' + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_class('bareos::storage') } + it { is_expected.to contain_file(filename).with_content(%r{^Ndmp \{$}) } + it { is_expected.to contain_file(filename).with_content(%r{Name = "name"$}) } + end + + context 'with all params set' do + res = BareosResourceHelper.new('Ndmp') + res.param('name', 'Name', 'name'). + param('description', 'Description', 'string'). + param('auth_type', 'Auth Type', 'auth_type'). + param('log_level', 'Log Level', 'pint32'). + param('password', 'Password', 'autopassword'). + param('username', 'Username', 'string') + + let(:params) { res.params } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_file(filename).with_content(res.content) } + it do + is_expected.to contain_file(filename). + that_notifies('Service[bareos-sd]') + end + end + + context 'with ensure absent' do + let(:params) { { 'ensure' => 'absent' } } + + it { is_expected.to contain_file(filename).with_ensure('absent') } + end +end diff --git a/spec/functions/bareos_settings_spec.rb b/spec/functions/bareos_settings_spec.rb index f687bc7..955421f 100644 --- a/spec/functions/bareos_settings_spec.rb +++ b/spec/functions/bareos_settings_spec.rb @@ -48,7 +48,7 @@ end context 'type is an string with quotes' do - %w[audit-command runscript_short autopassword md5password directory string strname address device plugin_names].each do |type| + %w[audit_command runscript_short autopassword md5password directory string strname address device plugin_names].each do |type| it 'runs with compatible values' do ['Not a number', 'MyString', '23 free usage of Text.!', 'Special ".-,= Chars'].each do |val| is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = \"#{val}\"") @@ -109,7 +109,6 @@ end end - # add addresss context 'type is an hashed addresses value' do %w[addresses].each do |type| it 'runs with compatible values' do @@ -208,6 +207,156 @@ end end + context 'type is encryption_cipher' do + %w[encryption_cipher].each do |type| + it 'runs with compatible values' do + %w[aes128 AES192 aes256 camellia128 camellia192 camellia256 aes128hmacsha1 aes256hmacsha1 blowfish].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' aes'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is auth_type' do + %w[auth_type].each do |type| + it 'runs with compatible values' do + %w[clear MD5].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' clear'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is auth_protocol_type' do + %w[auth_protocol_type].each do |type| + it 'runs with compatible values' do + %w[native NDMP].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' ndmp'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is pooltype' do + %w[pooltype].each do |type| + it 'runs with compatible values' do + %w[backup ARCHIVE cloned migration copy save scratch].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' backup'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is label' do + %w[label].each do |type| + it 'runs with compatible values' do + %w[ansi IBM bareos].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' bareos'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is migration_type' do + %w[migration_type].each do |type| + it 'runs with compatible values' do + %w[smallestvolume oldestvolume client volume Job sqlquery pooloccupancy pooltime pooluncopiedjobs].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' JOB'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is job_type' do + %w[job_type].each do |type| + it 'runs with compatible values' do + %w[backup restore verify ADMIN migrate copy consolidate].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' backup'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is replace_option' do + %w[replace_option].each do |type| + it 'runs with compatible values' do + %w[Always ifnewer ifolder never].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' never'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is device_type' do + %w[device_type].each do |type| + it 'runs with compatible values' do + %w[TAPE file fifo gfapi rados].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' File'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + + context 'type is compression_algorithm' do + %w[compression_algorithm].each do |type| + it 'runs with compatible values' do + %w[GZIP LZO lzfast lz4 lz4hc].each do |val| + is_expected.to run.with_params([val, 'Test', type, true]).and_return("#{indent_default}Test = #{val}") + end + end + it 'not runs with incompatible values' do + ['wrong', ' gzip'].each do |val| + is_expected.not_to run.with_params([val, 'Test', type, true]) + end + end + end + end + context 'type is not compatible' do %w[invalid doesNotExist really_not_exists].each do |type| it 'raise error' do diff --git a/spec/settings_helper.rb b/spec/settings_helper.rb new file mode 100644 index 0000000..cd0a6f2 --- /dev/null +++ b/spec/settings_helper.rb @@ -0,0 +1,116 @@ +# Provide some generic helper to test classes/defines for bareos +require 'spec_helper' + +# This simplifies the generic build of the bareos template config checks +class BareosResourceHelper + attr_reader :config, :resource + + def initialize(resource) + @resource = resource + @config = {} + end + + # return params for let + # attr name, directive name and bareos type + def param(attr, directive, type) + result = nil + val = 'not set' + sep = ' = ' + type.gsub!(%r{([_-]list)$}, '') + + case type + # short hack to have simple res names + when 'name', 'res', 'resource' + val = 'name' + result = '"name"' + # maybe check more than it is an int + when 'int32', 'pint16', 'pint32', 'port', 'max_blocksize' + val = 42 + when 'audit_command', 'runscript_short', 'autopassword', 'md5password', 'directory', 'string', 'strname', 'address', 'device', 'plugin_names' + val = 'Example Value' + result = '"Example Value"' + when 'acl', 'messages', 'type', 'string_noquote', 'schedule_run_command' + val = 'Long text without direct "quotes' + when 'speed' + val = '1337 MB/s' + when 'size64' + val = '1337 MB' + when 'time' + val = '1337 sec' + when 'boolean', 'bit' + val = false + when 'addresses', 'include_exclude_item', 'runscript', 'hash' + sep = ' ' unless type == 'addresses' + val = { + 'x' => 'y' + } + result = '{ + x = y + }' + when 'backup_level' + val = 'full' + when 'io_direction' + val = 'in' + when 'action_on_purge' + val = 'truncate' + when 'encryption_cipher' + val = 'aes192' + when 'auth_type' + val = 'clear' + when 'auth_protocol_type', 'protocol_type' + val = 'native' + when 'pooltype' + val = 'backup' + when 'label' + val = 'ANSI' + when 'migration_type' + val = 'job' + when 'job_type' + val = 'backup' + when 'replace_option' + val = 'always' + when 'device_type' + val = 'file' + when 'compression_algorithm' + val = 'gzip' + else + raise "Missing setting type '#{type}'" + end + + @config[attr] = { + 'dir' => directive, + 'type' => type, + 'val' => val, + 'res' => result.nil? ? val : result, + 'sep' => sep + } + + self + end + + # set custom value + def param_val(attr, val, res) + @config[attr]['val'] = val + @config[attr]['res'] = res + self + end + + # get params for :let + def params + tmp = {} + @config.each do |k, v| + tmp[k] = v['val'] + end + tmp + end + + # build content to compare with created file + def content + tmp = "# This file is managed by puppet\n#{@resource} {\n" + @config.each do |_, v| + tmp = "#{tmp} #{v['dir']}#{v['sep']}#{v['res']}\n" + end + tmp = "#{tmp}}\n" + tmp + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d6702f1..ae6411c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,6 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require_relative './settings_helper.rb' + RSpec.configure do |c| c.default_facts = { operatingsystem: 'Redhat',