def test_stop_should_not_throw_ex_when_project_id_none(self, mock_hook):
     op = GceInstanceStopOperator(zone=GCE_ZONE,
                                  resource_id=RESOURCE_ID,
                                  task_id='id')
     op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         zone=GCE_ZONE, resource_id=RESOURCE_ID, project_id=None)
 def test_stop_should_throw_ex_when_missing_zone(self, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         op = GceInstanceStopOperator(project_id=GCP_PROJECT_ID,
                                      zone="",
                                      resource_id=RESOURCE_ID,
                                      task_id='id')
         op.execute(None)
     err = cm.exception
     self.assertIn("The required parameter 'zone' is missing", str(err))
     mock_hook.assert_not_called()
 def test_instance_stop(self, mock_hook):
     op = GceInstanceStopOperator(project_id=GCP_PROJECT_ID,
                                  zone=GCE_ZONE,
                                  resource_id=RESOURCE_ID,
                                  task_id='id')
     op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         zone=GCE_ZONE, resource_id=RESOURCE_ID, project_id=GCP_PROJECT_ID)
 def test_stop_should_throw_ex_when_missing_resource_id(self, mock_hook):
     with self.assertRaises(AirflowException) as cm:
         op = GceInstanceStopOperator(
             project_id=GCP_PROJECT_ID,
             zone=GCE_ZONE,
             resource_id="",
             task_id='id'
         )
         op.execute(None)
     err = cm.exception
     self.assertIn("The required parameter 'resource_id' is missing", str(err))
     mock_hook.assert_not_called()
 def test_instance_stop(self, mock_hook):
     mock_hook.return_value.stop_instance.return_value = True
     op = GceInstanceStopOperator(project_id=PROJECT_ID,
                                  zone=LOCATION,
                                  resource_id=RESOURCE_ID,
                                  task_id='id')
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         PROJECT_ID, LOCATION, RESOURCE_ID)
     self.assertTrue(result)
 def test_stop_should_not_throw_ex_when_project_id_none(self, mock_hook):
     op = GceInstanceStopOperator(
         zone=GCE_ZONE,
         resource_id=RESOURCE_ID,
         task_id='id'
     )
     op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         zone=GCE_ZONE, resource_id=RESOURCE_ID, project_id=None
     )
 def test_instance_stop(self, mock_hook):
     op = GceInstanceStopOperator(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=RESOURCE_ID,
         task_id='id'
     )
     op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         zone=GCE_ZONE, resource_id=RESOURCE_ID, project_id=GCP_PROJECT_ID
     )
 def test_instance_stop(self, mock_hook):
     mock_hook.return_value.stop_instance.return_value = True
     op = GceInstanceStopOperator(
         project_id=PROJECT_ID,
         zone=ZONE,
         resource_id=RESOURCE_ID,
         task_id='id'
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='v1',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.stop_instance.assert_called_once_with(
         PROJECT_ID, ZONE, RESOURCE_ID
     )
     self.assertTrue(result)
 def test_instance_stop_with_templates(self, _):
     dag_id = 'test_dag_id'
     args = {'start_date': DEFAULT_DATE}
     self.dag = DAG(dag_id, default_args=args)
     op = GceInstanceStopOperator(project_id='{{ dag.dag_id }}',
                                  zone='{{ dag.dag_id }}',
                                  resource_id='{{ dag.dag_id }}',
                                  gcp_conn_id='{{ dag.dag_id }}',
                                  api_version='{{ dag.dag_id }}',
                                  task_id='id',
                                  dag=self.dag)
     ti = TaskInstance(op, DEFAULT_DATE)
     ti.render_templates()
     self.assertEqual(dag_id, getattr(op, 'project_id'))
     self.assertEqual(dag_id, getattr(op, 'zone'))
     self.assertEqual(dag_id, getattr(op, 'resource_id'))
     self.assertEqual(dag_id, getattr(op, 'gcp_conn_id'))
     self.assertEqual(dag_id, getattr(op, 'api_version'))
Exemplo n.º 10
0
     project_id=GCP_PROJECT_ID,
     zone=GCE_ZONE,
     resource_id=GCE_INSTANCE,
     task_id='gcp_compute_start_task')
 # [END howto_operator_gce_start]
 # Duplicate start for idempotence testing
 # [START howto_operator_gce_start_no_project_id]
 gce_instance_start2 = GceInstanceStartOperator(
     zone=GCE_ZONE,
     resource_id=GCE_INSTANCE,
     task_id='gcp_compute_start_task2')
 # [END howto_operator_gce_start_no_project_id]
 # [START howto_operator_gce_stop]
 gce_instance_stop = GceInstanceStopOperator(
     project_id=GCP_PROJECT_ID,
     zone=GCE_ZONE,
     resource_id=GCE_INSTANCE,
     task_id='gcp_compute_stop_task')
 # [END howto_operator_gce_stop]
 # Duplicate stop for idempotence testing
 # [START howto_operator_gce_stop_no_project_id]
 gce_instance_stop2 = GceInstanceStopOperator(
     zone=GCE_ZONE,
     resource_id=GCE_INSTANCE,
     task_id='gcp_compute_stop_task2')
 # [END howto_operator_gce_stop_no_project_id]
 # [START howto_operator_gce_set_machine_type]
 gce_set_machine_type = GceSetMachineTypeOperator(
     project_id=GCP_PROJECT_ID,
     zone=GCE_ZONE,
     resource_id=GCE_INSTANCE,
Exemplo n.º 11
0
     zone=LOCATION,
     resource_id=INSTANCE,
     task_id='gcp_compute_start_task'
 )
 # [END howto_operator_gce_start]
 # Duplicate start for idempotence testing
 gce_instance_start2 = GceInstanceStartOperator(
     project_id=PROJECT_ID,
     zone=LOCATION,
     resource_id=INSTANCE,
     task_id='gcp_compute_start_task2'
 )
 # [START howto_operator_gce_stop]
 gce_instance_stop = GceInstanceStopOperator(
     project_id=PROJECT_ID,
     zone=LOCATION,
     resource_id=INSTANCE,
     task_id='gcp_compute_stop_task'
 )
 # [END howto_operator_gce_stop]
 # Duplicate stop for idempotence testing
 gce_instance_stop2 = GceInstanceStopOperator(
     project_id=PROJECT_ID,
     zone=LOCATION,
     resource_id=INSTANCE,
     task_id='gcp_compute_stop_task2'
 )
 # [START howto_operator_gce_set_machine_type]
 gce_set_machine_type = GceSetMachineTypeOperator(
     project_id=PROJECT_ID,
     zone=LOCATION,
     resource_id=INSTANCE,