Пример #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)
 def test_instance_import(self, mock_hook):
     mock_hook.return_value.export_instance.return_value = True
     op = CloudSqlInstanceImportOperator(
         project_id=PROJECT_ID,
         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, INSTANCE_NAME, IMPORT_BODY
     )
     self.assertTrue(result)
Пример #3
0
    # 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]
    prev_task = next_dep(sql_gcp_add_bucket_permission_2_task, prev_task)

    # [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]
    prev_task = next_dep(sql_import_task, prev_task)
    prev_task = next_dep(sql_import_task2, prev_task)

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

    # [START howto_operator_cloudsql_db_delete]
    sql_db_delete_task = CloudSqlInstanceDatabaseDeleteOperator(
        project_id=GCP_PROJECT_ID,
        instance=INSTANCE_NAME,
Пример #4
0
            BQ_PROJECT),
        destination_cloud_storage_uris='{}/cloudSQLexport_temp.csv'.format(
            DIR_TMP),
        export_format='CSV',
        print_header=False,
        bigquery_conn_id=cfg.bigquery_conn_id)

    import_to_csql = CloudSqlInstanceImportOperator(
        task_id='import_to_csql',
        project_id=SQL_PROJECT,
        instance='servicedat-cal-mysql',
        body={
            "importContext": {
                "kind": "sql#importContext",
                "fileType": 'CSV',
                "uri": '{}/cloudSQLexport_temp.csv'.format(DIR_TMP),
                "database": DATABASE,
                "csvImportOptions": {
                    "table": TABLE
                }
            }
        },
        api_version='v1beta4',
        gcp_conn_id='cloudsql_pipeline')

    delete_tmp_table = BigQueryTableDeleteOperator(
        task_id='delete_tmp_table',
        deletion_dataset_table='{}.Temporal.cloudSQLexport_tmp'.format(
            BQ_PROJECT),
        bigquery_conn_id=cfg.bigquery_conn_id)