summaryrefslogtreecommitdiffstats
path: root/build/patches/puppet-neutron-add-sfc.patch
blob: 2e5246d3a56bf67ebfa6fe6d616219613185264b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
From eb10444f029efae83dbb2cae5f161447f033be6a Mon Sep 17 00:00:00 2001
From: Tim Rozet <trozet@redhat.com>
Date: Tue, 1 Aug 2017 12:41:22 -0400
Subject: [PATCH] Adds support for networking-sfc

Implements: blueprint networking-sfc-support

Change-Id: I09ce12298caee6fb2194240f2e19b4771ab797b0
Signed-off-by: Tim Rozet <trozet@redhat.com>
---
 .../neutron_sfc_service_config/openstackconfig.rb  | 15 ++++
 lib/puppet/type/neutron_sfc_service_config.rb      | 36 ++++++++
 manifests/config.pp                                |  6 ++
 manifests/deps.pp                                  |  1 +
 manifests/params.pp                                |  1 +
 manifests/services/sfc.pp                          | 90 ++++++++++++++++++++
 .../notes/add_sfc_support-dc48691618415e97.yaml    |  4 +
 spec/classes/neutron_services_sfc_spec.rb          | 96 ++++++++++++++++++++++
 .../openstackconfig_spec.rb                        | 74 +++++++++++++++++
 spec/unit/type/neutron_sfc_service_config_spec.rb  | 20 +++++
 10 files changed, 343 insertions(+)
 create mode 100644 lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
 create mode 100644 lib/puppet/type/neutron_sfc_service_config.rb
 create mode 100644 manifests/services/sfc.pp
 create mode 100644 releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
 create mode 100644 spec/classes/neutron_services_sfc_spec.rb
 create mode 100644 spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
 create mode 100644 spec/unit/type/neutron_sfc_service_config_spec.rb

diff --git a/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb b/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
new file mode 100644
index 0000000..088f147
--- /dev/null
+++ b/lib/puppet/provider/neutron_sfc_service_config/openstackconfig.rb
@@ -0,0 +1,15 @@
+Puppet::Type.type(:neutron_sfc_service_config).provide(
+  :openstackconfig,
+  :parent => Puppet::Type.type(:openstack_config).provider(:ruby)
+) do
+
+  def self.file_path
+    '/etc/neutron/networking_sfc.conf'
+  end
+
+  # added for backwards compatibility with older versions of inifile
+  def file_path
+    self.class.file_path
+  end
+
+end
diff --git a/lib/puppet/type/neutron_sfc_service_config.rb b/lib/puppet/type/neutron_sfc_service_config.rb
new file mode 100644
index 0000000..05aef99
--- /dev/null
+++ b/lib/puppet/type/neutron_sfc_service_config.rb
@@ -0,0 +1,36 @@
+Puppet::Type.newtype(:neutron_sfc_service_config) do
+
+  ensurable
+
+  newparam(:name, :namevar => true) do
+    desc 'Section/setting name to manage from networking_sfc.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
+      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 ['python-networking-sfc'] end
+
+end
diff --git a/manifests/config.pp b/manifests/config.pp
index 9237493..491a572 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -36,6 +36,9 @@
 # [*l2gw_service_config*]
 #   (optional) Manage configuration of l2gw_plugin.ini
 #
+# [*sfc_service_config*]
+#   (optional) Manage configuration of networking_bgpvpn.conf
+#
 # [*l3_agent_config*]
 #   (optional) Manage configuration of l3_agent.ini
 #
