Bug 8985 - Configure SNAT to use conntack 07/61607/7
authorJanki Chhatbar <jchhatba@redhat.com>
Mon, 14 Aug 2017 12:16:41 +0000 (17:46 +0530)
committerJanki Chhatbar <jchhatba@redhat.com>
Tue, 15 Aug 2017 12:43:28 +0000 (18:13 +0530)
Configure SNAT to use conntrack by default. controller mechanism
can be used by changing 'snat_mechanism' parameter to 'controller'.

Change-Id: I21a1f4e0ddcaa1d434cb91cb15d987a4c2c0f8b7
Signed-Off-By: Janki Chhatbar <jchhatba@redhat.com>
CHANGELOG
README.markdown
manifests/config.pp
manifests/init.pp
manifests/params.pp
metadata.json
spec/acceptance/class_spec.rb
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb
spec/spec_helper_acceptance.rb
templates/netvirt-natservice-config.xml.erb [new file with mode: 0644]

index c4b4ef056dd42da28420e901ea54d977b06eb61e..a9a7b0ba972f0194e324669776cf0a67718950a7 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -44,3 +44,5 @@
 - Move to ODL-managed repo
 2017-07-20 Release 4.1.0
 - Add log size/rotate config params
+2017-08-14 Release 4.2.0
+- Add param to config SNAT mechanism
index 978da525579f8cb2de60a215800dcff607736fa8..6a7f619429a88e97df1d2dd5e281796a86842415 100644 (file)
@@ -366,6 +366,14 @@ Default: `stateful`
 
 Valid options: `transparent`, `learn`, `stateless`
 
+##### `snat_mechanism`
+
+Specifies the mechanism to be used for SNAT.
+
+Default: `controller`
+
+Valid options: `conntrack`, `controller`
+
 ##### `vpp_routing_node`
 
 Specifies the routing node for VPP deployment. A non-empty string will create config file
index f6f837bac9e8ff7b8828b5f852a86ba8d9e3b098..2f16454c9c725a45a49678ec2fedf3e8c9f88534 100644 (file)
@@ -137,6 +137,18 @@ class opendaylight::config {
     }
   }
 
+  # Configure SNAT
+  if ('odl-netvirt-openstack' in $opendaylight::features) {
+    file { 'netvirt-natservice-config.xml':
+      ensure  => file,
+      path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
+      owner   => 'odl',
+      group   => 'odl',
+      content => template('opendaylight/netvirt-natservice-config.xml.erb'),
+      require => File['/opt/opendaylight/etc/opendaylight/datastore/initial/config'],
+    }
+  }
+
   #configure VPP routing node
   if ! empty($::opendaylight::vpp_routing_node) {
     file { 'org.opendaylight.groupbasedpolicy.neutron.vpp.mapper.startup.cfg':
index c1b96d300779fbc28fd1a8ee75228bbf884ce0f8..99bee07e5e884f8cce5d4de133966438c01bdb51 100644 (file)
@@ -42,6 +42,8 @@
 #   Maxium size of OpenDaylight's log file.
 # [*log_max_rollover*]
 #   Maxium number of OpenDaylight log rollovers to keep.
+# [*snat_mechanism*]
+#   Sets the mechanism to be used for SNAT (conntrack, controller)
 #
 # === Deprecated Parameters
 #
@@ -67,7 +69,8 @@ class opendaylight (
   $username            = $::opendaylight::params::username,
   $password            = $::opendaylight::params::password,
   $log_max_size        = $::opendaylight::params::log_max_size,
-  $log_max_rollover    = $::opendaylight::params::log_max_rollover
+  $log_max_rollover    = $::opendaylight::params::log_max_rollover,
+  $snat_mechanism      = $::opendaylight::params::snat_mechanism
 ) inherits ::opendaylight::params {
 
   # Validate OS family
index a133202ef3f683730b46bd0770f2f2b219770b3c..9c90cb8c453442fb1930eb8ecb04b47a53dff2a9 100644 (file)
@@ -27,4 +27,5 @@ class opendaylight::params {
   $password = 'admin'
   $log_max_size = '10GB'
   $log_max_rollover = 2
+  $snat_mechanism = 'controller'
 }
index 3974b227b36676209c874f09cb708865ef2a1349..a03c43e9ac42ca1c30847e9ad37b0bb73297b978 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name": "opendaylight-opendaylight",
-    "version": "4.1.0",
+    "version": "4.2.0",
     "author": "Daniel Farrell",
     "summary": "Puppet module that installs and configures the OpenDaylight SDN controller",
     "license": "BSD-2-Clause",
index c437257a31d5b4161745683b7cff698cdc25e215..db51e110a5aa53ce8794aa13419d5a035f8a0096 100644 (file)
@@ -192,4 +192,22 @@ describe 'opendaylight class' do
                             ha_node_ips: odl_ips, ha_db_modules: db_modules)
     end
   end
+
+  describe 'testing configuring SNAT' do
+    context 'using default SNAT mechanism' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl(extra_features: ['odl-netvirt-openstack'])
+
+      # Call specialized helper fn for SNAT config validations
+      snat_mechanism_validations
+    end
+
+    context 'using conntrack SNAT' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl(extra_features: ['odl-netvirt-openstack'], snat_mechanism: 'conntrack')
+
+      # Call specialized helper fn for SNAT mechanism validations
+      snat_mechanism_validations(snat_mechanism: 'conntrack')
+    end
+  end
 end
index 89895158057c56f4ca4a937e686d46884a0c070e..66a6d88abfae7bad24c2dddd0257fc7d776c08ca 100644 (file)
@@ -808,6 +808,56 @@ describe 'opendaylight' do
     end
   end
 
+  # SNAT Mechanism tests
+  describe 'SNAT mechanism tests' do
+    # Non-OS-type tests assume CentO
+    #   See issue #43 for reasoning:
+    #   https://github.com/dfarrell07/puppet-opendaylight/issues/43#issue-57343159
+    osfamily = 'RedHat'
+    operatingsystem = 'CentOS'
+    operatingsystemmajrelease = '7'
+    context 'using controller' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :extra_features => ['odl-netvirt-openstack'],
+      }}
+
+      # Run shared tests applicable to all supported OSs
+      # Note that this function is defined in spec_helper
+      generic_tests
+
+      # Run test that specialize in checking security groups
+      # Note that this function is defined in spec_helper
+      snat_mechanism_tests
+    end
+
+    context 'using conntrack' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+        :snat_mechanism => 'conntrack',
+        :extra_features => ['odl-netvirt-openstack'],
+      }}
+
+      # Run shared tests applicable to all supported OSs
+      # Note that this function is defined in spec_helper
+      generic_tests
+
+      # Run test that specialize in checking security groups
+      # Note that this function is defined in spec_helper
+      snat_mechanism_tests('conntrack')
+    end
+  end
+
   # VPP routing node config tests
   describe 'VPP routing node tests' do
     # Non-OS-type tests assume CentOS 7
