summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKris Shannon <k.shannon@amaze.com.au>2019-11-22 18:15:58 +1100
committerKris Shannon <k.shannon@amaze.com.au>2019-11-22 18:15:58 +1100
commitcb9f1fa9b67674098e847a0f022a7eaaa448a2ea (patch)
tree6736e058cbdcc2590cd9110a337d410b7852b449
parent7bb642fb9952f310d36912e9eb7191de6d452040 (diff)
downloadohai-cb9f1fa9b67674098e847a0f022a7eaaa448a2ea.tar.gz
Remove the `0x` prefix from the argument to hex_to_dec_netmask
This is going to be extracted into a helper for use on other platforms Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
-rw-r--r--lib/ohai/plugins/aix/network.rb8
-rw-r--r--spec/unit/plugins/aix/network_spec.rb2
2 files changed, 5 insertions, 5 deletions
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
index b7915d7e..d0ec1ab4 100644
--- a/lib/ohai/plugins/aix/network.rb
+++ b/lib/ohai/plugins/aix/network.rb
@@ -25,9 +25,9 @@ Ohai.plugin(:Network) do
# Helpers
def hex_to_dec_netmask(netmask)
- # example '0xffff0000' -> '255.255.0.0'
- dec = netmask[2..3].to_i(16).to_s(10)
- [4, 6, 8].each { |n| dec = dec + "." + netmask[n..n + 1].to_i(16).to_s(10) }
+ # example 'ffff0000' -> '255.255.0.0'
+ dec = netmask[0..1].to_i(16).to_s(10)
+ [2, 4, 6].each { |n| dec = dec + "." + netmask[n..n + 1].to_i(16).to_s(10) }
dec
end
@@ -80,7 +80,7 @@ Ohai.plugin(:Network) do
if lin =~ %r{inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/(\d{1,2}))?}
tmp_addr, tmp_prefix = $1, $3
if tmp_prefix.nil?
- netmask = hex_to_dec_netmask($1) if lin =~ /netmask\s(\S+)\s/
+ netmask = hex_to_dec_netmask($1) if lin =~ /netmask\s0x(\S+)\s/
unless netmask
tmp_prefix ||= "32"
netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb
index a290e48a..9d408d94 100644
--- a/spec/unit/plugins/aix/network_spec.rb
+++ b/spec/unit/plugins/aix/network_spec.rb
@@ -307,7 +307,7 @@ describe Ohai::System, "AIX network plugin" do
end
it "converts a netmask from hexadecimal form to decimal form" do
- expect(@plugin.hex_to_dec_netmask("0xffff0000")).to eq("255.255.0.0")
+ expect(@plugin.hex_to_dec_netmask("ffff0000")).to eq("255.255.0.0")
end
end
end