summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-09-30 13:12:41 -0700
committerGitHub <noreply@github.com>2020-09-30 13:12:41 -0700
commit234c5c959624c8311e984879ca36ded148ef054d (patch)
treeac0dea8257ace1e0d39b7ea1b99c461de0047615
parente0d81b68c3b78712e0c34ce14ff60d7dcc662d25 (diff)
parenta60af6b1f3b9d0fde917b9a70fe4f493b0b822fa (diff)
downloadohai-234c5c959624c8311e984879ca36ded148ef054d.tar.gz
Merge pull request #1521 from jasonwbarnett/feature/add-additional-detection-logic-for-azure
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/azure.rb22
-rw-r--r--spec/unit/plugins/azure_spec.rb43
2 files changed, 64 insertions, 1 deletions
diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb
index c19d3c80..31cbaeed 100644
--- a/lib/ohai/plugins/azure.rb
+++ b/lib/ohai/plugins/azure.rb
@@ -34,7 +34,7 @@ Ohai.plugin(:Azure) do
azure Mash.new
azure_metadata_from_hints.each { |k, v| azure[k] = v }
azure["metadata"] = parse_metadata
- elsif has_waagent? || has_dhcp_option_245?
+ elsif has_waagent? || has_dhcp_option_245? || has_reddog_dhcp_domain?
logger.trace("Plugin Azure: No hints present, but system appears to be on Azure.")
azure Mash.new
azure["metadata"] = parse_metadata
@@ -67,6 +67,26 @@ Ohai.plugin(:Azure) do
has_245
end
+ def has_reddog_dhcp_domain?
+ tcp_ip_dhcp_domain == "reddog.microsoft.com"
+ end
+
+ def tcp_ip_dhcp_domain
+ return unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
+
+ require "win32/registry" unless defined?(Win32::Registry)
+
+ begin
+ key = Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters")
+ dhcp_domain = key["DhcpDomain"]
+ Ohai::Log.trace("Plugin Azure: DhcpDomain registry value is #{dhcp_domain}")
+ rescue Win32::Registry::Error
+ Ohai::Log.trace("Plugin Azure: DhcpDomain registry value cannot be found")
+ end
+
+ dhcp_domain
+ end
+
# create the basic structure we'll store our data in
def initialize_metadata_mash_compute
metadata = Mash.new
diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb
index 8ffd6222..86e8ec86 100644
--- a/spec/unit/plugins/azure_spec.rb
+++ b/spec/unit/plugins/azure_spec.rb
@@ -72,6 +72,49 @@ describe Ohai::System, "plugin azure" do
end
end
+ context "when on windows", :windows_only do
+ let(:plugin) do
+ get_plugin("azure").tap do |plugin|
+ plugin[:platform_family] = "windows"
+ end
+ end
+
+ let(:tcpip_reg_key) { "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" }
+ let(:win_reg_double) { instance_double("Win32::Registry") }
+
+ before do
+ allow(Win32::Registry::HKEY_LOCAL_MACHINE)
+ .to receive(:open)
+ .with(tcpip_reg_key)
+ .and_return(win_reg_double)
+ allow(win_reg_double).to receive(:[]).with("DhcpDomain").and_return("domain.com")
+ end
+
+ context "without azure hint file or agent" do
+ before do
+ allow(plugin).to receive(:hint?).with("azure").and_return(false)
+ allow(plugin).to receive(:has_waagent?).and_return(false)
+ allow(plugin).to receive(:has_dhcp_option_245?).and_return(false)
+ end
+
+ context "DHCP option 15 is set to reddog.microsoft.com" do
+ before do
+ allow(win_reg_double).to receive(:[]).with("DhcpDomain").and_return("reddog.microsoft.com")
+ end
+
+ it_behaves_like "azure"
+ end
+
+ context "DHCP option 15 is not set to reddog.microsoft.com" do
+ before do
+ allow(win_reg_double).to receive(:[]).with("DhcpDomain").and_return("domain.com")
+ end
+
+ it_behaves_like "!azure"
+ end
+ end
+ end
+
describe "with azure hint file" do
before do
allow(plugin).to receive(:hint?).with("azure").and_return(hint)