@@ -93,6 +96,7 @@ class neutron::config (
   $bgpvpn_service_config         = {},
   $l2gw_agent_config             = {},
   $l2gw_service_config           = {},
+  $sfc_service_config         = {},
   $l3_agent_config               = {},
   $dhcp_agent_config             = {},
   $lbaas_agent_config            = {},
@@ -118,6 +122,7 @@ class neutron::config (
   validate_hash($bgpvpn_service_config)
   validate_hash($l2gw_agent_config)
   validate_hash($l2gw_service_config)
+  validate_hash($sfc_service_config)
   validate_hash($l3_agent_config)
   validate_hash($dhcp_agent_config)
   validate_hash($lbaas_agent_config)
@@ -139,6 +144,7 @@ class neutron::config (
   create_resources('neutron_api_config', $api_config)
   create_resources('neutron_bgpvpn_service_config', $bgpvpn_service_config)
   create_resources('neutron_l2gw_agent_config', $l2gw_agent_config)
+  create_resources('neutron_sfc_service_config', $sfc_service_config)
   create_resources('neutron_l3_agent_config', $l3_agent_config)
   create_resources('neutron_dhcp_agent_config', $dhcp_agent_config)
   create_resources('neutron_lbaas_agent_config', $lbaas_agent_config)
diff --git a/manifests/deps.pp b/manifests/deps.pp
index 38bb664..5b55830 100644
--- a/manifests/deps.pp
+++ b/manifests/deps.pp
@@ -39,6 +39,7 @@ class neutron::deps {
   Anchor['neutron::config::begin'] -> Neutron_api_config<||> ~> Anchor['neutron::config::end']
   Anchor['neutron::config::begin'] -> Neutron_api_paste_ini<||> ~> Anchor['neutron::config::end']
   Anchor['neutron::config::begin'] -> Neutron_bgpvpn_service_config<||> ~> Anchor['neutron::config::end']
+  Anchor['neutron::config::begin'] -> Neutron_sfc_service_config<||> ~> Anchor['neutron::config::end']
   Anchor['neutron::config::begin'] -> Neutron_config<||> ~> Anchor['neutron::config::end']
   Anchor['neutron::config::begin'] -> Neutron_dhcp_agent_config<||> ~> Anchor['neutron::config::end']
   Anchor['neutron::config::begin'] -> Neutron_fwaas_service_config<||> ~> Anchor['neutron::config::end']
diff --git a/manifests/params.pp b/manifests/params.pp
index 55321b7..1439551 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -30,6 +30,7 @@ class neutron::params {
   $l3_agent_service            = 'neutron-l3-agent'
   $metadata_agent_service      = 'neutron-metadata-agent'
   $bgpvpn_plugin_package       = 'python-networking-bgpvpn'
+  $sfc_package          = 'python-networking-sfc'
   $l2gw_agent_service          = 'neutron-l2gw-agent'
 
   if($::osfamily == 'Redhat') {
diff --git a/manifests/services/sfc.pp b/manifests/services/sfc.pp
new file mode 100644
index 0000000..2995f18
--- /dev/null
+++ b/manifests/services/sfc.pp
@@ -0,0 +1,90 @@
+#
+# Copyright (C) 2017 Red Hat Inc.
+#
+# Author: Bernard Cafarelli <bcafarel@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::sfc
+#
+# Configure the Service Function Chaining Neutron extension
+#
+# === Parameters:
+#
+# [*package_ensure*]
+#   Whether to install the bgpvpn service package
+#   Default to 'present'
+#
+# [*sfc_driver*]
+#   (optional) SFC driver to use
+#   Defaults to $::os_service_default
+#
+# [*fc_driver*]
+#   (optional) Flow classifier driver to use
+#   Defaults to $::os_service_default
+#
+# [*sync_db*]
+#   Whether 'sfc-db-sync' should run to create and/or synchronize the
+#   database with networking-sfc specific tables. Default to false
+#
+# [*purge_config*]
+#   (optional) Whether to set only the specified config options
+#   in the sfc config.
+#   Default to false.
+#
+class neutron::services::sfc (
+  $package_ensure    = 'present',
+  $sfc_driver        = $::os_service_default,
+  $fc_driver         = $::os_service_default,
+  $sync_db           = false,
+  $purge_config      = false,
+) {
+
+  include ::neutron::deps
+  include ::neutron::params
+
+  ensure_resource( 'package', $::neutron::params::sfc_package, {
+    ensure => $package_ensure,
+    name   => $::neutron::params::sfc_package,
+    tag    => ['openstack', 'neutron-package'],
+  })
+
+  neutron_sfc_service_config {
+      'sfc/drivers':              value => $sfc_driver;
+      'flowclassifier/drivers':   value => $fc_driver;
+  }
+
+  resources { 'neutron_sfc_service_config':
+    purge => $purge_config,
+  }
+
+  neutron_config {
+    'sfc/drivers':            value => $sfc_driver;
+    'flowclassifier/drivers': value => $fc_driver;
+  }
+
+  if $sync_db {
+    Package<| title == $::neutron::params::sfc_package |> ~> Exec['sfc-db-sync']
+    exec { 'sfc-db-sync':
+      command     => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --subproject networking-sfc upgrade head',
+      path        => '/usr/bin',
+      subscribe   => [
+        Anchor['neutron::install::end'],
+        Anchor['neutron::config::end'],
+        Anchor['neutron::dbsync::begin']
+      ],
+      notify      => Anchor['neutron::dbsync::end'],
+      refreshonly => true
+    }
+  }
+}
diff --git a/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml b/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
new file mode 100644
index 0000000..bdac2df
--- /dev/null
+++ b/releasenotes/notes/add_sfc_support-dc48691618415e97.yaml
@@ -0,0 +1,4 @@
+---
+features:
+  - Adds ability to configure networking-sfc neutron
+    service.
diff --git a/spec/classes/neutron_services_sfc_spec.rb b/spec/classes/neutron_services_sfc_spec.rb
new file mode 100644
index 0000000..1a365b2
--- /dev/null
+++ b/spec/classes/neutron_services_sfc_spec.rb
@@ -0,0 +1,96 @@
+# Copyright (C) 2017 Red Hat Inc.
+#
+# Author: Tim Rozet <trozet@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.
+
+require 'spec_helper'
+
+describe 'neutron::services::sfc' do
+
+  let :default_params do
+    { :package_ensure => 'present',
+      :sfc_driver     => '<SERVICE DEFAULT>',
+      :fc_driver     => '<SERVICE DEFAULT>',
+      :sync_db        => true,
+    }
+  end
+
+  shared_examples_for 'neutron sfc service plugin' do
+
+    context 'with default params' do
+      let :params do
+        default_params
+      end
+
+      it 'installs sfc package' do
+        is_expected.to contain_package('python-networking-sfc').with(
+          :ensure => params[:package_ensure],
+          :name   => platform_params[:sfc_package_name],
+        )
+      end
+
+      it 'runs neutron-db-sync' do
+        is_expected.to contain_exec('sfc-db-sync').with(
+          :command     => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --subproject networking-sfc upgrade head',
+          :path        => '/usr/bin',
+          :subscribe   => ['Anchor[neutron::install::end]',
+                           'Anchor[neutron::config::end]',
+                           'Anchor[neutron::dbsync::begin]'
+                           ],
+          :notify      => 'Anchor[neutron::dbsync::end]',
+          :refreshonly => 'true',
+        )
+      end
+    end
+
+    context 'with sfc and classifier drivers' do
+      let :params do
+        default_params.merge(
+          { :sfc_driver => 'odl_v2',
+            :fc_driver  => 'odl_v2'
+          }
+        )
+      end
+
+      it 'configures networking_sfc.conf' do
+        is_expected.to contain_neutron_sfc_service_config(
+          'DEFAULT/sfc_driver'
+        ).with_value('odl_v2')
+        is_expected.to contain_neutron_sfc_service_config(
+          'DEFAULT/fc_driver'
+        ).with_value('odl_v2')
+      end
+    end
+  end
+
+  on_supported_os({
+    :supported_os   => OSDefaults.get_supported_os
+  }).each do |os,facts|
+    context "on #{os}" do
+      let (:facts) do
+        facts.merge(OSDefaults.get_facts())
+      end
+
+      let (:platform_params) do
+        case facts[:osfamily]
+        when 'RedHat'
+          { :sfc_package_name => 'python-networking-sfc' }
+        when 'Debian'
+          { :sfc_package_name => 'python-networking-sfc' }
+        end
+      end
+      it_configures 'neutron sfc service plugin'
+    end
+  end
+end
diff --git a/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb b/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
new file mode 100644
index 0000000..e7f684b
--- /dev/null
+++ b/spec/unit/provider/neutron_sfc_service_config/openstackconfig_spec.rb
@@ -0,0 +1,74 @@
+$LOAD_PATH.push(
+  File.join(
+    File.dirname(__FILE__),
+    '..',
+    '..',
+    '..',
+    'fixtures',
+    'modules',
+    'inifile',
+    'lib')
+)
+$LOAD_PATH.push(
+  File.join(
+    File.dirname(__FILE__),
+    '..',
+    '..',
+    '..',
+    'fixtures',
+    'modules',
+    'openstacklib',
+    'lib')
+)
+
+require 'spec_helper'
+
+provider_class = Puppet::Type.type(:neutron_sfc_service_config).provider(:openstackconfig)
+
+describe provider_class do
+
+  it 'should default to the default setting when no other one is specified' do
+    resource = Puppet::Type::Neutron_sfc_service_config.new(
+      {
+        :name => 'DEFAULT/foo',
+        :value => 'bar'
+      }
+    )
+    provider = provider_class.new(resource)
+    expect(provider.section).to eq('DEFAULT')
+    expect(provider.setting).to eq('foo')
+    expect(provider.file_path).to eq('/etc/neutron/networking_sfc.conf')
+  end
+
+  it 'should allow setting to be set explicitly' do
+    resource = Puppet::Type::Neutron_sfc_service_config.new(
+      {
+        :name => 'dude/foo',
+        :value => 'bar'
+      }
+    )
+    provider = provider_class.new(resource)
+    expect(provider.section).to eq('dude')
+    expect(provider.setting).to eq('foo')
+    expect(provider.file_path).to eq('/etc/neutron/networking_sfc.conf')
+  end
+
+  it 'should ensure absent when <SERVICE DEFAULT> is specified as a value' do
+    resource = Puppet::Type::Neutron_sfc_service_config.new(
+      {:name => 'dude/foo', :value => '<SERVICE DEFAULT>'}
+    )
+    provider = provider_class.new(resource)
+    provider.exists?
+    expect(resource[:ensure]).to eq :absent
+  end
+
+  it 'should ensure absent when value matches ensure_absent_val' do
+    resource = Puppet::Type::Neutron_sfc_service_config.new(
+      {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' }
+    )
+    provider = provider_class.new(resource)
+    provider.exists?
+    expect(resource[:ensure]).to eq :absent
+  end
+
+end
diff --git a/spec/unit/type/neutron_sfc_service_config_spec.rb b/spec/unit/type/neutron_sfc_service_config_spec.rb
new file mode 100644
index 0000000..d0a0899
--- /dev/null
+++ b/spec/unit/type/neutron_sfc_service_config_spec.rb
@@ -0,0 +1,20 @@
+require 'puppet'
+require 'puppet/type/neutron_sfc_service_config'
+
+describe 'Puppet::Type.type(:neutron_sfc_service_config)' do
+
+  before :each do
+    @neutron_sfc_service_config = Puppet::Type.type(:neutron_sfc_service_config).new(:name => 'DEFAULT/foo', :value => 'bar')
+  end
+
+  it 'should autorequire the package that install the file' do
+    catalog = Puppet::Resource::Catalog.new
+    package = Puppet::Type.type(:package).new(:name => 'python-networking-sfc')
+    catalog.add_resource package, @neutron_sfc_service_config
+    dependency = @neutron_sfc_service_config.autorequire
+    expect(dependency.size).to eq(1)
+    expect(dependency[0].target).to eq(@neutron_sfc_service_config)
+    expect(dependency[0].source).to eq(package)
+  end
+
+end
-- 
2.9.4