Exemplo n.º 1
0
 def test_instance_export_missing_project_id(self, mock_hook):
     mock_hook.return_value.export_instance.return_value = True
     op = CloudSqlInstanceExportOperator(instance=INSTANCE_NAME,
                                         body=EXPORT_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.export_instance.assert_called_once_with(
         project_id=None, instance=INSTANCE_NAME, body=EXPORT_BODY)
     self.assertTrue(result)
 def test_instance_export(self, mock_hook):
     mock_hook.return_value.export_instance.return_value = True
     op = CloudSqlInstanceExportOperator(
         project_id=PROJECT_ID,
         instance=INSTANCE_NAME,
         body=EXPORT_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.export_instance.assert_called_once_with(
         PROJECT_ID, INSTANCE_NAME, EXPORT_BODY
     )
     self.assertTrue(result)
Exemplo n.º 3
0
    # For export to work we need to add the Cloud SQL instance's Service Account
    # write access to the destination GCS bucket.
    # [START howto_operator_cloudsql_export_gcs_permissions]
    sql_gcp_add_bucket_permission_task = GoogleCloudStorageBucketCreateAclEntryOperator(
        entity="user-{{ task_instance.xcom_pull("
        "'sql_instance_create_task', key='service_account_email') "
        "}}",
        role="WRITER",
        bucket=export_url_split[1],  # netloc (bucket)
        task_id='sql_gcp_add_bucket_permission_task')
    # [END howto_operator_cloudsql_export_gcs_permissions]
    prev_task = next_dep(sql_gcp_add_bucket_permission_task, prev_task)

    # [START howto_operator_cloudsql_export]
    sql_export_task = CloudSqlInstanceExportOperator(project_id=GCP_PROJECT_ID,
                                                     body=export_body,
                                                     instance=INSTANCE_NAME,
                                                     task_id='sql_export_task')
    sql_export_task2 = CloudSqlInstanceExportOperator(
        body=export_body, instance=INSTANCE_NAME, task_id='sql_export_task2')
    # [END howto_operator_cloudsql_export]
    prev_task = next_dep(sql_export_task, prev_task)
    prev_task = next_dep(sql_export_task2, prev_task)

    # ############################################## #
    # ### IMPORTING SQL TO INSTANCE 2 ############## #
    # ############################################## #
    import_url_split = urlsplit(IMPORT_URI)

    # For import to work we need to add the Cloud SQL instance's Service Account
    # read access to the target GCS object.
    # [START howto_operator_cloudsql_import_gcs_permissions]