From 49e103bbeb4d6efe1ca75f581d41ee6a8ed7caf5 Mon Sep 17 00:00:00 2001 From: Romanos Skiadas Date: Wed, 2 Nov 2016 14:51:47 -0400 Subject: [PATCH] Don't write absent to redhat route files and test for this Signed-off-by: Allain Legacy --- .../network/lib/puppet/provider/network_route/redhat.rb | 9 +++++++-- .../spec/unit/provider/network_route/redhat_spec.rb | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packstack/puppet/modules/network/lib/puppet/provider/network_route/redhat.rb b/packstack/puppet/modules/network/lib/puppet/provider/network_route/redhat.rb index f45eab5..9841c8e 100644 --- a/packstack/puppet/modules/network/lib/puppet/provider/network_route/redhat.rb +++ b/packstack/puppet/modules/network/lib/puppet/provider/network_route/redhat.rb @@ -84,10 +84,15 @@ Puppet::Type.type(:network_route).provide(:redhat) do raise Puppet::Error, "#{provider.name} does not have a #{prop}." if provider.send(prop).nil? end if provider.network == "default" - contents << "#{provider.network} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n" + contents << "#{provider.network} via #{provider.gateway} dev #{provider.interface}\n" else - contents << "#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface} #{provider.options}\n" + contents << "#{provider.network}/#{provider.netmask} via #{provider.gateway} dev #{provider.interface}\n" end + contents << if provider.options == :absent + "\n" + else + " #{provider.options}\n" + end end contents.join end diff --git a/packstack/puppet/modules/network/spec/unit/provider/network_route/redhat_spec.rb b/packstack/puppet/modules/network/spec/unit/provider/network_route/redhat_spec.rb index dfc9d6b..1ad2128 100644 --- a/packstack/puppet/modules/network/spec/unit/provider/network_route/redhat_spec.rb +++ b/packstack/puppet/modules/network/spec/unit/provider/network_route/redhat_spec.rb @@ -91,7 +91,18 @@ describe Puppet::Type.type(:network_route).provider(:redhat) do ) end - let(:content) { described_class.format_file('', [route1_provider, route2_provider, defaultroute_provider]) } + let(:nooptions_provider) do + stub('nooptions_provider', + name: 'default', + network: 'default', + netmask: '', + gateway: '10.0.0.1', + interface: 'eth2', + options: :absent + ) + end + + let(:content) { described_class.format_file('', [route1_provider, route2_provider, defaultroute_provider, nooptions_provider]) } describe "writing the route line" do describe "For standard (non-default) routes" do @@ -122,6 +133,10 @@ describe Puppet::Type.type(:network_route).provider(:redhat) do it "should have the correct fields appended" do content.scan(/^default .*$/).first.should be_include("default via 10.0.0.1 dev eth1") end + + it 'should not contain the word absent when no options are defined' do + expect(content).to_not match(/absent/) + end end end end -- 1.8.3.1