Akosiaris has submitted this change and it was merged.

Change subject: Adding bacula module rspec tests
......................................................................


Adding bacula module rspec tests

Change-Id: Ie075c20329b09d606b43aa35c37ded4af2bec321
---
A modules/bacula/.rspec
A modules/bacula/Rakefile
A modules/bacula/spec/classes/bacula_client_spec.rb
A modules/bacula/spec/classes/bacula_console_spec.rb
A modules/bacula/spec/classes/bacula_director_spec.rb
A modules/bacula/spec/classes/bacula_storage_spec.rb
A modules/bacula/spec/defines/catalog_spec.rb
A modules/bacula/spec/defines/fileset_spec.rb
A modules/bacula/spec/defines/job_spec.rb
A modules/bacula/spec/defines/jobdefaults_spec.rb
A modules/bacula/spec/defines/pool_spec.rb
A modules/bacula/spec/defines/schedule_spec.rb
A modules/bacula/spec/defines/storage_device_spec.rb
A modules/bacula/spec/fixtures/manifests/site.pp
A modules/bacula/spec/spec_helper.rb
15 files changed, 441 insertions(+), 0 deletions(-)

Approvals:
  Akosiaris: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/bacula/.rspec b/modules/bacula/.rspec
new file mode 100644
index 0000000..f449dae
--- /dev/null
+++ b/modules/bacula/.rspec
@@ -0,0 +1,2 @@
+--format doc
+--color
diff --git a/modules/bacula/Rakefile b/modules/bacula/Rakefile
new file mode 100644
index 0000000..d9226a8
--- /dev/null
+++ b/modules/bacula/Rakefile
@@ -0,0 +1,37 @@
+require 'rake'
+require 'fileutils'
+
+require 'rspec/core/rake_task'
+
+modulename = File.basename(File.expand_path(File.dirname(__FILE__)))
+
+symlinks = { 'spec/fixtures/modules/%s/files' % modulename => 
'../../../../files',
+  'spec/fixtures/modules/%s/manifests' % modulename => '../../../../manifests',
+  'spec/fixtures/modules/%s/templates' % modulename => '../../../../templates',
+}
+
+
+task :setup do
+  FileUtils.mkdir_p('spec/fixtures/modules/%s' % modulename)
+  symlinks.each do |x|
+    if !File.exist?(x[0])
+      FileUtils.ln_s(x[1], x[0])
+    end
+  end
+end
+
+task :teardown do
+  symlinks.each { |x| FileUtils.rm(x[0], :force => true) }
+  FileUtils.rmdir('spec/fixtures/modules/%s' % modulename)
+  FileUtils.rmdir('spec/fixtures/modules')
+end
+
+RSpec::Core::RakeTask.new(:realspec) do |t|
+  t.fail_on_error = false
+  t.pattern = 'spec/*/*_spec.rb'
+end
+
+task :spec => [ :setup, :realspec, :teardown]
+
+task :default => :spec do
+end
diff --git a/modules/bacula/spec/classes/bacula_client_spec.rb 
b/modules/bacula/spec/classes/bacula_client_spec.rb
new file mode 100644
index 0000000..c289d4c
--- /dev/null
+++ b/modules/bacula/spec/classes/bacula_client_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe 'bacula::client', :type => :class do
+    let(:node) { 'testhost.example.com' }
+    let(:params) { {
+        :director => 'testdirector',
+        :catalog => 'testcatalog',
+        :file_retention => 'testfr',
+        :job_retention => 'testjr',
+        :fdport => '2000',
+        :directorpassword => 'testdirectorpass',
+        }
+    }
+
+    it { should contain_package('bacula-fd') }
+    it { should contain_service('bacula-fd') }
+    it { should contain_exec('concat-bacula-keypair') }
+    it 'should generate valid content for /etc/bacula/bacula-fd.conf' do
+        should contain_file('/etc/bacula/bacula-fd.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'root',
+            'mode'    => '0400',
+        }) \
+        .with_content(/Name = "testdirector"/) \
+        .with_content(/Password = "testdirectorpass"/) \
+        .with_content(/TLS Certificate = 
"\/var\/lib\/puppet\/ssl\/certs\/testhost.example.com.pem"/) \
+        .with_content(/TLS Key = 
"\/var\/lib\/puppet\/ssl\/private_keys\/testhost.example.com.pem"/) \
+        .with_content(/Name = "testhost.example.com-fd"/) \
+        .with_content(/FDport = 2000/) \
+        .with_content(/PKI Keypair = 
"\/var\/lib\/puppet\/ssl\/private_keys\/bacula-keypair-testhost.example.com.pem"/)
+    end
+end
diff --git a/modules/bacula/spec/classes/bacula_console_spec.rb 
b/modules/bacula/spec/classes/bacula_console_spec.rb
new file mode 100644
index 0000000..4dd7916
--- /dev/null
+++ b/modules/bacula/spec/classes/bacula_console_spec.rb
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe 'bacula::console', :type => :class do
+    let(:params) { { :director => 'testdirector' } }
+
+    it { should contain_package('bacula-console') }
+end
diff --git a/modules/bacula/spec/classes/bacula_director_spec.rb 
b/modules/bacula/spec/classes/bacula_director_spec.rb
new file mode 100644
index 0000000..6c63475
--- /dev/null
+++ b/modules/bacula/spec/classes/bacula_director_spec.rb
@@ -0,0 +1,84 @@
+require 'spec_helper'
+
+describe 'bacula::director', :type => :class do
+    let(:node) { 'testhost.example.com' }
+    let(:params) { {
+        :max_dir_concur_jobs => '10',
+        :sqlvariant => 'testsql',
+        :dir_port => '9900',
+        :bconsolepassword => 'bconsolepass',
+        }
+    }
+
+    it { should contain_package('bacula-director-testsql') }
+    it { should contain_service('bacula-director') }
+    it do
+        should contain_file('/etc/bacula/conf.d').with({
+        'ensure'  => 'directory',
+        'recurse' => 'true',
+        'force'   => 'true',
+        'purge'   => 'true',
+        'mode'    => '0444',
+        'owner'   => 'root',
+        'group'   => 'bacula',
+        })
+    end
+    it do
+        should contain_file('/etc/bacula/jobs.d').with({
+        'ensure'  => 'directory',
+        'recurse' => 'true',
+        'force'   => 'true',
+        'purge'   => 'true',
+        'mode'    => '0444',
+        'owner'   => 'root',
+        'group'   => 'bacula',
+        })
+    end
+    it do
+        should contain_file('/etc/bacula/clients.d').with({
+        'ensure'  => 'directory',
+        'recurse' => 'true',
+        'force'   => 'true',
+        'purge'   => 'true',
+        'mode'    => '0444',
+        'owner'   => 'root',
+        'group'   => 'bacula',
+        })
+    end
+    it do
+        should contain_file('/etc/bacula/storages.d').with({
+        'ensure'  => 'directory',
+        'recurse' => 'true',
+        'force'   => 'true',
+        'purge'   => 'true',
+        'mode'    => '0444',
+        'owner'   => 'root',
+        'group'   => 'bacula',
+        })
+    end
+    it 'should generate valid content for /etc/bacula/bacula-dir.conf' do
+        should contain_file('/etc/bacula/bacula-dir.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'bacula',
+            'mode'    => '0440',
+        }) \
+        .with_content(/Name = "testhost.example.com"/) \
+        .with_content(/Password = "bconsolepass"/) \
+        .with_content(/TLS Certificate = 
"\/var\/lib\/puppet\/ssl\/certs\/testhost.example.com.pem"/) \
+        .with_content(/TLS Key = 
"\/var\/lib\/puppet\/ssl\/private_keys\/testhost.example.com.pem"/) \
+        .with_content(/DIRport = 9900/) \
+        .with_content(/Maximum Concurrent Jobs = 10/)
+    end
+    it 'should generate valid content for 
/etc/bacula/jobs.d/restore-migrate-jobs.conf' do
+        should 
contain_file('/etc/bacula/jobs.d/restore-migrate-jobs.conf').with({
+            'ensure'  => 'file',
+            'owner'   => 'root',
+            'group'   => 'bacula',
+            'mode'    => '0444',
+        }) \
+        .with_content(/Client = testhost.example.com-fd/) \
+        .with_content(/Type = Restore/) \
+        .with_content(/Type = Migrate/) \
+    end
+end
diff --git a/modules/bacula/spec/classes/bacula_storage_spec.rb 
b/modules/bacula/spec/classes/bacula_storage_spec.rb
new file mode 100644
index 0000000..e33364e
--- /dev/null
+++ b/modules/bacula/spec/classes/bacula_storage_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+describe 'bacula::storage', :type => :class do
+    let(:node) { 'testhost.example.com' }
+    let(:params) { {
+        :director => 'testdirector',
+        :sd_max_concur_jobs => '10',
+        :sqlvariant => 'testsql',
+        :sd_port => '9000',
+        :directorpassword => 'testdirectorpass',
+        }
+    }
+
+    it { should contain_package('bacula-sd-testsql') }
+    it { should contain_service('bacula-sd') }
+    it do
+        should contain_file('/etc/bacula/sd-devices.d').with({
+        'ensure'  => 'directory',
+        'recurse' => 'true',
+        'force'   => 'true',
+        'purge'   => 'true',
+        'mode'    => '0444',
+        'owner'   => 'root',
+        'group'   => 'bacula',
+        })
+    end
+    it 'should generate valid content for /etc/bacula/bacula-sd.conf' do
+        should contain_file('/etc/bacula/bacula-sd.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'root',
+            'mode'    => '0400',
+        }) \
+        .with_content(/Name = "testdirector"/) \
+        .with_content(/Password = "testdirectorpass"/) \
+        .with_content(/TLS Certificate = 
"\/var\/lib\/puppet\/ssl\/certs\/testhost.example.com.pem"/) \
+        .with_content(/TLS Key = 
"\/var\/lib\/puppet\/ssl\/private_keys\/testhost.example.com.pem"/) \
+        .with_content(/Name = "testhost.example.com-fd"/) \
+        .with_content(/SDport = 9000/) \
+        .with_content(/Maximum Concurrent Jobs = 10/)
+    end
+end
diff --git a/modules/bacula/spec/defines/catalog_spec.rb 
b/modules/bacula/spec/defines/catalog_spec.rb
new file mode 100644
index 0000000..4787b31
--- /dev/null
+++ b/modules/bacula/spec/defines/catalog_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe 'bacula::director::catalog', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { {
+        :dbname      => 'bacula',
+        :dbuser      => 'bacula',
+        :dbhost      => 'bacula-db.example.org',
+        :dbport      => '3306',
+        :dbpassword  => 'bacula',
+        }
+    }
+
+    it 'should create valid content for 
/etc/bacula/conf.d/catalog-something.conf' do
+        should contain_file('/etc/bacula/conf.d/catalog-something.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'bacula',
+            'mode'    => '0440',
+        }) \
+        .with_content(/Name = something/) \
+        .with_content(/dbname = bacula/) \
+        .with_content(/user = bacula/) \
+        .with_content(/password = bacula/) \
+        .with_content(/DB Address = bacula-db.example.org/) \
+        .with_content(/DB Port = 3306/)
+    end
+end
diff --git a/modules/bacula/spec/defines/fileset_spec.rb 
b/modules/bacula/spec/defines/fileset_spec.rb
new file mode 100644
index 0000000..f494abe
--- /dev/null
+++ b/modules/bacula/spec/defines/fileset_spec.rb
@@ -0,0 +1,38 @@
+require 'spec_helper'
+
+describe 'bacula::director::fileset', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { { :includes    => [ "/", "/var", ], } }
+
+    it 'should create /etc/bacula/conf.d/fileset-something.conf' do
+        should contain_file('/etc/bacula/conf.d/fileset-something.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'bacula',
+            'mode'    => '0440',
+        })
+    end
+
+    context 'without excludes' do
+        it 'should create valid content for 
/etc/bacula/conf.d/fileset-something.conf' do
+            should contain_file('/etc/bacula/conf.d/fileset-something.conf') \
+            .with_content(/File = \//) \
+            .with_content(/File = \/var/)
+        end
+    end
+
+    context 'with excludes' do
+        let(:params) { {
+            :includes    => [ "/", "/var",],
+            :excludes    => [ "/tmp", ],
+            }
+        }
+        it 'should create valid content for 
/etc/bacula/conf.d/fileset-something.conf' do
+            should contain_file('/etc/bacula/conf.d/fileset-something.conf') \
+            .with_content(/File = \//) \
+            .with_content(/File = \/var/) \
+            .with_content(/File = \/tmp/)
+        end
+    end
+
+end
diff --git a/modules/bacula/spec/defines/job_spec.rb 
b/modules/bacula/spec/defines/job_spec.rb
new file mode 100644
index 0000000..58c2e28
--- /dev/null
+++ b/modules/bacula/spec/defines/job_spec.rb
@@ -0,0 +1,10 @@
+require 'spec_helper'
+
+describe 'bacula::client::job', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { {
+        :fileset      => 'root',
+        :jobdefaults  => 'testdefaults',
+        }
+    }
+end
diff --git a/modules/bacula/spec/defines/jobdefaults_spec.rb 
b/modules/bacula/spec/defines/jobdefaults_spec.rb
new file mode 100644
index 0000000..f9873c1
--- /dev/null
+++ b/modules/bacula/spec/defines/jobdefaults_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'bacula::director::jobdefaults', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { {
+        :when => 'never',
+        :pool => 'testpool',
+        }
+    }
+
+    it 'should create /etc/bacula/conf.d/jobdefaults-something.conf' do
+        should 
contain_file('/etc/bacula/conf.d/jobdefaults-something.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'bacula',
+            'mode'    => '0440',
+        }) \
+            .with_content(/Name = something/) \
+            .with_content(/Type = Backup/) \
+            .with_content(/Accurate = no/) \
+            .with_content(/Spool Data = no/) \
+            .with_content(/Schedule = never/) \
+            .with_content(/Pool = testpool/) \
+            .with_content(/Priority = 10/)
+    end
+end
diff --git a/modules/bacula/spec/defines/pool_spec.rb 
b/modules/bacula/spec/defines/pool_spec.rb
new file mode 100644
index 0000000..eb98b8d
--- /dev/null
+++ b/modules/bacula/spec/defines/pool_spec.rb
@@ -0,0 +1,56 @@
+require 'spec_helper'
+
+describe 'bacula::director::pool', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { {
+        :max_vols => '10',
+        :storage => 'teststorage',
+        :volume_retention => '10 days',
+        }
+    }
+
+    context 'without label_fmt, max_vol_bytes' do
+        it 'should create /etc/bacula/conf.d/pool-something.conf' do
+            should 
contain_file('/etc/bacula/conf.d/pool-something.conf').with({
+                'ensure'  => 'present',
+                'owner'   => 'root',
+                'group'   => 'bacula',
+                'mode'    => '0440',
+            }) \
+            .with_content(/Name = something/) \
+            .with_content(/Maximum Volumes = 10/) \
+            .with_content(/Storage = teststorage/) \
+            .with_content(/Volume Retention = 10 days/) \
+            .with_content(/AutoPrune = yes/) \
+            .with_content(/Recycle = yes/) \
+            .with_content(/Catalog Files = yes/)
+        end
+    end
+
+    context 'with max_vol_bytes' do
+        let(:params) { {
+            :max_vols => '10',
+            :storage => 'teststorage',
+            :volume_retention => '10 days',
+            :max_vol_bytes => '2000',
+            }
+        }
+        it 'should create /etc/bacula/conf.d/pool-something.conf' do
+            should contain_file('/etc/bacula/conf.d/pool-something.conf') \
+            .with_content(/Maximum Volume Bytes = 2000/) \
+        end
+    end
+    context 'with max_vol_bytes' do
+        let(:params) { {
+            :max_vols => '10',
+            :storage => 'teststorage',
+            :volume_retention => '10 days',
+            :label_fmt => 'TEST',
+            }
+        }
+        it 'should create /etc/bacula/conf.d/pool-something.conf' do
+            should contain_file('/etc/bacula/conf.d/pool-something.conf') \
+            .with_content(/Label Format = "TEST"/) \
+        end
+    end
+end
diff --git a/modules/bacula/spec/defines/schedule_spec.rb 
b/modules/bacula/spec/defines/schedule_spec.rb
new file mode 100644
index 0000000..7db8c82
--- /dev/null
+++ b/modules/bacula/spec/defines/schedule_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'bacula::director::schedule', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { {
+        :runs => [
+            { 'level' => 'Full', 'at' => '1st Sat at 00:00'},
+            { 'level' => 'Differential', 'at' => '3rd Sat at 00:00'},
+            ]
+        }
+    }
+
+    it 'should create /etc/bacula/conf.d/schedule-something.conf' do
+        should 
contain_file('/etc/bacula/conf.d/schedule-something.conf').with({
+            'ensure'  => 'present',
+            'owner'   => 'root',
+            'group'   => 'bacula',
+            'mode'    => '0440',
+        }) \
+        .with_content(/Name = something/) \
+        .with_content(/Run = Level=Full 1st Sat at 00:00/) \
+        .with_content(/Run = Level=Differential 3rd Sat at 00:00/)
+    end
+end
diff --git a/modules/bacula/spec/defines/storage_device_spec.rb 
b/modules/bacula/spec/defines/storage_device_spec.rb
new file mode 100644
index 0000000..8b83ff6
--- /dev/null
+++ b/modules/bacula/spec/defines/storage_device_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe 'bacula::storage::device', :type => :define do
+    let(:title) { 'something' }
+    let(:params) { {
+        :device_type => 'File',
+        :media_type  => 'File',
+        :archive_device => '/dev/nst0',
+        :max_concur_jobs => '10',
+        }
+    }
+
+    context 'without spool_dir, max_spool_size' do
+        it 'should create /etc/bacula/sd-devices.d/something.conf' do
+            should 
contain_file('/etc/bacula/sd-devices.d/something.conf').with({
+                'ensure'  => 'present',
+                'owner'   => 'root',
+                'group'   => 'root',
+                'mode'    => '0400',
+            }) \
+            .with_content(/Name = something/) \
+            .with_content(/Device Type = File/) \
+            .with_content(/Media Type = File/) \
+            .with_content(/Archive Device = \/dev\/nst0/) \
+            .with_content(/Maximum Concurrent Jobs = 10/)
+        end
+    end
+
+    context 'with spool_dir, max_spool_size' do
+        let(:params) { {
+            :device_type => 'File',
+            :media_type  => 'File',
+            :archive_device => '/dev/nst0',
+            :max_concur_jobs => '10',
+            :spool_dir => '/tmp',
+            :max_spool_size => '100',
+            }
+        }
+
+        it 'should create /etc/bacula/sd-devices.d/something.conf' do
+            should contain_file('/etc/bacula/sd-devices.d/something.conf') \
+            .with_content(/Maximum Spool Size = 100/) \
+            .with_content(/Spool Directory = \/tmp/)
+        end
+    end
+end
diff --git a/modules/bacula/spec/fixtures/manifests/site.pp 
b/modules/bacula/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/modules/bacula/spec/fixtures/manifests/site.pp
diff --git a/modules/bacula/spec/spec_helper.rb 
b/modules/bacula/spec/spec_helper.rb
new file mode 100644
index 0000000..d3923f8
--- /dev/null
+++ b/modules/bacula/spec/spec_helper.rb
@@ -0,0 +1,8 @@
+require 'rspec-puppet'
+
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+
+RSpec.configure do |c|
+  c.module_path = File.join(fixture_path, 'modules')
+  c.manifest_dir = File.join(fixture_path, 'manifests')
+end

-- 
To view, visit https://gerrit.wikimedia.org/r/86850
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie075c20329b09d606b43aa35c37ded4af2bec321
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Akosiaris <akosia...@wikimedia.org>
Gerrit-Reviewer: Akosiaris <akosia...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to