Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add possibility to force service and spec tests for service #87

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions data/Debian-family.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# Defaults for Debian os family (eg. Debian, Ubuntu etc)

prosody::service::hasstatus: ~
prosody::service::restart: ~
5 changes: 5 additions & 0 deletions data/OpenBSD-family.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# Defaults for OpenBSD os family

prosody::service::hasstatus: ~
prosody::service::restart: ~
3 changes: 3 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ prosody::community_modules::ensure: present
prosody::community_modules::path: /var/lib/prosody/modules
prosody::community_modules::source: https://hg.prosody.im/prosody-modules/
prosody::community_modules::type: hg

prosody::service::hasstatus: false
prosody::service::restart: '/usr/bin/prosodyctl reload'
3 changes: 3 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ hierarchy:
- name: "osname"
paths:
- "os/%{facts.os.name}.yaml"
- name: "osfamily"
paths:
- "%{facts.os.family}-family.yaml"
- name: common
path: common.yaml
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Optional[Stdlib::Absolutepath] $ssl_cert = undef,
Optional[Stdlib::Absolutepath] $ssl_key = undef,
Optional[String] $ssl_protocol = undef,
Optional[Boolean] $manage_service = undef,
trefzer marked this conversation as resolved.
Show resolved Hide resolved
) {
if ($community_modules != []) {
class { 'prosody::community_modules':
Expand Down
37 changes: 12 additions & 25 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
# == Class: prosody::service
class prosody::service {
if $prosody::daemonize {
case $facts['os']['family'] {
'OpenBSD': {
service { 'prosody':
ensure => running,
enable => true,
require => Class[prosody::config],
}
}
'Debian': {
service { 'prosody':
ensure => running,
enable => true,
require => Class[prosody::config],
}
}
default: {
service { 'prosody' :
ensure => running,
hasstatus => false,
restart => '/usr/bin/prosodyctl reload',
require => Class[prosody::config],
}
}
#
class prosody::service (
Optional[Boolean] $hasstatus = undef,
Optional[String] $restart = undef,
) {
if pick($prosody::manage_service, $prosody::daemonize) {
service { 'prosody':
ensure => running,
enable => true,
hasstatus => $hasstatus,
restart => $restart,
require => Class[prosody::config],
}
}
}
72 changes: 72 additions & 0 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'spec_helper'

describe 'prosody::service' do
let(:pre_condition) { 'include prosody' }

shared_examples 'prosody::service with defaults' do
it {
if facts[:os]['family'] == 'Debian'
if facts[:os]['name'] == 'Debian'
is_expected.not_to contain_service('prosody')
else
is_expected.to contain_service('prosody').
with_ensure('running').
with_enable(true).
without_hasstatus.
without_restart
end

elsif facts[:os]['family'] == 'OpenBSD'
is_expected.not_to contain_service('prosody').
with_ensure('running').
with_enable(true).
without_hasstatus.
without_restart
else
is_expected.to contain_service('prosody').
with_ensure('running').
with_hasstatus(false).
with_restart('/usr/bin/prosodyctl reload')
end
}
end

on_supported_os.each do |os, os_facts|
context "on os #{os}" do
let(:facts) do
os_facts
end

context 'with defaults' do
let(:pre_condition) { 'class {"prosody": }' }

it_behaves_like 'prosody::service with defaults'
end

context 'with manage=> true' do
let(:pre_condition) do
'class {"prosody":
manage_service => true
}'
end

it {
is_expected.to contain_service('prosody').
with_ensure('running').
with_enable(true)
}
end
context 'with manage => false' do
let(:pre_condition) do
'class {"prosody":
manage_service => false
}'
end

it {
is_expected.not_to contain_service('prosody')
}
end
end
end
end