Skip to content

Commit

Permalink
Merge pull request redhat-openstack#34 from ghoneycutt/add_firewall
Browse files Browse the repository at this point in the history
Add firewall
  • Loading branch information
saz committed Feb 5, 2014
2 parents d009260 + 9dc9231 commit d266757
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 18 deletions.
9 changes: 8 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
@@ -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}"
14 changes: 0 additions & 14 deletions .gemfile

This file was deleted.

5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |-
Expand All @@ -34,4 +35,4 @@ matrix:
env: PUPPET_GEM_VERSION="~> 2.6.0"
notifications:
email: false
gemfile: .gemfile
gemfile: Gemfile
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright 2011 Steffen Zieger
Copyright 2014 Garrett Honeycutt <code@garretthoneycutt.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 28 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# == Class: memcached::params
#
class memcached::params {
case $::osfamily {
'Debian': {
Expand Down
48 changes: 48 additions & 0 deletions spec/classes/memcached_spec.rb
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'rubygems'
require 'puppetlabs_spec_helper/module_spec_helper'

0 comments on commit d266757

Please sign in to comment.