summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKris Shannon <k.shannon@amaze.com.au>2019-11-22 21:39:12 +1100
committerKris Shannon <k.shannon@amaze.com.au>2019-11-22 21:39:12 +1100
commitae3930b699be1707d595743e77808548d98c0233 (patch)
treecbbe996144f46fb1a03baf784e24e33b31b69fc3
parent964903716867f6a1a09f4c6a3b270ef331c856c7 (diff)
downloadohai-ae3930b699be1707d595743e77808548d98c0233.tar.gz
Extract `hex_to_dec_netmask` into mixin/network_helper.rb
Signed-off-by: Kris Shannon <k.shannon@amaze.com.au>
-rw-r--r--lib/ohai/mixin/network_helper.rb7
-rw-r--r--lib/ohai/plugins/aix/network.rb9
-rw-r--r--spec/unit/mixin/network_helper_spec.rb30
-rw-r--r--spec/unit/plugins/aix/network_spec.rb10
4 files changed, 39 insertions, 17 deletions
diff --git a/lib/ohai/mixin/network_helper.rb b/lib/ohai/mixin/network_helper.rb
index b76f8033..be783722 100644
--- a/lib/ohai/mixin/network_helper.rb
+++ b/lib/ohai/mixin/network_helper.rb
@@ -24,6 +24,13 @@ module Ohai
"inet" => "default",
"inet6" => "default_inet6",
}.freeze
+
+ def hex_to_dec_netmask(netmask)
+ # 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
end
end
end
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
index d0ec1ab4..c0d5fb77 100644
--- a/lib/ohai/plugins/aix/network.rb
+++ b/lib/ohai/plugins/aix/network.rb
@@ -20,16 +20,11 @@
Ohai.plugin(:Network) do
require "ipaddr"
+ require_relative "../../mixin/network_helper"
provides "network", "counters/network", "macaddress"
- # Helpers
- def hex_to_dec_netmask(netmask)
- # 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
+ include Ohai::Mixin::NetworkHelper
collect_data(:aix) do
# Loads following information.
diff --git a/spec/unit/mixin/network_helper_spec.rb b/spec/unit/mixin/network_helper_spec.rb
new file mode 100644
index 00000000..ec0b2472
--- /dev/null
+++ b/spec/unit/mixin/network_helper_spec.rb
@@ -0,0 +1,30 @@
+#
+# Author:: Kris Shannon <k.shannon@amaze.com.au>
+# Copyright:: Copyright (c) 2019 Amaze Communication.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+require "ohai/mixin/network_helper"
+
+describe Ohai::Mixin::NetworkHelper, "Network Helper Mixin" do
+ let(:mixin) { Object.new.extend(Ohai::Mixin::NetworkHelper) }
+
+ describe "hex_to_dec_netmask method" do
+ it "converts a netmask from hexadecimal form to decimal form" do
+ expect(mixin.hex_to_dec_netmask("ffff0000")).to eq("255.255.0.0")
+ end
+ end
+end
diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb
index 9d408d94..e96db800 100644
--- a/spec/unit/plugins/aix/network_spec.rb
+++ b/spec/unit/plugins/aix/network_spec.rb
@@ -300,14 +300,4 @@ describe Ohai::System, "AIX network plugin" do
expect(@plugin["network"]["arp"][0][:remote_mac]).to eq("6e:87:70:0:40:3")
end
end
-
- describe "hex_to_dec_netmask method" do
- before do
- @plugin.run
- end
-
- it "converts a netmask from hexadecimal form to decimal form" do
- expect(@plugin.hex_to_dec_netmask("ffff0000")).to eq("255.255.0.0")
- end
- end
end