Skip to content

Commit

Permalink
Apply require speedups to ohai
Browse files Browse the repository at this point in the history
Same kinds of fixes from chef core with require_relative and
idempotency checks.

Signed-off-by: Lamont Granquist <[email protected]>
  • Loading branch information
lamont-granquist committed May 15, 2019
1 parent 62a8798 commit 537596b
Show file tree
Hide file tree
Showing 44 changed files with 85 additions and 85 deletions.
8 changes: 4 additions & 4 deletions lib/ohai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.
#

require "ohai/version"
require "ohai/config"
require "ohai/system"
require "ohai/exception"
require_relative "ohai/version"
require_relative "ohai/config"
require_relative "ohai/system"
require_relative "ohai/exception"
6 changes: 3 additions & 3 deletions lib/ohai/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

require "chef-config/path_helper"
require "chef-config/workstation_config_loader"
require "ohai"
require "ohai/log"
require "mixlib/cli"
require_relative "../ohai"
require_relative "log"
require "mixlib/cli" unless defined?(Mixlib::CLI)
require "benchmark"

# The Application class is what is called by the Ohai CLI binary. It handles:
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#

require "chef-config/config"
require "ohai/exception"
require "ohai/plugin_config"
require_relative "exception"
require_relative "plugin_config"

module Ohai
Config = ChefConfig::Config
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
# limitations under the License.
#

require "ohai/dsl/plugin"
require "ohai/dsl/plugin/versionvii"
require_relative "dsl/plugin"
require_relative "dsl/plugin/versionvii"
10 changes: 5 additions & 5 deletions lib/ohai/dsl/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# limitations under the License.
#

require "ohai/mixin/os"
require "ohai/mixin/command"
require "ohai/mixin/seconds_to_human"
require "ohai/hints"
require "ohai/util/file_helper"
require_relative "../mixin/os"
require_relative "../mixin/command"
require_relative "../mixin/seconds_to_human"
require_relative "../hints"
require_relative "../util/file_helper"

module Ohai

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/hints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# limitations under the License.
#

require "ffi_yajl"
require "ffi_yajl" unless defined?(FFI_Yajl)

module Ohai
# Ohai hints are json files on disk that give ohai a hint to things that are often
Expand Down
8 changes: 4 additions & 4 deletions lib/ohai/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#

require "chef-config/path_helper"
require "ohai/log"
require "ohai/mash"
require "ohai/dsl"
require "pathname"
require_relative "log"
require_relative "mash"
require_relative "dsl"
require "pathname" unless defined?(Pathname)

module Ohai

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/azure_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "net/http"
require "net/http" unless defined?(Net::HTTP)

module Ohai
module Mixin
Expand Down
6 changes: 3 additions & 3 deletions lib/ohai/mixin/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# limitations under the License.
#

require "ohai/exception"
require "ohai/log"
require "mixlib/shellout"
require_relative "../exception"
require_relative "../log"
require "mixlib/shellout" unless defined?(Mixlib::ShellOut)

module Ohai
module Mixin
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/do_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "net/http"
require "net/http" unless defined?(Net::HTTP)

module Ohai
module Mixin
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/ec2_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "net/http"
require "net/http" unless defined?(Net::HTTP)

module Ohai
module Mixin
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/gce_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "net/http"
require "net/http" unless defined?(Net::HTTP)

module Ohai
module Mixin
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/http_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "socket"
require "socket" unless defined?(Socket)

module Ohai
module Mixin
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/scaleway_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require "net/http"
require "net/http" unless defined?(Net::HTTP)

module Ohai
module Mixin
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/mixin/softlayer_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# limitations under the License.

require "net/https"
require "uri"
require "uri" unless defined?(URI)

# https://softlayer.github.io/reference/services/SoftLayer_Resource_Metadata/
module ::Ohai::Mixin::SoftlayerMetadata
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugin_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

require "ohai/exception"
require_relative "exception"

module Ohai
class PluginConfig < Hash
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/azure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#

Ohai.plugin(:Azure) do
require "ohai/mixin/azure_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/azure_metadata"
require_relative "../mixin/http_helper"

include Ohai::Mixin::AzureMetadata
include Ohai::Mixin::HttpHelper
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/bsd/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Ohai.plugin(:Virtualization) do
provides "virtualization"
depends "dmi"
require "ohai/mixin/dmi_decode"
require_relative "../../mixin/dmi_decode"
include Ohai::Mixin::DmiDecode

collect_data(:freebsd, :openbsd, :netbsd, :dragonflybsd) do
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/digital_ocean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# limitations under the License.

Ohai.plugin(:DigitalOcean) do
require "ohai/mixin/do_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/do_metadata"
require_relative "../mixin/http_helper"

include Ohai::Mixin::DOMetadata
include Ohai::Mixin::HttpHelper
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# dmidecode does not return data without access to /dev/mem (or its equivalent)

collect_data do
require "ohai/common/dmi"
require_relative "../common/dmi"
dmi Mash.new

# all output lines should fall within one of these patterns
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances

Ohai.plugin(:EC2) do
require "ohai/mixin/ec2_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/ec2_metadata"
require_relative "../mixin/http_helper"
require "base64"

