summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Duffield <tom@chef.io>2017-01-31 17:43:39 -0600
committerTom Duffield <tom@chef.io>2017-01-31 17:49:01 -0600
commit3ef8b02143c251180f7bf6212550c1ad3c44ef55 (patch)
treecb071bc94bcaa83cf23c5a8a5fec1931f7c89eb6
parentb3ae36cb4759a1ee16368b78558b69c553e650d8 (diff)
downloadchef-3ef8b02143c251180f7bf6212550c1ad3c44ef55.tar.gz
Use CIDR block rather than netmask in route-eth0 file
Convert the netmask into the CIDR block for the route-eth0 file. Signed-off-by: Tom Duffield <tom@chef.io>
-rw-r--r--lib/chef/provider/route.rb2
-rw-r--r--spec/unit/provider/route_spec.rb8
2 files changed, 8 insertions, 2 deletions
diff --git a/lib/chef/provider/route.rb b/lib/chef/provider/route.rb
index f2b7b33419..5e20fdf11e 100644
--- a/lib/chef/provider/route.rb
+++ b/lib/chef/provider/route.rb
@@ -219,7 +219,7 @@ class Chef
case action
when :add
content << (options[:target]).to_s
- content << "/#{options[:netmask]}" if options[:netmask]
+ content << "/#{MASK[options[:netmask].to_s]}" if options[:netmask]
content << " via #{options[:gateway]}" if options[:gateway]
content << "\n"
end
diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb
index 7058d76590..03d1ad2477 100644
--- a/spec/unit/provider/route_spec.rb
+++ b/spec/unit/provider/route_spec.rb
@@ -230,13 +230,19 @@ describe Chef::Provider::Route do
@run_context.resource_collection << Chef::Resource::Route.new("192.168.1.0/24 via 192.168.0.1")
@run_context.resource_collection << Chef::Resource::Route.new("192.168.2.0/24 via 192.168.0.1")
@run_context.resource_collection << Chef::Resource::Route.new("192.168.3.0/24 via 192.168.0.1")
+ @run_context.resource_collection << Chef::Resource::Route.new("Complex Route").tap do |r|
+ r.target "192.168.4.0"
+ r.gateway "192.168.0.1"
+ r.netmask "255.255.255.0"
+ end
@provider.action = :add
@provider.generate_config
- expect(route_file.string.split("\n").size).to eq(3)
+ expect(route_file.string.split("\n").size).to eq(4)
expect(route_file.string).to match(/^192\.168\.1\.0\/24 via 192\.168\.0\.1$/)
expect(route_file.string).to match(/^192\.168\.2\.0\/24 via 192\.168\.0\.1$/)
expect(route_file.string).to match(/^192\.168\.3\.0\/24 via 192\.168\.0\.1$/)
+ expect(route_file.string).to match(/^192\.168\.4\.0\/24 via 192\.168\.0\.1$/)
end
end
end