summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-10-09 11:26:32 -0700
committerGitHub <noreply@github.com>2019-10-09 11:26:32 -0700
commit016fb7c8e061cce167496cb20db56c5b0d9b1deb (patch)
treee54abbd8340e11b8853b647919c132d473894928
parentc38939e8312d6e5ba9707c646f937852f3aa8bcf (diff)
parent4746690b98172c89abc2b6836e0aac1d039306dd (diff)
downloadchef-016fb7c8e061cce167496cb20db56c5b0d9b1deb.tar.gz
Merge pull request #8978 from chef/ifconfig
ifconfig: fix regex matching interface name with hyphen
-rw-r--r--lib/chef/provider/ifconfig.rb10
-rw-r--r--spec/unit/provider/ifconfig_spec.rb11
2 files changed, 17 insertions, 4 deletions
diff --git a/lib/chef/provider/ifconfig.rb b/lib/chef/provider/ifconfig.rb
index 070a4686ba..607f1fa47b 100644
--- a/lib/chef/provider/ifconfig.rb
+++ b/lib/chef/provider/ifconfig.rb
@@ -108,19 +108,21 @@ 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] = Hash.new
@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]}"
- @interfaces[@int_name] = Hash.new
+ @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
else
diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb
index 8c63a3e46e..b25c8f70ca 100644
--- a/spec/unit/provider/ifconfig_spec.rb
+++ b/spec/unit/provider/ifconfig_spec.rb
@@ -94,6 +94,17 @@ EOS
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