rework service and fix service for debian jessie

- use ::vswitch::params for service parameters
- on debian jessie openvswitch has now proper init scripts
  with status. This patch avoids restarting ovs on each
  puppet run on jessie.
- this patch breaks debian versions older than wheezy
  (which are not supported by debian anymore)

Change-Id: I48c81b9987935c848009b4bf3ed010c70ab1a404
Co-Authored-By:  Alex Schultz <aschultz@redhat.com>
This commit is contained in:
Benedikt Trefzer 2016-05-29 13:52:49 +02:00 committed by Alex Schultz
parent 3bf8dbb121
commit 0b1ea47ed2
4 changed files with 49 additions and 61 deletions

View File

@ -47,29 +47,6 @@ class vswitch::ovs(
}
}
case $::operatingsystem {
'Ubuntu': {
# ubuntu 16.04 doesn't have upstart
# this workaround should be removed when https://bugs.launchpad.net/ubuntu/+source/openvswitch/+bug/1585201
# will be resolved
if versioncmp($::operatingsystemmajrelease, '16') >= 0 {
$ovs_status = '/etc/init.d/openvswitch-switch status | fgrep -q "not running"; if [ $? -eq 0 ]; then exit 1; else exit 0; fi'
} else {
$ovs_status = '/sbin/status openvswitch-switch | fgrep "start/running"'
}
}
default: {
$ovs_status = '/etc/init.d/openvswitch-switch status | fgrep -q "not running"; if [ $? -eq 0 ]; then exit 1; else exit 0; fi'
}
}
service { 'openvswitch':
ensure => true,
enable => true,
name => $::vswitch::params::ovs_service_name,
hasstatus => false, # the supplied command returns true even if it's not running
status => $ovs_status,
}
if $::ovs_version {
$major_version = regsubst($::ovs_version, '^(\d+).*', '\1')
if $major_version == '1' {
@ -80,51 +57,35 @@ class vswitch::ovs(
}
}
'Redhat': {
service { 'openvswitch':
ensure => true,
enable => true,
name => $::vswitch::params::ovs_service_name,
}
}
'FreeBSD': {
Package {
provider => 'pkgng',
}
service { 'ovsdb-server':
ensure => true,
enable => true,
name => $::vswitch::params::ovsdb_service_name,
status => $::vswitch::params::ovsdb_status,
}
~>
service { 'openvswitch':
ensure => true,
enable => true,
name => $::vswitch::params::ovs_service_name,
status => $::vswitch::params::ovs_status,
}
}
'Solaris': {
service { 'ovsdb-server':
ensure => true,
enable => true,
name => $::vswitch::params::ovsdb_service_name,
status => $::vswitch::params::ovsdb_status,
}
~>
service { 'openvswitch':
ensure => true,
enable => true,
name => $::vswitch::params::ovs_service_name,
status => $::vswitch::params::ovs_status,
}
}
default: {
fail( "${::osfamily} not yet supported by puppet-vswitch")
# to appease the lint gods.
}
}
service { 'openvswitch':
ensure => true,
enable => true,
name => $::vswitch::params::ovs_service_name,
status => $::vswitch::params::ovs_status,
hasstatus => $::vswitch::params::ovs_service_hasstatus
}
if $::vswitch::params::ovsdb_service_name {
service { 'ovsdb-server':
ensure => true,
enable => true,
name => $::vswitch::params::ovsdb_service_name,
status => $::vswitch::params::ovsdb_status,
}
Service['ovsdb-server'] ~> Service['openvswitch']
}
package { $::vswitch::params::ovs_package_name:
ensure => $package_ensure,
before => Service['openvswitch'],

View File

@ -25,6 +25,30 @@ class vswitch::params {
$ovs_dkms_package_name = 'openvswitch-datapath-dkms'
$ovs_service_name = 'openvswitch-switch'
$provider = 'ovs'
case $::operatingsystem {
'ubuntu': {
# ubuntu 16.04 doesn't have upstart
# this workaround should be removed when https://bugs.launchpad.net/ubuntu/+source/openvswitch/+bug/1585201
# will be resolved
if versioncmp($::operatingsystemmajrelease, '16') >= 0 {
$ovs_status = '/etc/init.d/openvswitch-switch status | fgrep -q "not running"; if [ $? -eq 0 ]; then exit 1; else exit 0; fi'
} else {
$ovs_status = '/sbin/status openvswitch-switch | fgrep "start/running"'
}
$ovs_service_hasstatus = false
}
'debian': {
if ($::lsbdistcodename == 'wheezy') {
$ovs_service_hasstatus = false
$ovs_status = '/etc/init.d/openvswitch-switch status | fgrep -q "not running"; if [ $? -eq 0 ]; then exit 1; else exit 0; fi' # lint:ignore:140chars
} else {
$ovs_service_hasstatus = true
}
}
default: {
fail('Unsupported Debian based system')
}
}
}
'FreeBSD': {
$ovs_package_name = 'openvswitch'

View File

@ -0,0 +1,4 @@
---
fixes:
- Updates to service options for ovs when running under Debian jessie to
not restart ovs on each puppet run.

View File

@ -261,8 +261,7 @@ describe 'vswitch::ovs' do
:ovs_dkms_package_name => 'openvswitch-datapath-dkms',
:ovs_service_name => 'openvswitch-switch',
:provider => 'ovs',
:service_hasstatus => false,
:service_status => '/etc/init.d/openvswitch-switch status | fgrep -q "not running"; if [ $? -eq 0 ]; then exit 1; else exit 0; fi',
:service_hasstatus => true,
}
elsif facts[:operatingsystem] == 'Ubuntu'
{