Skip to content

(FACT-1383) Add Azure instance metadata fact#2298

Merged
mihaibuzgau merged 2 commits intopuppetlabs:3.xfrom
luchihoratiu:FACT-1383_3.x
Mar 2, 2021
Merged

(FACT-1383) Add Azure instance metadata fact#2298
mihaibuzgau merged 2 commits intopuppetlabs:3.xfrom
luchihoratiu:FACT-1383_3.x

Conversation

@luchihoratiu
Copy link
Copy Markdown
Contributor

@luchihoratiu luchihoratiu commented Mar 2, 2021

This commit adds the az_metadata fact that contains all available metadata information of the Microsoft Azure instance on which facter is being run. Support added for Linux and Windows.

@luchihoratiu luchihoratiu requested a review from a team March 2, 2021 12:52
@luchihoratiu luchihoratiu force-pushed the FACT-1383_3.x branch 2 times, most recently from dfbb88f to 1888c22 Compare March 2, 2021 13:22
This commit adds the `az_metadata` fact that contains all available
metadata information of the Microsoft Azure instance on which facter is
being run. Support added for Linux and Windows.
Due to the previous nature of the test (expecting to not see any
`caching` in stderr output), the `az_metadata` fact was causing
`no_cache_should_not_refresh_cached_facts.rb` and
`no_cache_should_not_cache_facts.rb` to fail because of its output.

Seen example:
`"osDisk" => { "caching" => "ReadOnly"`

This commit makes the tests more specific: from not expecting any
`caching` to not expecting any `caching values for`.
Copy link
Copy Markdown
Contributor

@GabrielNagy GabrielNagy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍, just a minor comment about a leftover EC2. Tested both this and the Ruby version and these are my findings:

  1. the fact correctly resolves if on hyperv and the endpoint is available ✔️
  2. the fact silently fails to resolve if on hyperv and the endpoint is not available ✔️
  3. the fact does not resolve at all if not on hyperv ✔️

The only difference I was able to spot was how empty arrays are rendered, but this is something that appears to be different in the Facter 4 code that pretty-prints the json, which is unrelated to this work:

$ diff -u <(bundle exec facter az_metadata) <(../3.x_facter/bin/facter az_metadata)
--- /dev/fd/63	2021-03-02 17:22:36.085844995 +0000
+++ /dev/fd/62	2021-03-02 17:22:36.085844995 +0000
@@ -21,9 +21,7 @@
     platformFaultDomain => "0",
     platformUpdateDomain => "0",
     provider => "Microsoft.Compute",
-    publicKeys => [
-
-    ],
+    publicKeys => [],
     publisher => "canonical",
     resourceGroupName => "test-facter-azure_group",
     resourceId => "/subscriptions/de8aa4b1-87d7-41be-ada7-5e2e4b4768e5/resourceGroups/test-facter-azure_group/providers/Microsoft.Compute/virtualMachines/test-facter-azure",
@@ -87,9 +85,7 @@
     },
     subscriptionId => "de8aa4b1-87d7-41be-ada7-5e2e4b4768e5",
     tags => "",
-    tagsList => [
-
-    ],
+    tagsList => [],
     version => "20.04.202102020",
     vmId => "9e5e7e81-8db0-4ff1-adc3-2dcfcd7f2727",
     vmScaleSetName => "",
@@ -114,9 +110,7 @@
           ]
         },
         ipv6 => {
-          ipAddress => [
-
-          ]
+          ipAddress => []
         },
         macAddress => "000D3A38BFF9"
       }

}
} catch (lth_curl::http_request_exception& ex) {
LOG_DEBUG("Azure instance metadata fact is unavailable: not running under an Azure instance or Azure is not responding in a timely manner.");
LOG_TRACE("EC2 metadata request failed: {1}", ex.what());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be AZ/Azure

@mihaibuzgau mihaibuzgau merged commit 003e79d into puppetlabs:3.x Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants