diff --git a/manifests/worker.pp b/manifests/worker.pp new file mode 100644 index 00000000..fc4050d1 --- /dev/null +++ b/manifests/worker.pp @@ -0,0 +1,66 @@ +# +# Copyright (C) 2018 Binero +# +# Author: Tobias Urdin +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# == Class: barbican::worker +# +# Manage the barbican-worker package and service. +# +# === Parameters +# +# [*package_ensure*] +# (Optional) The state of the barbican-worker package. +# Defaults to 'present' +# +# [*manage_service*] +# (Optional) If we should manage the barbican-worker service. +# Defaults to true +# +# [*enabled*] +# (Optional) Whether to enable the barbican-worker service. +# Defaults to true +# +class barbican::worker ( + $package_ensure = 'present', + $manage_service = true, + $enabled = true, +) inherits barbican::params { + + include ::barbican::deps + + package { 'barbican-worker': + ensure => $package_ensure, + name => $::barbican::params::worker_package_name, + tag => ['openstack', 'barbican-package'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + + service { 'barbican-worker': + ensure => $service_ensure, + name => $::barbican::params::worker_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => 'barbican-service', + } + } +} diff --git a/releasenotes/notes/worker-class-a35a35e71399695f.yaml b/releasenotes/notes/worker-class-a35a35e71399695f.yaml new file mode 100644 index 00000000..17fa8b58 --- /dev/null +++ b/releasenotes/notes/worker-class-a35a35e71399695f.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Added new class barbican::worker which can be used to manage the package + and service for the barbican-worker. diff --git a/spec/classes/barbican_worker_spec.rb b/spec/classes/barbican_worker_spec.rb new file mode 100644 index 00000000..7b52fa7b --- /dev/null +++ b/spec/classes/barbican_worker_spec.rb @@ -0,0 +1,99 @@ +# +# Copyright (C) 2018 Binero +# +# Author: Tobias Urdin +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +require 'spec_helper' + +describe 'barbican::worker' do + let :params do + {} + end + + shared_examples 'barbican::worker' do + context 'with default parameters' do + it { should contain_package('barbican-worker').with( + :ensure => 'present', + :name => platform_params[:worker_package_name], + :tag => ['openstack', 'barbican-package'] + )} + + it { should contain_service('barbican-worker').with( + :ensure => 'running', + :name => platform_params[:worker_service_name], + :enable => true, + :hasstatus => true, + :hasrestart => true, + :tag => 'barbican-service' + )} + end + + context 'with package_ensure set to absent' do + before do + params.merge!( :package_ensure => 'absent' ) + end + + it { should contain_package('barbican-worker').with_ensure('absent') } + end + + context 'with manage_service set to false' do + before do + params.merge!( :manage_service => false ) + end + + it { should contain_package('barbican-worker').with_ensure('present') } + it { should_not contain_service('barbican-worker') } + end + + context 'with enabled set to false' do + before do + params.merge!( :enabled => false ) + end + + it { should contain_package('barbican-worker').with_ensure('present') } + it { should contain_service('barbican-worker').with_enable(false) } + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge(OSDefaults.get_facts()) + end + + case facts[:osfamily] + when 'RedHat' + let (:platform_params) do + { + :worker_package_name => 'openstack-barbican-worker', + :worker_service_name => 'openstack-barbican-worker' + } + end + when 'Debian' + let (:platform_params) do + { + :worker_package_name => 'barbican-worker', + :worker_service_name => 'barbican-worker' + } + end + end + + it_behaves_like 'barbican::worker' + end + end +end