From 9fbcdfd30d2704855a98b926cd3f9590ca013cec Mon Sep 17 00:00:00 2001 From: I Smith Date: Tue, 17 May 2016 14:13:35 -0700 Subject: [PATCH] Fix testing, fix graphite plugin recipe bugs, cleanup (+12 squashed commits) Squashed commits: [10a37f9] Cleaner attribute listing [269f9e7] Moving the plugin packages out of attributes and into recipe Easier to test this part of the recipe if implemented this way. Chefspec/rspec was having a hard time rendering what packages were needed for the install, this took out the abstraction and allowed rspec to just work.. [992224f] Lacking consistency [ac9ce9d] Adding explicit action for rspec testing [ddb614e] Adding rspec documentation and color output Make it much easier to parse the test output to see what is going wrong and where. [442968c] Adding supported platforms definition to call in tests Saw this implementation method in the apache2 cookbook, very useful to quickly add testing for all your supported platforms. See default_spec test for a test implementation example [28ae93e] Lacking consistency [19dcff6] Completely reworked, added more tests as well [ec58006] Adding new spec test for the graphite plugin recipe [8986ec7] This test never really worked right, removed [9245fa9] Condense tests, adding testing for the graphite plugin Includes test for the files being pulled down for the plugin, content of files and the cronjob being added [dbee4c0] CHANGELOG Update/Cleanup * Standardize markdown formatting current and past entries * Add new content related to release 3.0.3 --- .rspec | 2 - CHANGELOG.md | 140 ++++++++++-------- README.md | 3 +- attributes/default.rb | 8 +- recipes/graphite_plugin.rb | 8 +- recipes/repo.rb | 2 + spec/spec_helper.rb | 7 + spec/support/supported_platforms.rb | 7 + spec/unit/recipes/default_spec.rb | 111 +++++++------- spec/unit/recipes/graphite_plugin_spec.rb | 89 +++++++++++ spec/unit/recipes/repo_spec.rb | 63 -------- .../serverspec/bareos_spec.rb | 43 ++++-- 12 files changed, 273 insertions(+), 210 deletions(-) delete mode 100644 .rspec create mode 100644 spec/support/supported_platforms.rb create mode 100644 spec/unit/recipes/graphite_plugin_spec.rb delete mode 100644 spec/unit/recipes/repo_spec.rb diff --git a/.rspec b/.rspec deleted file mode 100644 index 83e16f8..0000000 --- a/.rspec +++ /dev/null @@ -1,2 +0,0 @@ ---color ---require spec_helper diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f58c95..886406b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,100 +3,114 @@ CHANGELOG Chef-Bareos Cookbook -------------------- -3.0.2 +3.0.3 ----- -- Ian Smith +#### Ian Smith + * Decided to change who owned all of the graphite_plugin bits + 1. Bareos plugin still seems to have some debugging code that will not only PRINT your password to the command line if done by hand, but will also EMAIL your main director password to whatever account owns, say, a cronjob (i.e. root). Seems like a security flaw? I submitted bugfix bareos/bareos-contrib/#14 to address this issue, waiting for merge. If you need an immediate fixed source, use my GitBytes/bareos-contrib fork. Sorry about that.. + 1. Pretty much wherever root was, I changed to bareos in the plugin recipe. + * Cleanup README and CHANGELOG raw syntax for GitHub and Supermarket rendering + * Add new chefspec/rspec unit tests, cleanup existing tests + 1. Removed unused `.rspec` config file + 1. Removed `repo_spec` test, never quite worked right + 1. Added `:documentation` and `color` output to chefspec/rspec testing + 1. Added `graphite_plugin_spec` test + 1. Condensed and cleaned up `default_spec` test, tests both the `repo` and `client` recipes on top of the implied `default` recipe + 1. Added ability to easily run tests against a variety of preset supported platforms via `spec/unit/support/supported_platforms` definition file (see `default_spec` test for example usage) + * Add new/optimize serverspec integration tests + 1. Condense tests for overall functionality of Bareos + 1. New graphite plugin testing: plugin, config, cronjob + * Bump patch version to `3.0.3` (tag v3.0.3) - - Complete re-work of cookbook, which includes the rework bits from version 2.0 - - Adding various features including: - * Templates populated from hash tables - * Up to date README - * Graphite plugin deployment recipe - * Migrate to postgresql cookbook version 4+ - * Better testing (rspec), testing against current ruby, need some more rspec tests but no time - * Various other updates and enhancements, see README for details - * Supermarket Release...finally - - ***NOTE*** This release adds functionality that is not backwards compatible. Version lock until you have time to test the migration to version 3.0+ +3.0.2 +----- +#### Ian Smith + + * Complete re-work of cookbook, which includes the rework bits from version 2.0 + * Adding various features including: + * Templates populated from hash tables + * Up to date README + * Graphite plugin deployment recipe + * Migrate to postgresql cookbook version 4+ + * Better testing (rspec), testing against current ruby, need some more rspec tests but no time + * Various other updates and enhancements, see README for details + * Supermarket Release...finally + * ***NOTE*** This release adds functionality that is not backwards compatible. Version lock until you have time to test the migration to version 3.0+ 2.2.13 ------ -- Ian Smith - - - Near complete refactoring of how the cookbook works +#### Ian Smith + * Near complete refactoring of how the cookbook works * Adding various ways to add configs based on hashes. Examples in attributes/default.rb - - Updating README for usage details - - If you are not prepared to use this cookbook version, please lock cookbook version to < 2.0.0 - - TODO: Refactor main bareos-dir/sd/fd configs to be fully based on hashes like other configs + * Updating README for usage details + * If you are not prepared to use this cookbook version, please lock cookbook version to < 2.0.0 + * TODO: Refactor main bareos-dir/sd/fd configs to be fully based on hashes like other configs * Remaining attributes support primary bareos-dir/sd/fd configs mostly, used elsewhere but not much 1.0.4 ----- -- Ian Smith - - - Updating and validating Kitchen testing with new methods - - Adding ability to use custom Storage Daemon Configs via wrapper recipe - - Fixed a race condition that was likely to come up both in testing and production +#### Ian Smith + * Updating and validating Kitchen testing with new methods + * Adding ability to use custom Storage Daemon Configs via wrapper recipe + * Fixed a race condition that was likely to come up both in testing and production * Was missing client config on fresh install so restart of dir would fail - - Limiting cookbook support for debian to ~>7.0 until we can test on 8+ - - Refined storage recipe to correctly create client configs based on BOTH role search and solo instances, may need a bit more tuning but should work in most cases - - Creating basic Full, Inc, and Diff pools even if not used, just as a place holder (default) - - Minor fixes - - Larger version bump for version clarity - - Updated Docs - - Adding support for Fedora and RHEL 6/7 - - Reworked the available repos to some better logic + * Limiting cookbook support for debian to ~>7.0 until we can test on 8+ + * Refined storage recipe to correctly create client configs based on BOTH role search and solo instances, may need a bit more tuning but should work in most cases + * Creating basic Full, Inc, and Diff pools even if not used, just as a place holder (default) + * Minor fixes + * Larger version bump for version clarity + * Updated Docs + * Adding support for Fedora and RHEL 6/7 + * Reworked the available repos to some better logic 0.1.4 ----- -- Ian Smith - - - Updating README - - Revamping server.rb recipe to better utilize the bareos-dir.d directory +#### Ian Smith + * Updating README + * Revamping server.rb recipe to better utilize the bareos-dir.d directory * Moving ALL host config files to the bareos-dir.d/hosts/ directory - * Revamping director config and moving host bits to seperate host.conf.erb template + * Revamping director config and moving host bits to separate host.conf.erb template * Adding feature for host based custom pools based on true/false attribute * Adding ability to fill in a block for virtual-full backup logic (not complete yet) - - Revamping storage.rb and storage template to what I am thinking was meant to happen originally - - Adding new kitchen suite and tests to verify host pools work - - Bugfixes - - Updating Kitchen Tests and ChefSpec Configs to match for verifying + * Revamping storage.rb and storage template to what I am thinking was meant to happen originally + * Adding new kitchen suite and tests to verify host pools work + * Bugfixes + * Updating Kitchen Tests and ChefSpec Configs to match for verifying * Addressing race condition in ChefSpec tests where debian was taking longer than expected to start the director 0.1.3 ----- -- Ian Smith - - - Updating README - - Updating CHANGELOG - - Updating metadata file +#### Ian Smith + * Updating README + * Updating CHANGELOG + * Updating metadata file 0.1.2 ----- -- Leonard TAVAE - - - The License has changed (Apache 2.0) - - The cookbook now passed foodcritic, rubocop and tailor with success - - Some minor bugs fix - -- Ian Smith - - - Updating Cookbook to use ChefDK >0.6.0 - - Updating Docs - - Updating Postgresql Logic/Commands - - Updating a couple of template bits for the director +#### Leonard TAVAE + * The License has changed (Apache 2.0) + * The cookbook now passed foodcritic, rubocop and tailor with success + * Some minor bugs fix + +#### Ian Smith + * Updating Cookbook to use ChefDK >0.6.0 + * Updating Docs + * Updating Postgresql Logic/Commands + * Updating a couple of template bits for the director * Adding new attributes, working on more for future implementation - - Updating Kitchen suites/platforms/provisioner + * Updating Kitchen suites/platforms/provisioner * Adding some test roles for tests - - Updating chefspec/rspec/serverspec testing - - Updating TravisCI testing parameters so they are more standard + * Updating chefspec/rspec/serverspec testing + * Updating TravisCI testing parameters so they are more standard 0.1.1 ----- -- Leonard TAVAE - Major release +#### Leonard TAVAE + * Major release 0.1.0 ----- -- Leonard TAVAE - Initial release of bareos - +#### Leonard TAVAE + * Initial release of bareos - - - diff --git a/README.md b/README.md index e9b5ddc..319dabe 100644 --- a/README.md +++ b/README.md @@ -118,14 +118,13 @@ A new plugin that will send statistics to a graphite server which can then be us | Attribute | Default Value | Description |------------------|---------------|------------ -| ['bareos']['plugins']['graphite']['packages'] | varies on platform | Default packages needed to get the plugin to work | ['bareos']['plugins']['graphite']['plugin_path'] | '/usr/sbin' | Default location for the plugin that runs in a defined cron job | ['bareos']['plugins']['graphite']['config_path'] | '/etc/bareos' | Default directory for the plugin config | ['bareos']['plugins']['graphite']['search_query'] | 'roles:bareos_director' | Default search string to populate the director name | ['bareos']['plugins']['graphite']['server'] | 'graphite' | Placeholder string for the graphite server DNS name | ['bareos']['plugins']['graphite']['graphite_port'] | '2003' | Default graphite communication port | ['bareos']['plugins']['graphite']['graphite_data_prefix'] | 'bareos.' | Default prefix for graphite data -| ['bareos']['plugins']['graphite']['graphite_plugin_src_url'] | 'https://raw.githubusercontent.com/bareos/bareos-contrib/master/misc/performance/graphite/bareos-graphite-poller.py' | Default URL to the plugin +| ['bareos']['plugins']['graphite']['graphite_plugin_src_url'] | See attributes file | Default URL to the plugin ## Recipes diff --git a/attributes/default.rb b/attributes/default.rb index b2d5ae8..1d62c84 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -113,12 +113,6 @@ default['bareos']['workstation']['name'] = node['fqdn'] # Graphite Plugin Default Attributes -default['bareos']['plugins']['graphite']['packages'] = if platform_family?('rhel') && node['platform_version'].to_i == 6 - %w(python python-bareos python-requests python-fedora-django) - else - %w(python python-bareos python-requests python-django) - end - default['bareos']['plugins']['graphite']['plugin_path'] = '/usr/sbin' default['bareos']['plugins']['graphite']['config_path'] = '/etc/bareos' default['bareos']['plugins']['graphite']['search_query'] = 'roles:bareos_director' @@ -126,7 +120,7 @@ default['bareos']['plugins']['graphite']['graphite_port'] = '2003' default['bareos']['plugins']['graphite']['graphite_data_prefix'] = 'bareos.' default['bareos']['plugins']['graphite']['graphite_plugin_src_url'] = 'https://raw.githubusercontent.com/bareos/bareos-contrib/master/misc/performance/graphite/bareos-graphite-poller.py' -defualt['bareos']['plugins']['graphite']['mailto'] = 'bareos' +default['bareos']['plugins']['graphite']['mail_to'] = 'bareos' ############################## # Examples - Default Hashes # diff --git a/recipes/graphite_plugin.rb b/recipes/graphite_plugin.rb index 80e391e..ced3cab 100644 --- a/recipes/graphite_plugin.rb +++ b/recipes/graphite_plugin.rb @@ -17,8 +17,10 @@ include_recipe 'chef-bareos::repo' -node['bareos']['plugins']['graphite']['packages'].each do |py_pkg| - package py_pkg +if platform_family?('rhel') && node['platform_version'].to_i == 6 + package ['python', 'python-bareos', 'python-requests', 'python-fedora-django'] +else + package ['python', 'python-bareos', 'python-requests', 'python-django'] end directory node['bareos']['plugins']['graphite']['config_path'] @@ -45,7 +47,7 @@ #{node['bareos']['plugins']['graphite']['plugin_path']}/bareos-graphite-poller.py\ -c #{node['bareos']['plugins']['graphite']['config_path']}/graphite-poller.conf EOH - mailto node['bareos']['plugins']['mailto'] + mailto node['bareos']['plugins']['graphite']['mail_to'] user 'bareos' minute '5' end diff --git a/recipes/repo.rb b/recipes/repo.rb index c6b9d22..ff609fa 100644 --- a/recipes/repo.rb +++ b/recipes/repo.rb @@ -38,12 +38,14 @@ components ['/'] distribution '' key node['bareos']['gpgkey'] + action :add end apt_repository 'bareos_contrib' do uri node['bareos']['contrib_baseurl'] components ['/'] distribution '' key node['bareos']['contrib_gpgkey'] + action :add end else Chef::Log.fatal('OS is not currently supported by this cookbook, submit enhancement request or PR') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4e00004..ee2166c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,11 @@ require 'chefspec' require 'chefspec/berkshelf' +Dir['./spec/support/**/*.rb'].sort.each { |f| require f } + +RSpec.configure do |config| + config.formatter = :documentation + config.color = true +end + at_exit { ChefSpec::Coverage.report! } diff --git a/spec/support/supported_platforms.rb b/spec/support/supported_platforms.rb new file mode 100644 index 0000000..4848aba --- /dev/null +++ b/spec/support/supported_platforms.rb @@ -0,0 +1,7 @@ +def supported_platforms + _platforms = { + 'ubuntu' => ['14.04'], + 'redhat' => ['6.6', '7.1'], + 'centos' => ['6.7', '7.2.1511'] + } +end diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb index 7407482..b5694b1 100644 --- a/spec/unit/recipes/default_spec.rb +++ b/spec/unit/recipes/default_spec.rb @@ -2,68 +2,71 @@ # Cookbook Name:: chef-bareos # Spec:: default # -# Copyright (c) 2015 The Authors, All Rights Reserved. +# Copyright (C) 2016 Leonard TAVAE require 'spec_helper' describe 'chef-bareos::default' do before do allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original - allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with('chef-bareos::client') end - - context 'When all attributes are default, on an unspecified platform' do - let(:chef_run) do - runner = ChefSpec::ServerRunner.new - runner.converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end - - it 'includes the client recipe' do - expect_any_instance_of(Chef::Recipe).to receive(:include_recipe).with('chef-bareos::client') - chef_run - end - end - - context 'on an ubuntu 14.04 box' do - let(:chef_run) do - runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '14.04') - runner.converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end - - it 'adds the apt repo bareos' do - expect(chef_run).to add_apt_repository('bareos') - end - - it 'adds the apt repo bareos_contrib' do - expect(chef_run).to add_apt_repository('bareos_contrib') - end - end - - context 'on an centos 6.7 box' do - let(:chef_run) do - runner = ChefSpec::ServerRunner.new(platform: 'centos', version: '6.7') do + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on an #{platform.capitalize}-#{version} box" do + let(:chef_run) do + runner = ChefSpec::ServerRunner.new(platform: platform, version: version) + runner.converge(described_recipe) + end + let(:template) { chef_run.template('/etc/bareos/bareos-fd.conf') } + let(:execute) { chef_run.execute('restart-fd') } + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + it 'includes the `chef-bareos::repo` recipe' do + expect(chef_run).to include_recipe('chef-bareos::repo') + chef_run + end + case platform + when 'ubuntu' + it 'adds the apt repo bareos' do + expect(chef_run).to add_apt_repository('bareos') + end + it 'adds the apt repo bareos_contrib' do + expect(chef_run).to add_apt_repository('bareos_contrib') + end + when 'centos', 'redhat' + it 'adds the yum repo bareos' do + expect(chef_run).to create_yum_repository('bareos') + end + it 'adds the yum repo bareos_contrib' do + expect(chef_run).to create_yum_repository('bareos_contrib') + end + end + it 'includes the `chef-bareos::client` recipe' do + expect(chef_run).to include_recipe('chef-bareos::client') + chef_run + end + it 'installs the bareos-filedaemon package' do + expect(chef_run).to install_package('bareos-filedaemon') + end + it 'renders the bareos-fd config' do + expect(chef_run).to create_template('/etc/bareos/bareos-fd.conf').with( + user: 'root', + group: 'bareos', + mode: '0640', + sensitive: true + ) + end + it 'creates the execute[restart-fd], subscribes to bareos-fd template, notifies bareos-fd to restart' do + expect(chef_run).to_not run_execute('restart-fd') + expect(execute).to subscribe_to('template[/etc/bareos/bareos-fd.conf]') + expect(execute).to notify('service[bareos-fd]').to(:restart) + end + it 'enables and starts the bareos-fd service' do + expect(chef_run).to enable_service('bareos-fd') + expect(chef_run).to start_service('bareos-fd') + end end - runner.converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end - - it 'adds the yum repo bareos' do - expect(chef_run).to create_yum_repository('bareos') - end - - it 'adds the yum repo bareos_contrib' do - expect(chef_run).to create_yum_repository('bareos_contrib') end end end diff --git a/spec/unit/recipes/graphite_plugin_spec.rb b/spec/unit/recipes/graphite_plugin_spec.rb new file mode 100644 index 0000000..92d8967 --- /dev/null +++ b/spec/unit/recipes/graphite_plugin_spec.rb @@ -0,0 +1,89 @@ +# +# Cookbook Name:: chef-bareos +# Spec:: graphite_plugin_spec +# +# Copyright (C) 2016 Leonard TAVAE + +require 'spec_helper' + +describe 'chef-bareos::graphite_plugin' do + before do + allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).and_call_original + end + supported_platforms.each do |platform, versions| + versions.each do |version| + context "on an #{platform.capitalize}-#{version} box" do + let(:chef_run) do + runner = ChefSpec::ServerRunner.new(platform: platform, version: version) + runner.node.set['bareos']['plugins']['graphite']['config_path'] = '/etc/bareos' + runner.node.set['bareos']['plugins']['graphite']['plugin_path'] = '/usr/sbin' + runner.node.set['bareos']['plugins']['graphite']['mailto'] = 'bareos' + runner.converge(described_recipe) + end + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + it 'includes the `chef-bareos::repo` recipe' do + expect(chef_run).to include_recipe('chef-bareos::repo') + chef_run + end + case platform + when 'ubuntu' + it 'adds the apt repo bareos' do + expect(chef_run).to add_apt_repository('bareos') + end + it 'adds the apt repo bareos_contrib' do + expect(chef_run).to add_apt_repository('bareos_contrib') + end + it 'installs plugin dependencies' do + expect(chef_run).to install_package(['python', 'python-bareos', 'python-requests', 'python-django']) + end + when 'centos', 'redhat' + it 'adds the yum repo bareos' do + expect(chef_run).to create_yum_repository('bareos') + end + it 'adds the yum repo bareos_contrib' do + expect(chef_run).to create_yum_repository('bareos_contrib') + end + if version.to_i == 6 + it 'installs EL6 plugin dependencies' do + expect(chef_run).to install_package(['python', 'python-bareos', 'python-requests', 'python-fedora-django']) + end + else + it 'installs EL7 plugin dependencies' do + expect(chef_run).to install_package(['python', 'python-bareos', 'python-requests', 'python-django']) + end + end + end + it 'verifies config_path is present' do + expect(chef_run).to create_directory('/etc/bareos') + chef_run + end + it 'creates the graphite-poller.conf via the template resource with attributes' do + expect(chef_run).to create_template('/etc/bareos/graphite-poller.conf').with( + user: 'bareos', + group: 'bareos', + mode: '0740' + ) + chef_run + end + it 'creates the bareos-graphite-poller.py remote_file with attributes' do + expect(chef_run).to create_remote_file('/usr/sbin/bareos-graphite-poller.py').with( + owner: 'bareos', + group: 'bareos', + mode: '0740' + ) + chef_run + end + it 'creates the bareos_graphite_poller cronjob with attributes' do + expect(chef_run).to create_cron('bareos_graphite_poller').with( + minute: '5', + user: 'bareos', + mailto: 'bareos' + ) + chef_run + end + end + end + end +end diff --git a/spec/unit/recipes/repo_spec.rb b/spec/unit/recipes/repo_spec.rb deleted file mode 100644 index ea35ede..0000000 --- a/spec/unit/recipes/repo_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# Test that the repo is being put on the box as desired - -require 'spec_helper' - -describe 'chef-bareos::repo' do - ['6.7', '7.2.1511'].each do |version| - context "on CentOS #{version}" do - before do - Fauxhai.mock(platform: 'centos', version: version) - end - - let(:chef_run) do - ChefSpec::SoloRunner.new do - end.converge('chef-bareos::repo') - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end - - it 'should add bareos yum repo' do - # expect(chef_run).to add_yum_repository('bareos') - end - - it 'should add bareos_contrib yum repo' do - # expect(chef_run).to add_yum_repository('bareos_contrib') - end - end - end - - ['12.04', '14.04'].each do |version| - context "on Ubuntu #{version}" do - before do - Fauxhai.mock(platform: 'ubuntu', version: version) - end - - let(:chef_run) do - ChefSpec::SoloRunner.new do - end.converge('chef-bareos::repo') - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end - - it 'should add bareos apt repo' do - # expect(chef_run).to add_apt_repository('bareos').with( - # 'uri' => node['bareos']['baseurl'], - # 'key' => node['bareos']['gpgkey'], - # 'components' => ['/'] - # ) - end - - it 'should add bareos_contrib apt repo' do - # expect(chef_run).to add_apt_repository('bareos_contrib').with( - # 'uri' => node['bareos']['contrib_baseurl'], - # 'key' => node['bareos']['contrib_gpgkey'], - # 'components' => ['/'] - # ) - end - end - end -end diff --git a/test/integration/bareos-aio-server/serverspec/bareos_spec.rb b/test/integration/bareos-aio-server/serverspec/bareos_spec.rb index b6b14ce..9efbcc8 100644 --- a/test/integration/bareos-aio-server/serverspec/bareos_spec.rb +++ b/test/integration/bareos-aio-server/serverspec/bareos_spec.rb @@ -1,30 +1,41 @@ require 'spec_helper' # Check Packages are installed -describe package('bareos-filedaemon') do - it { should be_installed } +%w(bareos-filedaemon bareos-storage bareos-director).each do |bareos_pkgs| + describe package(bareos_pkgs) do + it { should be_installed } + end end -describe package('bareos-storage') do - it { should be_installed } +# Check if Bareos services are enabled and running +%w(bareos-fd bareos-sd bareos-dir).each do |bareos_srv| + describe service(bareos_srv) do + it { should be_enabled } + it { should be_running } + end end -describe package('bareos-director') do - it { should be_installed } +describe command('echo status director | bconsole') do + its(:exit_status) { should eq 0 } end -# Check Services are running and enabled -describe service('bareos-fd') do - it { should be_enabled } - it { should be_running } +# Check if the graphite plugin was installed +%w(/etc/bareos/graphite-poller.conf /usr/sbin/bareos-graphite-poller.py).each do |plugin_files| + describe file(plugin_files) do + it { should be_file } + it { should exist } + end end -describe service('bareos-sd') do - it { should be_enabled } - it { should be_running } +describe file('/etc/bareos/graphite-poller.conf') do + it { should contain '[director]' } + it { should contain '[graphite]' } end -describe service('bareos-dir') do - it { should be_enabled } - it { should be_running } +describe file('/usr/sbin/bareos-graphite-poller.py') do + it { should contain 'BAREOS' } +end + +describe cron do + it { should have_entry('5 * * * * /usr/sbin/bareos-graphite-poller.py -c /etc/bareos/graphite-poller.conf').with_user('bareos') } end