Esempio n. 1
0
 def test_delete_execute_empty_project_id(self, mock_hook):
     op = BigtableDeleteInstanceOperator(instance_id=INSTANCE_ID,
                                         task_id="id",
                                         gcp_conn_id=GCP_CONN_ID)
     op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.delete_instance.assert_called_once_with(
         project_id=None, instance_id=INSTANCE_ID)
Esempio n. 2
0
 def test_deleting_instance_that_doesnt_exists_empty_project_id(
         self, mock_hook):
     op = BigtableDeleteInstanceOperator(instance_id=INSTANCE_ID,
                                         task_id="id",
                                         gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.delete_instance.side_effect = mock.Mock(
         side_effect=google.api_core.exceptions.NotFound(
             "Instance not found."))
     op.execute(None)
     mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.delete_instance.assert_called_once_with(
         project_id=None, instance_id=INSTANCE_ID)
Esempio n. 3
0
    def test_different_error_reraised(self, mock_hook):
        op = BigtableDeleteInstanceOperator(project_id=PROJECT_ID,
                                            instance_id=INSTANCE_ID,
                                            task_id="id",
                                            gcp_conn_id=GCP_CONN_ID)
        mock_hook.return_value.delete_instance.side_effect = mock.Mock(
            side_effect=google.api_core.exceptions.GoogleAPICallError('error'))

        with self.assertRaises(google.api_core.exceptions.GoogleAPICallError):
            op.execute(None)

        mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
        mock_hook.return_value.delete_instance.assert_called_once_with(
            project_id=PROJECT_ID, instance_id=INSTANCE_ID)
Esempio n. 4
0
 def test_empty_attribute(self, missing_attribute, project_id, instance_id,
                          mock_hook):
     with self.assertRaises(AirflowException) as e:
         BigtableDeleteInstanceOperator(project_id=project_id,
                                        instance_id=instance_id,
                                        task_id="id")
     err = e.exception
     self.assertEqual(str(err),
                      'Empty parameter: {}'.format(missing_attribute))
     mock_hook.assert_not_called()
Esempio n. 5
0
        nodes=int(CBT_CLUSTER_NODES_UPDATED),
        task_id='update_cluster_task',
    )
    cluster_update_task2 = BigtableUpdateClusterOperator(
        instance_id=CBT_INSTANCE_ID,
        cluster_id=CBT_CLUSTER_ID,
        nodes=int(CBT_CLUSTER_NODES_UPDATED),
        task_id='update_cluster_task2',
    )
    cluster_update_task >> cluster_update_task2
    # [END howto_operator_gcp_bigtable_cluster_update]

    # [START howto_operator_gcp_bigtable_instance_delete]
    delete_instance_task = BigtableDeleteInstanceOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=CBT_INSTANCE_ID,
        task_id='delete_instance_task',
    )
    delete_instance_task2 = BigtableDeleteInstanceOperator(
        instance_id=CBT_INSTANCE_ID,
        task_id='delete_instance_task2',
    )
    # [END howto_operator_gcp_bigtable_instance_delete]

    # [START howto_operator_gcp_bigtable_table_create]
    create_table_task = BigtableCreateTableOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=CBT_INSTANCE_ID,
        table_id=CBT_TABLE_ID,
        task_id='create_table',
    )