summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/route.rb14
-rw-r--r--spec/unit/provider/route_spec.rb10
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb
index 56689c8364..222d35181e 100644
--- a/lib/chef/provider/route.rb
+++ b/lib/chef/provider/route.rb
@@ -87,14 +87,13 @@ class Chef
# cidr or quad dot mask
new_ip = if new_resource.target == "default"
- nil
+ IPAddr.new(new_resource.gateway)
elsif new_resource.netmask
IPAddr.new("#{new_resource.target}/#{new_resource.netmask}")
else
IPAddr.new(new_resource.target)
end
- return unless new_ip
# For linux, we use /proc/net/route file to read proc table info
return if node[:os] != "linux"
@@ -208,14 +207,9 @@ class Chef
case action
when :add
- if target == "default"
- command = [ "ip", "route", "replace", target ]
- command += [ "via", new_resource.gateway ] if new_resource.gateway
- else
- command = [ "ip", "route", "replace", target ]
- command += [ "via", new_resource.gateway ] if new_resource.gateway
- command += [ "dev", new_resource.device ] if new_resource.device
- end
+ command = [ "ip", "route", "replace", target ]
+ command += [ "via", new_resource.gateway ] if new_resource.gateway
+ command += [ "dev", new_resource.device ] if new_resource.device
when :delete
command = [ "ip", "route", "delete", target ]
command += [ "via", new_resource.gateway ] if new_resource.gateway
diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb
index 2beb765259..a9c7d91457 100644
--- a/spec/unit/provider/route_spec.rb
+++ b/spec/unit/provider/route_spec.rb
@@ -29,9 +29,14 @@ describe Chef::Provider::Route do
@new_resource.gateway "10.0.0.9"
@current_resource = Chef::Resource::Route.new("10.0.0.10")
@current_resource.gateway "10.0.0.9"
+ @default_resource = Chef::Resource::Route.new("default")
+ @default_resource.gateway "10.0.0.9"
@provider = Chef::Provider::Route.new(@new_resource, @run_context)
@provider.current_resource = @current_resource
+
+ @default_provider = Chef::Provider::Route.new(@default_resource, @run_context)
+ @default_provider.current_resource = @default_resource
end
describe Chef::Provider::Route, "hex2ip" do
@@ -161,6 +166,11 @@ describe Chef::Provider::Route do
@new_resource.gateway(nil)
expect(@provider.generate_command(:add).join(" ")).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}/)
end
+
+ it "should use the gatway when target is default" do
+ @default_resource.gateway("10.0.0.10")
+ expect(@default_provider.generate_command(:add).join(" ")).to match(/10.0.0.10/)
+ end
end
describe Chef::Provider::Route, "generate_command for action_delete" do