Add tests for tripleo::keepalived

This change adds test coverage for the tripleo::keepalived class
and exposes the ability to pass network_vips as a parameter rather than
just via hiera.

Change-Id: Ied2f26f6bfdcd9c4fe85f08461b997c15c66345f
This commit is contained in:
Alex Schultz 2018-02-06 16:30:22 -07:00
parent 2fca306c13
commit e083f248a9
4 changed files with 230 additions and 4 deletions

View File

@ -77,3 +77,7 @@ mod 'collectd',
:git => 'https://github.com/voxpupuli/puppet-collectd',
:ref => 'master'
# see https://github.com/rdo-packages/puppet-keepalived-distgit/blob/rpm-master/puppet-keepalived.spec
mod 'keepalived',
:git => 'https://github.com/Unyonsys/puppet-module-keepalived',
:ref => 'bbca37ade629a9178f09366fd0368187fb645f4e'

View File

@ -74,8 +74,12 @@
# be used to override the distro defaults in this module.
# Defaults to false.
#
# [*network_vips*]
# A hash of networks with related ip address information.
# Example:
# { 'internal_api' => { 'ip_address' => '10.0.0.1', 'index' => 1' } }
# Defaults to hiera('network_virtual_ips', {})
#
class tripleo::keepalived (
$controller_virtual_ip,
$control_virtual_interface,
@ -84,11 +88,12 @@ class tripleo::keepalived (
$redis_virtual_ip = false,
$ovndbs_virtual_ip = false,
$virtual_router_id_base = 50,
$custom_vrrp_script = false,
$network_vips = hiera('network_virtual_ips', {}),
# DEPRECATED PARAMETERS
$internal_api_virtual_ip = false,
$storage_virtual_ip = false,
$storage_mgmt_virtual_ip = false,
$custom_vrrp_script = false,
) {
case $::osfamily {
@ -171,7 +176,6 @@ class tripleo::keepalived (
$last_fixed_vrouter_id = $virtual_router_id_base + 4
# Set up all vips for isolated networks, the vrouter id is based on a sequential index
$network_vips = hiera('network_virtual_ips', {})
$network_vips.each |String $net_name, $vip_info| {
$virtual_ip = $vip_info[ip_address]
if $virtual_ip and $virtual_ip != $controller_virtual_ip {

View File

@ -0,0 +1,9 @@
---
other:
- |
Added unit test for tripleo::keepalived class.
- |
Added network_vips parameter to the tripleo::keepalived class where
previously it was only exposed via the network_virtual_ips hiera data key.
The new parameter still uses the network_virtual_ips hiera data for the
default value or falls back to an empty hash.

View File

@ -0,0 +1,209 @@
#
# Copyright (C) 2018 Red Hat, Inc.
#
# 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'
require 'puppet'
describe 'tripleo::keepalived' do
shared_examples_for 'tripleo::keeplived' do
before(:each) do
# mock interface_for_ip function
Puppet::Parser::Functions.newfunction(:interface_for_ip, :type => :rvalue) do |arg|
return 'br-foo'
end
end
let :default_params do
{
:controller_virtual_ip => '10.0.0.1',
:control_virtual_interface => 'eth0',
:public_virtual_interface => 'eth1',
:public_virtual_ip => '192.168.0.1',
}
end
context 'with defaults' do
let :params do
default_params
end
it {
is_expected.to contain_class('keepalived')
is_expected.to contain_keepalived__vrrp_script('haproxy').with(
:name_is_process => platform_params[:name_is_process],
:script => platform_params[:vrrp_script]
)
is_expected.to contain_keepalived__instance('51').with(
:interface => params[:control_virtual_interface],
:virtual_ips => [ "#{params[:controller_virtual_ip]} dev #{params[:control_virtual_interface]}" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
is_expected.to contain_keepalived__instance('52').with(
:interface => params[:public_virtual_interface],
:virtual_ips => [ "#{params[:public_virtual_ip]} dev #{params[:public_virtual_interface]}" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
}
end
context 'with custom vrrp script' do
let :params do
default_params.merge({
:custom_vrrp_script => 'foobar'
})
end
it {
is_expected.to contain_keepalived__vrrp_script('haproxy').with(
:name_is_process => platform_params[:name_is_process],
:script => params[:custom_vrrp_script]
)
}
end
context 'with redis virtual ipv4' do
let :params do
default_params.merge({
:redis_virtual_ip => '10.1.1.1'
})
end
it {
is_expected.to contain_keepalived__instance('53').with(
:interface => 'br-foo',
:virtual_ips => [ "#{params[:redis_virtual_ip]}/32 dev br-foo" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
}
end
context 'with redis virtual ipv6' do
let :params do
default_params.merge({
:redis_virtual_ip => 'dead:beef::1'
})
end
it {
is_expected.to contain_keepalived__instance('53').with(
:interface => 'br-foo',
:virtual_ips => [ "#{params[:redis_virtual_ip]}/64 dev br-foo" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
}
end
context 'with ovndbs virtual ip' do
let :params do
default_params.merge({
:ovndbs_virtual_ip => '10.1.1.1'
})
end
it {
is_expected.to contain_keepalived__instance('54').with(
:interface => 'br-foo',
:virtual_ips => [ "#{params[:ovndbs_virtual_ip]} dev br-foo" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
}
end
context 'with network ipv4 vips' do
let :params do
default_params.merge({
:network_vips => {
'internal_api' => { 'ip_address' => '10.1.0.1', 'index' => 1 },
'tenant' => { 'ip_address' => '10.2.0.1', 'index' => 2 }
}
})
end
it {
is_expected.to contain_class('keepalived')
is_expected.to contain_keepalived__instance('55').with(
:interface => 'br-foo',
:virtual_ips => [ "10.1.0.1/32 dev br-foo" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
is_expected.to contain_keepalived__instance('56').with(
:interface => 'br-foo',
:virtual_ips => [ "10.2.0.1/32 dev br-foo" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
}
end
context 'with network ipv6 vips' do
let :params do
default_params.merge({
:network_vips => {
'internal_api' => { 'ip_address' => 'dead:beef::1', 'index' => 1 },
}
})
end
it {
is_expected.to contain_class('keepalived')
is_expected.to contain_keepalived__instance('55').with(
:interface => 'br-foo',
:virtual_ips => [ "dead:beef::1/64 dev br-foo" ],
:state => 'MASTER',
:track_script => ['haproxy'],
:priority => 101
)
}
end
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge({})
end
let (:platform_params) do
case facts[:osfamily]
when 'RedHat'
{ :name_is_process => 'false',
:vrrp_script => 'systemctl status haproxy.service' }
when 'Debian'
{ :name_is_process => 'true',
:vrrp_script => nil }
end
end
it_behaves_like 'tripleo::keeplived'
end
end
end