include Ohai::Mixin::Ec2Metadata
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/eucalyptus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

Ohai.plugin(:Eucalyptus) do
# eucalyptus metadata service is compatible with the ec2 service calls
require "ohai/mixin/ec2_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/ec2_metadata"
require_relative "../mixin/http_helper"

include Ohai::Mixin::Ec2Metadata
include Ohai::Mixin::HttpHelper
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/gce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

Ohai.plugin(:GCE) do
require "ohai/mixin/gce_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/gce_metadata"
require_relative "../mixin/http_helper"

include Ohai::Mixin::GCEMetadata
include Ohai::Mixin::HttpHelper
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#

Ohai.plugin(:Hostname) do
require "socket"
require "socket" unless defined?(Socket)
require "ipaddr"

provides "domain", "hostname", "fqdn", "machinename"
Expand Down Expand Up @@ -161,7 +161,7 @@ def collect_hostname

collect_data(:windows) do
require "wmi-lite/wmi"
require "socket"
require "socket" unless defined?(Socket)

wmi = WmiLite::Wmi.new
host = wmi.first_of("Win32_ComputerSystem")
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def blacklisted_wmi_name?(name)
end

collect_data(:windows) do
require "win32ole"
require "win32ole" unless defined?(WIN32OLE)
require "wmi-lite/wmi"

WIN32OLE.codepage = WIN32OLE::CP_UTF8
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/linux/fips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
collect_data(:linux) do
fips Mash.new

require "openssl"
require "openssl" unless defined?(OpenSSL)
if defined?(OpenSSL.fips_mode) && OpenSSL.fips_mode && !$FIPS_TEST_MODE
fips["kernel"] = { "enabled" => true }
else
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/linux/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Ohai.plugin(:Virtualization) do
provides "virtualization"
depends "dmi"
require "ohai/mixin/dmi_decode"
require_relative "../../mixin/dmi_decode"
include Ohai::Mixin::DmiDecode

def lxc_version_exists?
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

Ohai.plugin(:NetworkAddresses) do
require "ipaddress"
require "ohai/mixin/network_constants"
require_relative "../mixin/network_constants"
include Ohai::Mixin::NetworkConstants

provides "ipaddress", "ip6address", "macaddress"
Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# limitations under the License.

Ohai.plugin(:Openstack) do
require "ohai/mixin/ec2_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/ec2_metadata"
require_relative "../mixin/http_helper"
include Ohai::Mixin::Ec2Metadata
include Ohai::Mixin::HttpHelper

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#

Ohai.plugin(:OS) do
require "ohai/mixin/os"
require_relative "../mixin/os"
provides "os", "os_version"
depends "kernel"

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def collect_programs_from_registry_key(key_path)
end

collect_data(:windows) do
require "win32/registry"
require "win32/registry" unless defined?(Win32::Registry)
packages Mash.new
collect_programs_from_registry_key('Software\Microsoft\Windows\CurrentVersion\Uninstall')
# on 64 bit systems, 32 bit programs are stored here
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/passwd.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Ohai.plugin(:Passwd) do
require "etc"
require "etc" unless defined?(Etc)
provides "etc", "current_user"
optional true

Expand Down
4 changes: 2 additions & 2 deletions lib/ohai/plugins/scaleway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.

Ohai.plugin(:Scaleway) do
require "ohai/mixin/scaleway_metadata"
require "ohai/mixin/http_helper"
require_relative "../mixin/scaleway_metadata"
require_relative "../mixin/http_helper"

include Ohai::Mixin::ScalewayMetadata
include Ohai::Mixin::HttpHelper
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/scsi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
provides "scsi"
optional true

require "mixlib/shellout"
require "mixlib/shellout" unless defined?(Mixlib::ShellOut)

collect_data(:linux) do
devices = Mash.new
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/softlayer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# limitations under the License.

Ohai.plugin(:Softlayer) do
require "ohai/mixin/softlayer_metadata"
require_relative "../mixin/softlayer_metadata"
include ::Ohai::Mixin::SoftlayerMetadata

provides "softlayer"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/solaris2/dmi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
provides "dmi"

collect_data(:solaris2) do
require "ohai/common/dmi"
require_relative "../../common/dmi"

# if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios
# note that a single key just means dmidecode exited with its version
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/solaris2/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#

Ohai.plugin(:Virtualization) do
require "ohai/mixin/dmi_decode"
require_relative "../../mixin/dmi_decode"
include Ohai::Mixin::DmiDecode
provides "virtualization"
depends "dmi"
Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/uptime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#

Ohai.plugin(:Uptime) do
require "ohai/mixin/seconds_to_human"
require_relative "../mixin/seconds_to_human"
provides "uptime", "uptime_seconds"
provides "idletime", "idletime_seconds" # linux only

Expand Down
2 changes: 1 addition & 1 deletion lib/ohai/plugins/windows/fips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
collect_data(:windows) do
fips Mash.new

require "openssl"
require "openssl" unless defined?(OpenSSL)
if defined?(OpenSSL.fips_mode) && OpenSSL.fips_mode && !$FIPS_TEST_MODE
fips["kernel"] = { "enabled" => true }
else
Expand Down
Loading

0 comments on commit 537596b

Please sign in to comment.