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

Improvements to CentOS Image search #502

Merged
merged 2 commits into from
Jul 13, 2020
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
27 changes: 25 additions & 2 deletions lib/kitchen/driver/aws/standard_platform/centos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class StandardPlatform
class Centos < StandardPlatform
StandardPlatform.platforms["centos"] = self

CENTOS_OWNER_ID = "125523088429".freeze
PRODUCT_CODES = {
"6" => "6x5jmcajty9edm3f211pqjfn2",
"7" => "aw0evgkw8e5c1q413zgy5pjce",
# It appears that v8 is not published to the
# AWS marketplace and hence does not have a product code
}.freeze

# default username for this platform's ami
# @return [String]
def username
Expand All @@ -34,10 +42,25 @@ def username
end

def image_search
# Version 8+ are published directly, not to the AWS marketplace. Use OWNER ID.
search = {
"owner-alias" => "aws-marketplace",
"name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"],
"owner-id" => CENTOS_OWNER_ID,
"name" => ["CentOS #{version}*", "CentOS-#{version}*-GA-*"],
}

if version && version.split(".").first.to_i < 8
# Versions <8 are published to the AWS marketplace and use a different naming convention
search = {
"owner-alias" => "aws-marketplace",
"name" => ["CentOS Linux #{version}*", "CentOS-#{version}*-GA-*"],
}
# For versions published to aws-marketplace, additionally filter on product code to
# avoid non-official AMIs. Can't use CentOS owner ID here, as the owner ID is that of aws marketplace.
# https://github.com/test-kitchen/kitchen-ec2/issues/456
PRODUCT_CODES.keys.each do |major_version|
search["product-code"] = PRODUCT_CODES[major_version] if version.start_with?(major_version)
end
end
search["architecture"] = architecture if architecture
search
end
Expand Down
17 changes: 13 additions & 4 deletions spec/kitchen/driver/aws/image_selection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,34 +79,43 @@ def new_instance(platform_name: "blarghle")
],

"centos" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux *", "CentOS-*-GA-*"] },
{ name: "owner-id", values: %w{125523088429} },
{ name: "name", values: ["CentOS *", "CentOS-*-GA-*"] },
],
"centos-8" => [
{ name: "owner-id", values: %w{125523088429} },
{ name: "name", values: ["CentOS 8*", "CentOS-8*-GA-*"] },
],
"centos-7" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux 7*", "CentOS-7*-GA-*"] },
{ name: "product-code", values: ["aw0evgkw8e5c1q413zgy5pjce"] },
],
"centos-6" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux 6*", "CentOS-6*-GA-*"] },
{ name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] },
],
"centos-6.3" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux 6.3*", "CentOS-6.3*-GA-*"] },
{ name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] },
],
"centos-x86_64" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux *", "CentOS-*-GA-*"] },
{ name: "owner-id", values: %w{125523088429} },
{ name: "name", values: ["CentOS *", "CentOS-*-GA-*"] },
{ name: "architecture", values: %w{x86_64} },
],
"centos-6.3-x86_64" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux 6.3*", "CentOS-6.3*-GA-*"] },
{ name: "product-code", values: ["6x5jmcajty9edm3f211pqjfn2"] },
{ name: "architecture", values: %w{x86_64} },
],
"centos-7-x86_64" => [
{ name: "owner-alias", values: %w{aws-marketplace} },
{ name: "name", values: ["CentOS Linux 7*", "CentOS-7*-GA-*"] },
{ name: "product-code", values: ["aw0evgkw8e5c1q413zgy5pjce"] },
{ name: "architecture", values: %w{x86_64} },
],

Expand Down