This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new edd44b90aee Ignore Amazon Linux preview AMIs in get_latest_ami_id 
(#72520)
edd44b90aee is described below

commit edd44b90aeeba01839a9e61d5349443b67a39902
Author: Vincent <[email protected]>
AuthorDate: Tue Sep 8 19:48:14 2026 -0500

    Ignore Amazon Linux preview AMIs in get_latest_ami_id (#72520)
    
    get_latest_ami_id() returns the newest Amazon owned AMI whose description
    matches "Amazon Linux*". As soon as a preview AMI for an unreleased Amazon
    Linux generation is published it is newer than every released image, so the
    helper starts handing that preview image to example_ec2 and example_ssm.
    
    Preview images are not supported by every AWS service. SSM Patch Manager for
    instance has no patch baseline operating system for them, so tooling that
    patches the instances these system tests start fails for as long as one of
    them is running.
    
    Filter out any image whose name or description mentions "preview" so the
    helper keeps returning a released image, and drop the stale comment about 
the
    Amazon Linux 2022 rename.
---
 .../amazon/tests/system/amazon/aws/utils/ec2.py    | 24 ++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/providers/amazon/tests/system/amazon/aws/utils/ec2.py 
b/providers/amazon/tests/system/amazon/aws/utils/ec2.py
index 15c6a8e9a23..c162df118b8 100644
--- a/providers/amazon/tests/system/amazon/aws/utils/ec2.py
+++ b/providers/amazon/tests/system/amazon/aws/utils/ec2.py
@@ -56,12 +56,12 @@ def _get_next_available_cidr(vpc_id: str) -> str:
 
 @task
 def get_latest_ami_id():
-    """Returns the AMI ID of the most recently-created Amazon Linux image"""
+    """Returns the AMI ID of the most recently-created released Amazon Linux 
image"""
 
-    # Amazon is retiring AL2 in 2023 and replacing it with Amazon Linux 2022.
-    # This image prefix should be futureproof, but may need adjusting depending
-    # on how they name the new images.  This page should have AL2022 info when
-    # it comes available: https://aws.amazon.com/linux/amazon-linux-2022/faqs/
+    # Amazon Linux images are published with a description such as
+    # "Amazon Linux 2023 AMI 2023.9.20260819.0 arm64 HVM kernel-6.1", so this 
prefix matches every
+    # generation without needing an update when a new one is released. It also 
matches the preview
+    # images of unreleased generations, which are filtered out below.
     image_prefix = "Amazon Linux*"
     root_device_name = "/dev/xvda"
 
@@ -80,8 +80,20 @@ def get_latest_ami_id():
         ],
         Owners=["amazon"],
     )
+
+    # Preview images of an unreleased Amazon Linux generation are always newer 
than the latest released
+    # one, and they are not supported by every AWS service, so they must not 
be picked here. describe_images
+    # filters cannot express "does not contain", hence the filtering below.
+    released_images = [
+        image
+        for image in images["Images"]
+        if "preview" not in f"{image.get('Name', '')} 
{image.get('Description', '')}".lower()
+    ]
+    if not released_images:
+        raise ValueError("No released Amazon Linux AMI matching the requested 
criteria was found.")
+
     # Sort on CreationDate
-    return max(images["Images"], key=itemgetter("CreationDate"))["ImageId"]
+    return max(released_images, key=itemgetter("CreationDate"))["ImageId"]
 
 
 @task

Reply via email to