From 168424499efb9c7ed35bf627c417f323164682fa Mon Sep 17 00:00:00 2001 From: Tim Rozet Date: Tue, 19 Sep 2017 09:45:21 -0400 Subject: [PATCH] Fix bind IP config for REST Changes bind ip to be set as a default attribute rather than value and also configures pax web cfg as recommended in https://bugs.opendaylight.org/show_bug.cgi?id=9158 Note explicitly configuring 0.0.0.0 does not work so if default we skip configuring bind IP and it defaults to 0.0.0.0. Also increases sleep before curling REST in acceptance tests because Karaf 4 takes longer to boot. Change-Id: I23e7b1d501c782d5d1df0aa6d8b3e6cac9540de7 Signed-off-by: Tim Rozet --- .gitignore | 1 + manifests/config.pp | 35 ++++++++++++++++++++++++------- spec/acceptance/class_spec.rb | 5 +++-- spec/classes/opendaylight_spec.rb | 5 +++-- spec/spec_helper.rb | 18 ++++++++++++++-- spec/spec_helper_acceptance.rb | 2 +- 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 96d1f9c..9f9ccf7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ vendor Gemfile.lock *.log *.tox +.idea/** diff --git a/manifests/config.pp b/manifests/config.pp index f508999..373b8ad 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -19,17 +19,38 @@ class opendaylight::config { match => '^featuresBoot=.*$', } - # Configuration of ODL NB REST port and IP to listen on - augeas {'jetty.xml': + # Configuration of ODL NB REST port to listen on + augeas {'ODL REST Port': incl => '/opt/opendaylight/etc/jetty.xml', context => '/files/opt/opendaylight/etc/jetty.xml/Configure', lens => 'Xml.lns', changes => [ - "set Call[2]/Arg/New/Set[#attribute[name='port']]/Property/#attribute/default ${opendaylight::odl_rest_port}", - "set Call[1]/Arg/New/Set[#attribute[name='host']]/#text[1] ${opendaylight::odl_bind_ip}", - "rm Call[1]/Arg/New/Set[#attribute[name='host']]/Property", - "set Call[2]/Arg/New/Set[#attribute[name='host']]/#text[1] ${opendaylight::odl_bind_ip}", - "rm Call[2]/Arg/New/Set[#attribute[name='host']]/Property"] + "set Call[2]/Arg/New/Set[#attribute[name='port']]/Property/#attribute/default ${opendaylight::odl_rest_port}"] + } + + if $opendaylight::odl_bind_ip != '0.0.0.0' { + # Configuration of ODL NB REST IP to listen on + augeas { 'ODL REST IP': + incl => '/opt/opendaylight/etc/jetty.xml', + context => '/files/opt/opendaylight/etc/jetty.xml/Configure', + lens => 'Xml.lns', + changes => [ + "set Call[1]/Arg/New/Set[#attribute[name='host']]/Property/#attribute/default ${opendaylight::odl_bind_ip}", + "set Call[2]/Arg/New/Set[#attribute[name='host']]/Property/#attribute/default ${opendaylight::odl_bind_ip}"] + } + + file { 'org.ops4j.pax.web.cfg': + ensure => file, + path => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg', + # Set user:group owners + owner => 'odl', + group => 'odl', + } + -> file_line { 'org.ops4j.pax.web.cfg': + ensure => present, + path => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg', + line => "org.ops4j.pax.web.listening.addresses = ${opendaylight::odl_bind_ip}" + } } # Set any custom log levels diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 384ea8a..df3bc4b 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -160,10 +160,11 @@ describe 'opendaylight class' do end describe 'testing odl username/password' do + bind_ip = '127.0.0.1' context 'using default username/password' do - context 'using default log levels' do + context 'using non-default bind ip' do # Call specialized helper fn to install OpenDaylight - install_odl({:extra_features => ['odl-restconf']}) + install_odl({:odl_bind_ip => bind_ip, :extra_features => ['odl-restconf']}) # Call specialized helper fn for username/password validations username_password_validations diff --git a/spec/classes/opendaylight_spec.rb b/spec/classes/opendaylight_spec.rb index eb4910d..e591fbb 100644 --- a/spec/classes/opendaylight_spec.rb +++ b/spec/classes/opendaylight_spec.rb @@ -351,7 +351,7 @@ describe 'opendaylight' do odl_rest_port_tests end - context 'overriding default REST port' do + context 'overriding default REST and IP port' do let(:facts) {{ :osfamily => osfamily, :operatingsystem => operatingsystem, @@ -360,6 +360,7 @@ describe 'opendaylight' do let(:params) {{ :odl_rest_port => 7777, + :odl_bind_ip => '127.0.0.1' }} # Run shared tests applicable to all supported OSs @@ -368,7 +369,7 @@ describe 'opendaylight' do # Run test that specialize in checking ODL REST port config # Note that this function is defined in spec_helper - odl_rest_port_tests(odl_rest_port: 7777) + odl_rest_port_tests(odl_rest_port: 7777, odl_bind_ip: '127.0.0.1') end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1726a30..a30c708 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -118,13 +118,27 @@ def odl_rest_port_tests(options = {}) # NB: This default value should be the same as one in opendaylight::params # TODO: Remove this possible source of bugs^^ odl_rest_port = options.fetch(:odl_rest_port, 8080) - + 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_augeas('jetty.xml') + should contain_augeas('ODL REST Port') } + + if not odl_bind_ip.eql? '0.0.0.0' + it { + should contain_augeas('ODL REST IP') + should contain_file_line('org.ops4j.pax.web.cfg').with( + 'path' => '/opt/opendaylight/etc/org.ops4j.pax.web.cfg', + 'line' => "org.ops4j.pax.web.listening.addresses = #{odl_bind_ip}", + ) + } + else + it { + should_not contain_augeas('ODL REST IP') + } + end end def log_level_tests(options = {}) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 44d70ea..04cf2b5 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -383,7 +383,7 @@ def username_password_validations(options = {}) it { should be_file } end - describe command("sleep 60 && curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do + describe command("sleep 180 && curl -o /dev/null --fail --silent --head -u #{odl_username}:#{odl_password} #{odl_check_url}") do its(:exit_status) { should eq 0 } end end -- 2.36.6