From 2fec5ca7f617ac38bfc6d306830c9be563f14789 Mon Sep 17 00:00:00 2001 From: Matthew Black Date: Tue, 5 Apr 2016 11:59:35 -0400 Subject: [PATCH] lbaas v2 service plugin support. lbaas v2 services has to be configured for each lbaas component (Octavia, Haproxy, A10, etc). This change adds classes to configure octavia and haproxy at the service level. The lbaas agent class has been updated to install the v2 agent on debian and manage the agent services on both debian and redhat. Change-Id: I39d9a53dd18cd966818d242b8ca1d4a829d73acc Closes-Bug: 1565754 --- .../openstackconfig.rb | 2 +- .../type/neutron_lbaas_service_config.rb | 4 +- manifests/agents/lbaas.pp | 45 ++++++++++-- manifests/params.pp | 6 ++ manifests/server.pp | 2 + manifests/services/lbaas.pp | 30 ++++---- manifests/services/lbaas/haproxy.pp | 68 +++++++++++++++++++ manifests/services/lbaas/octavia.pp | 57 ++++++++++++++++ ...v2_agent_and_service-ca5e38a07566ad1e.yaml | 9 +++ spec/acceptance/basic_neutron_spec.rb | 2 + spec/acceptance/neutron_config_spec.rb | 5 +- .../neutron_services_lbaas_haproxy_spec.rb | 63 +++++++++++++++++ .../neutron_services_lbaas_octavia_spec.rb | 63 +++++++++++++++++ spec/classes/neutron_services_lbaas_spec.rb | 18 ++--- 14 files changed, 337 insertions(+), 37 deletions(-) create mode 100644 manifests/services/lbaas/haproxy.pp create mode 100644 manifests/services/lbaas/octavia.pp create mode 100644 releasenotes/notes/lbaasv2_agent_and_service-ca5e38a07566ad1e.yaml create mode 100644 spec/classes/neutron_services_lbaas_haproxy_spec.rb create mode 100644 spec/classes/neutron_services_lbaas_octavia_spec.rb diff --git a/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb b/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb index 143430c95..59721b262 100644 --- a/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb +++ b/lib/puppet/provider/neutron_lbaas_service_config/openstackconfig.rb @@ -4,7 +4,7 @@ Puppet::Type.type(:neutron_lbaas_service_config).provide( ) do def self.file_path - '/etc/neutron/neutron_lbaas.conf' + '/etc/neutron/neutron.conf' end # added for backwards compatibility with older versions of inifile diff --git a/lib/puppet/type/neutron_lbaas_service_config.rb b/lib/puppet/type/neutron_lbaas_service_config.rb index 511fab4e1..590d6fd9c 100644 --- a/lib/puppet/type/neutron_lbaas_service_config.rb +++ b/lib/puppet/type/neutron_lbaas_service_config.rb @@ -3,7 +3,7 @@ Puppet::Type.newtype(:neutron_lbaas_service_config) do ensurable newparam(:name, :namevar => true) do - desc 'Section/setting name to manage from neutron_lbaas.conf' + desc 'Section/setting name to manage from neutron.conf' newvalues(/\S+\/\S+/) end @@ -34,7 +34,7 @@ Puppet::Type.newtype(:neutron_lbaas_service_config) do end autorequire(:package) do - 'neutron-lbaas-agent' + 'neutron-server' end end diff --git a/manifests/agents/lbaas.pp b/manifests/agents/lbaas.pp index 2c9d59344..06f126082 100644 --- a/manifests/agents/lbaas.pp +++ b/manifests/agents/lbaas.pp @@ -37,6 +37,14 @@ # in the lbaas config. # Defaults to false. # +# [*enable_v1*] +# (optional) Whether to use lbaas v1 agent or not. +# Defaults to true +# +# [*enable_v2*] +# (optional) Whether to use lbaas v2 agent or not. +# Defaults to false +# class neutron::agents::lbaas ( $package_ensure = present, $enabled = true, @@ -47,6 +55,8 @@ class neutron::agents::lbaas ( $user_group = $::neutron::params::nobody_user_group, $manage_haproxy_package = true, $purge_config = false, + $enable_v1 = true, + $enable_v2 = false, ) { include ::neutron::params @@ -54,6 +64,10 @@ class neutron::agents::lbaas ( Neutron_config<||> ~> Service['neutron-lbaas-service'] Neutron_lbaas_agent_config<||> ~> Service['neutron-lbaas-service'] + if $enable_v1 and $enable_v2 { + fail('neutron agents LBaaS enable_v1 and enable_v2 parameters cannot both be true') + } + case $device_driver { /\.haproxy/: { Package <| title == $::neutron::params::haproxy_package |> -> Package <| title == 'neutron-lbaas-agent' |> @@ -86,20 +100,41 @@ class neutron::agents::lbaas ( name => $::neutron::params::lbaas_agent_package, tag => ['openstack', 'neutron-package'], }) + if $::osfamily == 'Debian' { + ensure_packages(['neutron-lbaasv2-package'], { + ensure => $package_ensure, + name => $::neutron::params::lbaasv2_agent_package, + tag => ['openstack', 'neutron-package'], + }) + Package['neutron'] -> Package['neutron-lbaasv2-package'] + } if $manage_service { - if $enabled { - $service_ensure = 'running' + if $enable_v1 { + $service_v1_ensure = 'running' + $service_v2_ensure = 'stopped' + } elsif $enable_v2 { + $service_v1_ensure = 'stopped' + $service_v2_ensure = 'running' } else { - $service_ensure = 'stopped' + $service_v1_ensure = 'stopped' + $service_v2_ensure = 'stopped' } Package['neutron'] ~> Service['neutron-lbaas-service'] Package['neutron-lbaas-agent'] ~> Service['neutron-lbaas-service'] } service { 'neutron-lbaas-service': - ensure => $service_ensure, + ensure => $service_v1_ensure, name => $::neutron::params::lbaas_agent_service, - enable => $enabled, + enable => $enable_v1, + require => Class['neutron'], + tag => 'neutron-service', + } + + service { 'neutron-lbaasv2-service': + ensure => $service_v2_ensure, + name => $::neutron::params::lbaasv2_agent_service, + enable => $enable_v2, require => Class['neutron'], tag => 'neutron-service', } diff --git a/manifests/params.pp b/manifests/params.pp index 3516bf9e7..6b8774df3 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -61,6 +61,9 @@ class neutron::params { $lbaas_agent_package = 'openstack-neutron-lbaas' $lbaas_agent_service = 'neutron-lbaas-agent' + $lbaasv2_agent_package = false + $lbaasv2_agent_service = 'neutron-lbaasv2-agent' + $haproxy_package = 'haproxy' $metering_agent_package = 'openstack-neutron-metering-agent' @@ -147,6 +150,9 @@ class neutron::params { $lbaas_agent_package = 'neutron-lbaas-agent' $lbaas_agent_service = 'neutron-lbaas-agent' + $lbaasv2_agent_package = 'neutron-lbaasv2-agent' + $lbaasv2_agent_service = 'neutron-lbaasv2-agent' + $haproxy_package = 'haproxy' $metering_agent_package = 'neutron-metering-agent' diff --git a/manifests/server.pp b/manifests/server.pp index e028f7ef7..0158d54a3 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -358,6 +358,7 @@ class neutron::server ( Neutron_config<||> ~> Service['neutron-server'] Neutron_api_config<||> ~> Service['neutron-server'] + Neutron_lbaas_service_config<||> ~> Service['neutron-server'] Class['neutron::policy'] ~> Service['neutron-server'] Neutron_config<||> -> Neutron_network<||> @@ -419,6 +420,7 @@ class neutron::server ( if ($::neutron::params::server_package) { Package['neutron-server'] -> Neutron_api_config<||> Package['neutron-server'] -> Neutron_config<||> + Package['neutron-server'] -> Neutron_lbaas_service_config<||> Package['neutron-server'] -> Service['neutron-server'] Package['neutron-server'] -> Class['neutron::policy'] package { 'neutron-server': diff --git a/manifests/services/lbaas.pp b/manifests/services/lbaas.pp index 6265d7e91..67b8bef1c 100644 --- a/manifests/services/lbaas.pp +++ b/manifests/services/lbaas.pp @@ -22,10 +22,6 @@ # # === Parameters: # -# [*package_ensure*] -# (required) Whether or not to install the LBaaS Neutron plugin package -# present -# # [*service_providers*] # (optional) Array of allowed service types or ''. # Note: The default upstream value is empty. @@ -35,24 +31,34 @@ # Must be in form ::[:default]. # Defaults to $::os_service_default # +# === Deprecated Parameters +# +# [*package_ensure*] +# (optional) Deprecated. Used to install the lbaas v2 agent. This was moved into +# neutron::agents::lbaas as the lbaas services handles scheduling of new load balancers +# Defaults to false +# class neutron::services::lbaas ( - $package_ensure = 'present', + $package_ensure = false, $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 $package_ensure { + warning('Package ensure is deprecated. The neutron::agents::lbaas class should be used to install the agent') + # 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, } + Package<| tag == 'neutron-package' |> -> Neutron_lbaas_service_config<||> } } diff --git a/manifests/services/lbaas/haproxy.pp b/manifests/services/lbaas/haproxy.pp new file mode 100644 index 000000000..587bd0271 --- /dev/null +++ b/manifests/services/lbaas/haproxy.pp @@ -0,0 +1,68 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# 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::haproxy +# +# Configure the haproxy LBaaS service provider +# +# === Parameters: +# +# [*interface_driver*] +# (optional) The driver to manage the virtual interface +# Defaults to $::os_service_default +# +# [*periodic_interval*] +# (optional) Seconds between periodic task runs +# Defaults to $::os_service_default +# +# [*loadbalancer_state_path*] +# (optional) Location to store config and state files +# Defaults to $::os_service_default +# +# [*user_group*] +# (optional) The user/group to run haproxy. +# Defaults to $::os_service_default +# +# [*send_gratuitous_arp*] +# (optional) Send gratuitous arps to flush the arp cache +# when VIP is deleted and re-added. +# Defaults to $::os_service_default +# +# [*jinja_config_template*] +# (optional) The template location to be used for haproxy. +# Defaults to $::os_service_default +# +# + +class neutron::services::lbaas::haproxy( + $interface_driver = $::os_service_default, + $periodic_interval = $::os_service_default, + $loadbalancer_state_path = $::os_service_default, + $user_group = $::os_service_default, + $send_gratuitous_arp = $::os_service_default, + $jinja_config_template = $::os_service_default +) { + + neutron_config { + 'haproxy/interface_driver': value => $interface_driver; + 'haproxy/periodic_interval': value => $periodic_interval; + 'haproxy/loadbalancer_state_path': value => $loadbalancer_state_path; + 'haproxy/user_group': value => $user_group; + 'haproxy/send_gratuitous_arp': value => $send_gratuitous_arp; + 'haproxy/jinja_config_template': value => $jinja_config_template; + } +} diff --git a/manifests/services/lbaas/octavia.pp b/manifests/services/lbaas/octavia.pp new file mode 100644 index 000000000..ba9970071 --- /dev/null +++ b/manifests/services/lbaas/octavia.pp @@ -0,0 +1,57 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# 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::octavia +# +# Configure the Octavia LBaaS service provider +# +# === Parameters: +# +# [*base_url*] +# (optional) The url endpoint for Octavia. +# Defaults to 'https://127.0.0.1:9876' +# +# [*request_poll_interval*] +# (optional) Interval in sections to poll octavia when +# entity is created, updated, or deleted +# Defaults to $::os_service_default +# +# [*request_poll_timeout*] +# (optional) Time to stop polling octavia when status +# of an entity does not change. +# Defaults to $::os_service_default +# +# [*allocates_vip*] +# (optional) Whether Octavia is responsible for allocating +# the VIP. +# Defaults to $::os_service_default +# + +class neutron::services::lbaas::octavia( + $base_url = 'http://127.0.0.1:9876', + $request_poll_interval = $::os_service_default, + $request_poll_timeout = $::os_service_default, + $allocates_vip = $::os_service_default +) { + + neutron_config { + 'octavia/base_url': value => $base_url; + 'octavia/request_poll_interval': value => $request_poll_interval; + 'octavia/request_poll_timeout': value => $request_poll_timeout; + 'octavia/allocates_vip': value => $allocates_vip; + } +} diff --git a/releasenotes/notes/lbaasv2_agent_and_service-ca5e38a07566ad1e.yaml b/releasenotes/notes/lbaasv2_agent_and_service-ca5e38a07566ad1e.yaml new file mode 100644 index 000000000..bfe345ae4 --- /dev/null +++ b/releasenotes/notes/lbaasv2_agent_and_service-ca5e38a07566ad1e.yaml @@ -0,0 +1,9 @@ +--- +features: + - Added octavia lbaas v2 services class. + - Added haproxy lbaas v2 services class. + - Added option to use either v1 or v2 agent in neutron agents lbaas. +deprecations: + - The lbaas v2 agent package ensure in neutron services lbaas + has been deprecated, the agent should be installed from + neutron agents lbaas. diff --git a/spec/acceptance/basic_neutron_spec.rb b/spec/acceptance/basic_neutron_spec.rb index 062c7a24b..20445e76c 100644 --- a/spec/acceptance/basic_neutron_spec.rb +++ b/spec/acceptance/basic_neutron_spec.rb @@ -76,6 +76,8 @@ describe 'basic neutron' do class { '::neutron::services::lbaas': service_providers => 'LOADBALANCER:Haproxy:neutron_lbaas.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default', } + class { '::neutron::services::lbaas::haproxy': } + class { '::neutron::services::lbaas::octavia': } EOS diff --git a/spec/acceptance/neutron_config_spec.rb b/spec/acceptance/neutron_config_spec.rb index c5a0a655f..ae8b81fea 100644 --- a/spec/acceptance/neutron_config_spec.rb +++ b/spec/acceptance/neutron_config_spec.rb @@ -576,8 +576,7 @@ describe 'basic neutron_config resource' do '/etc/neutron/plugins/networking-ovn/networking-ovn.ini', '/etc/neutron/plugins/plumgrid/plumgrid.ini', '/etc/neutron/plugins/ml2/ml2_conf_sriov.ini', - '/etc/neutron/plugins/ml2/sriov_agent.ini', - '/etc/neutron/neutron_lbaas.conf'] + '/etc/neutron/plugins/ml2/sriov_agent.ini'] $neutron_files.each do |neutron_conf_file| describe file(neutron_conf_file) do @@ -592,7 +591,7 @@ describe 'basic neutron_config resource' do end end - describe file('/etc/neutron/neutron_lbaas.conf') do + describe file('/etc/neutron/neutron.conf') do it { is_expected.to contain('thisshouldexist3=value1') } it { is_expected.to contain('thisshouldexist3=value2') } end diff --git a/spec/classes/neutron_services_lbaas_haproxy_spec.rb b/spec/classes/neutron_services_lbaas_haproxy_spec.rb new file mode 100644 index 000000000..e6a40b989 --- /dev/null +++ b/spec/classes/neutron_services_lbaas_haproxy_spec.rb @@ -0,0 +1,63 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# 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::haproxy class +# + +require 'spec_helper' + +describe 'neutron::services::lbaas::haproxy' do + + let :default_params do + { :interface_driver => '', + :periodic_interval => '', + :loadbalancer_state_path => '', + :user_group => '', + :send_gratuitous_arp => '', + :jinja_config_template => ''} + end + + context 'with default params' do + let :params do + default_params + end + + it 'configures haproxy service plugin' do + is_expected.to contain_neutron_config('haproxy/interface_driver').with_value('') + is_expected.to contain_neutron_config('haproxy/periodic_interval').with_value('') + is_expected.to contain_neutron_config('haproxy/loadbalancer_state_path').with_value('') + is_expected.to contain_neutron_config('haproxy/user_group').with_value('') + is_expected.to contain_neutron_config('haproxy/send_gratuitous_arp').with_value('') + is_expected.to contain_neutron_config('haproxy/jinja_config_template').with_value('') + end + end + + context 'when interface driver and gratuitous arp is set' do + let :params do + default_params.merge( + { :interface_driver => 'neutron.agent.linux.interface.OVSInterfaceDriver', + :send_gratuitous_arp => true, + } + ) + end + + it 'configures haproxy service plugin custom parameters' do + is_expected.to contain_neutron_config('haproxy/interface_driver').with_value('neutron.agent.linux.interface.OVSInterfaceDriver') + is_expected.to contain_neutron_config('haproxy/send_gratuitous_arp').with_value(true) + end + end +end diff --git a/spec/classes/neutron_services_lbaas_octavia_spec.rb b/spec/classes/neutron_services_lbaas_octavia_spec.rb new file mode 100644 index 000000000..4f03f8793 --- /dev/null +++ b/spec/classes/neutron_services_lbaas_octavia_spec.rb @@ -0,0 +1,63 @@ +# +# Copyright (C) 2016 Matthew J. Black +# +# Author: Matthew J. Black +# +# 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::octavia class +# + +require 'spec_helper' + +describe 'neutron::services::lbaas::octavia' do + + let :default_params do + { :base_url => 'http://127.0.0.1:9876', + :request_poll_interval => '', + :request_poll_timeout => '', + :allocates_vip => ''} + end + + context 'with default params' do + let :params do + default_params + end + + it 'configures octavia service plugin' do + is_expected.to contain_neutron_config('octavia/base_url').with_value('http://127.0.0.1:9876') + is_expected.to contain_neutron_config('octavia/request_poll_interval').with_value('') + is_expected.to contain_neutron_config('octavia/request_poll_timeout').with_value('') + is_expected.to contain_neutron_config('octavia/allocates_vip').with_value('') + end + end + + context 'when base_url is set' do + let :params do + default_params.merge( + { :base_url => 'http://octavia.example.org:9876', + :request_poll_interval => '3', + :request_poll_timeout => '100', + :allocates_vip => 'false' + } + ) + end + + it 'configures octavia service plugin custom parameters' do + is_expected.to contain_neutron_config('octavia/base_url').with_value('http://octavia.example.org:9876') + is_expected.to contain_neutron_config('octavia/request_poll_interval').with_value('3') + is_expected.to contain_neutron_config('octavia/request_poll_timeout').with_value('100') + is_expected.to contain_neutron_config('octavia/allocates_vip').with_value('false') + end + end +end diff --git a/spec/classes/neutron_services_lbaas_spec.rb b/spec/classes/neutron_services_lbaas_spec.rb index 3b280560f..fdd3d980c 100644 --- a/spec/classes/neutron_services_lbaas_spec.rb +++ b/spec/classes/neutron_services_lbaas_spec.rb @@ -23,8 +23,7 @@ require 'spec_helper' describe 'neutron::services::lbaas' do let :default_params do - { :package_ensure => 'present', - :service_providers => ''} + { :service_providers => ''} end shared_examples_for 'neutron lbaas service plugin' do @@ -33,13 +32,6 @@ describe 'neutron::services::lbaas' 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 @@ -49,13 +41,12 @@ describe 'neutron::services::lbaas' do ) end - it 'configures neutron_lbaas.conf' do + it 'configures neutron.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 @@ -66,7 +57,7 @@ describe 'neutron::services::lbaas' do end let :platform_params do - { :lbaas_package_name => 'neutron-lbaas-agent'} + {} end it_configures 'neutron lbaas service plugin' @@ -81,10 +72,9 @@ describe 'neutron::services::lbaas' do end let :platform_params do - { :lbaas_package_name => 'openstack-neutron-lbaas'} + {} end it_configures 'neutron lbaas service plugin' end - end