Add unit test for tripleo::haproxy::service_endpoints

In order to get a proper unit test suits, we need to change the
separator from the "dot" to "double-semicolons".

The "." is a reserved character in YAML for hashes. In puppet world,
we commonly use "::".

Unit tests don't work if we let the "dot" separator, and apparently it's
an intended outcome with that kind of syntax.

Fact it's working in the deploy process is kind of black magic (see the
tripleo::firewall::service_rules resource for example). And the "dot"
creates something weird, as all other resources are using the standard
double-semicolon.

Change-Id: I78625a6e69f58dfb2bbad83fdd4f798cd3f4c281
Closes-Bug: 1737086
This commit is contained in:
Cédric Jeanneret 2017-12-07 07:22:11 +01:00
parent 5f635d6e56
commit 4430253701
4 changed files with 75 additions and 4 deletions

View File

@ -29,10 +29,14 @@ define tripleo::haproxy::service_endpoints ($service_name = $title) {
# This allows each composable service to load its own custom rules by
# creating its own flat hiera key named:
# tripleo.<service name with underscores>.haproxy_endpoints
$service_endpoints = hiera("tripleo.${underscore_name}.haproxy_endpoints", {})
$dots_endpoints = hiera("tripleo.${underscore_name}.haproxy_endpoints", {})
if !empty($service_endpoints) {
create_resources('tripleo::haproxy::endpoint', $service_endpoints)
}
# Supports standard "::" notation
# tripleo::<service name with underscores>::haproxy_endpoints
$colons_endpoints = hiera("tripleo::${underscore_name}::haproxy_endpoints", {})
# Merge hashes
$service_endpoints = merge($colons_endpoints, $dots_endpoints)
create_resources('tripleo::haproxy::endpoint', $service_endpoints)
}

View File

@ -0,0 +1,11 @@
---
features:
- |
Adds support for puppet standard separator notation in order to be
able to have unit tests. The "." separator notation doesn't work in
puppet-rspec, probably because "hiera" isn't called per se. This new
feature allows to get two hashes, they are merged in the definition.
fixes:
- Partly fixes `bug 1737086
<https://bugs.launchpad.net/tripleo/+bug/1737086>`__ for unit tests on
haproxy service_endpoints

View File

@ -0,0 +1,45 @@
require 'spec_helper'
describe 'tripleo::haproxy::service_endpoints' do
let :pre_condition do
'include ::haproxy'
end
shared_examples_for 'tripleo haproxy service_endpoints' do
context 'with basic parameters to configure neutron binding' do
let(:title) { 'dynamic-stuff' }
it 'should compile' do
is_expected.to compile.with_all_deps
end
it 'should configure haproxy' do
is_expected.to contain_tripleo__haproxy__endpoint('neutron')
end
end
context 'with non-existent hiera entry' do
let(:title) { 'non-existent' }
it 'should compile' do
is_expected.to compile.with_all_deps
end
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian',
:hostname => 'myhost' }
end
it_configures 'tripleo haproxy service_endpoints'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat',
:hostname => 'myhost' }
end
it_configures 'tripleo haproxy service_endpoints'
end
end

View File

@ -66,3 +66,14 @@ keystone::admin_password: 'password'
tripleo::dynamic_rules::firewall_rules:
'11-neutron':
port: 1138
# HAProxy endpoints
tripleo::dynamic_stuff::haproxy_endpoints:
neutron:
public_virtual_ip: '192.168.0.1'
internal_ip: '10.0.0.1'
service_port: 9696
ip_addresses: ['10.0.0.2', '10.0.0.3', '10.0.0.4']
server_names: ['controller1', 'controller2', 'controller3']
public_ssl_port: 19696
member_options: [ 'check', 'inter 2000', 'rise 2', 'fall 5' ]
haproxy_listen_bind_param: ['transparent']