Update openstack refs to opendev
[apex.git] / build / patches / puppet-neutron-add-sfc.patch
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
5
6 Implements: blueprint networking-sfc-support
7
8 Change-Id: I09ce12298caee6fb2194240f2e19b4771ab797b0
9 Signed-off-by: Tim Rozet <trozet@redhat.com>
10 ---
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
29
30 diff --git a/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb b/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
31 new file mode 100644
32 index 0000000..088f147
33 --- /dev/null
34 +++ b/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
35 @@ -0,0 +1,15 @@
36 +Puppet::Type.type(:neutron_sfc_service_config).provide(
37 +  :openstackconfig,
38 +  :parent => Puppet::Type.type(:openstack_config).provider(:ruby)
39 +) do
40 +
41 +  def self.file_path
42 +    '/etc/neutron/networking_sfc.conf'
43 +  end
44 +
45 +  # added for backwards compatibility with older versions of inifile
46 +  def file_path
47 +    self.class.file_path
48 +  end
49 +
50 +end
51 diff --git a/lib/puppet/type/neutron_sfc_service_config.rb b/lib/puppet/type/neutron_sfc_service_config.rb
52 new file mode 100644
53 index 0000000..05aef99
54 --- /dev/null
55 +++ b/lib/puppet/type/neutron_sfc_service_config.rb
56 @@ -0,0 +1,36 @@
57 +Puppet::Type.newtype(:neutron_sfc_service_config) do
58 +
59 +  ensurable
60 +
61 +  newparam(:name, :namevar => true) do
62 +    desc 'Section/setting name to manage from networking_sfc.conf'
63 +    newvalues(/\S+\/\S+/)
64 +  end
65 +
66 +  newproperty(:value, :array_matching => :all) do
67 +    desc 'The value of the setting to be defined.'
68 +    def insync?(is)
69 +      return true if @should.empty?
70 +      return false unless is.is_a? Array
71 +      return false unless is.length == @should.length
72 +      return (
73 +        is & @should == is or
74 +        is & @should.map(&:to_s) == is
75 +      )
76 +    end
77 +
78 +    munge do |value|
79 +      value = value.to_s.strip
80 +      value.capitalize! if value =~ /^(true|false)$/i
81 +      value
82 +    end
83 +  end
84 +
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>')
88 +  end
89 +
90 +  autorequire(:package) do ['python-networking-sfc'] end
91 +
92 +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
97 @@ -36,6 +36,9 @@
98  # [*l2gw_service_config*]
99  #   (optional) Manage configuration of l2gw_plugin.ini
100  #
101 +# [*sfc_service_config*]
102 +#   (optional) Manage configuration of networking_bgpvpn.conf
103 +#
104  # [*l3_agent_config*]
105  #   (optional) Manage configuration of l3_agent.ini
106  #
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'
153  
154    if($::osfamily == 'Redhat') {
155 diff --git a/manifests/services/sfc.pp b/manifests/services/sfc.pp
156 new file mode 100644
157 index 0000000..2995f18
158 --- /dev/null
159 +++ b/manifests/services/sfc.pp
160 @@ -0,0 +1,90 @@
161 +#
162 +# Copyright (C) 2017 Red Hat Inc.
163 +#
164 +# Author: Bernard Cafarelli <bcafarel@redhat.com>
165 +#
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
169 +#
170 +#      http://www.apache.org/licenses/LICENSE-2.0
171 +#
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.
177 +#
178 +# == Class: neutron::services::sfc
179 +#
180 +# Configure the Service Function Chaining Neutron extension
181 +#
182 +# === Parameters:
183 +#
184 +# [*package_ensure*]
185 +#   Whether to install the bgpvpn service package
186 +#   Default to 'present'
187 +#
188 +# [*sfc_driver*]
189 +#   (optional) SFC driver to use
190 +#   Defaults to $::os_service_default
191 +#
192 +# [*fc_driver*]
193 +#   (optional) Flow classifier driver to use
194 +#   Defaults to $::os_service_default
195 +#
196 +# [*sync_db*]
197 +#   Whether 'sfc-db-sync' should run to create and/or synchronize the
198 +#   database with networking-sfc specific tables. Default to false
199 +#
200 +# [*purge_config*]
201 +#   (optional) Whether to set only the specified config options
202 +#   in the sfc config.
203 +#   Default to false.
204 +#
205 +class neutron::services::sfc (
206 +  $package_ensure    = 'present',
207 +  $sfc_driver        = $::os_service_default,
208 +  $fc_driver         = $::os_service_default,
209 +  $sync_db           = false,
210 +  $purge_config      = false,
211 +) {
212 +
213 +  include ::neutron::deps
214 +  include ::neutron::params
215 +
216 +  ensure_resource( 'package', $::neutron::params::sfc_package, {
217 +    ensure => $package_ensure,
218 +    name   => $::neutron::params::sfc_package,
219 +    tag    => ['openstack', 'neutron-package'],
220 +  })
221 +
222 +  neutron_sfc_service_config {
223 +      'sfc/drivers':              value => $sfc_driver;
224 +      'flowclassifier/drivers':   value => $fc_driver;
225 +  }
226 +
227 +  resources { 'neutron_sfc_service_config':
228 +    purge => $purge_config,
229 +  }
230 +
231 +  neutron_config {
232 +    'sfc/drivers':            value => $sfc_driver;
233 +    'flowclassifier/drivers': value => $fc_driver;
234 +  }
235 +
236 +  if $sync_db {
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',
241 +      subscribe   => [
242 +        Anchor['neutron::install::end'],
243 +        Anchor['neutron::config::end'],
244 +        Anchor['neutron::dbsync::begin']
245 +      ],
246 +      notify      => Anchor['neutron::dbsync::end'],
247 +      refreshonly => true
248 +    }
249 +  }
250 +}
251 diff --git a/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml b/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
252 new file mode 100644
253 index 0000000..bdac2df
254 --- /dev/null
255 +++ b/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
256 @@ -0,0 +1,4 @@
257 +---
258 +features:
259 +  - Adds ability to configure networking-sfc neutron
260 +    service.
261 diff --git a/spec/classes/neutron_services_sfc_spec.rb b/spec/classes/neutron_services_sfc_spec.rb
262 new file mode 100644
263 index 0000000..1a365b2
264 --- /dev/null
265 +++ b/spec/classes/neutron_services_sfc_spec.rb
266 @@ -0,0 +1,96 @@
267 +# Copyright (C) 2017 Red Hat Inc.
268 +#
269 +# Author: Tim Rozet <trozet@redhat.com>
270 +#
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
274 +#
275 +#   http://www.apache.org/licenses/LICENSE-2.0
276 +#
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.
282 +
283 +require 'spec_helper'
284 +
285 +describe 'neutron::services::sfc' do
286 +
287 +  let :default_params do
288 +    { :package_ensure => 'present',
289 +      :sfc_driver     => '<SERVICE DEFAULT>',
290 +      :fc_driver     => '<SERVICE DEFAULT>',
291 +      :sync_db        => true,
292 +    }
293 +  end
294 +
295 +  shared_examples_for 'neutron sfc service plugin' do
296 +
297 +    context 'with default params' do
298 +      let :params do
299 +        default_params
300 +      end
301 +
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],
306 +        )
307 +      end
308 +
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]'
316 +                           ],
317 +          :notify      => 'Anchor[neutron::dbsync::end]',
318 +          :refreshonly => 'true',
319 +        )
320 +      end
321 +    end
322 +
323 +    context 'with sfc and classifier drivers' do
324 +      let :params do
325 +        default_params.merge(
326 +          { :sfc_driver => 'odl_v2',
327 +            :fc_driver  => 'odl_v2'
328 +          }
329 +        )
330 +      end
331 +
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')
339 +      end
340 +    end
341 +  end
342 +
343 +  on_supported_os({
344 +    :supported_os   => OSDefaults.get_supported_os
345 +  }).each do |os,facts|
346 +    context "on #{os}" do
347 +      let (:facts) do
348 +        facts.merge(OSDefaults.get_facts())
349 +      end
350 +
351 +      let (:platform_params) do
352 +        case facts[:osfamily]
353 +        when 'RedHat'
354 +          { :sfc_package_name => 'python-networking-sfc' }
355 +        when 'Debian'
356 +          { :sfc_package_name => 'python-networking-sfc' }
357 +        end
358 +      end
359 +      it_configures 'neutron sfc service plugin'
360 +    end
361 +  end
362 +end
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
364 new file mode 100644
365 index 0000000..e7f684b
366 --- /dev/null
367 +++ b/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
368 @@ -0,0 +1,74 @@
369 +$LOAD_PATH.push(
370 +  File.join(
371 +    File.dirname(__FILE__),
372 +    '..',
373 +    '..',
374 +    '..',
375 +    'fixtures',
376 +    'modules',
377 +    'inifile',
378 +    'lib')
379 +)
380 +$LOAD_PATH.push(
381 +  File.join(
382 +    File.dirname(__FILE__),
383 +    '..',
384 +    '..',
385 +    '..',
386 +    'fixtures',
387 +    'modules',
388 +    'openstacklib',
389 +    'lib')
390 +)
391 +
392 +require 'spec_helper'
393 +
394 +provider_class = Puppet::Type.type(:neutron_sfc_service_config).provider(:openstackconfig)
395 +
396 +describe provider_class do
397 +
398 +  it 'should default to the default setting when no other one is specified' do
399 +    resource = Puppet::Type::Neutron_sfc_service_config.new(
400 +      {
401 +        :name => 'DEFAULT/foo',
402 +        :value => 'bar'
403 +      }
404 +    )
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')
409 +  end
410 +
411 +  it 'should allow setting to be set explicitly' do
412 +    resource = Puppet::Type::Neutron_sfc_service_config.new(
413 +      {
414 +        :name => 'dude/foo',
415 +        :value => 'bar'
416 +      }
417 +    )
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')
422 +  end
423 +
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>'}
427 +    )
428 +    provider = provider_class.new(resource)
429 +    provider.exists?
430 +    expect(resource[:ensure]).to eq :absent
431 +  end
432 +
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' }
436 +    )
437 +    provider = provider_class.new(resource)
438 +    provider.exists?
439 +    expect(resource[:ensure]).to eq :absent
440 +  end
441 +
442 +end
443 diff --git a/spec/unit/type/neutron_sfc_service_config_spec.rb b/spec/unit/type/neutron_sfc_service_config_spec.rb
444 new file mode 100644
445 index 0000000..d0a0899
446 --- /dev/null
447 +++ b/spec/unit/type/neutron_sfc_service_config_spec.rb
448 @@ -0,0 +1,20 @@
449 +require 'puppet'
450 +require 'puppet/type/neutron_sfc_service_config'
451 +
452 +describe 'Puppet::Type.type(:neutron_sfc_service_config)' do
453 +
454 +  before :each do
455 +    @neutron_sfc_service_config = Puppet::Type.type(:neutron_sfc_service_config).new(:name => 'DEFAULT/foo', :value => 'bar')
456 +  end
457 +
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)
466 +  end
467 +
468 +end
469 -- 
470 2.9.4
471