Source code for tests.system.google.cloud.compute.example_compute_igm
## 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:* creates a copy of existing Instance Template* updates existing template in Instance Group Manager"""from__future__importannotationsimportosfromdatetimeimportdatetimefromairflow.models.dagimportDAGfromairflow.providers.google.cloud.operators.computeimport(ComputeEngineCopyInstanceTemplateOperator,ComputeEngineDeleteInstanceGroupManagerOperator,ComputeEngineDeleteInstanceTemplateOperator,ComputeEngineInsertInstanceGroupManagerOperator,ComputeEngineInsertInstanceTemplateOperator,ComputeEngineInstanceGroupUpdateManagerTemplateOperator,)fromairflow.utils.trigger_ruleimportTriggerRulefromproviders.tests.system.googleimportDEFAULT_GCP_SYSTEM_TEST_PROJECT_ID
# [END howto_operator_gce_igm_insert_template]# Added to check for idempotence# [START howto_operator_gce_igm_insert_template_no_project_id]gce_instance_template_insert2=ComputeEngineInsertInstanceTemplateOperator(task_id="gcp_compute_create_template_task_2",body=INSTANCE_TEMPLATE_BODY,)# [END howto_operator_gce_igm_insert_template_no_project_id]# [START howto_operator_gce_igm_copy_template]gce_instance_template_copy=ComputeEngineCopyInstanceTemplateOperator(task_id="gcp_compute_igm_copy_template_task",project_id=PROJECT_ID,resource_id=TEMPLATE_NAME,body_patch=INSTANCE_TEMPLATE_BODY_UPDATE,)# [END howto_operator_gce_igm_copy_template]# Added to check for idempotence# [START howto_operator_gce_igm_copy_template_no_project_id]gce_instance_template_copy2=ComputeEngineCopyInstanceTemplateOperator(task_id="gcp_compute_igm_copy_template_task_2",resource_id=TEMPLATE_NAME,body_patch=INSTANCE_TEMPLATE_BODY_UPDATE,)# [END howto_operator_gce_igm_copy_template_no_project_id]# [START howto_operator_gce_insert_igm]gce_igm_insert=ComputeEngineInsertInstanceGroupManagerOperator(task_id="gcp_compute_create_group_task",zone=LOCATION,body=INSTANCE_GROUP_MANAGER_BODY,project_id=PROJECT_ID,)# [END howto_operator_gce_insert_igm]# Added to check for idempotence# [START howto_operator_gce_insert_igm_no_project_id]gce_igm_insert2=ComputeEngineInsertInstanceGroupManagerOperator(task_id="gcp_compute_create_group_task_2",zone=LOCATION,body=INSTANCE_GROUP_MANAGER_BODY,)# [END howto_operator_gce_insert_igm_no_project_id]# [START howto_operator_gce_igm_update_template]gce_instance_group_manager_update_template=ComputeEngineInstanceGroupUpdateManagerTemplateOperator(task_id="gcp_compute_igm_group_manager_update_template",project_id=PROJECT_ID,resource_id=INSTANCE_GROUP_MANAGER_NAME,zone=LOCATION,source_template=SOURCE_TEMPLATE_URL,destination_template=DESTINATION_TEMPLATE_URL,update_policy=UPDATE_POLICY,)# [END howto_operator_gce_igm_update_template]# Added to check for idempotence (and without UPDATE_POLICY)# [START howto_operator_gce_igm_update_template_no_project_id]gce_instance_group_manager_update_template2=ComputeEngineInstanceGroupUpdateManagerTemplateOperator(task_id="gcp_compute_igm_group_manager_update_template_2",resource_id=INSTANCE_GROUP_MANAGER_NAME,zone=LOCATION,source_template=SOURCE_TEMPLATE_URL,destination_template=DESTINATION_TEMPLATE_URL,)# [END howto_operator_gce_igm_update_template_no_project_id]# [START howto_operator_gce_delete_old_template_no_project_id]gce_instance_template_old_delete=ComputeEngineDeleteInstanceTemplateOperator(task_id="gcp_compute_delete_old_template_task",resource_id=TEMPLATE_NAME,trigger_rule=TriggerRule.ALL_DONE,)# [END howto_operator_gce_delete_old_template_no_project_id]# [START howto_operator_gce_delete_new_template_no_project_id]gce_instance_template_new_delete=ComputeEngineDeleteInstanceTemplateOperator(task_id="gcp_compute_delete_new_template_task",resource_id=NEW_TEMPLATE_NAME,trigger_rule=TriggerRule.ALL_DONE,)# [END howto_operator_gce_delete_new_template_no_project_id]# [START howto_operator_gce_delete_igm_no_project_id]gce_igm_delete=ComputeEngineDeleteInstanceGroupManagerOperator(task_id="gcp_compute_delete_group_task",resource_id=INSTANCE_GROUP_MANAGER_NAME,zone=LOCATION,trigger_rule=TriggerRule.ALL_DONE,)# [END howto_operator_gce_delete_igm_no_project_id](# TEST SETUPgce_instance_template_insert>>gce_instance_template_insert2>>gce_instance_template_copy>>gce_instance_template_copy2# TEST BODY>>gce_igm_insert>>gce_igm_insert2>>gce_instance_group_manager_update_template>>gce_instance_group_manager_update_template2# TEST TEARDOWN>>gce_igm_delete>>gce_instance_template_old_delete>>gce_instance_template_new_delete)# ### Everything below this line is not part of example #### ### Just for system tests purpose ###fromdev.tests_common.test_utils.watcherimportwatcher# This test needs watcher in order to properly mark success/failure# when "tearDown" task with trigger rule is part of the DAGlist(dag.tasks)>>watcher()fromdev.tests_common.test_utils.system_testsimportget_test_run# noqa: E402# Needed to run the example DAG with pytest (see: tests/system/README.md#run_via_pytest)