Class: Kitchen::Driver::Aws::StandardPlatform::Centos

Inherits:
StandardPlatform
  • Object
show all
Defined in:
lib/kitchen/driver/aws/standard_platform/centos.rb

Overview

Constant Summary collapse

CENTOS_OWNER_ID =

The AWS account CentOS publishes its images under. Releases from 8 onwards are published directly rather than through the AWS Marketplace, so images are found by owner rather than by product.

"125523088429".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_image(driver, image) ⇒ Centos?

Detect this platform from an EC2 image.

Matching is done on the image name, which is the only reliable signal EC2 exposes about what an AMI actually contains.



87
88
89
90
91
92
# File 'lib/kitchen/driver/aws/standard_platform/centos.rb', line 87

def self.from_image(driver, image)
  return unless /centos/i.match?(image.name)

  image.name =~ /\b(\d+(\.\d+)?)\b/i
  new(driver, "centos", (Regexp.last_match || [])[1], image.architecture)
end

Instance Method Details

#image_search ⇒ Hash{String => String, Array<String>}

EC2 image filters that select CentOS Linux and CentOS Stream images.

A filter is added for Kitchen::Driver::Aws::StandardPlatform#architecture only when one was requested, so that an unspecified architecture matches any of them.



51
52
53
54
55
56
57
58
59
60
# File 'lib/kitchen/driver/aws/standard_platform/centos.rb', line 51

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

  search["architecture"] = architecture if architecture
  search
end

#sort_by_version(images) ⇒ Array<Aws::EC2::Image>

Sort images newest release first.

CentOS mixes bare majors ("CentOS Stream 9") with dotted releases ("CentOS 7.9"). A bare major is scored as ".999" so that Stream 9 ranks above 9.0 while still ranking below 10.



70
71
72
73
74
75
76
77
# File 'lib/kitchen/driver/aws/standard_platform/centos.rb', line 70

def sort_by_version(images)
  # 7.1 -> [ img1, img2, img3 ]
  # 6 -> [ img4, img5 ]
  # ...
  images.group_by { |image| self.class.from_image(driver, image).version }
    .sort_by { |k, _v| (k && k.include?(".") ? k.to_f : "#{k}.999".to_f) }
    .reverse.flat_map { |_k, v| v }
end

#username ⇒ String

The account EC2 creates on this platform's official AMIs.

CentOS 8 and earlier ship a "centos" account; Stream 9 moved to the "ec2-user" convention used by the other EL-family distributions.



39
40
41
# File 'lib/kitchen/driver/aws/standard_platform/centos.rb', line 39

def username
  version && version.to_f < 9.0 ? "centos" : "ec2-user"
end