Gehel has uploaded a new change for review.
https://gerrit.wikimedia.org/r/277476
Change subject: Adding the ability to ensure nginx => absent
......................................................................
Adding the ability to ensure nginx => absent
The default behaviour is unchanged, but by adding ensure => absent will
remove nginx and its configuration.
Bug: T129934
Change-Id: Icf6e0247e5a4443373d9e9180eff0c0e80f469f0
---
A .rspec
A Rakefile
M manifests/init.pp
A spec/defines/nginx_rspec.rb
A spec/fixtures/manifests/site.pp
A spec/spec_helper.rb
6 files changed, 80 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet/nginx
refs/changes/76/277476/1
diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..f449dae
--- /dev/null
+++ b/.rspec
@@ -0,0 +1,2 @@
+--format doc
+--color
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..6471966
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,7 @@
+require 'rake'
+
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.pattern = 'spec/*/*_rspec.rb'
+end
diff --git a/manifests/init.pp b/manifests/init.pp
index 57fa30c..92b1a63 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -22,22 +22,26 @@
# 'nginx-full', 'nginx-light' or 'nginx-extras' packages.
#
class nginx(
+ $ensure = 'present',
$managed = true,
$variant = 'full',
-)
-{
+) {
+ validate_re($ensure, ['^present$', '^absent$'])
+
if $variant !~ /^(full|extras|light$)/ {
fail("'variant' must be 'full', 'extras', or 'light' (got:
'${variant}').")
}
- package { [ "nginx-${variant}", 'nginx-common' ]: }
+ package { [ "nginx-${variant}", 'nginx-common' ]:
+ ensure => $ensure,
+ }
# In the unmanaged case, this prevents the scenario where after the
# initial puppet run that installs the package, the net resulting state is
# a fully deployed configuration on disk, but the running instance still
# running the default configuration from the package. With this, it gets
# stopped before the service clause checks->starts it with good config.
- if ! $managed {
+ if ! $managed and ($ensure == 'present') {
exec { 'stop-default-nginx':
command => '/usr/sbin/service nginx stop',
subscribe => Package["nginx-${variant}"],
@@ -47,14 +51,14 @@
}
service { 'nginx':
- ensure => running,
+ ensure => ensure_service($ensure),
enable => true,
provider => 'debian',
hasrestart => true,
}
file { [ '/etc/nginx/conf.d', '/etc/nginx/sites-available',
'/etc/nginx/sites-enabled' ]:
- ensure => directory,
+ ensure => ensure_directory($ensure),
recurse => true,
purge => true,
force => true,
@@ -83,7 +87,7 @@
# nginx will buffer e.g. large body content into this directory
# very briefly, so keep it off the disks.
mount { '/var/lib/nginx':
- ensure => mounted,
+ ensure => ensure_mounted($ensure),
device => 'tmpfs',
fstype => 'tmpfs',
options => 'defaults,noatime,uid=0,gid=0,mode=755,size=1g',
diff --git a/spec/defines/nginx_rspec.rb b/spec/defines/nginx_rspec.rb
new file mode 100644
index 0000000..73e9e2a
--- /dev/null
+++ b/spec/defines/nginx_rspec.rb
@@ -0,0 +1,47 @@
+require 'spec_helper'
+
+describe 'nginx', :type => :class do
+ let(:facts) {{
+ :lsbdistrelease => 'ubuntu',
+ :lsbdistid => 'trusty'
+ }}
+
+ context 'with ensure => present' do
+ let(:params) { { :ensure => 'present' } }
+
+ it 'should install nginx packages' do
+ should contain_package('nginx-common').with({'ensure' => 'present'})
+ should contain_package('nginx-full').with({'ensure' => 'present'})
+ end
+
+ it 'should ensure that nginx service is started' do
+ should contain_service('nginx').with({'ensure' => 'running'})
+ end
+
+ it 'should ensure that nginx configuration directories exist' do
+ should contain_file('/etc/nginx/conf.d').with({'ensure' => 'directory'})
+ should contain_file('/etc/nginx/sites-available').with({'ensure' =>
'directory'})
+ should contain_file('/etc/nginx/sites-enabled').with({'ensure' =>
'directory'})
+ end
+ end
+
+ context 'with ensure => absent' do
+ let(:params) { { :ensure => 'absent' } }
+
+ it 'should remove nginx packages' do
+ should contain_package('nginx-common').with({'ensure' => 'absent'})
+ should contain_package('nginx-full').with({'ensure' => 'absent'})
+ end
+
+ it 'should ensure that nginx service is stopped' do
+ should contain_service('nginx').with({'ensure' => 'stopped'})
+ end
+
+ it 'should ensure that nginx configuration directories are removed' do
+ should contain_file('/etc/nginx/conf.d').with({'ensure' => 'absent'})
+ should contain_file('/etc/nginx/sites-available').with({'ensure' =>
'absent'})
+ should contain_file('/etc/nginx/sites-enabled').with({'ensure' =>
'absent'})
+ end
+ end
+
+end
diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/spec/fixtures/manifests/site.pp
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..7036cf5
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,13 @@
+require 'puppet'
+require 'rspec'
+require 'rspec-puppet'
+
+def param_value(subject, type, title, param)
+ subject.resource(type, title).send(:parameters)[param.to_sym]
+end
+
+RSpec.configure do |c|
+ c.module_path = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
+ # Using an empty site.pp file to avoid:
https://github.com/rodjek/rspec-puppet/issues/15
+ c.manifest_dir = File.expand_path(File.join(File.dirname(__FILE__),
'fixtures/manifests'))
+end
--
To view, visit https://gerrit.wikimedia.org/r/277476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf6e0247e5a4443373d9e9180eff0c0e80f469f0
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet/nginx
Gerrit-Branch: master
Gerrit-Owner: Gehel <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits