Configures websocket listener IP 75/64775/15
authorTim Rozet <trozet@redhat.com>
Thu, 26 Oct 2017 20:55:07 +0000 (15:55 -0500)
committerTim Rozet <trozet@redhat.com>
Fri, 17 Nov 2017 16:43:30 +0000 (11:43 -0500)
Will use the already provided bind ip to also bind websocket listener.

Change-Id: Ia2084fd3e064f579d34ba7a60fec0df5b910e411
Signed-off-by: Tim Rozet <trozet@redhat.com>
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
CHANGELOG
README.markdown
manifests/config.pp
metadata.json
spec/acceptance/class_spec.rb
spec/classes/opendaylight_spec.rb
spec/spec_helper.rb
spec/spec_helper_acceptance.rb
templates/10-rest-connector.xml.erb [new file with mode: 0644]

index 741e513bb54ccc17bc1778356eb368aa9543dc05..cd187b2c02ae5c01b0ada4c0596e2b16d0dd5afa 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -50,3 +50,5 @@
 - Only support stateful security mode. Remove all related configs
 2017-11-15 Release 6.0.0
 - Allow full customization of ODL RPM repo
+2017-11-17 Release 6.1.0
+- Configure websocket address
index cb5b304407ebd788ae8158c866b9fa94cd5610d2..7ea980d42f2b8d101e617f9f9042ab0b9f11f1b3 100644 (file)
@@ -173,6 +173,11 @@ class { 'opendaylight':
 }
 ```
 
+### Configuring websocket address
+
+Websocket address can be configured to the IP of ODL rather than default 0.0.0.0. This IP will
+be defined by `odl_bind_ip`.
+
 ## Reference
 
 ### Classes
index 4d6d4a02fd3b2b4646bde83e414874fde7abc132..1654a756f0a5becc3d675fc2b0d4e989787d2a46 100644 (file)
@@ -27,6 +27,14 @@ class opendaylight::config {
     changes => [
       "set Call[2]/Arg/New/Set[#attribute[name='port']]/Property/#attribute/default ${opendaylight::odl_rest_port}"]
   }
+  $initial_config_dir = '/opt/opendaylight/configuration/initial'
+
+  file { $initial_config_dir:
+        ensure => directory,
+        mode   => '0755',
+        owner  => 'odl',
+        group  => 'odl',
+  }
 
   if $opendaylight::odl_bind_ip != '0.0.0.0' {
     # Configuration of ODL NB REST IP to listen on
@@ -83,40 +91,32 @@ class opendaylight::config {
   if $::opendaylight::enable_ha {
     if $ha_node_count >= 2 {
       # Configure ODL OSVDB Clustering
-      $cluster_config_dir = '/opt/opendaylight/configuration/initial'
-
-      file { $cluster_config_dir:
-        ensure => directory,
-        mode   => '0755',
-        owner  => 'odl',
-        group  => 'odl',
-      }
 
       file {'akka.conf':
         ensure  => file,
-        path    => "${cluster_config_dir}/akka.conf",
+        path    => "${initial_config_dir}/akka.conf",
         owner   => 'odl',
         group   => 'odl',
         content => template('opendaylight/akka.conf.erb'),
-        require => File[$cluster_config_dir]
+        require => File[$initial_config_dir]
       }
 
       file {'modules.conf':
         ensure  => file,
-        path    => "${cluster_config_dir}/modules.conf",
+        path    => "${initial_config_dir}/modules.conf",
         owner   => 'odl',
         group   => 'odl',
         content => template('opendaylight/modules.conf.erb'),
-        require => File[$cluster_config_dir]
+        require => File[$initial_config_dir]
       }
 
       file {'module-shards.conf':
         ensure  => file,
-        path    => "${cluster_config_dir}/module-shards.conf",
+        path    => "${initial_config_dir}/module-shards.conf",
         owner   => 'odl',
         group   => 'odl',
         content => template('opendaylight/module-shards.conf.erb'),
-        require => File[$cluster_config_dir]
+        require => File[$initial_config_dir]
       }
 
     } else {
@@ -124,22 +124,25 @@ class opendaylight::config {
     }
   }
 
+  $odl_dirs = [
+    '/opt/opendaylight/etc/opendaylight',
+    '/opt/opendaylight/etc/opendaylight/karaf',
+    '/opt/opendaylight/etc/opendaylight/datastore',
+    '/opt/opendaylight/etc/opendaylight/datastore/initial',
+    '/opt/opendaylight/etc/opendaylight/datastore/initial/config',
+  ]
+
+  file { $odl_dirs:
+    ensure => directory,
+    mode   => '0755',
+    owner  => 'odl',
+    group  => 'odl',
+  }
+
   if ('odl-netvirt-openstack' in $opendaylight::features or 'odl-netvirt-sfc' in $opendaylight::features) {
     # Configure SNAT
-    $odl_datastore = [
-      '/opt/opendaylight/etc/opendaylight',
-      '/opt/opendaylight/etc/opendaylight/datastore',
-      '/opt/opendaylight/etc/opendaylight/datastore/initial',
-      '/opt/opendaylight/etc/opendaylight/datastore/initial/config',
-    ]
-
-    file { $odl_datastore:
-      ensure => directory,
-      mode   => '0755',
-      owner  => 'odl',
-      group  => 'odl',
-    }
-    -> file { 'netvirt-natservice-config.xml':
+
+    file { 'netvirt-natservice-config.xml':
       ensure  => file,
       path    => '/opt/opendaylight/etc/opendaylight/datastore/initial/config/netvirt-natservice-config.xml',
       owner   => 'odl',
@@ -190,4 +193,14 @@ class opendaylight::config {
     password => $::opendaylight::password,
     before   => Service['opendaylight'],
   }
+
+  # Configure websocket address
+  file { '10-rest-connector.xml':
+    ensure  => file,
+    path    => '/opt/opendaylight/etc/opendaylight/karaf/10-rest-connector.xml',
+    owner   => 'odl',
+    group   => 'odl',
+    content => template('opendaylight/10-rest-connector.xml.erb'),
+    require => File['/opt/opendaylight/etc/opendaylight/karaf'],
+  }
 }
index 30aafb1fe7a1e7daab9c27aa727e23145f681fcd..83e076403b89a9cf75f501d1c90f0d804eafc1f5 100644 (file)
@@ -1,6 +1,6 @@
 {
     "name": "opendaylight-opendaylight",
-    "version": "6.0.0",
+    "version": "6.1.0",
     "author": "Daniel Farrell",
     "summary": "Puppet module that installs and configures the OpenDaylight SDN controller",
     "license": "BSD-2-Clause",
index df3bc4b96ee28ebebaa0b600f3538e929632078f..4ec3f60d95b5f0492c68162dbfab7b808842ddd3 100644 (file)
@@ -221,4 +221,22 @@ describe 'opendaylight class' do
       sfc_validations
     end
   end
+
+  describe 'testing websocket address config' do
+    context 'using default ip' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl
+
+      # Call specialized helper fn for websocket address config validations
+      websocket_address_validations
+    end
+
+    context 'overriding default ip' do
+      # Call specialized helper fn to install OpenDaylight
+      install_odl(odl_bind_ip: '127.0.0.1')
+
+      # Call specialized helper fn for websocket address config validations
+      websocket_address_validations(odl_bind_ip: '127.0.0.1')
+    end
+  end
 end
index 79c62086e808bb89d168783cf34b85f531a89048..5b7c866163473b44fa49d9ad0b6bc07aa9f25f5e 100644 (file)
@@ -906,4 +906,51 @@ describe 'opendaylight' do
       username_password_tests('test', 'test')
     end
   end
+
+  # websocket address tests
+  describe 'ODL websocket address 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 default websocket address' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{ }}
+
+      # 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 websocket address
+      # Note that this function is defined in spec_helper
+      odl_websocket_address_tests
+    end
+
+    context 'overriding websocket address' do
+      let(:facts) {{
+        :osfamily => osfamily,
+        :operatingsystem => operatingsystem,
+        :operatingsystemmajrelease => operatingsystemmajrelease,
+      }}
+
+      let(:params) {{
+       :odl_bind_ip => '127.0.0.1'
+       }}
+
+      # 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 websocket address
+      # Note that this function is defined in spec_helper
+      odl_websocket_address_tests(odl_bind_ip: '127.0.0.1')
+    end
+  end
 end
index f0355eb3bf74e2d19f521e5d6c511b193ed98889..205081817fbcfecdea8bc0b49a556fcea19ee1ca 100644 (file)
@@ -392,3 +392,23 @@ def username_password_tests(username, password)
     )
   }
 end
+
+# ODL websocket address tests
+def odl_websocket_address_tests(options = {})
+  # Extract params
+  # NB: This default value should be the same as one in opendaylight::params
+  # TODO: Remove this possible source of bugs^^
+  odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
+  # Confirm properties of ODL REST port config file
+  # NB: These hashes don't work with Ruby 1.8.7, but we
+  #   don't support 1.8.7 so that's okay. See issue #36.
+  it {
+    should contain_file('10-rest-connector.xml').with(
+      'ensure'      => 'file',
+      'path'        => '/opt/opendaylight/etc/opendaylight/karaf/10-rest-connector.xml',
+      'owner'   => 'odl',
+      'group'   => 'odl',
+      'content'     =>  /<websocket-address>#{odl_bind_ip}<\/websocket-address>/
+    )
+  }
+end
\ No newline at end of file
index 92d4fe0dc17bbd39e9f8f154bbeaaf9c1d40dfba..d757b80a71083fabc1482055b58d9a2bc4f4f1eb 100644 (file)
@@ -421,3 +421,17 @@ def sfc_validations()
     its(:content) { should match /<gpe-extension-enabled>true<\/gpe-extension-enabled>/ }
   end
 end
+
+def websocket_address_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^^
+  odl_bind_ip = options.fetch(:odl_bind_ip, '0.0.0.0')
+
+  describe file('/opt/opendaylight/etc/opendaylight/karaf/10-rest-connector.xml') do
+    it { should be_file }
+    it { should be_owned_by 'odl' }
+    it { should be_grouped_into 'odl' }
+    its(:content) { should match /<websocket-address>#{odl_bind_ip}<\/websocket-address>/ }
+  end
+end
diff --git a/templates/10-rest-connector.xml.erb b/templates/10-rest-connector.xml.erb
new file mode 100644 (file)
index 0000000..3a5d6cf
--- /dev/null
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
+-->
+<snapshot>
+  <configuration>
+    <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
+      <modules xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+        <!-- default OF-switch-connection-provider (port 6633) -->
+        <module>
+          <type xmlns:rest="urn:opendaylight:params:xml:ns:yang:controller:md:sal:rest:connector">rest:rest-connector-impl</type>
+          <name>rest-connector-default-impl</name>
+          <websocket-address><%= scope.lookupvar('opendaylight::odl_bind_ip') %></websocket-address>
+          <websocket-port>8185</websocket-port>
+          <dom-broker>
+            <type xmlns:dom="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">dom:dom-broker-osgi-registry</type>
+            <name>dom-broker</name>
+          </dom-broker>
+        </module>
+      </modules>
+
+      <services xmlns="urn:opendaylight:params:xml:ns:yang:controller:config">
+        <service>
+          <type xmlns:rest="urn:opendaylight:params:xml:ns:yang:controller:md:sal:rest:connector">rest:rest-connector</type>
+          <instance>
+            <name>rest-connector-default</name>
+            <provider>
+              /modules/module[type='rest-connector-impl'][name='rest-connector-default-impl']
+            </provider>
+          </instance>
+        </service>
+      </services>
+    </data>
+  </configuration>
+  <required-capabilities>
+      <capability>urn:opendaylight:params:xml:ns:yang:controller:md:sal:rest:connector?module=opendaylight-rest-connector&amp;revision=2014-07-24</capability>
+  </required-capabilities>
+</snapshot>
\ No newline at end of file