summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCollin McNeese <cmcneese@chef.io>2021-02-19 08:37:35 -0600
committerCollin McNeese <cmcneese@chef.io>2021-02-19 08:37:35 -0600
commitd0fc735cf5df82f4b4cb3715fb78f5d099ac5fe3 (patch)
tree9613122ac0228395d8a5a691220dfa6774f4c313
parent0b0000147a2b251744ddc3b5db406af5bac4017a (diff)
downloadohai-d0fc735cf5df82f4b4cb3715fb78f5d099ac5fe3.tar.gz
Updates habitat plugin to use path returned from which for shell_outs
Signed-off-by: Collin McNeese <cmcneese@chef.io>
-rw-r--r--lib/ohai/plugins/habitat.rb10
-rw-r--r--spec/unit/plugins/habitat_spec.rb10
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/ohai/plugins/habitat.rb b/lib/ohai/plugins/habitat.rb
index 09a741c2..9dad5032 100644
--- a/lib/ohai/plugins/habitat.rb
+++ b/lib/ohai/plugins/habitat.rb
@@ -18,18 +18,18 @@
Ohai.plugin(:Habitat) do
provides "habitat"
- def habitat_exists?
+ def habitat_binary
which("hab")
end
def fetch_habitat_version
- shell_out(["hab"], ["-V"]).stdout.gsub(/hab\s*/, "").strip
+ shell_out([habitat_binary, "-V"]).stdout.gsub(/hab\s*/, "").strip
rescue Ohai::Exceptions::Exec
logger.trace("Plugin Habitat: Unable to determine the installed version of Habitat, skipping collection.")
end
def fetch_habitat_packages
- shell_out(["hab", "pkg", "list", "--all"]).stdout.split.sort.select { |pkg| pkg.match?(%r{.*/.*/.*/.*}) }
+ shell_out([habitat_binary, "pkg", "list", "--all"]).stdout.split.sort.select { |pkg| pkg.match?(%r{.*/.*/.*/.*}) }
rescue Ohai::Exceptions::Exec
logger.trace("Plugin Habitat: Unable to determine the installed Habitat packages, skipping collection.")
end
@@ -55,14 +55,14 @@ Ohai.plugin(:Habitat) do
end
def fetch_habitat_services
- services_shell_out = shell_out(%w{hab svc status}).stdout
+ services_shell_out = shell_out([habitat_binary, "svc", "status"]).stdout
load_habitat_service_via_cli(services_shell_out) if services_shell_out
rescue Ohai::Exceptions::Exec
logger.trace("Plugin Habitat: Unable to determine the installed Habitat services, skipping collection.")
end
collect_data(:default) do
- return unless habitat_exists?
+ return unless habitat_binary
habitat Mash.new
habitat["version"] = fetch_habitat_version
diff --git a/spec/unit/plugins/habitat_spec.rb b/spec/unit/plugins/habitat_spec.rb
index 183a2174..b9c9e2c6 100644
--- a/spec/unit/plugins/habitat_spec.rb
+++ b/spec/unit/plugins/habitat_spec.rb
@@ -29,12 +29,12 @@ describe "plugin habitat" do
origin1/package1/version1/release1 standalone up up 60 100 package1.default
origin2/package2/version2/release2 standalone up up 60 101 package2.default
SVC
- allow(plugin).to receive(:shell_out).with(["hab"],
- ["-V"]).and_return(mock_shell_out(0, "hab 1.1.1/202001010000", ""))
- allow(plugin).to receive(:shell_out).with(["hab", "pkg", "list",
+ allow(plugin).to receive(:habitat_binary).and_return("/some/path/hab")
+ allow(plugin).to receive(:shell_out).with(["/some/path/hab",
+ "-V"]).and_return(mock_shell_out(0, "hab 1.1.1/202001010000", ""))
+ allow(plugin).to receive(:shell_out).with(["/some/path/hab", "pkg", "list",
"--all"]).and_return(mock_shell_out(0, pkg_result, ""))
- allow(plugin).to receive(:shell_out).with(%w{hab svc status}).and_return(mock_shell_out(0, svc_result, ""))
- allow(plugin).to receive(:habitat_exists?).and_return(true)
+ allow(plugin).to receive(:shell_out).with(["/some/path/hab", "svc", "status"]).and_return(mock_shell_out(0, svc_result, ""))
plugin.run
end