Skip to content

Commit

Permalink
Improve bareos type checking, fix bugs and add specs.
Browse files Browse the repository at this point in the history
 * 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
  • Loading branch information
project0 committed Aug 15, 2017
1 parent bae82ed commit e7a1aa2
Show file tree
Hide file tree
Showing 49 changed files with 2,285 additions and 161 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 22 additions & 2 deletions lib/puppet/parser/functions/bareos_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifests/client/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion manifests/client/director.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
6 changes: 6 additions & 0 deletions manifests/director.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
9 changes: 1 addition & 8 deletions manifests/director/catalog.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
}
37 changes: 2 additions & 35 deletions manifests/director/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand Down
9 changes: 9 additions & 0 deletions manifests/director/counter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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":
Expand All @@ -76,5 +84,6 @@
group => $::bareos::file_group,
content => template('bareos/resource.erb'),
notify => Service[$::bareos::director::service_name],
require => $_require_resource,
}
}
2 changes: 1 addition & 1 deletion manifests/director/director.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 5 additions & 27 deletions manifests/director/job.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -682,7 +675,6 @@
$storage = undef,
$strip_prefix = undef,
$type = undef,
$verify_job = undef,
$virtual_full_backup_pool = undef,
$where = undef,
$write_bootstrap = undef,
Expand Down Expand Up @@ -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] }
Expand All @@ -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],
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down
30 changes: 4 additions & 26 deletions manifests/director/jobdefs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -681,7 +674,6 @@
$storage = undef,
$strip_prefix = undef,
$type = undef,
$verify_job = undef,
$virtual_full_backup_pool = undef,
$where = undef,
$write_bootstrap = undef,
Expand All @@ -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] }
Expand All @@ -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],
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand Down
Loading

0 comments on commit e7a1aa2

Please sign in to comment.