Skip to content

Commit

Permalink
Merge pull request #1747 from chef/jfm/ohai_ruby3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmccrae committed Jun 2, 2022
2 parents 621d432 + d27e6f2 commit 568f67c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
7 changes: 4 additions & 3 deletions lib/ohai/mixin/azure_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ module AzureMetadata
AZURE_METADATA_ADDR ||= "169.254.169.254"

# it's important that the newer versions are at the end of this array so we can skip sorting it
AZURE_SUPPORTED_VERSIONS ||= %w{ 2017-04-02 2017-08-01 2017-12-01 2018-02-01 2018-04-02
2018-10-01 2019-02-01 2019-03-11 2019-04-30 2019-06-01
2019-06-04 2019-08-01 2019-08-15 2019-11-01 }.freeze
AZURE_SUPPORTED_VERSIONS ||= %w{ 2018-10-01 2019-02-01 2019-03-11 2019-04-30 2019-06-01
2019-06-04 2019-08-01 2019-08-15 2019-11-01 2020-06-01
2020-07-15 2020-09-01 2020-10-01 2020-12-01 2021-01-01
2021-02-01 2021-03-01 2021-05-01 2021-10-01 }.freeze

def best_api_version
@api_version ||= begin
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/mixin/azure_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@
end

context "when azure doesn't return any versions we know about" do
let(:response) { double("Net::HTTP Response", body: "{\"error\":\"Bad request. api-version was not specified in the request. For more information refer to aka.ms/azureimds\",\"newest-versions\":[\"2021-01-02\",\"2020-08-01\",\"2020-07-15\"]}", code: "400") }
let(:response) { double("Net::HTTP Response", body: "{\"error\":\"Bad request. api-version was not specified in the request. For more information refer to aka.ms/azureimds\",\"newest-versions\":[\"2020-12-01\",\"2020-10-01\",\"2020-09-01\"]}", code: "400") }

it "returns the most recent version we know of" do
expect(mixin.best_api_version).to eq("2019-11-01")
expect(mixin.best_api_version).to eq("2020-12-01")
end
end

context "when the response code is 404" do
let(:response) { double("Net::HTTP Response", code: "404") }

it "returns the most recent version we know of" do
expect(mixin.best_api_version).to eq("2019-11-01")
expect(mixin.best_api_version).to eq("2021-10-01")
end
end

context "when the response code is unexpected" do
let(:response) { double("Net::HTTP Response", body: "{\"error\":\"Bad request. api-version was not specified in the request. For more information refer to aka.ms/azureimds\",\"newest-versions\":[\"2021-01-02\",\"2020-08-01\",\"2020-07-15\"]}", code: "418") }
let(:response) { double("Net::HTTP Response", body: "{\"error\":\"Bad request. api-version was not specified in the request. For more information refer to aka.ms/azureimds\",\"newest-versions\":[\"2021-10-01\",\"2021-05-01\",\"2021-03-01\"]}", code: "418") }

it "raises an error" do
expect { mixin.best_api_version }.to raise_error(RuntimeError)
Expand All @@ -81,7 +81,7 @@

describe "#fetch_metadata" do
before do
allow(mixin).to receive(:best_api_version).and_return("2019-11-01")
allow(mixin).to receive(:best_api_version).and_return("2021-10-01")
end

it "returns an empty hash given a non-200 response" do
Expand Down

0 comments on commit 568f67c

Please sign in to comment.