Source code for tests.system.amazon.aws.example_glacier_to_gcs
# 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.from__future__importannotationsfromdatetimeimportdatetimeimportboto3fromairflow.decoratorsimporttaskfromairflow.models.baseoperatorimportchainfromairflow.models.dagimportDAGfromairflow.providers.amazon.aws.operators.glacierimport(GlacierCreateJobOperator,GlacierUploadArchiveOperator,)fromairflow.providers.amazon.aws.sensors.glacierimportGlacierJobOperationSensorfromairflow.providers.amazon.aws.transfers.glacier_to_gcsimportGlacierToGCSOperatorfromairflow.utils.trigger_ruleimportTriggerRulefromsystem.amazon.aws.utilsimportSystemTestContextBuilder
env_id=test_context["ENV_ID"]vault_name=f"{env_id}-vault"gcs_bucket_name=f"{env_id}-bucket"gcs_object_name=f"{env_id}-object"# [START howto_operator_glacier_create_job]create_glacier_job=GlacierCreateJobOperator(task_id="create_glacier_job",vault_name=vault_name)JOB_ID='{{ task_instance.xcom_pull("create_glacier_job")["jobId"] }}'# [END howto_operator_glacier_create_job]# [START howto_sensor_glacier_job_operation]wait_for_operation_complete=GlacierJobOperationSensor(vault_name=vault_name,job_id=JOB_ID,task_id="wait_for_operation_complete",)# [END howto_sensor_glacier_job_operation]# [START howto_operator_glacier_upload_archive]upload_archive_to_glacier=GlacierUploadArchiveOperator(task_id="upload_data_to_glacier",vault_name=vault_name,body=b"Test Data")# [END howto_operator_glacier_upload_archive]# [START howto_transfer_glacier_to_gcs]transfer_archive_to_gcs=GlacierToGCSOperator(task_id="transfer_archive_to_gcs",vault_name=vault_name,bucket_name=gcs_bucket_name,object_name=gcs_object_name,gzip=False,# Override to match your needs# If chunk size is bigger than actual file size# then whole file will be downloadedchunk_size=1024,)# [END howto_transfer_glacier_to_gcs]chain(# TEST SETUPtest_context,create_vault(vault_name),# TEST BODYcreate_glacier_job,wait_for_operation_complete,upload_archive_to_glacier,transfer_archive_to_gcs,# TEST TEARDOWNdelete_vault(vault_name),)fromtests_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()fromtests_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)