Hashar has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/399965 )

Change subject: rspec-puppet for all the roles
......................................................................

rspec-puppet for all the roles

Bump rspec-puppet 2.5.0...2.6.9 to catch up with a lot of fixed issues
and implemented features.
Update rspec but stick to 3.5.x for now (ran bundle update rspec-puppet)

Under /puppet add the boilerplate to support rspec-puppet. The usage is
pretty straightforward:

  bundle install
  cd puppet
  bundle exec rake spec

That will look up for all manifests in /puppet/modules/role/manifests/
and attempt to compile the catalog for each of them. That is similar to
what we do on operations/puppet.

Under the hood, it uses rspec, and one can pass it options via the
SPEC_OPTS environment variable:

 cd puppet
 SPEC_OPTS='--help' bundle exec rake spec

Set spec statuses persistence so one can easily rerun solely the failed
tests via:

 cd puppet
 SPEC_OPTS='--only-failures'

The processorcount is always set, that is used by a few roles:
- role::analytics
- role::hadoop
- role::hive
- role::hue
- role::oozie

Pending:
- puppet version is wrong
- should set facts using rspec-puppet-facts

Bug: T183570
X-Notable-Event: Merry-Christmas
Change-Id: I5e286b88d1dbecb10860afbf2ac99704b33c5e58
---
M Gemfile
M Gemfile.lock
A puppet/.rspec
A puppet/LICENSE
A puppet/README
A puppet/Rakefile
A puppet/spec/.gitignore
A puppet/spec/integration/roles_spec.rb
A puppet/spec/spec_helper.rb
9 files changed, 120 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/vagrant 
refs/changes/65/399965/1

diff --git a/Gemfile b/Gemfile
index 46d7c7a..0e63da2 100644
--- a/Gemfile
+++ b/Gemfile
@@ -8,6 +8,7 @@
   gem 'puppet', '~> 4.8.2'
   gem 'puppet-lint', '2.3.3'
   gem 'puppetlabs_spec_helper', '< 2.0.0', require: false
+  gem 'rspec-puppet', '~> 2.6.5', require: false
   gem 'puppet-strings', '~> 1.0.0'
   gem 'safe_yaml', '~> 1.0.4'
   gem 'rake', '~> 12.0.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index db35020..3aa9f13 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -191,6 +191,7 @@
   puppetlabs_spec_helper (< 2.0.0)
   rake (~> 12.0.0)
   rspec (~> 3.1, >= 3.1.0)
+  rspec-puppet (~> 2.6.5)
   rubocop (~> 0.51)
   safe_yaml (~> 1.0.4)
   vagrant!
diff --git a/puppet/.rspec b/puppet/.rspec
new file mode 100644
index 0000000..f449dae
--- /dev/null
+++ b/puppet/.rspec
@@ -0,0 +1,2 @@
+--format doc
+--color
diff --git a/puppet/LICENSE b/puppet/LICENSE
new file mode 100644
index 0000000..6f155bb
--- /dev/null
+++ b/puppet/LICENSE
@@ -0,0 +1,21 @@
+Copyright (C) 2016,2017 Antoine Musso <has...@free.fr>
+Copyright (C) 2016,2016 Wikimedia Foundation Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/puppet/README b/puppet/README
new file mode 100644
index 0000000..5d733c9
--- /dev/null
+++ b/puppet/README
@@ -0,0 +1,25 @@
+Test suite for /puppet
+----------------------
+
+    bundle install
+    bundle exec rake spec
+
+It uses rspec under the hood, you can pass it options via SPEC_OPTS:
+
+  SPEC_OPTS=--help bundle exec rake spec
+
+Some examples:
+
+Filter by example name:
+
+  SPEC_OPTS="-e role::wikitech"
+
+Only run tests that previously failed:
+
+  SPEC_OPTS="--only-failures"
+
+Run next failure:
+
+  SPEC_OPTS="--next-failure"
+
+The spec status are stored in /puppet/rspec_status
diff --git a/puppet/Rakefile b/puppet/Rakefile
new file mode 100644
index 0000000..cd3d379
--- /dev/null
+++ b/puppet/Rakefile
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/rake_tasks'
diff --git a/puppet/spec/.gitignore b/puppet/spec/.gitignore
new file mode 100644
index 0000000..cf996da
--- /dev/null
+++ b/puppet/spec/.gitignore
@@ -0,0 +1,2 @@
+/fixtures
+/rspec_status
diff --git a/puppet/spec/integration/roles_spec.rb 
b/puppet/spec/integration/roles_spec.rb
new file mode 100644
index 0000000..b0e6328
--- /dev/null
+++ b/puppet/spec/integration/roles_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+role_manifests = File.join(puppet_path, 'modules/role/manifests')
+puts role_manifests
+
+Dir.glob(File.join(role_manifests, '**/*.pp')).sort.each do |role_file|
+  relative = 
Pathname.new(role_file).relative_path_from(Pathname.new(role_manifests))
+  role_name = 'role::' + relative.to_s.gsub(%r{(/|\.pp$)}, { '/' => '::', 
'\.pp' => '' })
+
+  # Sub roles tend to be defines and we can not test them here
+  # eg role::thumb_on_404::multiwiki has:
+  #   define role::thumb_on_404::multiwiki(
+  if role_name.scan(/::/).count >= 2
+    manifest = File.read(role_file)
+    next if manifest.match(%(^define #{role_name}\\W))
+  end
+
+  describe role_name, :type => :class do
+    it { is_expected.to compile }
+  end
+end
diff --git a/puppet/spec/spec_helper.rb b/puppet/spec/spec_helper.rb
new file mode 100644
index 0000000..e1617c8
--- /dev/null
+++ b/puppet/spec/spec_helper.rb
@@ -0,0 +1,46 @@
+require 'rspec-puppet'
+
+def puppet_path
+  File.expand_path(File.join(__FILE__, '../..'))
+end
+
+# Load the modules libraries such as stdlib/wmflib
+Dir.glob(File.join(puppet_path, 'modules/*/lib')).each do |module_lib|
+  $LOAD_PATH.unshift module_lib
+end
+
+def hiera_config_fixture
+  fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+  conf = File.read(File.join(puppet_path, 'hiera.yaml'))
+  conf.gsub!(%r{/vagrant/puppet}, puppet_path)
+
+  fixture = File.join(fixture_path, 'hiera.yaml')
+  File.write(fixture, conf)
+
+  fixture
+end
+
+RSpec.configure do |c|
+  c.manifest_dir = File.join(puppet_path, 'manifests')
+  c.manifest = File.join(c.manifest_dir, 'site.pp')
+  c.module_path = File.join(puppet_path, 'modules')
+  c.hiera_config = hiera_config_fixture
+
+  c.default_facts = {
+    lsbdistcodename: 'stretch',
+    processorcount: 2,
+    git_user: 'nobody',
+    shared_apt_cache: nil,
+    share_group: 'nogroup',
+    share_owner: 'nobody',
+    site: 'local',
+  }
+
+  # For --next-failure / --only-failures
+  c.example_status_persistence_file_path = File.join(
+    File.dirname(__FILE__), 'rspec_status')
+end
+
+
+Puppet::Util::Log.level = :debug
+Puppet::Util::Log.newdestination(:console)

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5e286b88d1dbecb10860afbf2ac99704b33c5e58
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/vagrant
Gerrit-Branch: stretch-migration
Gerrit-Owner: Hashar <has...@free.fr>

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

Reply via email to