vincbeck commented on code in PR #66046:
URL: https://github.com/apache/airflow/pull/66046#discussion_r3169745824


##########
providers/amazon/tests/system/amazon/aws/example_mwaa_serverless.py:
##########
@@ -0,0 +1,162 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from datetime import datetime
+
+from airflow.providers.amazon.aws.operators.mwaa_serverless import (
+    MwaaServerlessStartWorkflowRunOperator,
+)
+from airflow.providers.amazon.aws.operators.s3 import (
+    S3CreateBucketOperator,
+    S3CreateObjectOperator,
+    S3DeleteBucketOperator,
+)
+from airflow.providers.common.compat.sdk import DAG, chain
+
+from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+    from airflow.sdk import TriggerRule, task
+else:
+    from airflow.decorators import task  # type: ignore[attr-defined,no-redef]
+    from airflow.utils.trigger_rule import TriggerRule  # type: 
ignore[no-redef,attr-defined]
+
+DAG_ID = "example_mwaa_serverless"
+
+# Externally fetched variables:
+ROLE_ARN_KEY = "ROLE_ARN"
+
+# Valid MWAA Serverless YAML: tasks as mapping, FQN operators, flat parameters.
+WORKFLOW_YAML = """\
+systest_mwaa_serverless:
+  schedule: null
+  description: "System test: S3 key sensor on workflow definition"
+  tasks:
+    check_file:
+      task_id: check_file
+      operator: airflow.providers.amazon.aws.sensors.s3.S3KeySensor
+      bucket_name: {bucket}
+      bucket_key: workflow.yaml
+"""
+
+sys_test_context_task = 
SystemTestContextBuilder().add_variable(ROLE_ARN_KEY).build()
+
+
+@task
+def create_workflow(bucket: str, role_arn: str) -> str:
+    """Create the MWAA Serverless workflow with retry for IAM propagation."""
+    import boto3
+    from tenacity import retry, retry_if_exception_type, stop_after_attempt, 
wait_exponential
+
+    @retry(
+        retry=retry_if_exception_type(Exception),
+        stop=stop_after_attempt(5),
+        wait=wait_exponential(multiplier=2, min=4, max=30),
+        reraise=True,
+    )
+    def _create():
+        mwaa = boto3.client("mwaa-serverless")
+        return mwaa.create_workflow(
+            Name=bucket,
+            DefinitionS3Location={"Bucket": bucket, "ObjectKey": 
"workflow.yaml"},
+            RoleArn=role_arn,
+        )["WorkflowArn"]
+
+    return _create()
+
+
+@task(trigger_rule=TriggerRule.ALL_DONE)
+def stop_workflow_run(workflow_arn: str, run_id: str):
+    """Stop the workflow run."""
+    import boto3
+
+    try:
+        
boto3.client("mwaa-serverless").stop_workflow_run(WorkflowArn=workflow_arn, 
RunId=run_id)
+    except Exception:

Review Comment:
   No need to wrap it up, the `stop` should succeed



##########
providers/amazon/tests/system/amazon/aws/example_mwaa_serverless.py:
##########
@@ -0,0 +1,162 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from datetime import datetime
+
+from airflow.providers.amazon.aws.operators.mwaa_serverless import (
+    MwaaServerlessStartWorkflowRunOperator,
+)
+from airflow.providers.amazon.aws.operators.s3 import (
+    S3CreateBucketOperator,
+    S3CreateObjectOperator,
+    S3DeleteBucketOperator,
+)
+from airflow.providers.common.compat.sdk import DAG, chain
+
+from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder
+from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
+
+if AIRFLOW_V_3_0_PLUS:
+    from airflow.sdk import TriggerRule, task
+else:
+    from airflow.decorators import task  # type: ignore[attr-defined,no-redef]
+    from airflow.utils.trigger_rule import TriggerRule  # type: 
ignore[no-redef,attr-defined]
+
+DAG_ID = "example_mwaa_serverless"
+
+# Externally fetched variables:
+ROLE_ARN_KEY = "ROLE_ARN"
+
+# Valid MWAA Serverless YAML: tasks as mapping, FQN operators, flat parameters.
+WORKFLOW_YAML = """\
+systest_mwaa_serverless:
+  schedule: null
+  description: "System test: S3 key sensor on workflow definition"
+  tasks:
+    check_file:
+      task_id: check_file
+      operator: airflow.providers.amazon.aws.sensors.s3.S3KeySensor
+      bucket_name: {bucket}
+      bucket_key: workflow.yaml
+"""
+
+sys_test_context_task = 
SystemTestContextBuilder().add_variable(ROLE_ARN_KEY).build()
+
+
+@task
+def create_workflow(bucket: str, role_arn: str) -> str:
+    """Create the MWAA Serverless workflow with retry for IAM propagation."""
+    import boto3
+    from tenacity import retry, retry_if_exception_type, stop_after_attempt, 
wait_exponential
+
+    @retry(
+        retry=retry_if_exception_type(Exception),
+        stop=stop_after_attempt(5),
+        wait=wait_exponential(multiplier=2, min=4, max=30),
+        reraise=True,
+    )

Review Comment:
   Let's simplify it, move this to the `create_workflow` function level and 
import `tenacity` at the top level, no need to have nested function



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to