diff options
author | Tim Smith <tsmith@chef.io> | 2019-08-23 06:22:41 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-23 06:22:41 -0400 |
commit | 3e665b2f892039cca731866dbb5b5bfe6505dff2 (patch) | |
tree | 2d313e132e4a36020f467dcf8dd92a6677668668 | |
parent | d02c9a4406b296d9c9ce016b4a99b00a8c4f019a (diff) | |
parent | 8e295ba6e3397add1ad26d92d97d66b58659424e (diff) | |
download | chef-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.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig_spec.rb | 11 |
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 |