From c42c673d5bb10ad37a3034e2a8dd625cb42dfefc Mon Sep 17 00:00:00 2001 From: David Ashton Date: Fri, 24 Nov 2023 10:47:56 -0500 Subject: [PATCH 1/5] Update example_ec2 instance to support hibernation --- tests/system/providers/amazon/aws/example_ec2.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/system/providers/amazon/aws/example_ec2.py b/tests/system/providers/amazon/aws/example_ec2.py index aeffe4ad34ff7..6143696f73a76 100644 --- a/tests/system/providers/amazon/aws/example_ec2.py +++ b/tests/system/providers/amazon/aws/example_ec2.py @@ -50,11 +50,14 @@ def get_latest_ami_id(): # 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/ image_prefix = "Amazon Linux*" + root_device_name = "/dev/xvda" images = boto3.client("ec2").describe_images( Filters=[ {"Name": "description", "Values": [image_prefix]}, - {"Name": "architecture", "Values": ["arm64"]}, + {"Name": "architecture", "Values": ["x86_64"]}, + {"Name": "root-device-type", "Values": ["ebs"]}, + {"Name": "root-device-name", "Values": [root_device_name]}, ], Owners=["amazon"], ) @@ -97,7 +100,7 @@ def parse_response(instance_ids: list): image_id = get_latest_ami_id() config = { - "InstanceType": "t4g.micro", + "InstanceType": "t3.micro", "KeyName": key_name, "TagSpecifications": [ {"ResourceType": "instance", "Tags": [{"Key": "Name", "Value": instance_name}]} @@ -106,6 +109,9 @@ def parse_response(instance_ids: list): # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html "MetadataOptions": {"HttpEndpoint": "enabled", "HttpTokens": "required"}, "HibernationOptions": {"Configured": True}, + "BlockDeviceMappings": [ + {"DeviceName": "/dev/xvda", "Ebs": {"Encrypted": True, "DeleteOnTermination": True}} + ], } # EC2CreateInstanceOperator creates and starts the EC2 instances. To test the EC2StartInstanceOperator, From ae55a85bce092239dd5afa73b2f3dc4cc2d8ae38 Mon Sep 17 00:00:00 2001 From: David Ashton Date: Fri, 24 Nov 2023 16:03:54 -0500 Subject: [PATCH 2/5] Add wait_for_completion for hibernate and reboot operators in EC2 example --- tests/system/providers/amazon/aws/example_ec2.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/system/providers/amazon/aws/example_ec2.py b/tests/system/providers/amazon/aws/example_ec2.py index 6143696f73a76..4552c02fdf945 100644 --- a/tests/system/providers/amazon/aws/example_ec2.py +++ b/tests/system/providers/amazon/aws/example_ec2.py @@ -155,6 +155,7 @@ def parse_response(instance_ids: list): reboot_instance = EC2RebootInstanceOperator( task_id="reboot_instace", instance_ids=instance_id, + wait_for_completion=True, ) # [END howto_operator_ec2_reboot_instance] @@ -162,6 +163,7 @@ def parse_response(instance_ids: list): hibernate_instance = EC2HibernateInstanceOperator( task_id="hibernate_instace", instance_ids=instance_id, + wait_for_completion=True, ) # [END howto_operator_ec2_hibernate_instance] From 00e06ce86601f8c2c54b9e16ccb6177477c76b7a Mon Sep 17 00:00:00 2001 From: David Ashton Date: Tue, 28 Nov 2023 20:28:42 -0500 Subject: [PATCH 3/5] Change max_attempts to 75 for example_ec2 DAG --- tests/system/providers/amazon/aws/example_ec2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/system/providers/amazon/aws/example_ec2.py b/tests/system/providers/amazon/aws/example_ec2.py index 4552c02fdf945..778bab2875abf 100644 --- a/tests/system/providers/amazon/aws/example_ec2.py +++ b/tests/system/providers/amazon/aws/example_ec2.py @@ -164,6 +164,7 @@ def parse_response(instance_ids: list): task_id="hibernate_instace", instance_ids=instance_id, wait_for_completion=True, + max_attempts=75, ) # [END howto_operator_ec2_hibernate_instance] From b8e65688f4d6db438465c82d2146333d2e117e71 Mon Sep 17 00:00:00 2001 From: David Ashton Date: Thu, 30 Nov 2023 20:18:07 -0500 Subject: [PATCH 4/5] Move configurations out of code block --- tests/system/providers/amazon/aws/example_ec2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/providers/amazon/aws/example_ec2.py b/tests/system/providers/amazon/aws/example_ec2.py index 778bab2875abf..dbed6d31b0a83 100644 --- a/tests/system/providers/amazon/aws/example_ec2.py +++ b/tests/system/providers/amazon/aws/example_ec2.py @@ -155,18 +155,18 @@ def parse_response(instance_ids: list): reboot_instance = EC2RebootInstanceOperator( task_id="reboot_instace", instance_ids=instance_id, - wait_for_completion=True, ) # [END howto_operator_ec2_reboot_instance] + reboot_instance.wait_for_completion = True # [START howto_operator_ec2_hibernate_instance] hibernate_instance = EC2HibernateInstanceOperator( task_id="hibernate_instace", instance_ids=instance_id, - wait_for_completion=True, - max_attempts=75, ) # [END howto_operator_ec2_hibernate_instance] + hibernate_instance.wait_for_completion = True + hibernate_instance.max_attempts = 75 # [START howto_operator_ec2_terminate_instance] terminate_instance = EC2TerminateInstanceOperator( From 4089321bc32e1f5c21246afc3920e8b804aed0a6 Mon Sep 17 00:00:00 2001 From: David Ashton Date: Mon, 4 Dec 2023 18:50:38 -0500 Subject: [PATCH 5/5] add comments to ec2 example --- tests/system/providers/amazon/aws/example_ec2.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/system/providers/amazon/aws/example_ec2.py b/tests/system/providers/amazon/aws/example_ec2.py index dbed6d31b0a83..11320f1047cc9 100644 --- a/tests/system/providers/amazon/aws/example_ec2.py +++ b/tests/system/providers/amazon/aws/example_ec2.py @@ -55,8 +55,14 @@ def get_latest_ami_id(): images = boto3.client("ec2").describe_images( Filters=[ {"Name": "description", "Values": [image_prefix]}, - {"Name": "architecture", "Values": ["x86_64"]}, - {"Name": "root-device-type", "Values": ["ebs"]}, + { + "Name": "architecture", + "Values": ["x86_64"], + }, # t3 instances are only compatible with x86 architecture + { + "Name": "root-device-type", + "Values": ["ebs"], + }, # instances which are capable of hibernation need to use an EBS-backed AMI {"Name": "root-device-name", "Values": [root_device_name]}, ], Owners=["amazon"],