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

ferruzzi 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 25f6675f8d4 Fix example_opensearch_serverless system test (#67666)
25f6675f8d4 is described below

commit 25f6675f8d469b1808ebacd6956c26f2c68843b9
Author: D. Ferruzzi <[email protected]>
AuthorDate: Fri May 29 17:27:14 2026 -0700

    Fix example_opensearch_serverless system test (#67666)
    
    Add encryption security policy creation before CreateCollection.
    OpenSearch Serverless requires an encryption policy matching the
    collection name before a collection can be created.
    
    Also add cleanup of the encryption policy in teardown.
---
 .../amazon/aws/example_opensearch_serverless.py    | 27 ++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/providers/amazon/tests/system/amazon/aws/example_opensearch_serverless.py 
b/providers/amazon/tests/system/amazon/aws/example_opensearch_serverless.py
index 66e3a79346a..91f788d6563 100644
--- a/providers/amazon/tests/system/amazon/aws/example_opensearch_serverless.py
+++ b/providers/amazon/tests/system/amazon/aws/example_opensearch_serverless.py
@@ -16,8 +16,11 @@
 # under the License.
 from __future__ import annotations
 
+import json
 from datetime import datetime
 
+import boto3
+
 from airflow.providers.amazon.aws.operators.opensearch_serverless import (
     OpenSearchServerlessCreateCollectionOperator,
 )
@@ -40,10 +43,27 @@ DAG_ID = "example_opensearch_serverless"
 sys_test_context_task = SystemTestContextBuilder().build()
 
 
+@task
+def create_encryption_policy(collection_name: str, policy_name: str):
+    boto3.client("opensearchserverless").create_security_policy(
+        name=policy_name,
+        type="encryption",
+        policy=json.dumps(
+            {
+                "Rules": [{"ResourceType": "collection", "Resource": 
[f"collection/{collection_name}"]}],
+                "AWSOwnedKey": True,
+            }
+        ),
+    )
+
+
 @task(trigger_rule=TriggerRule.ALL_DONE)
-def delete_collection(collection_id: str):
-    import boto3
+def delete_encryption_policy(policy_name: str):
+    
boto3.client("opensearchserverless").delete_security_policy(name=policy_name, 
type="encryption")
+
 
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def delete_collection(collection_id: str):
     boto3.client("opensearchserverless").delete_collection(id=collection_id)
 
 
@@ -56,6 +76,7 @@ with DAG(
     test_context = sys_test_context_task()
     env_id = test_context[ENV_ID_KEY]
     collection_name = f"{env_id}-collection"
+    encryption_policy_name = f"{env_id}-enc-policy"
 
     # [START howto_operator_opensearch_serverless_create_collection]
     create_collection = OpenSearchServerlessCreateCollectionOperator(
@@ -75,11 +96,13 @@ with DAG(
     chain(
         # TEST SETUP
         test_context,
+        create_encryption_policy(collection_name, encryption_policy_name),
         # TEST BODY
         create_collection,
         wait_for_collection,
         # TEST TEARDOWN
         delete_collection(create_collection.output),
+        delete_encryption_policy(encryption_policy_name),
     )
 
     from tests_common.test_utils.watcher import watcher

Reply via email to