summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-07-06 14:05:09 -0700
committerGitHub <noreply@github.com>2018-07-06 14:05:09 -0700
commit27b63f5a1f457ba964fa4516031d56a9808d66ec (patch)
tree0d3b293fbfbb4d3ae4c0f4f2e6872cedb110286c
parent5a2245db6bac52861bfc4e0762155cc2f60968db (diff)
parentaf7d8766966ca0eaeb4312e7e953d7d5e207f85b (diff)
downloadohai-27b63f5a1f457ba964fa4516031d56a9808d66ec.tar.gz
Merge pull request #1214 from chef/fix_amazon_2
Properly detect Amazon Linux 2 final release platform version
-rw-r--r--lib/ohai/plugins/linux/platform.rb8
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb16
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 380475e3..39f2b602 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -24,8 +24,14 @@ Ohai.plugin(:Platform) do
contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
end
+ # Amazon Linux AMI release 2013.09
+ # Amazon Linux 2
+ # Fedora release 28 (Twenty Eight)
+ # CentOS release 5.8 (Final)
+ # CentOS release 6.7 (Final)
+ # Red Hat Enterprise Linux Server release 7.5 (Maipo)
def get_redhatish_version(contents)
- contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1]
+ contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/(release)? ([\d\.]+)/, 2]
end
#
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index cc301cc1..bf84d9b9 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -458,6 +458,22 @@ OS_RELEASE
expect(@plugin[:platform_version].to_f).to eq(7.3)
end
+ it "should read the platform as amazon and version as 2 on the RC release" do
+ expect(File).to receive(:read).with("/etc/redhat-release").and_return("Amazon Linux release 2 (2017.12) LTS Release Candidate")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("amazon")
+ expect(@plugin[:platform_family]).to eq("amazon")
+ expect(@plugin[:platform_version].to_f).to eq(2)
+ end
+
+ it "should read the platform as amazon and version as 2 on the final release" do
+ expect(File).to receive(:read).with("/etc/redhat-release").and_return("Amazon Linux 2")
+ @plugin.run
+ expect(@plugin[:platform]).to eq("amazon")
+ expect(@plugin[:platform_family]).to eq("amazon")
+ expect(@plugin[:platform_version].to_f).to eq(2)
+ end
+
# https://github.com/chef/ohai/issues/560
# Issue is seen on EL7, so that's what we're testing.
context "on versions that have /etc/os-release" do