@@ -902,5 +952,4 @@ describe 'opendaylight' do
       username_password_tests('test', 'test')
     end
   end
-
-end
+end
\ No newline at end of file
index 2f9b7bf1594338a41d3a71533e8499ad662e6b42..51f7c7a14239a7811ffa5e32be7d2e40af0cb27d 100644 (file)
@@ -355,6 +355,25 @@ def enable_sg_tests(sg_mode='stateful', os_release)
   end
 end
 
+# Shared tests that specialize in testing SNAT mechanism
+def snat_mechanism_tests(snat_mechanism='controller')
+  it { should contain_file('/opt/opendaylight/etc/opendaylight') }
+  it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore')}
+  it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial')}
+  it { should contain_file('/opt/opendaylight/etc/opendaylight/datastore/initial/config')}
+
+  # Confirm snat_mechanism
+  it {
+    should contain_file('netvirt-natservice-config.xml').with(
+      'ensure'      => 'file',
+      'path'        => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
+      'owner'   => 'odl',
+      'group'   => 'odl',
+      'content'     =>  /<nat-mode>#{snat_mechanism}<\/nat-mode>/
+      )
+    }
+end
+
 # Shared tests that specialize in testing VPP routing node config
 def vpp_routing_node_tests(options = {})
   # Extract params
index 49dbbe0a3524a53cc49383421bc0aa79f5471438..014746e7ee38c92aaff6b5567c9af865b547d643 100644 (file)
@@ -71,6 +71,7 @@ def install_odl(options = {})
   password = options.fetch(:password, 'admin')
   log_max_size = options.fetch(:log_max_size, '10GB')
   log_max_rollover = options.fetch(:log_max_rollover, 2)
+  snat_mechanism = options.fetch(:snat_mechanism, 'controller')
 
   # Build script for consumption by Puppet apply
   it 'should work idempotently with no errors' do
@@ -91,6 +92,7 @@ def install_odl(options = {})
       password => #{password},
       log_max_size => '#{log_max_size}',
       log_max_rollover => #{log_max_rollover},
+      snat_mechanism => #{snat_mechanism},
     }
     EOS
 
@@ -391,3 +393,18 @@ def username_password_validations(options = {})
     its(:exit_status) { should eq 0 }
   end
 end
+
+# Shared function for validations related to the SNAT config file
+def snat_mechanism_validations(options = {})
+  # NB: This param default should match the one used by the opendaylight
+  #   class, which is defined in opendaylight::params
+  # TODO: Remove this possible source of bugs^^
+  snat_mechanism = options.fetch(:snat_mechanism, 'controller')
+
+  describe file('/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml') do
+    it { should be_file }
+    it { should be_owned_by 'odl' }
+    it { should be_grouped_into 'odl' }
+    its(:content) { should match /<nat-mode>#{snat_mechanism}<\/nat-mode>/ }
+  end
+end
\ No newline at end of file
diff --git a/templates/netvirt-natservice-config.xml.erb b/templates/netvirt-natservice-config.xml.erb
new file mode 100644 (file)
index 0000000..b271cba
--- /dev/null
@@ -0,0 +1,3 @@
+<natservice-config xmlns="urn:opendaylight:netvirt:natservice:config">
+  <nat-mode><%= scope.lookupvar('opendaylight::snat_mechanism') %></nat-mode>
+</natservice-config>
\ No newline at end of file