You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by hu...@apache.org on 2023/11/29 17:03:20 UTC
(airflow) branch main updated: Fix EC2Hook get_instance for client_type api (#35960)
This is an automated email from the ASF dual-hosted git repository.
husseinawala 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 ab835c20b2 Fix EC2Hook get_instance for client_type api (#35960)
ab835c20b2 is described below
commit ab835c20b2e9bce8311d906d223ecca5e0f85627
Author: Hussein Awala <hu...@awala.fr>
AuthorDate: Wed Nov 29 19:03:12 2023 +0200
Fix EC2Hook get_instance for client_type api (#35960)
---
airflow/providers/amazon/aws/hooks/ec2.py | 2 +-
tests/providers/amazon/aws/hooks/test_ec2.py | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/airflow/providers/amazon/aws/hooks/ec2.py b/airflow/providers/amazon/aws/hooks/ec2.py
index c22f258dfd..4fdf409bbb 100644
--- a/airflow/providers/amazon/aws/hooks/ec2.py
+++ b/airflow/providers/amazon/aws/hooks/ec2.py
@@ -85,7 +85,7 @@ class EC2Hook(AwsBaseHook):
:return: Instance object
"""
if self._api_type == "client_type":
- return self.get_instances(filters=filters, instance_ids=[instance_id])
+ return self.get_instances(filters=filters, instance_ids=[instance_id])[0]
return self.conn.Instance(id=instance_id)
diff --git a/tests/providers/amazon/aws/hooks/test_ec2.py b/tests/providers/amazon/aws/hooks/test_ec2.py
index 8d852b4858..b989a57a65 100644
--- a/tests/providers/amazon/aws/hooks/test_ec2.py
+++ b/tests/providers/amazon/aws/hooks/test_ec2.py
@@ -77,6 +77,14 @@ class TestEC2Hook:
existing_instance = ec2_hook.get_instance(instance_id=created_instance_id)
assert created_instance_id == existing_instance.instance_id
+ @mock_ec2
+ def test_get_instance_client_type(self):
+ ec2_hook = EC2Hook(api_type="client_type")
+ created_instance_id = self._create_instance(ec2_hook)
+ # test get_instance method
+ existing_instance = ec2_hook.get_instance(instance_id=created_instance_id)
+ assert created_instance_id == existing_instance["InstanceId"]
+
@mock_ec2
def test_get_instance_state(self):
ec2_hook = EC2Hook()