Giuseppe Lavagetto has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394273 )

Change subject: spec: make jenkins, zuul, monitoring, profile work with puppet 4
......................................................................

spec: make jenkins, zuul, monitoring, profile work with puppet 4

Change-Id: Ie18130f6d833584d403783ae2071da4e14de7991
---
M modules/jenkins/spec/classes/jenkins_spec.rb
M modules/jenkins/spec/hosts/master_and_slave_spec.rb
M modules/jenkins/spec/spec_helper.rb
M modules/monitoring/spec/defines/monitoring_host_spec.rb
M modules/profile/spec/classes/profile_base_certificate_spec.rb
M modules/profile/spec/spec_helper.rb
M modules/zuul/spec/classes/zuul_spec.rb
M modules/zuul/spec/spec_helper.rb
8 files changed, 96 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/73/394273/1

diff --git a/modules/jenkins/spec/classes/jenkins_spec.rb 
b/modules/jenkins/spec/classes/jenkins_spec.rb
index 6a7458e..4b87d70 100644
--- a/modules/jenkins/spec/classes/jenkins_spec.rb
+++ b/modules/jenkins/spec/classes/jenkins_spec.rb
@@ -1,6 +1,14 @@
 require 'spec_helper'
 
 describe 'jenkins' do
+    precondition = <<-EOF
+class profile::base {
+      $notifications_enabled = '1'
+}
+include ::profile::base
+EOF
+    let(:node_params) { {'cluster' => 'ci', 'site' => 'eqiad'} }
+    let(:pre_condition) { precondition }
     let(:params) { {
         :prefix => '/ci',
     } }
diff --git a/modules/jenkins/spec/hosts/master_and_slave_spec.rb 
b/modules/jenkins/spec/hosts/master_and_slave_spec.rb
index f1ec814..f37583d 100644
--- a/modules/jenkins/spec/hosts/master_and_slave_spec.rb
+++ b/modules/jenkins/spec/hosts/master_and_slave_spec.rb
@@ -1,8 +1,13 @@
 require 'spec_helper'
 
 describe 'Host being both a Jenkins master and a slave' do
-    let(:pre_condition) {
+  let(:node_params) { {'cluster' => 'ci', 'site' => 'eqiad'} }
+  let(:pre_condition) {
         """
+        class profile::base {
+           $notifications_enabled = '1'
+        }
+        include ::profile::base
         class { 'jenkins':
             prefix => '/jenkins',
         }
@@ -10,6 +15,6 @@
             ssh_key => 'fake ssh key',
         }
         """
-    }
-    it { should compile }
+  }
+  it { should compile }
 end
diff --git a/modules/jenkins/spec/spec_helper.rb 
b/modules/jenkins/spec/spec_helper.rb
index 7af690f..4a20b40 100644
--- a/modules/jenkins/spec/spec_helper.rb
+++ b/modules/jenkins/spec/spec_helper.rb
@@ -1,14 +1,17 @@
 require 'rspec-puppet'
 require 'puppetlabs_spec_helper/module_spec_helper'
+require 'rspec-puppet-facts'
+
+include RspecPuppetFacts
 
 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')
-  c.default_facts = {
-      :initsystem => 'systemd',
-      :lsbdistid => 'Debian',
-      :lsbdistrelease => '8.0',
-  }
+  test_on = { supported_os: [{'operatingsystem' => 'Debian', 
'operatingsystemrelease' => ['8']}]}
+  on_supported_os(test_on).each do |_, facts|
+    facts[:initsystem] = 'systemd'
+    c.default_facts = facts
+  end
 end
diff --git a/modules/monitoring/spec/defines/monitoring_host_spec.rb 
b/modules/monitoring/spec/defines/monitoring_host_spec.rb
index b108b7d..2b51025 100644
--- a/modules/monitoring/spec/defines/monitoring_host_spec.rb
+++ b/modules/monitoring/spec/defines/monitoring_host_spec.rb
@@ -6,9 +6,18 @@
       'fake_secret'
     }
   end
-  # We abuse RSpec a bit throughout the spec setting site to a fact
-  # Unfortunately RSpec node level parameters do not seem to work
+
   context 'with a standard physical host' do
+    let(:pre_condition){
+      """
+    class passwords::nagios::mysql {
+      $mysql_check_pass='foo'
+    }
+    class {'passwords::nagios::mysql': }
+    """
+    }
+    let(:node_params) { {'cluster' => 'ci', 'site' => 'eqiad'} }
+
     let(:facts) {
       {
         :hostname        => 'ahost',
@@ -18,7 +27,6 @@
         :lldp_parent     => 'ahosts_parent',
         :has_ipmi        => true,
         :ipmi_lan        => { :ipaddress => '2.2.2.2', },
-        :site            => 'blabla',
       }
     }
     let(:title) { 'ahost' }
@@ -64,6 +72,16 @@
   end
 
   context 'with a standard virtual host' do
