make dkms on Debian/Ubuntu optional, add tests

Adds a parameter to turn off dkms for kernel
module.
By default the old behaviour of the modules stays.
On RedHat this parameter has no function.

Dkms Package for openvswitch are not available
on Debian newer than wheezy and Ubuntu newer
than utopic (or on backports). Which makes
the manifests fail on these systems whithout
setting dkms_ensure to false.

Add some initial rspec tests.

Change-Id: Id20ed728e9ed416ae0ff40e26d61ba3ca022355c
This commit is contained in:
Benedikt Trefzer
2015-01-30 14:13:36 +01:00
parent 58e807a42c
commit 8bdf36261b
4 changed files with 212 additions and 33 deletions

View File

@@ -1,22 +1,52 @@
# vswitch: open-vswitch
# == Class: vswitch::ovs
#
# installs openvswitch
#
# === Parameters:
#
# [*package_ensure*]
# (Optional) State of the openvswitch package
# Defaults to 'present'.
#
# [*dkms_ensure*]
# (optional) on debian/wheezy, ubuntu/precise, ubuntu/trusty and
# ubuntu/utopic dkms (Dynamic Kernel Module Support) is used to
# have a kernel module which matches the running kernel.
# In newer distributions (which ship with a newer kernel) dkms
# is not available anymore for openvswitch.
# For RedHat this parameter is ignored.
# If you like turn off dkms on Debian/Ubuntu set to
# false. defaults to true.
class vswitch::ovs(
$package_ensure = 'present'
$package_ensure = 'present',
$dkms_ensure = true,
) {
include ::vswitch::params
case $::osfamily {
'Debian': {
# OVS doesn't build unless the kernel headers are present.
$kernelheaders_pkg = "linux-headers-${::kernelrelease}"
if ! defined(Package[$kernelheaders_pkg]) {
package { $kernelheaders_pkg: ensure => $package_ensure }
if $dkms_ensure {
package { $::vswitch::params::ovs_dkms_package_name:
ensure => $package_ensure,
}
# OVS doesn't build unless the kernel headers are present.
$kernelheaders_pkg = "linux-headers-${::kernelrelease}"
if ! defined(Package[$kernelheaders_pkg]) {
package { $kernelheaders_pkg: ensure => $package_ensure }
}
exec { 'rebuild-ovsmod':
command => '/usr/sbin/dpkg-reconfigure openvswitch-datapath-dkms > /tmp/reconf-log',
creates => "/lib/modules/${::kernelrelease}/updates/dkms/openvswitch_mod.ko",
require => [Package[$::vswitch::params::ovs_dkms_package_name , $kernelheaders_pkg]],
before => Package['openvswitch-switch'],
refreshonly => true,
}
}
case $::operatingsystem {
'ubuntu': {
$ovs_status = '/sbin/status openvswitch-switch | fgrep "start/running"'
@@ -31,14 +61,7 @@ class vswitch::ovs(
name => $::vswitch::params::ovs_service_name,
hasstatus => false, # the supplied command returns true even if it's not running
# Not perfect - should spot if either service is not running - but it'll do
status => $ovs_status,
}
exec { 'rebuild-ovsmod':
command => '/usr/sbin/dpkg-reconfigure openvswitch-datapath-dkms > /tmp/reconf-log',
creates => "/lib/modules/${::kernelrelease}/updates/dkms/openvswitch_mod.ko",
require => [Package['openvswitch-datapath-dkms', $kernelheaders_pkg]],
before => Package['openvswitch-switch'],
refreshonly => true,
status => $ovs_status
}
}
'Redhat': {

View File

@@ -3,14 +3,16 @@
class vswitch::params {
case $::osfamily {
'Redhat': {
$ovs_package_name = 'openvswitch'
$ovs_service_name = 'openvswitch'
$provider = 'ovs_redhat'
$ovs_package_name = 'openvswitch'
$ovs_dkms_package_name = undef
$ovs_service_name = 'openvswitch'
$provider = 'ovs_redhat'
}
'Debian': {
$ovs_package_name = ['openvswitch-switch', 'openvswitch-datapath-dkms']
$ovs_service_name = 'openvswitch-switch'
$provider = 'ovs'
$ovs_package_name = 'openvswitch-switch'
$ovs_dkms_package_name = 'openvswitch-datapath-dkms'
$ovs_service_name = 'openvswitch-switch'
$provider = 'ovs'
}
default: {
fail " Osfamily ${::osfamily} not supported yet"

View File

@@ -2,26 +2,176 @@ require 'spec_helper'
describe 'vswitch::ovs' do
let :default_params do {
:package_ensure => 'present',
:dkms_ensure => true,
}
end
let :redhat_platform_params do {
:ovs_package_name => 'openvswitch',
:ovs_service_name => 'openvswitch',
:provider => 'ovs_redhat',
}
end
let :debian_platform_params do {
:ovs_package_name => 'openvswitch-switch',
: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 "is running"',
}
end
let :ubuntu_platform_params do {
:ovs_package_name => 'openvswitch-switch',
:ovs_dkms_package_name => 'openvswitch-datapath-dkms',
:ovs_service_name => 'openvswitch-switch',
:provider => 'ovs',
:service_hasstatus => false,
:service_status => '/sbin/status openvswitch-switch | fgrep "start/running"',
}
end
shared_examples_for 'vswitch ovs' do
it 'contains params' do
is_expected.to contain_class('vswitch::params')
end
it 'configures service' do
is_expected.to contain_service('openvswitch').with(
:ensure => true,
:enable => true,
:name => platform_params[:ovs_service_name],
:hasstatus => platform_params[:service_hasstatus],
:status => platform_params[:service_status],
)
end
it 'install package' do
is_expected.to contain_package(platform_params[:ovs_package_name]).with(
:name => platform_params[:ovs_package_name],
:ensure => params[:package_ensure],
:before => 'Service[openvswitch]'
)
end
end
shared_examples_for 'do not install dkms' do
it 'does not rebuild kernel module' do
is_expected.to_not contain_exec('rebuild-ovsmod')
end
end
shared_examples_for 'install dkms' do
it 'install kernel module' do
is_expected.to contain_package(platform_params[:ovs_dkms_package_name]).with(
:name => platform_params[:ovs_dkms_package_name],
:ensure => params[:package_ensure],
)
end
it 'rebuilds kernel module' do
is_expected.to contain_exec('rebuild-ovsmod').with(
:command => '/usr/sbin/dpkg-reconfigure openvswitch-datapath-dkms > /tmp/reconf-log',
:refreshonly => true,
)
end
end
context 'on redhat with default parameters' do
let :params do default_params end
let :facts do
{:osfamily => 'Redhat'}
end
it 'should contain the correct package and service' do
let :platform_params do redhat_platform_params end
is_expected.to contain_service('openvswitch').with(
:ensure => true,
:enable => true,
:name => 'openvswitch'
)
is_expected.to contain_package('openvswitch').with(
:name => 'openvswitch',
:ensure => 'present',
:before => 'Service[openvswitch]'
)
end
it_configures 'vswitch ovs'
it_configures 'do not install dkms'
end
context 'on redhat with parameters' do
let :params do {
:package_ensure => 'latest',
:dkms_ensure => false,
}
end
let :facts do
{:osfamily => 'Redhat'}
end
let :platform_params do redhat_platform_params end
it_configures 'vswitch ovs'
it_configures 'do not install dkms'
end
context 'on Debian with default parameters' do
let :params do default_params end
let :facts do
{:osfamily => 'Debian',
:operatingsystem => 'Debian',
}
end
let :platform_params do debian_platform_params end
it_configures 'vswitch ovs'
it_configures 'install dkms'
end
context 'on Debian with parameters' do
let :params do {
:package_ensure => 'latest',
:dkms_ensure => false,
}
end
let :facts do
{:osfamily => 'Debian',
:operatingsystem => 'Debian',
}
end
let :platform_params do debian_platform_params end
it_configures 'vswitch ovs'
it_configures 'do not install dkms'
end
context 'on Ubuntu with default parameters' do
let :params do default_params end
let :facts do
{:osfamily => 'Debian',
:operatingsystem => 'ubuntu',
}
end
let :platform_params do ubuntu_platform_params end
it_configures 'vswitch ovs'
it_configures 'install dkms'
end
context 'on Ubuntu with parameters' do
let :params do {
:package_ensure => 'latest',
:dkms_ensure => false,
}
end
let :facts do
{:osfamily => 'Debian',
:operatingsystem => 'ubuntu',
}
end
let :platform_params do ubuntu_platform_params end
it_configures 'vswitch ovs'
it_configures 'do not install dkms'
end
end

View File

@@ -1 +1,5 @@
require 'puppetlabs_spec_helper/module_spec_helper'
RSpec.configure do |c|
c.alias_it_should_behave_like_to :it_configures, 'configures'
end