diff --git a/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb b/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb new file mode 100644 index 000000000..b6b30e14b --- /dev/null +++ b/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb @@ -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 diff --git a/lib/puppet/type/neutron_lbaas_service_config.rb b/lib/puppet/type/neutron_lbaas_service_config.rb new file mode 100644 index 000000000..511fab4e1 --- /dev/null +++ b/lib/puppet/type/neutron_lbaas_service_config.rb @@ -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('') + end + + autorequire(:package) do + 'neutron-lbaas-agent' + end + +end diff --git a/manifests/agents/lbaas.pp b/manifests/agents/lbaas.pp index 25ea6024f..64434ec60 100644 --- a/manifests/agents/lbaas.pp +++ b/manifests/agents/lbaas.pp @@ -87,12 +87,12 @@ class neutron::agents::lbaas ( } } - Package['neutron'] -> Package['neutron-lbaas-agent'] - package { 'neutron-lbaas-agent': + Package['neutron'] -> Package['neutron-lbaas-agent'] + ensure_resource( 'package', 'neutron-lbaas-agent', { ensure => $package_ensure, name => $::neutron::params::lbaas_agent_package, tag => ['openstack', 'neutron-package'], - } + }) if $manage_service { if $enabled { $service_ensure = 'running' diff --git a/manifests/services/lbaas.pp b/manifests/services/lbaas.pp new file mode 100644 index 000000000..99208696d --- /dev/null +++ b/manifests/services/lbaas.pp @@ -0,0 +1,54 @@ +# +# Copyright (C) 2015 Red Hat Inc. +# +# Author: Martin Magr +# +# 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 ''. +# Must be in form ::[: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, + } + } +} diff --git a/spec/acceptance/basic_neutron_spec.rb b/spec/acceptance/basic_neutron_spec.rb index 2b17e4cd5..ba54e8a63 100644 --- a/spec/acceptance/basic_neutron_spec.rb +++ b/spec/acceptance/basic_neutron_spec.rb @@ -73,6 +73,7 @@ describe 'basic neutron' do mechanism_drivers => ['openvswitch', 'sriovnicswitch'] } class { '::neutron::agents::ml2::sriov': } + class { '::neutron::services::lbaas': } EOS diff --git a/spec/acceptance/neutron_config_spec.rb b/spec/acceptance/neutron_config_spec.rb index b4afb7b0f..3a6fe48cf 100644 --- a/spec/acceptance/neutron_config_spec.rb +++ b/spec/acceptance/neutron_config_spec.rb @@ -504,6 +504,28 @@ describe 'basic neutron_config resource' do ensure_absent_val => 'toto', } + neutron_lbaas_service_config { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + neutron_lbaas_service_config { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + neutron_lbaas_service_config { 'DEFAULT/thisshouldexist3' : + value => ['value1', 'value2'], + } + + neutron_lbaas_service_config { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + neutron_lbaas_service_config { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + EOS @@ -532,7 +554,8 @@ describe 'basic neutron_config resource' do '/etc/neutron/plugins/opencontrail/ContrailPlugin.ini', '/etc/neutron/plugins/plumgrid/plumgrid.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| describe file(neutron_conf_file) do @@ -547,5 +570,10 @@ describe 'basic neutron_config resource' do 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 diff --git a/spec/classes/neutron_services_lbaas_spec.rb b/spec/classes/neutron_services_lbaas_spec.rb new file mode 100644 index 000000000..3b280560f --- /dev/null +++ b/spec/classes/neutron_services_lbaas_spec.rb @@ -0,0 +1,90 @@ +# +# Copyright (C) 2014 Red Hat Inc. +# +# Author: Martin Magr +# +# 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 => ''} + 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