+    let(:pre_condition){
+      """
+    class passwords::nagios::mysql {
+      $mysql_check_pass='foo'
+    }
+    class {'passwords::nagios::mysql': }
+    """
+    }
+    let(:node_params) { {'cluster' => 'ci', 'site' => 'eqiad'} }
+
     let(:facts) {
       {
         :hostname        => 'ahost',
@@ -109,6 +127,18 @@
   end
 
   context 'with an icinga host' do
+    let(:pre_condition){
+      """
+    class profile::base { $notifications_enabled = '1' }
+    class passwords::nagios::mysql {
+      $mysql_check_pass='foo'
+    }
+    include ::profile::base
+    include icinga
+    """
+    }
+    let(:node_params) { {'cluster' => 'ci', 'site' => 'eqiad'} }
+
     let(:facts) {
       {
         :hostname        => 'icingahost',
@@ -118,15 +148,8 @@
         :lldp_parent     => 'ahosts_parent',
         :has_ipmi        => true,
         :ipmi_lan        => { :ipaddress => '2.2.2.2', },
-        :site            => 'blabla',
       }
     }
-    let(:pre_condition) do
-      '''
-      include icinga
-      class passwords::nagios::mysql {}
-      '''
-    end
 
     describe 'monitoring itself' do
       let(:title) { 'icingahost' }
diff --git a/modules/profile/spec/classes/profile_base_certificate_spec.rb 
b/modules/profile/spec/classes/profile_base_certificate_spec.rb
index 87e5167..d13c22b 100644
--- a/modules/profile/spec/classes/profile_base_certificate_spec.rb
+++ b/modules/profile/spec/classes/profile_base_certificate_spec.rb
@@ -3,9 +3,23 @@
 # Adding a test on the exposition of Puppet CA cert here to make it explicit
 # that clients of base::expose_puppet_certs most probably need this cert to be
 # exposed as well
+test_on = {
+  supported_os: [
+    {
+      'operatingsystem'        => 'Debian',
+      'operatingsystemrelease' => ['8', '9'],
+    }
+  ]
+}
+
 describe 'profile::base::certificates' do
-    it 'should exposes Puppet CA certificate' do
+  on_supported_os(test_on).each do |os, facts|
+    context "on #{os}" do
+      let(:facts) { facts }
+      it 'should expose Puppet CA certificate' do
         should 
contain_file('/usr/local/share/ca-certificates/Puppet_Internal_CA.crt')
-            .with({ 'ensure' => 'present' })
+                 .with({ 'ensure' => 'present' })
+      end
     end
+  end
 end
diff --git a/modules/profile/spec/spec_helper.rb 
b/modules/profile/spec/spec_helper.rb
index 421fd71..f603826 100644
--- a/modules/profile/spec/spec_helper.rb
+++ b/modules/profile/spec/spec_helper.rb
@@ -1,6 +1,8 @@
 require 'rspec-puppet'
 require 'puppetlabs_spec_helper/module_spec_helper'
+require 'rspec-puppet-facts'
 
+include RspecPuppetFacts
 fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
 
 RSpec.configure do |c|
diff --git a/modules/zuul/spec/classes/zuul_spec.rb 
b/modules/zuul/spec/classes/zuul_spec.rb
index 97b34cb..6bdb18c 100644
--- a/modules/zuul/spec/classes/zuul_spec.rb
+++ b/modules/zuul/spec/classes/zuul_spec.rb
@@ -1,24 +1,26 @@
 require 'spec_helper'
 
+test_on = {
+  supported_os: [
+    {
+      'operatingsystem'        => 'Debian',
+      'operatingsystemrelease' => ['8', '9'],
+    }
+  ]
+}
+
 describe 'zuul' do
-    context "on production" do
-        let(:facts) {{
-            :realm => 'production',
-            :operatingsystem => 'Debian',
-            # for wmflib os_version
-            :lsbdistid      => 'Debian',
-            :lsbdistrelease => '8.7',
-        }}
+  on_supported_os(test_on).each do |os, facts|
+    context "On #{os}" do
+      let(:facts) { facts }
+      context "on production" do
+        let(:node_params) {{realm: 'production', site: 'test'}}
         it { should compile }
-    end
-    context "on labs" do
-        let(:facts) {{
-            :realm => 'labs',
-            :operatingsystem => 'Debian',
-            # for wmflib os_version
-            :lsbdistid       => 'Debian',
-            :lsbdistrelease  => '8.7',
-        }}
+      end
+      context "on labs" do
+        let(:node_params) {{realm: 'labs', site: 'test'}}
         it { should compile }
+      end
     end
+  end
 end
diff --git a/modules/zuul/spec/spec_helper.rb b/modules/zuul/spec/spec_helper.rb
index 7965c90..b218f2a 100644
--- a/modules/zuul/spec/spec_helper.rb
+++ b/modules/zuul/spec/spec_helper.rb
@@ -1,6 +1,8 @@
 require 'rspec-puppet'
 require 'puppetlabs_spec_helper/module_spec_helper'
+require 'rspec-puppet-facts'
 
+include RspecPuppetFacts
 fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
 
 RSpec.configure do |c|

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie18130f6d833584d403783ae2071da4e14de7991
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org>

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

Reply via email to