This is an automated email from the ASF dual-hosted git repository.
potiuk 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 0dae1bcf29 Merge and optimize Cloud Build system tests (#33961)
0dae1bcf29 is described below
commit 0dae1bcf292dadda114db5d27b9795ec980c855d
Author: max <[email protected]>
AuthorDate: Fri Sep 1 14:34:45 2023 +0200
Merge and optimize Cloud Build system tests (#33961)
---
.../operators/cloud/cloud_build.rst | 16 +-
.../cloud/cloud_build/example_cloud_build.py | 298 +++++++++++++--------
.../cloud/cloud_build/example_cloud_build_async.py | 220 ---------------
.../cloud_build/example_cloud_build_trigger.py | 7 +-
.../cloud_build/resources/example_cloud_build.yaml | 2 +-
.../google/cloud/cloud_build/resources/file.tar.gz | Bin 135 -> 0 bytes
6 files changed, 194 insertions(+), 349 deletions(-)
diff --git
a/docs/apache-airflow-providers-google/operators/cloud/cloud_build.rst
b/docs/apache-airflow-providers-google/operators/cloud/cloud_build.rst
index 1ec7675cfe..f7d9115409 100644
--- a/docs/apache-airflow-providers-google/operators/cloud/cloud_build.rst
+++ b/docs/apache-airflow-providers-google/operators/cloud/cloud_build.rst
@@ -104,9 +104,9 @@ Trigger a build is performed with the
You can use deferrable mode for this action in order to run the operator
asynchronously:
-.. exampleinclude::
/../../tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
+.. exampleinclude::
../../../../tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
:language: python
- :dedent: 0
+ :dedent: 4
:start-after: [START howto_operator_create_build_from_storage_async]
:end-before: [END howto_operator_create_build_from_storage_async]
@@ -132,9 +132,9 @@ you can pass wait=False as example shown below.
You can use deferrable mode for this action in order to run the operator
asynchronously:
-.. exampleinclude::
/../../tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
+.. exampleinclude::
../../../../tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
:language: python
- :dedent: 0
+ :dedent: 4
:start-after: [START howto_operator_create_build_without_wait_async]
:end-before: [END howto_operator_create_build_without_wait_async]
@@ -149,9 +149,9 @@ that are needed for Cloud Build to perform your tasks. You
can write the build c
You can use deferrable mode for this action in order to run the operator
asynchronously:
-.. exampleinclude::
/../../tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
+.. exampleinclude::
../../../../tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
:language: python
- :dedent: 0
+ :dedent: 4
:start-after: [START howto_operator_gcp_create_build_from_yaml_body_async]
:end-before: [END howto_operator_gcp_create_build_from_yaml_body_async]
@@ -166,9 +166,9 @@ Once build has started, it ill build the code in source
repositories.
You can use deferrable mode for this action in order to run the operator
asynchronously:
-.. exampleinclude::
/../../tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
+.. exampleinclude::
../../../../tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
:language: python
- :dedent: 0
+ :dedent: 4
:start-after: [START howto_operator_create_build_from_repo_async]
:end-before: [END howto_operator_create_build_from_repo_async]
diff --git
a/tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
b/tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
index 1c14c53e31..8b0eed2c4c 100644
--- a/tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
+++ b/tests/system/providers/google/cloud/cloud_build/example_cloud_build.py
@@ -17,13 +17,6 @@
# under the License.
"""
Example Airflow DAG that displays interactions with Google Cloud Build.
-
-This DAG relies on the following OS environment variables:
-
-* PROJECT_ID - Google Cloud Project to use for the Cloud Function.
-* GCP_CLOUD_BUILD_ARCHIVE_URL - Path to the zipped source in Google Cloud
Storage.
- This object must be a gzipped archive file (.tar.gz) containing source to
build.
-* GCP_CLOUD_BUILD_REPOSITORY_NAME - Name of the Cloud Source Repository.
"""
from __future__ import annotations
@@ -31,12 +24,11 @@ import os
from datetime import datetime
from pathlib import Path
from typing import Any, cast
-from urllib.parse import urlsplit
import yaml
from airflow import models
-from airflow.models.baseoperator import chain
+from airflow.decorators import task_group
from airflow.models.xcom_arg import XComArg
from airflow.operators.bash import BashOperator
from airflow.providers.google.cloud.operators.cloud_build import (
@@ -46,35 +38,31 @@ from airflow.providers.google.cloud.operators.cloud_build
import (
CloudBuildListBuildsOperator,
CloudBuildRetryBuildOperator,
)
-from airflow.providers.google.cloud.operators.gcs import
GCSCreateBucketOperator, GCSDeleteBucketOperator
-from airflow.providers.google.cloud.transfers.local_to_gcs import
LocalFilesystemToGCSOperator
-from airflow.utils.trigger_rule import TriggerRule
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT")
DAG_ID = "example_gcp_cloud_build"
-BUCKET_NAME_SRC = f"bucket-src-{DAG_ID}-{ENV_ID}"
-
-GCP_SOURCE_ARCHIVE_URL = f"gs://{BUCKET_NAME_SRC}/file.tar.gz"
+GCP_SOURCE_ARCHIVE_URL =
"gs://airflow-system-tests-resources/cloud-build/file.tar.gz"
+# Repository with this name is expected created within the project
$SYSTEM_TESTS_GCP_PROJECT
+# If you'd like to run this system test locally, please
+# 1. Create Cloud Source Repository
+# 2. Push into a master branch the following file:
+#
tests/system/providers/google/cloud/cloud_build/resources/example_cloud_build.yaml
GCP_SOURCE_REPOSITORY_NAME = "test-cloud-build-repo"
-GCP_SOURCE_ARCHIVE_URL_PARTS = urlsplit(GCP_SOURCE_ARCHIVE_URL)
-GCP_SOURCE_BUCKET_NAME = GCP_SOURCE_ARCHIVE_URL_PARTS.netloc
-
CURRENT_FOLDER = Path(__file__).parent
-FILE_LOCAL_PATH = str(Path(CURRENT_FOLDER) / "resources" / "file.tar.gz")
# [START howto_operator_gcp_create_build_from_storage_body]
-create_build_from_storage_body = {
+CREATE_BUILD_FROM_STORAGE_BODY = {
"source": {"storage_source": GCP_SOURCE_ARCHIVE_URL},
"steps": [{"name": "ubuntu", "args": ["echo", "Hello world"]}],
}
# [END howto_operator_gcp_create_build_from_storage_body]
# [START howto_operator_create_build_from_repo_body]
-create_build_from_repo_body: dict[str, Any] = {
+CREATE_BUILD_FROM_REPO_BODY: dict[str, Any] = {
"source": {"repo_source": {"repo_name": GCP_SOURCE_REPOSITORY_NAME,
"branch_name": "master"}},
"steps": [{"name": "ubuntu", "args": ["echo", "Hello world"]}],
}
@@ -89,44 +77,98 @@ with models.DAG(
tags=["example"],
) as dag:
- create_bucket_src = GCSCreateBucketOperator(task_id="create_bucket_src",
bucket_name=BUCKET_NAME_SRC)
-
- upload_file = LocalFilesystemToGCSOperator(
- task_id="upload_file",
- src=FILE_LOCAL_PATH,
- dst="file.tar.gz",
- bucket=BUCKET_NAME_SRC,
- )
+ @task_group(group_id="build_from_storage")
+ def build_from_storage():
+ # [START howto_operator_create_build_from_storage]
+ create_build_from_storage = CloudBuildCreateBuildOperator(
+ task_id="create_build_from_storage",
+ project_id=PROJECT_ID,
+ build=CREATE_BUILD_FROM_STORAGE_BODY,
+ )
+ # [END howto_operator_create_build_from_storage]
+
+ # [START howto_operator_create_build_from_storage_result]
+ create_build_from_storage_result = BashOperator(
+ bash_command=f"echo {cast(str, XComArg(create_build_from_storage,
key='results'))}",
+ task_id="create_build_from_storage_result",
+ )
+ # [END howto_operator_create_build_from_storage_result]
+
+ create_build_from_storage >> create_build_from_storage_result
+
+ @task_group(group_id="build_from_storage_deferrable")
+ def build_from_storage_deferrable():
+ # [START howto_operator_create_build_from_storage_async]
+ create_build_from_storage = CloudBuildCreateBuildOperator(
+ task_id="create_build_from_storage",
+ project_id=PROJECT_ID,
+ build=CREATE_BUILD_FROM_STORAGE_BODY,
+ deferrable=True,
+ )
+ # [END howto_operator_create_build_from_storage_async]
+
+ create_build_from_storage_result = BashOperator(
+ bash_command=f"echo {cast(str, XComArg(create_build_from_storage,
key='results'))}",
+ task_id="create_build_from_storage_result",
+ )
+
+ create_build_from_storage >> create_build_from_storage_result
+
+ @task_group(group_id="build_from_repo")
+ def build_from_repo():
+ # [START howto_operator_create_build_from_repo]
+ create_build_from_repo = CloudBuildCreateBuildOperator(
+ task_id="create_build_from_repo",
+ project_id=PROJECT_ID,
+ build=CREATE_BUILD_FROM_REPO_BODY,
+ )
+ # [END howto_operator_create_build_from_repo]
+
+ # [START howto_operator_create_build_from_repo_result]
+ create_build_from_repo_result = BashOperator(
+ bash_command=f"echo {cast(str, XComArg(create_build_from_repo,
key='results'))}",
+ task_id="create_build_from_repo_result",
+ )
+ # [END howto_operator_create_build_from_repo_result]
+
+ create_build_from_repo >> create_build_from_repo_result
+
+ @task_group(group_id="build_from_repo_deferrable")
+ def build_from_repo_deferrable():
+ # [START howto_operator_create_build_from_repo_async]
+ create_build_from_repo = CloudBuildCreateBuildOperator(
+ task_id="create_build_from_repo",
+ project_id=PROJECT_ID,
+ build=CREATE_BUILD_FROM_REPO_BODY,
+ deferrable=True,
+ )
+ # [END howto_operator_create_build_from_repo_async]
+
+ create_build_from_repo_result = BashOperator(
+ bash_command=f"echo {cast(str, XComArg(create_build_from_repo,
key='results'))}",
+ task_id="create_build_from_repo_result",
+ )
+
+ create_build_from_repo >> create_build_from_repo_result
- # [START howto_operator_create_build_from_storage]
- create_build_from_storage = CloudBuildCreateBuildOperator(
- task_id="create_build_from_storage",
+ # [START howto_operator_gcp_create_build_from_yaml_body]
+ create_build_from_file = CloudBuildCreateBuildOperator(
+ task_id="create_build_from_file",
project_id=PROJECT_ID,
- build=create_build_from_storage_body,
- )
- # [END howto_operator_create_build_from_storage]
-
- # [START howto_operator_create_build_from_storage_result]
- create_build_from_storage_result = BashOperator(
- bash_command=f"echo {cast(str, XComArg(create_build_from_storage,
key='results'))}",
- task_id="create_build_from_storage_result",
+ build=yaml.safe_load((Path(CURRENT_FOLDER) / "resources" /
"example_cloud_build.yaml").read_text()),
+ params={"name": "Airflow"},
)
- # [END howto_operator_create_build_from_storage_result]
+ # [END howto_operator_gcp_create_build_from_yaml_body]
- # [START howto_operator_create_build_from_repo]
- create_build_from_repo = CloudBuildCreateBuildOperator(
- task_id="create_build_from_repo",
+ # [START howto_operator_gcp_create_build_from_yaml_body_async]
+ create_build_from_file_deferrable = CloudBuildCreateBuildOperator(
+ task_id="create_build_from_file_deferrable",
project_id=PROJECT_ID,
- build=create_build_from_repo_body,
- )
- # [END howto_operator_create_build_from_repo]
-
- # [START howto_operator_create_build_from_repo_result]
- create_build_from_repo_result = BashOperator(
- bash_command=f"echo {cast(str, XComArg(create_build_from_repo,
key='results'))}",
- task_id="create_build_from_repo_result",
+ build=yaml.safe_load((Path(CURRENT_FOLDER) / "resources" /
"example_cloud_build.yaml").read_text()),
+ params={"name": "Airflow"},
+ deferrable=True,
)
- # [END howto_operator_create_build_from_repo_result]
+ # [END howto_operator_gcp_create_build_from_yaml_body_async]
# [START howto_operator_list_builds]
list_builds = CloudBuildListBuildsOperator(
@@ -136,71 +178,91 @@ with models.DAG(
)
# [END howto_operator_list_builds]
- # [START howto_operator_create_build_without_wait]
- create_build_without_wait = CloudBuildCreateBuildOperator(
- task_id="create_build_without_wait",
- project_id=PROJECT_ID,
- build=create_build_from_repo_body,
- wait=False,
- )
- # [END howto_operator_create_build_without_wait]
-
- # [START howto_operator_cancel_build]
- cancel_build = CloudBuildCancelBuildOperator(
- task_id="cancel_build",
- id_=cast(str, XComArg(create_build_without_wait, key="id")),
- project_id=PROJECT_ID,
- )
- # [END howto_operator_cancel_build]
-
- # [START howto_operator_retry_build]
- retry_build = CloudBuildRetryBuildOperator(
- task_id="retry_build",
- id_=cast(str, XComArg(cancel_build, key="id")),
- project_id=PROJECT_ID,
- )
- # [END howto_operator_retry_build]
-
- # [START howto_operator_get_build]
- get_build = CloudBuildGetBuildOperator(
- task_id="get_build",
- id_=cast(str, XComArg(retry_build, key="id")),
- project_id=PROJECT_ID,
- )
- # [END howto_operator_get_build]
-
- # [START howto_operator_gcp_create_build_from_yaml_body]
- create_build_from_file = CloudBuildCreateBuildOperator(
- task_id="create_build_from_file",
- project_id=PROJECT_ID,
- build=yaml.safe_load((Path(CURRENT_FOLDER) / "resources" /
"example_cloud_build.yaml").read_text()),
- params={"name": "Airflow"},
- )
- # [END howto_operator_gcp_create_build_from_yaml_body]
-
- delete_bucket_src = GCSDeleteBucketOperator(
- task_id="delete_bucket_src",
- bucket_name=BUCKET_NAME_SRC,
- trigger_rule=TriggerRule.ALL_DONE,
- )
-
- chain(
- # TEST SETUP
- create_bucket_src,
- upload_file,
- # TEST BODY
- create_build_from_storage,
- create_build_from_storage_result,
- create_build_from_repo,
- create_build_from_repo_result,
- list_builds,
- create_build_without_wait,
- cancel_build,
- retry_build,
- get_build,
- create_build_from_file,
- # TEST TEARDOWN
- delete_bucket_src,
+ @task_group(group_id="no_wait_cancel_retry_get")
+ def no_wait_cancel_retry_get():
+
+ # [START howto_operator_create_build_without_wait]
+ create_build_without_wait = CloudBuildCreateBuildOperator(
+ task_id="create_build_without_wait",
+ project_id=PROJECT_ID,
+ build=CREATE_BUILD_FROM_REPO_BODY,
+ wait=False,
+ )
+ # [END howto_operator_create_build_without_wait]
+
+ # [START howto_operator_cancel_build]
+ cancel_build = CloudBuildCancelBuildOperator(
+ task_id="cancel_build",
+ id_=cast(str, XComArg(create_build_without_wait, key="id")),
+ project_id=PROJECT_ID,
+ )
+ # [END howto_operator_cancel_build]
+
+ # [START howto_operator_retry_build]
+ retry_build = CloudBuildRetryBuildOperator(
+ task_id="retry_build",
+ id_=cast(str, XComArg(cancel_build, key="id")),
+ project_id=PROJECT_ID,
+ )
+ # [END howto_operator_retry_build]
+
+ # [START howto_operator_get_build]
+ get_build = CloudBuildGetBuildOperator(
+ task_id="get_build",
+ id_=cast(str, XComArg(retry_build, key="id")),
+ project_id=PROJECT_ID,
+ )
+ # [END howto_operator_get_build]
+
+ create_build_without_wait >> cancel_build >> retry_build >> get_build
+
+ @task_group(group_id="no_wait_cancel_retry_get_deferrable")
+ def no_wait_cancel_retry_get_deferrable():
+ # [START howto_operator_create_build_without_wait_async]
+ create_build_without_wait = CloudBuildCreateBuildOperator(
+ task_id="create_build_without_wait",
+ project_id=PROJECT_ID,
+ build=CREATE_BUILD_FROM_REPO_BODY,
+ wait=False,
+ deferrable=True,
+ )
+ # [END howto_operator_create_build_without_wait_async]
+
+ cancel_build = CloudBuildCancelBuildOperator(
+ task_id="cancel_build",
+ id_=cast(str, XComArg(create_build_without_wait, key="id")),
+ project_id=PROJECT_ID,
+ )
+
+ retry_build = CloudBuildRetryBuildOperator(
+ task_id="retry_build",
+ id_=cast(str, XComArg(cancel_build, key="id")),
+ project_id=PROJECT_ID,
+ )
+
+ get_build = CloudBuildGetBuildOperator(
+ task_id="get_build",
+ id_=cast(str, XComArg(retry_build, key="id")),
+ project_id=PROJECT_ID,
+ )
+
+ create_build_without_wait >> cancel_build >> retry_build >> get_build
+
+ # TEST BODY
+ (
+ [
+ build_from_storage(),
+ build_from_storage_deferrable(),
+ build_from_repo(),
+ build_from_repo_deferrable(),
+ create_build_from_file,
+ create_build_from_file_deferrable,
+ ]
+ >> list_builds
+ >> [
+ no_wait_cancel_retry_get(),
+ no_wait_cancel_retry_get_deferrable(),
+ ]
)
from tests.system.utils.watcher import watcher
diff --git
a/tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
b/tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
deleted file mode 100644
index 42af8c4538..0000000000
---
a/tests/system/providers/google/cloud/cloud_build/example_cloud_build_async.py
+++ /dev/null
@@ -1,220 +0,0 @@
-#
-# 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.
-"""
-Example Airflow DAG that displays interactions with Google Cloud Build.
-
-This DAG relies on the following OS environment variables:
-
-* PROJECT_ID - Google Cloud Project to use for the Cloud Function.
-* GCP_CLOUD_BUILD_ARCHIVE_URL - Path to the zipped source in Google Cloud
Storage.
- This object must be a gzipped archive file (.tar.gz) containing source to
build.
-* GCP_CLOUD_BUILD_REPOSITORY_NAME - Name of the Cloud Source Repository.
-"""
-from __future__ import annotations
-
-import os
-from datetime import datetime
-from pathlib import Path
-from typing import Any, cast
-from urllib.parse import urlparse
-
-import yaml
-
-from airflow import models
-from airflow.models.baseoperator import chain
-from airflow.models.xcom_arg import XComArg
-from airflow.operators.bash import BashOperator
-from airflow.providers.google.cloud.operators.cloud_build import (
- CloudBuildCancelBuildOperator,
- CloudBuildCreateBuildOperator,
- CloudBuildGetBuildOperator,
- CloudBuildListBuildsOperator,
- CloudBuildRetryBuildOperator,
-)
-from airflow.providers.google.cloud.operators.gcs import
GCSCreateBucketOperator, GCSDeleteBucketOperator
-from airflow.providers.google.cloud.transfers.local_to_gcs import
LocalFilesystemToGCSOperator
-from airflow.utils.trigger_rule import TriggerRule
-
-ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
-PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT")
-
-DAG_ID = "example_gcp_cloud_build_async"
-
-BUCKET_NAME_SRC = f"bucket-src-{DAG_ID}-{ENV_ID}"
-
-GCP_SOURCE_ARCHIVE_URL = f"gs://{BUCKET_NAME_SRC}/file.tar.gz"
-GCP_SOURCE_REPOSITORY_NAME = "test-cloud-build-repo"
-
-GCP_SOURCE_ARCHIVE_URL_PARTS = urlparse(GCP_SOURCE_ARCHIVE_URL)
-GCP_SOURCE_BUCKET_NAME = GCP_SOURCE_ARCHIVE_URL_PARTS.netloc
-
-CURRENT_FOLDER = Path(__file__).parent
-FILE_LOCAL_PATH = str(Path(CURRENT_FOLDER) / "resources" / "file.tar.gz")
-
-# [START howto_operator_gcp_create_build_from_storage_body]
-create_build_from_storage_body = {
- "source": {"storage_source": GCP_SOURCE_ARCHIVE_URL},
- "steps": [{"name": "ubuntu", "args": ["echo", "Hello world"]}],
-}
-# [END howto_operator_gcp_create_build_from_storage_body]
-
-# [START howto_operator_create_build_from_repo_body]
-create_build_from_repo_body: dict[str, Any] = {
- "source": {"repo_source": {"repo_name": GCP_SOURCE_REPOSITORY_NAME,
"branch_name": "master"}},
- "steps": [{"name": "ubuntu", "args": ["echo", "Hello world"]}],
-}
-# [END howto_operator_create_build_from_repo_body]
-
-
-with models.DAG(
- DAG_ID,
- schedule="@once",
- start_date=datetime(2021, 1, 1),
- catchup=False,
- tags=["example"],
-) as dag:
-
- create_bucket_src = GCSCreateBucketOperator(task_id="create_bucket_src",
bucket_name=BUCKET_NAME_SRC)
-
- upload_file = LocalFilesystemToGCSOperator(
- task_id="upload_file",
- src=FILE_LOCAL_PATH,
- dst="file.tar.gz",
- bucket=BUCKET_NAME_SRC,
- )
-
- # [START howto_operator_create_build_from_storage_async]
- create_build_from_storage = CloudBuildCreateBuildOperator(
- task_id="create_build_from_storage",
- project_id=PROJECT_ID,
- build=create_build_from_storage_body,
- deferrable=True,
- )
- # [END howto_operator_create_build_from_storage_async]
-
- # [START howto_operator_create_build_from_storage_result]
- create_build_from_storage_result = BashOperator(
- bash_command=f"echo {cast(str, XComArg(create_build_from_storage,
key='results'))}",
- task_id="create_build_from_storage_result",
- )
- # [END howto_operator_create_build_from_storage_result]
-
- # [START howto_operator_create_build_from_repo_async]
- create_build_from_repo = CloudBuildCreateBuildOperator(
- task_id="create_build_from_repo",
- project_id=PROJECT_ID,
- build=create_build_from_repo_body,
- deferrable=True,
- )
- # [END howto_operator_create_build_from_repo_async]
-
- # [START howto_operator_create_build_from_repo_result]
- create_build_from_repo_result = BashOperator(
- bash_command=f"echo {cast(str, XComArg(create_build_from_repo,
key='results'))}",
- task_id="create_build_from_repo_result",
- )
- # [END howto_operator_create_build_from_repo_result]
-
- # [START howto_operator_list_builds]
- list_builds = CloudBuildListBuildsOperator(
- task_id="list_builds",
- project_id=PROJECT_ID,
- location="global",
- )
- # [END howto_operator_list_builds]
-
- # [START howto_operator_create_build_without_wait_async]
- create_build_without_wait = CloudBuildCreateBuildOperator(
- task_id="create_build_without_wait",
- project_id=PROJECT_ID,
- build=create_build_from_repo_body,
- wait=False,
- deferrable=True,
- )
- # [END howto_operator_create_build_without_wait_async]
-
- # [START howto_operator_cancel_build]
- cancel_build = CloudBuildCancelBuildOperator(
- task_id="cancel_build",
- id_=cast(str, XComArg(create_build_without_wait, key="id")),
- project_id=PROJECT_ID,
- )
- # [END howto_operator_cancel_build]
-
- # [START howto_operator_retry_build]
- retry_build = CloudBuildRetryBuildOperator(
- task_id="retry_build",
- id_=cast(str, XComArg(cancel_build, key="id")),
- project_id=PROJECT_ID,
- )
- # [END howto_operator_retry_build]
-
- # [START howto_operator_get_build]
- get_build = CloudBuildGetBuildOperator(
- task_id="get_build",
- id_=cast(str, XComArg(retry_build, key="id")),
- project_id=PROJECT_ID,
- )
- # [END howto_operator_get_build]
-
- # [START howto_operator_gcp_create_build_from_yaml_body_async]
- create_build_from_file = CloudBuildCreateBuildOperator(
- task_id="create_build_from_file",
- project_id=PROJECT_ID,
- build=yaml.safe_load((Path(CURRENT_FOLDER) / "resources" /
"example_cloud_build.yaml").read_text()),
- params={"name": "Airflow"},
- deferrable=True,
- )
- # [END howto_operator_gcp_create_build_from_yaml_body_async]
-
- delete_bucket_src = GCSDeleteBucketOperator(
- task_id="delete_bucket_src",
- bucket_name=BUCKET_NAME_SRC,
- trigger_rule=TriggerRule.ALL_DONE,
- )
-
- chain(
- # TEST SETUP
- create_bucket_src,
- upload_file,
- # TEST BODY
- create_build_from_storage,
- create_build_from_storage_result,
- create_build_from_repo,
- create_build_from_repo_result,
- list_builds,
- create_build_without_wait,
- cancel_build,
- retry_build,
- get_build,
- create_build_from_file,
- # TEST TEARDOWN
- delete_bucket_src,
- )
-
- from tests.system.utils.watcher import watcher
-
- # This test needs watcher in order to properly mark success/failure
- # when "tearDown" task with trigger rule is part of the DAG
- list(dag.tasks) >> watcher()
-
-
-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)
-test_run = get_test_run(dag)
diff --git
a/tests/system/providers/google/cloud/cloud_build/example_cloud_build_trigger.py
b/tests/system/providers/google/cloud/cloud_build/example_cloud_build_trigger.py
index 906f5df628..7828c33129 100644
---
a/tests/system/providers/google/cloud/cloud_build/example_cloud_build_trigger.py
+++
b/tests/system/providers/google/cloud/cloud_build/example_cloud_build_trigger.py
@@ -17,8 +17,6 @@
# under the License.
"""
Example Airflow DAG that displays interactions with Google Cloud Build.
-This DAG relies on the following OS environment variables:
-* PROJECT_ID - Google Cloud Project to use for the Cloud Function.
"""
from __future__ import annotations
@@ -44,6 +42,11 @@ PROJECT_ID = os.environ.get("SYSTEM_TESTS_GCP_PROJECT")
DAG_ID = "example_gcp_cloud_build_trigger"
+# Repository with this name is expected created within the project
$SYSTEM_TESTS_GCP_PROJECT
+# If you'd like to run this system test locally, please
+# 1. Create Cloud Source Repository
+# 2. Push into a master branch the following file:
+#
tests/system/providers/google/cloud/cloud_build/resources/example_cloud_build.yaml
GCP_SOURCE_REPOSITORY_NAME = "test-cloud-build-repo"
TRIGGER_NAME = f"cloud-build-trigger-{ENV_ID}"
diff --git
a/tests/system/providers/google/cloud/cloud_build/resources/example_cloud_build.yaml
b/tests/system/providers/google/cloud/cloud_build/resources/example_cloud_build.yaml
index 7d62a7ece1..7ec9e6a500 100644
---
a/tests/system/providers/google/cloud/cloud_build/resources/example_cloud_build.yaml
+++
b/tests/system/providers/google/cloud/cloud_build/resources/example_cloud_build.yaml
@@ -17,4 +17,4 @@
---
steps:
- name: 'ubuntu'
- args: ['echo', 'Hello {{ params.name}}']
+ args: ['echo', 'Hello {{ params.name }}']
diff --git
a/tests/system/providers/google/cloud/cloud_build/resources/file.tar.gz
b/tests/system/providers/google/cloud/cloud_build/resources/file.tar.gz
deleted file mode 100644
index 51657f1f67..0000000000
Binary files
a/tests/system/providers/google/cloud/cloud_build/resources/file.tar.gz and
/dev/null differ