From 45f8a57770f8b0e2c8a11bf3badfb1dde2721d78 Mon Sep 17 00:00:00 2001 From: Matthew Black Date: Thu, 21 Apr 2016 04:19:46 -0400 Subject: [PATCH] Added policy-rc.d class. On debian os family systems the methodology is to start services when installed. This causes a problem with keystone sometimes at random in CI jobs. Change-Id: Id0b38743a9bf536f69d155e1d6e664a5585e5e1d --- manifests/policyrcd.pp | 43 ++++++++++++++ ...age_policy_rc_d_file-747510db06792d52.yaml | 11 ++++ spec/classes/openstacklib_policyrcd_spec.rb | 57 +++++++++++++++++++ templates/policy-rc.d.erb | 8 +++ 4 files changed, 119 insertions(+) create mode 100644 manifests/policyrcd.pp create mode 100644 releasenotes/notes/manage_policy_rc_d_file-747510db06792d52.yaml create mode 100644 spec/classes/openstacklib_policyrcd_spec.rb create mode 100644 templates/policy-rc.d.erb diff --git a/manifests/policyrcd.pp b/manifests/policyrcd.pp new file mode 100644 index 00000000..58329923 --- /dev/null +++ b/manifests/policyrcd.pp @@ -0,0 +1,43 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# 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: openstacklib::policyrcd +# +# [*services*] +# (required) The services that should be in the policy-rc.d shell script +# that should not autostart on install. +# +class openstacklib::policyrcd( + $services +) { + + validate_array($services) + + if $::osfamily == 'Debian' { + # We put this out there so openstack services wont auto start + # when installed. + file { '/usr/sbin/policy-rc.d': + ensure => present, + content => template('openstacklib/policy-rc.d.erb'), + mode => '0755', + owner => root, + group => root, + } + + File['/usr/sbin/policy-rc.d'] -> Package<| tag == 'openstack' |> + } +} diff --git a/releasenotes/notes/manage_policy_rc_d_file-747510db06792d52.yaml b/releasenotes/notes/manage_policy_rc_d_file-747510db06792d52.yaml new file mode 100644 index 00000000..9db31c71 --- /dev/null +++ b/releasenotes/notes/manage_policy_rc_d_file-747510db06792d52.yaml @@ -0,0 +1,11 @@ +--- +features: + - Add a class that takes an array of services that can be + configured to not autostart on package install. The most + notable example is keystone. The policy-rc.d file is + generated to return the correct exit code to prevent the + services from autostarting on package install. This change + is only meant for debian based systems. +issues: + - ubuntu cloud archive keystone package is auto-starting the + eventlet process on package install. diff --git a/spec/classes/openstacklib_policyrcd_spec.rb b/spec/classes/openstacklib_policyrcd_spec.rb new file mode 100644 index 00000000..900b867f --- /dev/null +++ b/spec/classes/openstacklib_policyrcd_spec.rb @@ -0,0 +1,57 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# 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. +# +# Unit tests for openstacklib::policyrcd +# +require 'spec_helper' + +describe 'openstacklib::policyrcd' do + + let :params do + { :services => ['keystone'] + } + end + + let :test_facts do + { :operatingsystem => 'default', + :operatingsystemrelease => 'default' + } + end + + context 'on Debian platform' do + + let :facts do + @default_facts.merge(test_facts.merge( + { :osfamily => 'Debian' } + )) + end + + describe "with default value" do + + it 'creates policy-rc.d file' do + verify_contents(catalogue, '/usr/sbin/policy-rc.d', [ + '#!/bin/bash', + '', + 'if [ "$1" == "keystone" ]', + 'then', + ' exit 101', + 'fi' + ]) + end + end + end +end diff --git a/templates/policy-rc.d.erb b/templates/policy-rc.d.erb new file mode 100644 index 00000000..ca420a09 --- /dev/null +++ b/templates/policy-rc.d.erb @@ -0,0 +1,8 @@ +#!/bin/bash +<% @services.each do |service| %> +if [ "$1" == "<%= service %>" ] +then + exit 101 +fi +<% end %> +