1 From eb10444f029efae83dbb2cae5f161447f033be6a Mon Sep 17 00:00:00 2001
2 From: Tim Rozet <trozet@redhat.com>
3 Date: Tue, 1 Aug 2017 12:41:22 -0400
4 Subject: [PATCH] Adds support for networking-sfc
6 Implements: blueprint networking-sfc-support
8 Change-Id: I09ce12298caee6fb2194240f2e19b4771ab797b0
9 Signed-off-by: Tim Rozet <trozet@redhat.com>
11 .../neutron_sfc_service_config/openstackconfig.rb | 15 ++++
12 lib/puppet/type/neutron_sfc_service_config.rb | 36 ++++++++
13 manifests/config.pp | 6 ++
14 manifests/deps.pp | 1 +
15 manifests/params.pp | 1 +
16 manifests/services/sfc.pp | 90 ++++++++++++++++++++
17 .../notes/add_sfc_support-dc48691618415e97.yaml | 4 +
18 spec/classes/neutron_services_sfc_spec.rb | 96 ++++++++++++++++++++++
19 .../openstackconfig_spec.rb | 74 +++++++++++++++++
20 spec/unit/type/neutron_sfc_service_config_spec.rb | 20 +++++
21 10 files changed, 343 insertions(+)
22 create mode 100644 lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
23 create mode 100644 lib/puppet/type/neutron_sfc_service_config.rb
24 create mode 100644 manifests/services/sfc.pp
25 create mode 100644 releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
26 create mode 100644 spec/classes/neutron_services_sfc_spec.rb
27 create mode 100644 spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
28 create mode 100644 spec/unit/type/neutron_sfc_service_config_spec.rb
30 diff --git a/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb b/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
32 index 0000000..088f147
34 +++ b/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
36 +Puppet::Type.type(:neutron_sfc_service_config).provide(
38 + :parent => Puppet::Type.type(:openstack_config).provider(:ruby)
42 + '/etc/neutron/networking_sfc.conf'
45 + # added for backwards compatibility with older versions of inifile
47 + self.class.file_path
51 diff --git a/lib/puppet/type/neutron_sfc_service_config.rb b/lib/puppet/type/neutron_sfc_service_config.rb
53 index 0000000..05aef99
55 +++ b/lib/puppet/type/neutron_sfc_service_config.rb
57 +Puppet::Type.newtype(:neutron_sfc_service_config) do
61 + newparam(:name, :namevar => true) do
62 + desc 'Section/setting name to manage from networking_sfc.conf'
63 + newvalues(/\S+\/\S+/)
66 + newproperty(:value, :array_matching => :all) do
67 + desc 'The value of the setting to be defined.'
69 + return true if @should.empty?
70 + return false unless is.is_a? Array
71 + return false unless is.length == @should.length
73 + is & @should == is or
74 + is & @should.map(&:to_s) == is
79 + value = value.to_s.strip
80 + value.capitalize! if value =~ /^(true|false)$/i
85 + newparam(:ensure_absent_val) do
86 + desc 'A value that is specified as the value property will behave as if ensure => absent was specified'
87 + defaultto('<SERVICE DEFAULT>')
90 + autorequire(:package) do ['python-networking-sfc'] end
93 diff --git a/manifests/config.pp b/manifests/config.pp
94 index 9237493..491a572 100644
95 --- a/manifests/config.pp
96 +++ b/manifests/config.pp
98 # [*l2gw_service_config*]
99 # (optional) Manage configuration of l2gw_plugin.ini
101 +# [*sfc_service_config*]
102 +# (optional) Manage configuration of networking_bgpvpn.conf
104 # [*l3_agent_config*]
105 # (optional) Manage configuration of l3_agent.ini
107 @@ -93,6 +96,7 @@ class neutron::config (
108 $bgpvpn_service_config = {},
109 $l2gw_agent_config = {},
110 $l2gw_service_config = {},
111 + $sfc_service_config = {},
112 $l3_agent_config = {},
113 $dhcp_agent_config = {},
114 $lbaas_agent_config = {},
115 @@ -118,6 +122,7 @@ class neutron::config (
116 validate_hash($bgpvpn_service_config)
117 validate_hash($l2gw_agent_config)
118 validate_hash($l2gw_service_config)
119 + validate_hash($sfc_service_config)
120 validate_hash($l3_agent_config)
121 validate_hash($dhcp_agent_config)
122 validate_hash($lbaas_agent_config)
123 @@ -139,6 +144,7 @@ class neutron::config (
124 create_resources('neutron_api_config', $api_config)
125 create_resources('neutron_bgpvpn_service_config', $bgpvpn_service_config)
126 create_resources('neutron_l2gw_agent_config', $l2gw_agent_config)
127 + create_resources('neutron_sfc_service_config', $sfc_service_config)
128 create_resources('neutron_l3_agent_config', $l3_agent_config)
129 create_resources('neutron_dhcp_agent_config', $dhcp_agent_config)
130 create_resources('neutron_lbaas_agent_config', $lbaas_agent_config)
131 diff --git a/manifests/deps.pp b/manifests/deps.pp
132 index 38bb664..5b55830 100644
133 --- a/manifests/deps.pp
134 +++ b/manifests/deps.pp
135 @@ -39,6 +39,7 @@ class neutron::deps {
136 Anchor['neutron::config::begin'] -> Neutron_api_config<||> ~> Anchor['neutron::config::end']
137 Anchor['neutron::config::begin'] -> Neutron_api_paste_ini<||> ~> Anchor['neutron::config::end']
138 Anchor['neutron::config::begin'] -> Neutron_bgpvpn_service_config<||> ~> Anchor['neutron::config::end']
139 + Anchor['neutron::config::begin'] -> Neutron_sfc_service_config<||> ~> Anchor['neutron::config::end']
140 Anchor['neutron::config::begin'] -> Neutron_config<||> ~> Anchor['neutron::config::end']
141 Anchor['neutron::config::begin'] -> Neutron_dhcp_agent_config<||> ~> Anchor['neutron::config::end']
142 Anchor['neutron::config::begin'] -> Neutron_fwaas_service_config<||> ~> Anchor['neutron::config::end']
143 diff --git a/manifests/params.pp b/manifests/params.pp
144 index 55321b7..1439551 100644
145 --- a/manifests/params.pp
146 +++ b/manifests/params.pp
147 @@ -30,6 +30,7 @@ class neutron::params {
148 $l3_agent_service = 'neutron-l3-agent'
149 $metadata_agent_service = 'neutron-metadata-agent'
150 $bgpvpn_plugin_package = 'python-networking-bgpvpn'
151 + $sfc_package = 'python-networking-sfc'
152 $l2gw_agent_service = 'neutron-l2gw-agent'
154 if($::osfamily == 'Redhat') {
155 diff --git a/manifests/services/sfc.pp b/manifests/services/sfc.pp
157 index 0000000..2995f18
159 +++ b/manifests/services/sfc.pp
162 +# Copyright (C) 2017 Red Hat Inc.
164 +# Author: Bernard Cafarelli <bcafarel@redhat.com>
166 +# Licensed under the Apache License, Version 2.0 (the "License"); you may
167 +# not use this file except in compliance with the License. You may obtain
168 +# a copy of the License at
170 +# http://www.apache.org/licenses/LICENSE-2.0
172 +# Unless required by applicable law or agreed to in writing, software
173 +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
174 +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
175 +# License for the specific language governing permissions and limitations
176 +# under the License.
178 +# == Class: neutron::services::sfc
180 +# Configure the Service Function Chaining Neutron extension
184 +# [*package_ensure*]
185 +# Whether to install the bgpvpn service package
186 +# Default to 'present'
189 +# (optional) SFC driver to use
190 +# Defaults to $::os_service_default
193 +# (optional) Flow classifier driver to use
194 +# Defaults to $::os_service_default
197 +# Whether 'sfc-db-sync' should run to create and/or synchronize the
198 +# database with networking-sfc specific tables. Default to false
201 +# (optional) Whether to set only the specified config options
202 +# in the sfc config.
205 +class neutron::services::sfc (
206 + $package_ensure = 'present',
207 + $sfc_driver = $::os_service_default,
208 + $fc_driver = $::os_service_default,
210 + $purge_config = false,
213 + include ::neutron::deps
214 + include ::neutron::params
216 + ensure_resource( 'package', $::neutron::params::sfc_package, {
217 + ensure => $package_ensure,
218 + name => $::neutron::params::sfc_package,
219 + tag => ['openstack', 'neutron-package'],
222 + neutron_sfc_service_config {
223 + 'sfc/drivers': value => $sfc_driver;
224 + 'flowclassifier/drivers': value => $fc_driver;
227 + resources { 'neutron_sfc_service_config':
228 + purge => $purge_config,
232 + 'sfc/drivers': value => $sfc_driver;
233 + 'flowclassifier/drivers': value => $fc_driver;
237 + Package<| title == $::neutron::params::sfc_package |> ~> Exec['sfc-db-sync']
238 + exec { 'sfc-db-sync':
239 + command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --subproject networking-sfc upgrade head',
240 + path => '/usr/bin',
242 + Anchor['neutron::install::end'],
243 + Anchor['neutron::config::end'],
244 + Anchor['neutron::dbsync::begin']
246 + notify => Anchor['neutron::dbsync::end'],
247 + refreshonly => true
251 diff --git a/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml b/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
253 index 0000000..bdac2df
255 +++ b/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
259 + - Adds ability to configure networking-sfc neutron
261 diff --git a/spec/classes/neutron_services_sfc_spec.rb b/spec/classes/neutron_services_sfc_spec.rb
263 index 0000000..1a365b2
265 +++ b/spec/classes/neutron_services_sfc_spec.rb
267 +# Copyright (C) 2017 Red Hat Inc.
269 +# Author: Tim Rozet <trozet@redhat.com>
271 +# Licensed under the Apache License, Version 2.0 (the "License");
272 +# you may not use this file except in compliance with the License.
273 +# You may obtain a copy of the License at
275 +# http://www.apache.org/licenses/LICENSE-2.0
277 +# Unless required by applicable law or agreed to in writing, software
278 +# distributed under the License is distributed on an "AS IS" BASIS,
279 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
280 +# See the License for the specific language governing permissions and
281 +# limitations under the License.
283 +require 'spec_helper'
285 +describe 'neutron::services::sfc' do
287 + let :default_params do
288 + { :package_ensure => 'present',
289 + :sfc_driver => '<SERVICE DEFAULT>',
290 + :fc_driver => '<SERVICE DEFAULT>',
295 + shared_examples_for 'neutron sfc service plugin' do
297 + context 'with default params' do
302 + it 'installs sfc package' do
303 + is_expected.to contain_package('python-networking-sfc').with(
304 + :ensure => params[:package_ensure],
305 + :name => platform_params[:sfc_package_name],
309 + it 'runs neutron-db-sync' do
310 + is_expected.to contain_exec('sfc-db-sync').with(
311 + :command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --subproject networking-sfc upgrade head',
312 + :path => '/usr/bin',
313 + :subscribe => ['Anchor[neutron::install::end]',
314 + 'Anchor[neutron::config::end]',
315 + 'Anchor[neutron::dbsync::begin]'
317 + :notify => 'Anchor[neutron::dbsync::end]',
318 + :refreshonly => 'true',
323 + context 'with sfc and classifier drivers' do
325 + default_params.merge(
326 + { :sfc_driver => 'odl_v2',
327 + :fc_driver => 'odl_v2'
332 + it 'configures networking_sfc.conf' do
333 + is_expected.to contain_neutron_sfc_service_config(
334 + 'DEFAULT/sfc_driver'
335 + ).with_value('odl_v2')
336 + is_expected.to contain_neutron_sfc_service_config(
337 + 'DEFAULT/fc_driver'
338 + ).with_value('odl_v2')
344 + :supported_os => OSDefaults.get_supported_os
345 + }).each do |os,facts|
346 + context "on #{os}" do
348 + facts.merge(OSDefaults.get_facts())
351 + let (:platform_params) do
352 + case facts[:osfamily]
354 + { :sfc_package_name => 'python-networking-sfc' }
356 + { :sfc_package_name => 'python-networking-sfc' }
359 + it_configures 'neutron sfc service plugin'
363 diff --git a/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb b/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
365 index 0000000..e7f684b
367 +++ b/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
371 + File.dirname(__FILE__),
382 + File.dirname(__FILE__),
392 +require 'spec_helper'
394 +provider_class = Puppet::Type.type(:neutron_sfc_service_config).provider(:openstackconfig)
396 +describe provider_class do
398 + it 'should default to the default setting when no other one is specified' do
399 + resource = Puppet::Type::Neutron_sfc_service_config.new(
401 + :name => 'DEFAULT/foo',
405 + provider = provider_class.new(resource)
406 + expect(provider.section).to eq('DEFAULT')
407 + expect(provider.setting).to eq('foo')
408 + expect(provider.file_path).to eq('/etc/neutron/networking_sfc.conf')
411 + it 'should allow setting to be set explicitly' do
412 + resource = Puppet::Type::Neutron_sfc_service_config.new(
414 + :name => 'dude/foo',
418 + provider = provider_class.new(resource)
419 + expect(provider.section).to eq('dude')
420 + expect(provider.setting).to eq('foo')
421 + expect(provider.file_path).to eq('/etc/neutron/networking_sfc.conf')
424 + it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
425 + resource = Puppet::Type::Neutron_sfc_service_config.new(
426 + {:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
428 + provider = provider_class.new(resource)
430 + expect(resource[:ensure]).to eq :absent
433 + it 'should ensure absent when value matches ensure_absent_val' do
434 + resource = Puppet::Type::Neutron_sfc_service_config.new(
435 + {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
437 + provider = provider_class.new(resource)
439 + expect(resource[:ensure]).to eq :absent
443 diff --git a/spec/unit/type/neutron_sfc_service_config_spec.rb b/spec/unit/type/neutron_sfc_service_config_spec.rb
445 index 0000000..d0a0899
447 +++ b/spec/unit/type/neutron_sfc_service_config_spec.rb
450 +require 'puppet/type/neutron_sfc_service_config'
452 +describe 'Puppet::Type.type(:neutron_sfc_service_config)' do
455 + @neutron_sfc_service_config = Puppet::Type.type(:neutron_sfc_service_config).new(:name => 'DEFAULT/foo', :value => 'bar')
458 + it 'should autorequire the package that install the file' do
459 + catalog = Puppet::Resource::Catalog.new
460 + package = Puppet::Type.type(:package).new(:name => 'python-networking-sfc')
461 + catalog.add_resource package, @neutron_sfc_service_config
462 + dependency = @neutron_sfc_service_config.autorequire
463 + expect(dependency.size).to eq(1)
464 + expect(dependency[0].target).to eq(@neutron_sfc_service_config)
465 + expect(dependency[0].source).to eq(package)