Skip to content

Commit

Permalink
protected-mode configuration option (Redis 3.2+) (#243)
Browse files Browse the repository at this point in the history
* protected-mode configuration option (Redis 3.2+)

* Redis 3.2 basic new config support
  • Loading branch information
Dan70402 authored and petems committed Oct 16, 2017
1 parent f540ced commit 6c28bc3
Show file tree
Hide file tree
Showing 9 changed files with 827 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
# @param [String] package_name Upstream package name.
# @param [String] pid_file Where to store the pid.
# @param [String] port Configure which port to listen on.
# @param [String] protected_mode Whether protected mode is enabled or not. Only applicable when no bind is set.
# @param [String] ppa_repo Specify upstream (Ubuntu) PPA entry.
# @param [String] rdbcompression Enable/disable compression of string objects using LZF when dumping.
# @param [String] repl_backlog_size The replication backlog size
Expand Down Expand Up @@ -186,6 +187,7 @@
$package_name = $::redis::params::package_name,
$pid_file = $::redis::params::pid_file,
$port = $::redis::params::port,
$protected_mode = $::redis::params::protected_mode,
$ppa_repo = $::redis::params::ppa_repo,
$rdbcompression = $::redis::params::rdbcompression,
$repl_backlog_size = $::redis::params::repl_backlog_size,
Expand Down
5 changes: 5 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# @param [String] notify_keyspace_events Which events to notify Pub/Sub clients about events happening
# @param [String] pid_file Where to store the pid.
# @param [String] port Configure which port to listen on.
# @param [String] protected_mode Whether protected mode is enabled or not. Only applicable when no bind is set.
# @param [String] rdbcompression Enable/disable compression of string objects using LZF when dumping.
# @param [String] repl_backlog_size The replication backlog size
# @param [String] repl_backlog_ttl The number of seconds to elapse before freeing backlog buffer
Expand Down Expand Up @@ -170,6 +171,7 @@
$managed_by_cluster_manager = $::redis::managed_by_cluster_manager,
$package_ensure = $::redis::package_ensure,
$port = $::redis::port,
$protected_mode = $::redis::protected_mode,
$rdbcompression = $::redis::rdbcompression,
$repl_backlog_size = $::redis::repl_backlog_size,
$repl_backlog_ttl = $::redis::repl_backlog_ttl,
Expand Down Expand Up @@ -331,6 +333,9 @@
/^2.8./: {
File[$redis_file_name_orig] { content => template('redis/redis.conf.2.8.erb') }
}
/^3.2./: {
File[$redis_file_name_orig] { content => template('redis/redis.conf.3.2.erb') }
}
default: {
File[$redis_file_name_orig] { content => template($conf_template) }
}
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
$notify_keyspace_events = undef
$notify_service = true
$port = 6379
$protected_mode = 'yes'
$rdbcompression = true
$requirepass = undef
$save_db_to_disk = true
Expand Down
4 changes: 4 additions & 0 deletions spec/classes/redis_centos_6_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-zipmap-entries/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^protected-mode/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^tcp-backlog/) }
end

Expand All @@ -36,6 +37,7 @@

it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-zipmap-entries/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis.conf.puppet').without('content' => /^protected-mode/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^tcp-backlog/) }
end

Expand All @@ -50,6 +52,7 @@

it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-zipmap-entries/) }
it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis.conf.puppet').without('content' => /^protected-mode/) }
it { should contain_file('/etc/redis.conf.puppet').without('content' => /^tcp-backlog/) }

end
Expand All @@ -65,6 +68,7 @@

it { should contain_file('/etc/redis.conf.puppet').without('content' => /^hash-max-zipmap-entries/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^protected-mode/) }
it { should contain_file('/etc/redis.conf.puppet').with('content' => /^tcp-backlog/) }

end
Expand Down
13 changes: 13 additions & 0 deletions spec/classes/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,19 @@
}
end

describe 'with parameter protected-mode' do
let (:params) {
{
:protected_mode => '_VALUE_'
}
}

it { is_expected.to contain_file(config_file_orig).with(
'content' => /protected-mode.*_VALUE_/
)
}
end

describe 'with parameter hll_sparse_max_bytes' do
let (:params) {
{
Expand Down
7 changes: 7 additions & 0 deletions spec/classes/redis_ubuntu_1404_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').without('content' => /^tcp-backlog/) }
it { should contain_file('/etc/redis/redis.conf.puppet').without('content' => /^protected-mode/) }

end

Expand All @@ -32,6 +33,7 @@
let (:params) { { :package_ensure => '3.2.1' } }

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^protected-mode/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^tcp-backlog/) }

end
Expand All @@ -46,6 +48,7 @@
let (:params) { { :package_ensure => '3:3.2.1' } }

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^protected-mode/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^tcp-backlog/) }

end
Expand All @@ -60,6 +63,7 @@
let (:params) { { :package_ensure => '4:4.0-rc3' } }

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').without('content' => /^protected-mode/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^tcp-backlog/) }

end
Expand All @@ -73,6 +77,7 @@
let (:params) { { :package_ensure => '4.0-rc3' } }

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').without('content' => /^protected-mode/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^tcp-backlog/) }

end
Expand All @@ -87,6 +92,7 @@

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').without('content' => /^tcp-backlog/) }
it { should contain_file('/etc/redis/redis.conf.puppet').without('content' => /^protected-mode/) }

end

Expand All @@ -100,6 +106,7 @@

it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^hash-max-ziplist-entries/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^tcp-backlog/) }
it { should contain_file('/etc/redis/redis.conf.puppet').with('content' => /^protected-mode/) }

end
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/facts/redis_server_3209_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Redis server v=3.2.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=67e0f9d6580364c0
7 changes: 7 additions & 0 deletions spec/unit/redis_server_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
expect(Facter.fact(:redis_server_version).value).to eq('2.8.19')
end

it 'is 3.2.9 according to output' do
Facter::Util::Resolution.stubs(:which).with('redis-server').returns('/usr/bin/redis-server')
redis_server_3209_version = File.read(fixtures('facts', 'redis_server_3209_version'))
Facter::Util::Resolution.stubs(:exec).with('redis-server -v').returns(redis_server_3209_version)
expect(Facter.fact(:redis_server_version).value).to eq('3.2.9')
end

it 'is empty string if redis-server not installed' do
Facter::Util::Resolution.stubs(:which).with('redis-server').returns(nil)
expect(Facter.fact(:redis_server_version).value).to eq(nil)
Expand Down
Loading

0 comments on commit 6c28bc3

Please sign in to comment.