Example #1
0
 def test_instance_create_aborts_and_succeeds_if_instance_exists(self, mock_hook):
     mock_hook.return_value.get_instance.return_value = {"name": INSTANCE_ID}
     op = CloudSpannerInstanceDeployOperator(
         project_id=PROJECT_ID,
         instance_id=INSTANCE_ID,
         configuration_name=CONFIG_NAME,
         node_count=int(NODE_COUNT),
         display_name=DISPLAY_NAME,
         task_id="id"
     )
     result = op.execute(None)  # pylint: disable=assignment-from-no-return
     mock_hook.assert_called_once_with(gcp_conn_id="google_cloud_default")
     mock_hook.return_value.create_instance.assert_not_called()
     self.assertIsNone(result)
 def test_instance_create_ex_if_param_missing(self, project_id, instance_id,
                                              exp_msg, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         CloudSpannerInstanceDeployOperator(project_id=project_id,
                                            instance_id=instance_id,
                                            configuration_name=CONFIG_NAME,
                                            node_count=int(NODE_COUNT),
                                            display_name=DISPLAY_NAME,
                                            task_id="id")
     err = cm.exception
     self.assertIn("The required parameter '{}' is empty".format(exp_msg),
                   str(err))
     mock_hook.assert_not_called()
Example #3
0
OPERATION_ID = 'unique_operation_id'
# [END howto_operator_spanner_arguments]

default_args = {'start_date': airflow.utils.dates.days_ago(1)}

with models.DAG(
        'example_gcp_spanner',
        default_args=default_args,
        schedule_interval=None  # Override to match your needs
) as dag:
    # Create
    # [START howto_operator_spanner_deploy]
    spanner_instance_create_task = CloudSpannerInstanceDeployOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,
        configuration_name=GCP_SPANNER_CONFIG_NAME,
        node_count=int(GCP_SPANNER_NODE_COUNT),
        display_name=GCP_SPANNER_DISPLAY_NAME,
        task_id='spanner_instance_create_task')
    spanner_instance_update_task = CloudSpannerInstanceDeployOperator(
        instance_id=GCP_SPANNER_INSTANCE_ID,
        configuration_name=GCP_SPANNER_CONFIG_NAME,
        node_count=int(GCP_SPANNER_NODE_COUNT) + 1,
        display_name=GCP_SPANNER_DISPLAY_NAME + '_updated',
        task_id='spanner_instance_update_task')
    # [END howto_operator_spanner_deploy]

    # [START howto_operator_spanner_database_deploy]
    spanner_database_deploy_task = CloudSpannerInstanceDatabaseDeployOperator(
        project_id=GCP_PROJECT_ID,
        instance_id=GCP_SPANNER_INSTANCE_ID,