diff --git a/.fixtures.yml b/.fixtures.yml index ff6d34112..21aa9ebf9 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,3 +1,10 @@ fixtures: + repositories: + 'firewall': + repo: 'git://github.com/puppetlabs/puppetlabs-firewall.git' + ref: '0.1.0' + 'stdlib': + repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git' + ref: '3.2.0' symlinks: - "memcached": "#{source_dir}" + memcached: "#{source_dir}" diff --git a/.gemfile b/.gemfile deleted file mode 100644 index e9e12704e..000000000 --- a/.gemfile +++ /dev/null @@ -1,14 +0,0 @@ -source 'https://rubygems.org' - -group :development, :test do - gem 'rake', :require => false - gem 'puppet-lint', :require => false - gem 'rspec-puppet', :require => false - gem 'puppetlabs_spec_helper', :require => false -end - -if puppetversion = ENV['PUPPET_GEM_VERSION'] - gem 'puppet', puppetversion, :require => false -else - gem 'puppet', :require => false -end diff --git a/.travis.yml b/.travis.yml index f98750476..8e14c541f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ branches: - master language: ruby bundler_args: --without development -script: bundle exec rake spec SPEC_OPTS='--format documentation' +script: 'bundle exec rake validate && bundle exec rake lint && SPEC_OPTS="--format documentation" bundle exec rake spec' after_success: - git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng - .forge-releng/publish @@ -18,6 +18,7 @@ env: - PUPPET_GEM_VERSION="~> 3.1.0" - PUPPET_GEM_VERSION="~> 3.2.0" - PUPPET_GEM_VERSION="~> 3.3.0" + - PUPPET_GEM_VERSION="~> 3.4.0" global: - PUBLISHER_LOGIN=saz - secure: |- @@ -34,4 +35,4 @@ matrix: env: PUPPET_GEM_VERSION="~> 2.6.0" notifications: email: false -gemfile: .gemfile +gemfile: Gemfile diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..0a648da6d --- /dev/null +++ b/Gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3'] +gem 'puppet', puppetversion +gem 'puppetlabs_spec_helper', '>= 0.1.0' +gem 'puppet-lint', '>= 0.3.2' +gem 'facter', '>= 1.7.0', "< 1.8.0" diff --git a/LICENSE b/LICENSE index c46e2ee1d..7c6618932 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,5 @@ Copyright 2011 Steffen Zieger + Copyright 2014 Garrett Honeycutt Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Modulefile b/Modulefile index 9039e169e..9d1a8e99a 100644 --- a/Modulefile +++ b/Modulefile @@ -6,3 +6,6 @@ license 'Apache License, Version 2.0' summary 'UNKNOWN' description 'Manage memcached via Puppet' project_page 'https://github.com/saz/puppet-memcached' + +dependency 'puppetlabs/stdlib', '>= 3.2.0' +dependency 'puppetlabs/firewall', '>= 0.1.0' diff --git a/README.md b/README.md index dceda1bf4..fda97f5d9 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ If you find this module useful, send some bitcoins to 1Na3YFUmdxKxJLiuRXQYJU2kiN * $listen_ip = '0.0.0.0' * $tcp_port = 11211 * $udp_port = 11211 +* $manage_firewall = false * $user = '' (OS specific setting, see params.pp) * $max_connections = 8192 * $verbosity = undef diff --git a/Rakefile b/Rakefile index cd3d37995..0a28d845e 100644 --- a/Rakefile +++ b/Rakefile @@ -1 +1,18 @@ +require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"] + +desc "Run puppet in noop mode and check for syntax errors." +task :validate do + Dir['manifests/**/*.pp'].each do |manifest| + sh "puppet parser validate --noop #{manifest}" + end + Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file| + sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ + end + Dir['templates/**/*.erb'].each do |template| + sh "erb -P -x -T '-' #{template} | ruby -c" + end +end diff --git a/manifests/init.pp b/manifests/init.pp index 6aac02bd7..63c19e000 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,6 +1,11 @@ -class memcached( +# == Class: memcached +# +# Manage memcached +# +class memcached ( $package_ensure = 'present', $logfile = '/var/log/memcached.log', + $manage_firewall = false, $max_memory = false, $item_size = false, $lock_memory = false, @@ -15,6 +20,14 @@ $processorcount = $::processorcount ) inherits memcached::params { + # validate type and convert string to boolean if necessary + if type($manage_firewall) == 'String' { + $manage_firewall_bool = str2bool($manage_firewall) + } else { + $manage_firewall_bool = $manage_firewall + } + validate_bool($manage_firewall_bool) + if $package_ensure == 'absent' { $service_ensure = 'stopped' } else { @@ -32,6 +45,20 @@ } } + if $manage_firewall_bool == true { + firewall { "100_tcp_${tcp_port}_for_memcached": + port => $tcp_port, + proto => 'tcp', + action => 'accept', + } + + firewall { "100_udp_${udp_port}_for_memcached": + port => $udp_port, + proto => 'udp', + action => 'accept', + } + } + file { $memcached::params::config_file: owner => 'root', group => 'root', diff --git a/manifests/params.pp b/manifests/params.pp index ee77e1e1e..c1f4b8cb6 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,3 +1,5 @@ +# == Class: memcached::params +# class memcached::params { case $::osfamily { 'Debian': { diff --git a/spec/classes/memcached_spec.rb b/spec/classes/memcached_spec.rb index a56888f96..3ab780b1b 100644 --- a/spec/classes/memcached_spec.rb +++ b/spec/classes/memcached_spec.rb @@ -1,6 +1,51 @@ require 'spec_helper' describe 'memcached' do + describe 'with manage_firewall parameter' do + ['Debian','RedHat'].each do |osfam| + context "on osfamily #{osfam}" do + let(:facts) do + { :osfamily => osfam, + :memorysize => '1000 MB', + :processorcount => '1', + } + end + + ['true',true].each do |value| + context "set to #{value}" do + let(:params) { { :manage_firewall => value } } + + it { should contain_class('memcached') } + + it { should contain_firewall('100_tcp_11211_for_memcached') } + it { should contain_firewall('100_udp_11211_for_memcached') } + end + end + + ['false',false].each do |value| + context "set to #{value}" do + let(:params) { { :manage_firewall => value } } + + it { should contain_class('memcached') } + + it { should_not contain_firewall('100_tcp_11211_for_memcached') } + it { should_not contain_firewall('100_udp_11211_for_memcached') } + end + end + + context 'set to an invalid type (array)' do + let(:params) { { :manage_firewall => ['invalid','type'] } } + + it do + expect { + should contain_class('memcached') + }.to raise_error(Puppet::Error) + end + end + end + end + end + let :default_params do { :package_ensure => 'present', @@ -74,6 +119,9 @@ it { should contain_package("memcached").with_ensure(param_hash[:package_ensure]) } + it { should_not contain_firewall('100_tcp_11211_for_memcached') } + it { should_not contain_firewall('100_udp_11211_for_memcached') } + it { if param_hash[:install_dev] should contain_package("libmemcached-dev").with_ensure(param_hash[:package_ensure]) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f56649..dc7e9f4a0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,2 @@ +require 'rubygems' require 'puppetlabs_spec_helper/module_spec_helper'