Skip to content

Commit

Permalink
add veeam_agent_config type & provider, refactor
Browse files Browse the repository at this point in the history
This is a major rework of the module to use a type and provider instead
of a template for managing the configuration settings of a Veeam agent.
General refactoring and updating is also included.
  • Loading branch information
genebean committed Jun 22, 2018
1 parent a635f49 commit 5226270
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fixtures:
repositories:
inifile: "https://github.com/puppetlabs/puppetlabs-inifile.git"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
yum: "https://github.com/voxpupuli/puppet-yum"
symlinks:
"veeamagent": "#{source_dir}"

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
coverage/
Gemfile.lock
pkg/
vendor/
spec/fixtures/
vendor/
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ group :development, :unit_tests do

# puppet-lint and plugins
gem 'puppet-lint', '~> 2.2'
gem 'puppet-lint-absolute_classname-check', '~> 0.2'
gem 'puppet-lint-absolute_template_path', '~> 1.0'
gem 'puppet-lint-empty_string-check', '~> 0.2'
gem 'puppet-lint-leading_zero-check', '~> 0.1'
Expand Down
42 changes: 26 additions & 16 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
---
veeamagent::config_entries: {}
veeamagent::gpgkey_ca_ensure: present
veeamagent::gpgkey_ca_local: '/etc/pki/rpm-gpg/VeeamSoftwareRepo'
veeamagent::gpgkey_ca_source: 'http://repository.veeam.com/keys/VeeamSoftwareRepo'
veeamagent::gpgkey_ensure: present
veeamagent::gpgkey_local: '/etc/pki/rpm-gpg/RPM-GPG-KEY-VeeamSoftwareRepo'
veeamagent::gpgkey_source: 'http://repository.veeam.com/keys/RPM-GPG-KEY-VeeamSoftwareRepo'
veeamagent::package_ensure: present
veeamagent::package_manage: true
veeamagent::package_name: 'veeam'
veeamagent::repo_manage: true
veeamagent::repo_path: '/etc/yum.repos.d/veeam.repo'
veeamagent::repo_template: 'veeamagent/veeam-repo.epp'
veeamagent::service_enable: true
veeamagent::service_ensure: running
veeamagent::service_manage: true
veeamagent::service_name: 'veeamservice'


veeamagent::backup_job::block_size: 'KbBlockSize1024'
veeamagent::backup_job::compression_type: 'Lz4'
veeamagent::backup_job::config_dir: '/etc/veeam'
Expand Down Expand Up @@ -43,33 +62,24 @@ veeamagent::db_schemeupgradepath:
veeamagent::freepercent_limit:
veeamagent::freezethaw_timeout:
veeamagent::freezethawfailure_ignore:
veeamagent::gpgkey_ca_ensure: present
veeamagent::gpgkey_ca_local: '/etc/pki/rpm-gpg/VeeamSoftwareRepo'
veeamagent::gpgkey_ca_source: 'http://repository.veeam.com/keys/VeeamSoftwareRepo'
veeamagent::gpgkey_ensure: present
veeamagent::gpgkey_local: '/etc/pki/rpm-gpg/RPM-GPG-KEY-VeeamSoftwareRepo'
veeamagent::gpgkey_source: 'http://repository.veeam.com/keys/RPM-GPG-KEY-VeeamSoftwareRepo'

veeamagent::inactivelvm_ignore:
veeamagent::iorate_limit:
veeamagent::job_retries:
veeamagent::job_retryallerrors:
veeamagent::log_debuglevel:
veeamagent::log_dir:
veeamagent::package_ensure: present
veeamagent::package_manage: true
veeamagent::package_name: ['veeam']


veeamagent::prepost_timeout:
veeamagent::repo_baseurl: 'http://repository.veeam.com/backup/linux/agent/rpm/el/7/x86_64'
veeamagent::repo_manage: true
veeamagent::repo_path: '/etc/yum.repos.d/veeam.repo'
veeamagent::repo_template: 'veeamagent/veeam-repo.epp'
veeamagent::service_enable: true
veeamagent::service_ensure: running
veeamagent::service_name: 'veeamservice'



veeamagent::snapshot_location:
veeamagent::snapshot_maxsize:
veeamagent::snapshot_minsize:
veeamagent::snapshot_type:
veeamagent::socket_path:
veeamagent::stretchsnapshot_portionsize:
veeamagent::veeamcmd_path: ['/usr/bin', '/usr/sbin']
veeamagent::veeamcmd_path: ['/usr/bin', '/usr/sbin']
23 changes: 23 additions & 0 deletions lib/puppet/provider/veeam_agent_config/ini_setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# veeamagent/lib/puppet/provider/veeam_agent_config/ini_setting.rb
Puppet::Type.type(:veeam_agent_config).provide(
:ini_setting,
# set ini_setting as the parent provider
:parent => Puppet::Type.type(:ini_setting).provider(:ruby)
) do
# hard code the separator to the one used in the stock veeam.ini
def separator
'= '
end
# implement section as the first part of the namevar
def section
resource[:name].split('/', 2).first
end
def setting
# implement setting as the second part of the namevar
resource[:name].split('/', 2).last
end
# hard code the file path (this allows purging)
def self.file_path
'/etc/veeam/veeam.ini'
end
end
15 changes: 15 additions & 0 deletions lib/puppet/type/veeam_agent_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# veeamagent/lib/puppet/type/veeam_agent_config.rb
Puppet::Type.newtype(:veeam_agent_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from veeam.ini'
# namevar should be of the form section/setting
newvalues(/\S+\/\S+/)
end
newproperty(:value) do
desc 'The value of the setting to define'
munge do |v|
v.to_s.strip
end
end
end
6 changes: 1 addition & 5 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Handles the main configuration file.
class veeamagent::config inherits veeamagent {
file { $veeamagent::config_path:
ensure => $veeamagent::config_ensure,
content => epp('veeamagent/veeam.ini.epp'),
notify => Class['::veeamagent::service'],
}
create_resources(veeam_agent_config, $veeamagent::config_entries)
}
67 changes: 23 additions & 44 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# @param repo_template String Path to a template for the Veeeam package repository. Default value: `'veeamagent/veeam-repo.epp'`.
# @param service_enable Boolean Whether to enable the Veeam service. Default value: `true`.
# @param service_ensure String Ensure value for the Veeam service. Default value: `running`.
# @param service_manage Boolean Manage the service of the Veeam agent. Default value: true
# @param service_name String Name of the Veeam service. Default value: varies by operating system.
# @param snapshot_location [Optional[String]] Location folder for snapshot data, only for 'stretch' and 'common' snapshot. Default value: ''.
# @param snapshot_maxsize [Optional[Integer]] Maximum possible snapshot data size, not for stretch snapshot. Default value: ''.
Expand All @@ -44,54 +45,32 @@
# lint:endignore
# lint:endignore
class veeamagent(
Optional[Boolean] $bitlooker_enabled,
Optional[Integer] $cluster_align,
String $config_ensure,
String $config_path,
Optional[Integer] $cpu_priority,
Optional[String] $db_path,
Optional[String] $db_schemepath,
Optional[String] $db_schemeupgradepath,
Optional[Integer] $freepercent_limit,
Optional[Boolean] $freezethawfailure_ignore,
Optional[Integer] $freezethaw_timeout,
String $gpgkey_ca_ensure,
String $gpgkey_ca_local,
String $gpgkey_ca_source,
String $gpgkey_ensure,
String $gpgkey_local,
String $gpgkey_source,
Optional[Boolean] $inactivelvm_ignore,
Optional[Integer] $iorate_limit,
Optional[Integer] $job_retries,
Optional[Boolean] $job_retryallerrors,
Optional[Integer] $log_debuglevel,
Optional[String] $log_dir,
String $package_ensure,
Boolean $package_manage,
Array[String] $package_name,
Optional[Integer] $prepost_timeout,
Boolean $repo_manage,
String $repo_path,
String $repo_template,
Boolean $service_enable,
String $service_ensure,
String $service_name,
Optional[String] $snapshot_location,
Optional[Integer] $snapshot_maxsize,
Optional[Integer] $snapshot_minsize,
Optional[String] $snapshot_type,
Optional[String] $socket_path,
Optional[Integer] $stretchsnapshot_portionsize,
Boolean $service_manage,
Hash $config_entries,
String[1] $gpgkey_ca_ensure,
String[1] $gpgkey_ca_local,
String[1] $gpgkey_ca_source,
String[1] $gpgkey_ensure,
String[1] $gpgkey_local,
String[1] $gpgkey_source,
String[1] $package_ensure,
String[1] $package_name,
String[1] $repo_path,
String[1] $repo_template,
String[1] $service_ensure,
String[1] $service_name,
) {

contain ::veeamagent::preinstall
contain ::veeamagent::install
contain ::veeamagent::config
contain ::veeamagent::service
contain veeamagent::preinstall
contain veeamagent::install
contain veeamagent::config
contain veeamagent::service

Class['::veeamagent::preinstall']
-> Class['::veeamagent::install']
-> Class['::veeamagent::config']
~> Class['::veeamagent::service']
Class['veeamagent::preinstall']
-> Class['veeamagent::install']
-> Class['veeamagent::config']
~> Class['veeamagent::service']
}
6 changes: 3 additions & 3 deletions manifests/preinstall.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
if $veeamagent::repo_manage {
case $facts['os']['family'] {
'RedHat': {
::yum::gpgkey { $veeamagent::gpgkey_ca_local:
yum::gpgkey { $veeamagent::gpgkey_ca_local:
ensure => $veeamagent::gpgkey_ca_ensure,
source => $veeamagent::gpgkey_ca_source,
}

::yum::gpgkey { $veeamagent::gpgkey_local:
yum::gpgkey { $veeamagent::gpgkey_local:
ensure => $veeamagent::gpgkey_ensure,
source => $veeamagent::gpgkey_source,
}
}

default: {
fail("Repository management is not supported ${::osfamily}")
fail("Repository management is not supported ${facts['os']['family']}")
}
}

Expand Down
11 changes: 8 additions & 3 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Handles the service.
class veeamagent::service inherits veeamagent {
service { $veeamagent::service_name:
ensure => $veeamagent::service_ensure,
enable => $veeamagent::service_enable,
if $veeamagent::service_manage {
service { $veeamagent::service_name:
ensure => $veeamagent::service_ensure,
enable => $veeamagent::service_enable,
}

# Make sure that any new or changed veeam_agent_config's refres the service
Veeam_agent_config <| |> ~> Service[$veeamagent::service_name]
}
}
6 changes: 5 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"project_page": "https://github.com/thespain/thespain-veeamagent",
"issues_url": "https://github.com/thespain/thespain-veeamagent/issues",
"dependencies": [
{
"name": "puppetlabs-inifile",
"version_requirement": ">=2.2.2 < 3.0.0"
},
{
"name": "puppetlabs-stdlib",
"version_requirement": ">= 4.0.0 < 5.0.0"
Expand Down Expand Up @@ -36,7 +40,7 @@
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 4.7.0 < 6.0.0"
"version_requirement": ">= 4.7.0 < 7.0.0"
}
],
"description": "The veeamagent module installs, configures, and manages the Veeam Agent, Veeam backup jobs, and local repositories."
Expand Down
15 changes: 10 additions & 5 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
describe 'veeamagent::config' do
on_supported_os.each do |os, facts|
context "on #{os} with custom settings" do
let(:pre_condition) { 'class {"::veeamagent": cluster_align => 5}' }
let(:pre_condition) {
'class { "veeamagent":
config_entries => { "backup/cluster_align" => { value => 5 }},
}'
}

let(:facts) do
facts
end

case facts[:osfamily]
case facts[:os]['family']
when 'RedHat'
it { is_expected.to contain_file('/etc/veeam/veeam.ini') \
.with_content(/clusterAlign= 5/) }
it { is_expected.to contain_veeam_agent_config('backup/cluster_align') \
.with_value(5) }
end
end
end
end
end
4 changes: 2 additions & 2 deletions spec/classes/preinstall_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
end

context "on #{os} with repo_manage disabled" do
let(:pre_condition) { 'class {"::veeamagent": repo_manage => false}' }
let(:pre_condition) { 'class {"veeamagent": repo_manage => false}' }

it { is_expected.not_to contain_file('/etc/yum.repos.d/veeam.repo') }
end
end
end
end
9 changes: 9 additions & 0 deletions spec/types/veeam_agent_config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'spec_helper'

describe 'veeam_agent_config' do
let(:title) { 'section_foo/setting_bar'}
it { is_expected.to be_valid_type }
it { is_expected.to be_valid_type.with_provider(:ini_setting) }
it { is_expected.to be_valid_type.with_parameters('name') }
it { is_expected.to be_valid_type.with_properties('value') }
end

0 comments on commit 5226270

Please sign in to comment.