Ejemplo n.º 1
0
 def test_instance_import_missing_project_id(self, mock_hook):
     mock_hook.return_value.export_instance.return_value = True
     op = CloudSqlInstanceImportOperator(instance=INSTANCE_NAME,
                                         body=IMPORT_BODY,
                                         task_id="id")
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version="v1beta4",
                                       gcp_conn_id="google_cloud_default")
     mock_hook.return_value.import_instance.assert_called_once_with(
         project_id=None, instance=INSTANCE_NAME, body=IMPORT_BODY)
     self.assertTrue(result)
    # For import to work we also need to add the Cloud SQL instance's Service Account
    # write access to the whole bucket!.
    sql_gcp_add_bucket_permission_2_task = GoogleCloudStorageBucketCreateAclEntryOperator(
        entity="user-{{ task_instance.xcom_pull("
               "'sql_instance_create_task2', key='service_account_email') "
               "}}",
        role="WRITER",
        bucket=import_url_split[1],  # netloc
        task_id='sql_gcp_add_bucket_permission_2_task',
    )
    # [END howto_operator_cloudsql_import_gcs_permissions]

    # [START howto_operator_cloudsql_import]
    sql_import_task = CloudSqlInstanceImportOperator(
        project_id=GCP_PROJECT_ID,
        body=import_body,
        instance=INSTANCE_NAME2,
        task_id='sql_import_task'
    )
    sql_import_task2 = CloudSqlInstanceImportOperator(
        body=import_body,
        instance=INSTANCE_NAME2,
        task_id='sql_import_task2'
    )
    # [END howto_operator_cloudsql_import]

    # ############################################## #
    # ### DELETING A DATABASE FROM AN INSTANCE ##### #
    # ############################################## #

    # [START howto_operator_cloudsql_db_delete]
    sql_db_delete_task = CloudSqlInstanceDatabaseDeleteOperator(