Skip to content

Commit 49abce5

Browse files
authored
Improve system tests for Cloud Build (#8003)
1 parent 996bf2e commit 49abce5

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

β€Žairflow/providers/google/cloud/example_dags/example_cloud_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "example-project")
4141

4242
GCP_SOURCE_ARCHIVE_URL = os.environ.get("GCP_CLOUD_BUILD_ARCHIVE_URL", "gs://example-bucket/file")
43-
GCP_SOURCE_REPOSITORY_NAME = os.environ.get("GCP_CLOUD_BUILD_REPOSITORY_NAME", "")
43+
GCP_SOURCE_REPOSITORY_NAME = os.environ.get("GCP_CLOUD_BUILD_REPOSITORY_NAME", "repository-name")
4444

4545
GCP_SOURCE_ARCHIVE_URL_PARTS = urlparse(GCP_SOURCE_ARCHIVE_URL)
4646
GCP_SOURCE_BUCKET_NAME = GCP_SOURCE_ARCHIVE_URL_PARTS.netloc

β€Žtests/providers/google/cloud/operators/test_cloud_build_operator_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CloudBuildExampleDagsSystemTest(GoogleSystemTest):
3333
"""
3434
helper = GCPCloudBuildTestHelper()
3535

36-
@provide_gcp_context(GCP_CLOUD_BUILD_KEY)
36+
@provide_gcp_context(GCP_CLOUD_BUILD_KEY, project_id=GoogleSystemTest._project_id())
3737
def setUp(self):
3838
super().setUp()
3939
self.helper.create_repository_and_bucket()
@@ -42,7 +42,7 @@ def setUp(self):
4242
def test_run_example_dag(self):
4343
self.run_dag("example_gcp_cloud_build", CLOUD_DAG_FOLDER)
4444

45-
@provide_gcp_context(GCP_CLOUD_BUILD_KEY)
45+
@provide_gcp_context(GCP_CLOUD_BUILD_KEY, project_id=GoogleSystemTest._project_id())
4646
def tearDown(self):
4747
self.helper.delete_bucket()
4848
self.helper.delete_docker_images()

β€Žtests/providers/google/cloud/operators/test_cloud_build_system_helper.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from tests.providers.google.cloud.utils.gcp_authenticator import GCP_CLOUD_BUILD_KEY, GcpAuthenticator
2828
from tests.utils.logging_command_executor import LoggingCommandExecutor
2929

30-
GCE_INSTANCE = os.environ.get("GCE_INSTANCE", "testinstance")
3130
GCP_PROJECT_ID = os.environ.get("GCP_PROJECT_ID", "example-project")
3231
GCP_ARCHIVE_URL = os.environ.get("GCP_CLOUD_BUILD_ARCHIVE_URL", "gs://example-bucket/source-code.tar.gz")
3332
GCP_ARCHIVE_URL_PARTS = urlparse(GCP_ARCHIVE_URL)
@@ -71,7 +70,7 @@ def create_repository_and_bucket(self):
7170
self.execute_cmd(["gcloud", "source", "repos", "create", GCP_REPOSITORY_NAME])
7271
self.execute_cmd(["git", "init"], cwd=tmp_dir)
7372
self.execute_cmd(["git", "config", "user.email", "bot@example.com"], cwd=tmp_dir)
74-
self.execute_cmd(["git", "config", "user.name", "system-test"])
73+
self.execute_cmd(["git", "config", "user.name", "system-test"], cwd=tmp_dir)
7574
self.execute_cmd(
7675
["git", "config", "credential.https://source.developers.google.com.helper", "gcloud.sh"],
7776
cwd=tmp_dir,
@@ -82,7 +81,7 @@ def create_repository_and_bucket(self):
8281
GCP_PROJECT_ID, GCP_REPOSITORY_NAME
8382
)
8483
self.execute_cmd(["git", "remote", "add", "origin", repo_url], cwd=tmp_dir)
85-
self.execute_cmd(["git", "push", "origin", "master"], cwd=tmp_dir)
84+
self.execute_cmd(["git", "push", "--force", "origin", "master"], cwd=tmp_dir)
8685

8786
def delete_repo(self):
8887
"""Delete repository in Google Cloud Source Repository service"""
@@ -92,15 +91,15 @@ def delete_repo(self):
9291
def delete_bucket(self):
9392
"""Delete bucket in Google Cloud Storage service"""
9493

95-
self.execute_cmd(["gsutil", "rb", "gs://{}".format(GCP_BUCKET_NAME)])
94+
self.execute_cmd(["gsutil", "rm", "-r", "gs://{}".format(GCP_BUCKET_NAME)])
9695

9796
def delete_docker_images(self):
9897
"""Delete images in Google Cloud Container Registry"""
9998

10099
repo_image_name = "gcr.io/{}/{}".format(GCP_PROJECT_ID, GCP_REPOSITORY_NAME)
101-
self.execute_cmd(["gcloud", "container", "images", "delete", repo_image_name])
100+
self.execute_cmd(["gcloud", "container", "images", "delete", "--quiet", repo_image_name])
102101
bucket_image_name = "gcr.io/{}/{}".format(GCP_PROJECT_ID, GCP_BUCKET_NAME)
103-
self.execute_cmd(["gcloud", "container", "images", "delete", bucket_image_name])
102+
self.execute_cmd(["gcloud", "container", "images", "delete", "--quiet", bucket_image_name])
104103

105104

106105
if __name__ == "__main__":

0 commit comments

Comments
 (0)