LBaaSv2 support

This patch adds class for modifying LBaaS configuration in neutron_lbaas.conf

Depends-On: I619de3038cd2690bebe47cd601c085692506ac3d
Change-Id: I95cf32c3211bc4498eaa68e6e748a27dfd9af0fa
This commit is contained in:
Martin Mágr 2016-01-08 14:25:48 +01:00
parent 1d354007be
commit 567d41a349
7 changed files with 227 additions and 4 deletions

View File

@ -0,0 +1,10 @@
Puppet::Type.type(:neutron_lbaas_service_config).provide(
:openstackconfig,
:parent => Puppet::Type.type(:openstack_config).provider(:ruby)
) do
def file_path
'/etc/neutron/neutron_lbaas.conf'
end
end

View File

@ -0,0 +1,40 @@
Puppet::Type.newtype(:neutron_lbaas_service_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from neutron_lbaas.conf'
newvalues(/\S+\/\S+/)
end
newproperty(:value, :array_matching => :all) do
desc 'The value of the setting to be defined.'
def insync?(is)
return true if @should.empty?
return false unless is.is_a? Array
return false unless is.length == @should.length
# we don't care about the order of items in array, hence
# it is necessary to override insync
return (
is & @should == is or
is & @should.map(&:to_s) == is
)
end
munge do |value|
value = value.to_s.strip
value.capitalize! if value =~ /^(true|false)$/i
value
end
end
newparam(:ensure_absent_val) do
desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
defaultto('<SERVICE DEFAULT>')
end
autorequire(:package) do
'neutron-lbaas-agent'
end
end

View File

@ -87,12 +87,12 @@ class neutron::agents::lbaas (
} }
} }
Package['neutron'] -> Package['neutron-lbaas-agent'] Package['neutron'] -> Package['neutron-lbaas-agent']
package { 'neutron-lbaas-agent': ensure_resource( 'package', 'neutron-lbaas-agent', {
ensure => $package_ensure, ensure => $package_ensure,
name => $::neutron::params::lbaas_agent_package, name => $::neutron::params::lbaas_agent_package,
tag => ['openstack', 'neutron-package'], tag => ['openstack', 'neutron-package'],
} })
if $manage_service { if $manage_service {
if $enabled { if $enabled {
$service_ensure = 'running' $service_ensure = 'running'

View File

@ -0,0 +1,54 @@
#
# Copyright (C) 2015 Red Hat Inc.
#
# Author: Martin Magr <mmagr@redhat.com>
#
# 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: neutron::services::lbaas
#
# Configure the Loadbalancer as a Service Neutron Plugin
#
# === Parameters:
#
# [*package_ensure*]
# (required) Whether or not to install the LBaaS Neutron plugin package
# present
#
# [*service_providers*]
# (optional) Array of allowed service types or '<SERVICE DEFAULT>'.
# Must be in form <service_type>:<name>:<driver>[:default].
# Defaults to $::os_service_default
#
class neutron::services::lbaas (
$package_ensure = 'present',
$service_providers = $::os_service_default,
) {
include ::neutron::params
# agent package contains both agent and service resources
ensure_resource( 'package', 'neutron-lbaas-agent', {
ensure => $package_ensure,
name => $::neutron::params::lbaas_agent_package,
tag => ['openstack', 'neutron-package'],
})
if !is_service_default($service_providers) {
# default value is uncommented setting, so we should not touch it at all
neutron_lbaas_service_config { 'service_providers/service_provider':
value => $service_providers,
}
}
}

View File

@ -73,6 +73,7 @@ describe 'basic neutron' do
mechanism_drivers => ['openvswitch', 'sriovnicswitch'] mechanism_drivers => ['openvswitch', 'sriovnicswitch']
} }
class { '::neutron::agents::ml2::sriov': } class { '::neutron::agents::ml2::sriov': }
class { '::neutron::services::lbaas': }
EOS EOS

View File

@ -504,6 +504,28 @@ describe 'basic neutron_config resource' do
ensure_absent_val => 'toto', ensure_absent_val => 'toto',
} }
neutron_lbaas_service_config { 'DEFAULT/thisshouldexist' :
value => 'foo',
}
neutron_lbaas_service_config { 'DEFAULT/thisshouldexist2' :
value => '<SERVICE DEFAULT>',
ensure_absent_val => 'toto',
}
neutron_lbaas_service_config { 'DEFAULT/thisshouldexist3' :
value => ['value1', 'value2'],
}
neutron_lbaas_service_config { 'DEFAULT/thisshouldnotexist' :
value => '<SERVICE DEFAULT>',
}
neutron_lbaas_service_config { 'DEFAULT/thisshouldnotexist2' :
value => 'toto',
ensure_absent_val => 'toto',
}
EOS EOS
@ -532,7 +554,8 @@ describe 'basic neutron_config resource' do
'/etc/neutron/plugins/opencontrail/ContrailPlugin.ini', '/etc/neutron/plugins/opencontrail/ContrailPlugin.ini',
'/etc/neutron/plugins/plumgrid/plumgrid.ini', '/etc/neutron/plugins/plumgrid/plumgrid.ini',
'/etc/neutron/plugins/ml2/ml2_conf_sriov.ini', '/etc/neutron/plugins/ml2/ml2_conf_sriov.ini',
'/etc/neutron/plugins/ml2/sriov_agent.ini'] '/etc/neutron/plugins/ml2/sriov_agent.ini',
'/etc/neutron/neutron_lbaas.conf']
$neutron_files.each do |neutron_conf_file| $neutron_files.each do |neutron_conf_file|
describe file(neutron_conf_file) do describe file(neutron_conf_file) do
@ -547,5 +570,10 @@ describe 'basic neutron_config resource' do
end end
end end
describe file('/etc/neutron/neutron_lbaas.conf') do
it { is_expected.to contain('thisshouldexist3=value1') }
it { is_expected.to contain('thisshouldexist3=value2') }
end
end end
end end

View File

@ -0,0 +1,90 @@
#
# Copyright (C) 2014 Red Hat Inc.
#
# Author: Martin Magr <mmagr@redhat.com>
#
# 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 neutron::services::lbaas class
#
require 'spec_helper'
describe 'neutron::services::lbaas' do
let :default_params do
{ :package_ensure => 'present',
:service_providers => '<SERVICE_DEFAULT>'}
end
shared_examples_for 'neutron lbaas service plugin' do
context 'with default params' do
let :params do
default_params
end
it 'installs lbaas package' do
is_expected.to contain_package('neutron-lbaas-agent').with(
:ensure => params[:package_ensure],
:name => platform_params[:lbaas_package_name],
)
end
end
context 'with multiple service providers' do
let :params do
default_params.merge(
{ :service_providers => ['provider1', 'provider2'] }
)
end
it 'configures neutron_lbaas.conf' do
is_expected.to contain_neutron_lbaas_service_config(
'service_providers/service_provider'
).with_value(['provider1', 'provider2'])
end
end
end
context 'on Debian platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'Debian'
})
end
let :platform_params do
{ :lbaas_package_name => 'neutron-lbaas-agent'}
end
it_configures 'neutron lbaas service plugin'
end
context 'on Red Hat platforms' do
let :facts do
@default_facts.merge({
:osfamily => 'RedHat',
:operatingsystemrelease => '7'
})
end
let :platform_params do
{ :lbaas_package_name => 'openstack-neutron-lbaas'}
end
it_configures 'neutron lbaas service plugin'
end
end