Skip to content

Commit

Permalink
Add support for OpenBSD (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
buzzdeee authored May 19, 2024
1 parent 74c0aee commit c8c6fb7
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ memcached::instance{'11222':
* $install_dev = false (TRUE if 'libmemcached-dev' package should be installed)
* $processorcount = $::processorcount
* $service_restart = true (restart service after configuration changes, false to prevent restarts)
* $service_flags = '-l 127.0.0.1 -u _memcached -P /var/run/memcached.pid' (only relevant for OpenBSD, to configure the service)
* $use_sasl = false (start memcached with SASL support)
* $use_tls = false (start memcached with TLS support)
* $tls_cert_chain = undef
Expand Down
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class memcached (
Enum['present', 'latest', 'absent'] $package_ensure = 'present',
Boolean $service_manage = true,
Optional[String] $service_flags = $memcached::params::service_flags,
Optional[Stdlib::Absolutepath] $logfile = $memcached::params::logfile,
Boolean $logstdout = false,
Boolean $syslog = false,
Expand Down Expand Up @@ -98,7 +99,7 @@
}
}

if $manage_firewall {
if $facts['kernel'] == 'Linux' and $manage_firewall {
firewall { "100_tcp_${tcp_port}_for_memcached":
dport => $tcp_port,
proto => 'tcp',
Expand Down Expand Up @@ -147,6 +148,7 @@
service { $memcached::params::service_name:
ensure => $service_ensure,
enable => $service_enable,
flags => $service_flags,
hasrestart => true,
hasstatus => $memcached::params::service_hasstatus,
}
Expand Down
20 changes: 20 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$package_provider = undef
$service_name = 'memcached'
$service_hasstatus = false
$service_flags = undef
$dev_package_name = 'libmemcached-dev'
$config_file = '/etc/memcached.conf'
$config_tmpl = "${module_name}/memcached.conf.erb"
Expand All @@ -21,6 +22,7 @@
$package_provider = undef
$service_name = 'memcached'
$service_hasstatus = true
$service_flags = undef
$dev_package_name = 'libmemcached-devel'
$config_file = '/etc/sysconfig/memcached'
$config_tmpl = "${module_name}/memcached_sysconfig.erb"
Expand All @@ -35,6 +37,7 @@
$package_provider = 'chocolatey'
$service_name = 'memcached'
$service_hasstatus = true
$service_flags = undef
$dev_package_name = 'libmemcached-devel'
$config_file = undef
$config_tmpl = "${module_name}/memcached_windows.erb"
Expand All @@ -49,6 +52,7 @@
$package_provider = undef
$service_name = 'memcached'
$service_hasstatus = false
$service_flags = undef
$dev_package_name = 'libmemcached'
$config_file = undef
$config_tmpl = "${module_name}/memcached_svcprop.erb"
Expand All @@ -63,6 +67,7 @@
$package_provider = undef
$service_name = 'memcached'
$service_hasstatus = false
$service_flags = undef
$dev_package_name = 'libmemcached'
$config_file = '/etc/rc.conf.d/memcached'
$config_tmpl = "${module_name}/memcached_freebsd_rcconf.erb"
Expand All @@ -72,13 +77,28 @@
$use_registry = false
$use_svcprop = false
}
'OpenBSD': {
$package_name = 'memcached'
$package_provider = undef
$service_name = 'memcached'
$service_hasstatus = false
$service_flags = '-l 127.0.0.1 -u _memcached -P /var/run/memcached.pid'
$dev_package_name = 'libmemcached'
$config_file = undef
$config_tmpl = ''
$user = '_memcached'
$logfile = undef
$use_registry = false
$use_svcprop = false
}
default: {
case $facts['os']['name'] {
'Amazon': {
$package_name = 'memcached'
$package_provider = undef
$service_name = 'memcached'
$service_hasstatus = true
$service_flags = undef
$dev_package_name = 'libmemcached-devel'
$config_file = '/etc/sysconfig/memcached'
$config_tmpl = "${module_name}/memcached_sysconfig.erb"
Expand Down
6 changes: 6 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
},
{
"operatingsystem": "FreeBSD"
},
{
"operatingsystem": "OpenBSD",
"operatingsystemrelease": [
"7"
]
}
]
}
44 changes: 41 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
it { is_expected.not_to contain_firewall('100_tcp_11211_for_memcached') }
it { is_expected.not_to contain_firewall('100_udp_11211_for_memcached') }

context 'on OpenBSD', if: facts[:kernel] == 'OpenBSD' do
it { is_expected.not_to contain_file('/etc/sysconfig/memcached').with_ensure('file') }
it { is_expected.not_to contain_file('/var/log/memcached.log').with_ensure('file') }

it {
is_expected.to contain_service('memcached').with(
ensure: 'running',
enable: 'true',
flags: '-l 127.0.0.1 -u _memcached -P /var/run/memcached.pid'
)
}
end

context 'on RedHat', if: facts[:os]['family'] == 'RedHat' do
it { is_expected.to contain_file('/etc/sysconfig/memcached').with_ensure('file') }
end
Expand All @@ -30,13 +43,31 @@
end
end

describe 'with service_flags parameter', if: facts[:os]['family'] == 'OpenBSD' do
let(:params) { { service_flags: '-l 0.0.0.0 -u _memcached -P /var/run/memcached.pid' } }

it {
is_expected.to contain_service('memcached').with(
ensure: 'running',
enable: 'true',
flags: '-l 0.0.0.0 -u _memcached -P /var/run/memcached.pid'
)
}
end

describe 'with manage_firewall parameter' do
context 'with manage_firewall set to true and unset udp_port' do
let(:params) { { manage_firewall: true } }

it { is_expected.to contain_class('memcached') }

it { is_expected.to contain_firewall('100_tcp_11211_for_memcached') }
context 'on Linux', if: facts[:kernel] == 'Linux' do
it { is_expected.to contain_firewall('100_tcp_11211_for_memcached') }
end

context 'not on Linux', if: facts[:kernel] != 'Linux' do
it { is_expected.not_to contain_firewall('100_tcp_11211_for_memcached') }
end
end

context 'with manage_firewall set to true and udp_port set to 11211' do
Expand All @@ -49,8 +80,15 @@

it { is_expected.to contain_class('memcached') }

it { is_expected.to contain_firewall('100_tcp_11211_for_memcached') }
it { is_expected.to contain_firewall('100_udp_11211_for_memcached') }
context 'on Linux', if: facts[:kernel] == 'Linux' do
it { is_expected.to contain_firewall('100_tcp_11211_for_memcached') }
it { is_expected.to contain_firewall('100_udp_11211_for_memcached') }
end

context 'not on Linux', if: facts[:kernel] != 'Linux' do
it { is_expected.not_to contain_firewall('100_tcp_11211_for_memcached') }
it { is_expected.not_to contain_firewall('100_udp_11211_for_memcached') }
end
end
end

Expand Down
76 changes: 39 additions & 37 deletions spec/defines/instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,57 @@
facts
end

context 'with minimal params' do
let(:title) { '3489' }
if facts[:kernel] == 'Linux'
context 'with minimal params' do
let(:title) { '3489' }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('memcached::instance::servicefile') }
it { is_expected.to contain_service('[email protected]') }
it { is_expected.to contain_systemd__unit_file('[email protected]') }
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('memcached::instance::servicefile') }
it { is_expected.to contain_service('[email protected]') }
it { is_expected.to contain_systemd__unit_file('[email protected]') }

context 'on selinux', if: facts[:os]['selinux']['enabled'] == true do
it { is_expected.to contain_selinux__port('[email protected]') }
end
context 'on selinux', if: facts[:os]['selinux']['enabled'] == true do
it { is_expected.to contain_selinux__port('[email protected]') }
end

context 'without selinux', if: facts[:os]['family'] != 'RedHat' do
it { is_expected.not_to contain_selinux__port('[email protected]') }
context 'without selinux', if: facts[:os]['family'] != 'RedHat' do
it { is_expected.not_to contain_selinux__port('[email protected]') }
end
end
end

context 'with limits' do
let(:title) { '3489' }
context 'with limits' do
let(:title) { '3489' }

let :params do
{
limits: {
LimitNOFILE: 8192
let :params do
{
limits: {
LimitNOFILE: 8192
}
}
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('memcached::instance::servicefile') }
it { is_expected.to contain_service('[email protected]') }
it { is_expected.to contain_systemd__unit_file('[email protected]') }
it { is_expected.to contain_systemd__Service_limits('[email protected]') }
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('memcached::instance::servicefile') }
it { is_expected.to contain_service('[email protected]') }
it { is_expected.to contain_systemd__unit_file('[email protected]') }
it { is_expected.to contain_systemd__Service_limits('[email protected]') }
end
context 'with overrides' do
let(:title) { '3489' }

context 'with overrides' do
let(:title) { '3489' }
let :params do
{
override_content: "[Service]\nEnvironment='LISTEN=-l 0.0.0.0'"
}
end

let :params do
{
override_content: "[Service]\nEnvironment='LISTEN=-l 0.0.0.0'"
}
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('memcached::instance::servicefile') }
it { is_expected.to contain_service('[email protected]') }
it { is_expected.to contain_systemd__unit_file('[email protected]') }
it { is_expected.to contain_systemd__dropin_file('[email protected]') }
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('memcached::instance::servicefile') }
it { is_expected.to contain_service('[email protected]') }
it { is_expected.to contain_systemd__unit_file('[email protected]') }
it { is_expected.to contain_systemd__dropin_file('[email protected]') }
end
end
end
Expand Down

0 comments on commit c8c6fb7

Please sign in to comment.