From b0d01f5fe34fdae5aa286874dd79a5ffd99f570e Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Fri, 1 Sep 2023 17:49:04 +0800 Subject: [PATCH 1/2] test(providers/microsoft): add system test for AzureContainerVolumeHook and AzureContainerRegistryHook --- .../example_azure_container_instances.py | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/system/providers/microsoft/azure/example_azure_container_instances.py b/tests/system/providers/microsoft/azure/example_azure_container_instances.py index be0052f3a4014..1a9039dbddc42 100644 --- a/tests/system/providers/microsoft/azure/example_azure_container_instances.py +++ b/tests/system/providers/microsoft/azure/example_azure_container_instances.py @@ -24,10 +24,14 @@ from datetime import datetime, timedelta from airflow import DAG +from airflow.providers.microsoft.azure.hooks.container_volume import AzureContainerVolumeHook from airflow.providers.microsoft.azure.operators.container_instances import AzureContainerInstancesOperator ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") DAG_ID = "aci_example" +CONTAINER_REGISTRY_SERVER = os.environ.get("CONTAINER_REGISTRY_SERVER") +AZURE_VOLUME_SHARE_NAME = os.environ.get("AZURE_VOLUME_SHARE_NAME") +AZURE_STORAGE_ACOOUNT = os.environ.get("AZURE_STORAGE_ACOOUNT") with DAG( dag_id=DAG_ID, @@ -37,7 +41,6 @@ catchup=False, tags=["example"], ) as dag: - t1 = AzureContainerInstancesOperator( ci_conn_id="azure_default", registry_conn_id=None, @@ -52,7 +55,39 @@ task_id="start_container", ) + t2 = AzureContainerInstancesOperator( + ci_conn_id="azure_default", + registry_conn_id=None, + resource_group="resource-group", + name="aci-test-{{ ds }}", + image=f"{CONTAINER_REGISTRY_SERVER}:hello-world", + region="WestUS2", + environment_variables={}, + volumes=[], + memory_in_gb=4.0, + cpu=1.0, + task_id="start_container_with_custom_container_registry", + ) + t3 = AzureContainerInstancesOperator( + ci_conn_id="azure_default", + registry_conn_id=None, + resource_group="resource-group", + name="aci-test-{{ ds }}", + image="hello-world", + region="WestUS2", + environment_variables={}, + volumes=[ + AzureContainerVolumeHook().get_file_volume( + mount_name="mountname", + share_name=AZURE_VOLUME_SHARE_NAME, + storage_account_name=AZURE_STORAGE_ACOOUNT, + ) + ], + memory_in_gb=4.0, + cpu=1.0, + task_id="start_container_with_azure_container_volume", + ) from tests.system.utils import get_test_run # noqa: E402 # Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest) From 6bcef3c2690088613ac9d1e7bb9aff0b5d571df0 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Mon, 4 Sep 2023 17:52:21 +0800 Subject: [PATCH 2/2] test(providers/microsoft): fix wrong AzureContainerVolumeHook example --- .../azure/example_azure_container_instances.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/system/providers/microsoft/azure/example_azure_container_instances.py b/tests/system/providers/microsoft/azure/example_azure_container_instances.py index 1a9039dbddc42..9a7d8abac1cd4 100644 --- a/tests/system/providers/microsoft/azure/example_azure_container_instances.py +++ b/tests/system/providers/microsoft/azure/example_azure_container_instances.py @@ -24,7 +24,6 @@ from datetime import datetime, timedelta from airflow import DAG -from airflow.providers.microsoft.azure.hooks.container_volume import AzureContainerVolumeHook from airflow.providers.microsoft.azure.operators.container_instances import AzureContainerInstancesOperator ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") @@ -78,10 +77,12 @@ region="WestUS2", environment_variables={}, volumes=[ - AzureContainerVolumeHook().get_file_volume( - mount_name="mountname", - share_name=AZURE_VOLUME_SHARE_NAME, - storage_account_name=AZURE_STORAGE_ACOOUNT, + ( + "azure_container_volume_default", + AZURE_STORAGE_ACOOUNT, + AZURE_VOLUME_SHARE_NAME, + "/home", + True, ) ], memory_in_gb=4.0,