automation: always use latest Windows AMI
The old AMI isn't available any more.
We seem to run into this problem every few months. Amazon (or
Microsoft) appears to be removing the old AMIs when they are
superseded or something. Let's give up on tracking known images
and switch the image selection logic to use the latest published
image.
Differential Revision: https://phab.mercurial-scm.org/D8465
--- a/contrib/automation/hgautomation/aws.py Fri Apr 17 21:00:18 2020 -0400
+++ b/contrib/automation/hgautomation/aws.py Sun Apr 19 13:29:50 2020 -0700
@@ -59,7 +59,7 @@
UBUNTU_ACCOUNT_ID = '099720109477'
-WINDOWS_BASE_IMAGE_NAME = 'Windows_Server-2019-English-Full-Base-2019.11.13'
+WINDOWS_BASE_IMAGE_NAME = 'Windows_Server-2019-English-Full-Base-*'
KEY_PAIRS = {
@@ -464,7 +464,7 @@
profile.add_role(RoleName=role)
-def find_image(ec2resource, owner_id, name):
+def find_image(ec2resource, owner_id, name, reverse_sort_field=None):
"""Find an AMI by its owner ID and name."""
images = ec2resource.images.filter(
@@ -476,6 +476,13 @@
]
)
+ if reverse_sort_field:
+ images = sorted(
+ images,
+ key=lambda image: getattr(image, reverse_sort_field),
+ reverse=True,
+ )
+
for image in images:
return image
@@ -1059,7 +1066,7 @@
def ensure_windows_dev_ami(
- c: AWSConnection, prefix='hg-', base_image_name=WINDOWS_BASE_IMAGE_NAME
+ c: AWSConnection, prefix='hg-', base_image_name=WINDOWS_BASE_IMAGE_NAME,
):
"""Ensure Windows Development AMI is available and up-to-date.
@@ -1078,7 +1085,12 @@
name = '%s%s' % (prefix, 'windows-dev')
- image = find_image(ec2resource, AMAZON_ACCOUNT_ID, base_image_name)
+ image = find_image(
+ ec2resource,
+ AMAZON_ACCOUNT_ID,
+ base_image_name,
+ reverse_sort_field="name",
+ )
config = {
'BlockDeviceMappings': [