Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Azure Metadata to overcome stale dates which caused test failures #1747

Merged
merged 2 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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