Skip to content

Commit 9644451

Browse files
authored
Migrate Google example compute_igm to new design AIP-47 (#25132)
related: #22447, #22430
1 parent f36f81e commit 9644451

File tree

5 files changed

+46
-37
lines changed

5 files changed

+46
-37
lines changed

TESTING.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,7 @@ A simple example of a system test is available in:
11001100

11011101
``tests/providers/google/cloud/operators/test_compute_system.py``.
11021102

1103-
It runs two DAGs defined in ``airflow.providers.google.cloud.example_dags.example_compute.py`` and
1104-
``airflow.providers.google.cloud.example_dags.example_compute_igm.py``.
1103+
It runs two DAGs defined in ``airflow.providers.google.cloud.example_dags.example_compute.py``.
11051104

11061105
Preparing provider packages for System Tests for Airflow 1.10.* series
11071106
----------------------------------------------------------------------

docs/apache-airflow-providers-google/operators/cloud/compute.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ Using the operator
181181

182182
The code to create the operator:
183183

184-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_compute_igm.py
184+
.. exampleinclude:: /../../tests/system/providers/google/cloud/compute_igm/example_compute_igm.py
185185
:language: python
186186
:start-after: [START howto_operator_compute_template_copy_args]
187187
:end-before: [END howto_operator_compute_template_copy_args]
188188

189-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_compute_igm.py
189+
.. exampleinclude:: /../../tests/system/providers/google/cloud/compute_igm/example_compute_igm.py
190190
:language: python
191191
:dedent: 4
192192
:start-after: [START howto_operator_gce_igm_copy_template]
@@ -195,7 +195,7 @@ The code to create the operator:
195195
You can also create the operator without project id - project id will be retrieved
196196
from the Google Cloud connection used:
197197

198-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_compute_igm.py
198+
.. exampleinclude:: /../../tests/system/providers/google/cloud/compute_igm/example_compute_igm.py
199199
:language: python
200200
:dedent: 4
201201
:start-after: [START howto_operator_gce_igm_copy_template_no_project_id]
@@ -235,12 +235,12 @@ Using the operator
235235

236236
The code to create the operator:
237237

238-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_compute_igm.py
238+
.. exampleinclude:: /../../tests/system/providers/google/cloud/compute_igm/example_compute_igm.py
239239
:language: python
240240
:start-after: [START howto_operator_compute_igm_update_template_args]
241241
:end-before: [END howto_operator_compute_igm_update_template_args]
242242

243-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_compute_igm.py
243+
.. exampleinclude:: /../../tests/system/providers/google/cloud/compute_igm/example_compute_igm.py
244244
:language: python
245245
:dedent: 4
246246
:start-after: [START howto_operator_gce_igm_update_template]
@@ -249,7 +249,7 @@ The code to create the operator:
249249
You can also create the operator without project id - project id will be retrieved
250250
from the Google Cloud connection used:
251251

252-
.. exampleinclude:: /../../airflow/providers/google/cloud/example_dags/example_compute_igm.py
252+
.. exampleinclude:: /../../tests/system/providers/google/cloud/compute_igm/example_compute_igm.py
253253
:language: python
254254
:dedent: 4
255255
:start-after: [START howto_operator_gce_igm_update_template_no_project_id]

tests/providers/google/cloud/operators/test_compute_system.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,3 @@ def tearDown(self):
4141
@provide_gcp_context(GCP_COMPUTE_KEY)
4242
def test_run_example_dag_compute(self):
4343
self.run_dag('example_gcp_compute', CLOUD_DAG_FOLDER)
44-
45-
46-
@pytest.mark.backend("mysql", "postgres")
47-
@pytest.mark.credential_file(GCP_COMPUTE_KEY)
48-
class GcpComputeIgmExampleDagsSystemTest(GoogleSystemTest):
49-
helper = GCPComputeTestHelper()
50-
51-
@provide_gcp_context(GCP_COMPUTE_KEY)
52-
def setUp(self):
53-
super().setUp()
54-
self.helper.delete_instance_group_and_template(silent=True)
55-
self.helper.create_instance_group_and_template()
56-
57-
@provide_gcp_context(GCP_COMPUTE_KEY)
58-
def tearDown(self):
59-
self.helper.delete_instance_group_and_template()
60-
super().tearDown()
61-
62-
@provide_gcp_context(GCP_COMPUTE_KEY)
63-
def test_run_example_dag_compute_igm(self):
64-
self.run_dag('example_gcp_compute_igm', CLOUD_DAG_FOLDER)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.

airflow/providers/google/cloud/example_dags/example_compute_igm.py renamed to tests/system/providers/google/cloud/compute_igm/example_compute_igm.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@
4242
from datetime import datetime
4343

4444
from airflow import models
45-
from airflow.models.baseoperator import chain
4645
from airflow.providers.google.cloud.operators.compute import (
4746
ComputeEngineCopyInstanceTemplateOperator,
4847
ComputeEngineInstanceGroupUpdateManagerTemplateOperator,
4948
)
5049

50+
ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID")
5151
GCP_PROJECT_ID = os.environ.get('GCP_PROJECT_ID', 'example-project')
5252
GCE_ZONE = os.environ.get('GCE_ZONE', 'europe-west1-b')
5353

54+
DAG_ID = 'example_gcp_compute_igm'
55+
5456
# [START howto_operator_compute_template_copy_args]
5557
GCE_TEMPLATE_NAME = os.environ.get('GCE_TEMPLATE_NAME', 'instance-template-test')
5658
GCE_NEW_TEMPLATE_NAME = os.environ.get('GCE_NEW_TEMPLATE_NAME', 'instance-template-test-new')
@@ -91,11 +93,11 @@
9193

9294

9395
with models.DAG(
94-
'example_gcp_compute_igm',
96+
DAG_ID,
9597
schedule_interval='@once', # Override to match your needs
9698
start_date=datetime(2021, 1, 1),
9799
catchup=False,
98-
tags=['example'],
100+
tags=['example', 'igm'],
99101
) as dag:
100102
# [START howto_operator_gce_igm_copy_template]
101103
gce_instance_template_copy = ComputeEngineCopyInstanceTemplateOperator(
@@ -135,9 +137,22 @@
135137
)
136138
# [END howto_operator_gce_igm_update_template_no_project_id]
137139

138-
chain(
139-
gce_instance_template_copy,
140-
gce_instance_template_copy2,
141-
gce_instance_group_manager_update_template,
142-
gce_instance_group_manager_update_template2,
140+
(
141+
# TEST BODY
142+
gce_instance_template_copy
143+
>> gce_instance_template_copy2
144+
>> gce_instance_group_manager_update_template
145+
>> gce_instance_group_manager_update_template2
143146
)
147+
148+
from tests.system.utils.watcher import watcher
149+
150+
# This test needs watcher in order to properly mark success/failure
151+
# when "teardown" task with trigger rule is part of the DAG
152+
list(dag.tasks) >> watcher()
153+
154+
155+
from tests.system.utils import get_test_run # noqa: E402
156+
157+
# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)
158+
test_run = get_test_run(dag)

0 commit comments

Comments
 (0)