summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-08-23 06:22:41 -0400
committerGitHub <noreply@github.com>2019-08-23 06:22:41 -0400
commit3e665b2f892039cca731866dbb5b5bfe6505dff2 (patch)
tree2d313e132e4a36020f467dcf8dd92a6677668668
parentd02c9a4406b296d9c9ce016b4a99b00a8c4f019a (diff)
parent8e295ba6e3397add1ad26d92d97d66b58659424e (diff)
downloadchef-3e665b2f892039cca731866dbb5b5bfe6505dff2.tar.gz
Merge pull request #8756 from MsysTechnologiesllc/dh/MSYS-1033_fix_ifconfig_bridge_interface
ifconfig: fix regex matching interface name with hyphen
-rw-r--r--lib/chef/provider/ifconfig.rb8
-rw-r--r--spec/unit/provider/ifconfig_spec.rb11
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb
index 93db827e97..71b64169c2 100644
--- a/lib/chef/provider/ifconfig.rb
+++ b/lib/chef/provider/ifconfig.rb
@@ -109,18 +109,20 @@ class Chef
# RX errors 0 dropped 0 overruns 0 frame 0
# TX packets 1244218 bytes 977339327 (932.0 MiB)
# TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
+ #
+ # Permalink for addr_regex : https://rubular.com/r/JrykUpfjRnYeQD
@status = shell_out("ifconfig")
@status.stdout.each_line do |line|
- addr_regex = /^(\w+):?(\d*):?\ .+$/
+ addr_regex = /^((\w|-)+):?(\d*):?\ .+$/
if line =~ addr_regex
if line.match(addr_regex).nil?
@int_name = "nil"
- elsif line.match(addr_regex)[2] == ""
+ elsif line.match(addr_regex)[3] == ""
@int_name = line.match(addr_regex)[1]
@interfaces[@int_name] = {}
@interfaces[@int_name]["mtu"] = (line =~ /mtu (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /mtu/ && @interfaces[@int_name]["mtu"].nil?
else
- @int_name = "#{line.match(addr_regex)[1]}:#{line.match(addr_regex)[2]}"
+ @int_name = "#{line.match(addr_regex)[1]}:#{line.match(addr_regex)[3]}"
@interfaces[@int_name] = {}
@interfaces[@int_name]["mtu"] = (line =~ /mtu (\S+)/ ? Regexp.last_match(1) : "nil") if line =~ /mtu/ && @interfaces[@int_name]["mtu"].nil?
end
diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb
index 5b1256300e..38561d6e49 100644
--- a/spec/unit/provider/ifconfig_spec.rb
+++ b/spec/unit/provider/ifconfig_spec.rb
@@ -94,6 +94,17 @@ describe Chef::Provider::Ifconfig do
expect(@new_resource).not_to be_updated
end
+ it "should add a bridge interface" do
+ allow(@provider).to receive(:load_current_resource)
+ @new_resource.device "br-1234"
+ command = "ifconfig br-1234 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500"
+ expect(@provider).to receive(:shell_out_compacted!).with(*command.split(" "))
+ expect(@provider).to receive(:generate_config)
+
+ @provider.run_action(:add)
+ expect(@new_resource).to be_updated
+ end
+
# We are not testing this case with the assumption that anyone writing the cookbook would not make a typo == lo
# it "should add a blank command if the #{@new_resource.device} == lo" do
# end