def test_successful_instance_group_update_with_update_policy(
         self, mock_hook):
     mock_hook.return_value.get_instance_group_manager.return_value = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_GET)
     op = GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         task_id='id',
         update_policy=GCE_INSTANCE_GROUP_MANAGER_UPDATE_POLICY,
         source_template=GCE_INSTANCE_TEMPLATE_SOURCE_URL,
         destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL)
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='beta',
                                       gcp_conn_id='google_cloud_default')
     expected_patch_with_update_policy = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_EXPECTED_PATCH)
     expected_patch_with_update_policy[
         'updatePolicy'] = GCE_INSTANCE_GROUP_MANAGER_UPDATE_POLICY
     mock_hook.return_value.patch_instance_group_manager.assert_called_once_with(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         body=expected_patch_with_update_policy,
         request_id=None)
     self.assertTrue(result)
 def test_successful_instance_group_update_no_instance_template_field(self, mock_hook):
     instance_group_manager_no_template = deepcopy(GCE_INSTANCE_GROUP_MANAGER_GET)
     del instance_group_manager_no_template['instanceTemplate']
     mock_hook.return_value.get_instance_group_manager.return_value = \
         instance_group_manager_no_template
     op = GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         task_id='id',
         source_template=GCE_INSTANCE_TEMPLATE_SOURCE_URL,
         destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='beta',
                                       gcp_conn_id='google_cloud_default')
     expected_patch_no_instance_template = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_EXPECTED_PATCH)
     del expected_patch_no_instance_template['instanceTemplate']
     mock_hook.return_value.patch_instance_group_manager.assert_called_once_with(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         body=expected_patch_no_instance_template,
         request_id=None
     )
     self.assertTrue(result)
Esempio n. 3
0
 def test_successful_instance_group_update_no_versions_field(
         self, mock_hook):
     instance_group_manager_no_versions = deepcopy(
         GCE_INSTANCE_GROUP_MANAGER_GET)
     del instance_group_manager_no_versions['versions']
     mock_hook.return_value.get_instance_group_manager.return_value = \
         instance_group_manager_no_versions
     op = GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=PROJECT_ID,
         zone=ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         task_id='id',
         source_template=GCE_INSTANCE_TEMPLATE_SOURCE_URL,
         destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL)
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='beta',
                                       gcp_conn_id='google_cloud_default')
     expected_patch_no_versions = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_EXPECTED_PATCH)
     del expected_patch_no_versions['versions']
     mock_hook.return_value.patch_instance_group_manager.assert_called_once_with(
         project_id=PROJECT_ID,
         zone=ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         body=expected_patch_no_versions,
         request_id=None)
     self.assertTrue(result)
 def test_successful_instance_group_update_with_update_policy(self, mock_hook):
     mock_hook.return_value.get_instance_group_manager.return_value = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_GET)
     op = GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=PROJECT_ID,
         zone=ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         task_id='id',
         update_policy=GCE_INSTANCE_GROUP_MANAGER_UPDATE_POLICY,
         source_template=GCE_INSTANCE_TEMPLATE_SOURCE_URL,
         destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='beta',
                                       gcp_conn_id='google_cloud_default')
     expected_patch_with_update_policy = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_EXPECTED_PATCH)
     expected_patch_with_update_policy['updatePolicy'] = \
         GCE_INSTANCE_GROUP_MANAGER_UPDATE_POLICY
     mock_hook.return_value.patch_instance_group_manager.assert_called_once_with(
         project_id=PROJECT_ID,
         zone=ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         body=expected_patch_with_update_policy,
         request_id=None
     )
     self.assertTrue(result)
 def test_try_to_use_non_existing_template(self, mock_hook):
     mock_hook.return_value.get_instance_group_manager.return_value = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_GET)
     op = GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         task_id='id',
         source_template=GCE_INSTANCE_TEMPLATE_NON_EXISTING_URL,
         destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL)
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='beta',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.patch_instance_group_manager.assert_not_called()
     self.assertTrue(result)
 def test_try_to_use_non_existing_template(self, mock_hook):
     mock_hook.return_value.get_instance_group_manager.return_value = \
         deepcopy(GCE_INSTANCE_GROUP_MANAGER_GET)
     op = GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=GCP_PROJECT_ID,
         zone=GCE_ZONE,
         resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
         task_id='id',
         source_template=GCE_INSTANCE_TEMPLATE_NON_EXISTING_URL,
         destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL
     )
     result = op.execute(None)
     mock_hook.assert_called_once_with(api_version='beta',
                                       gcp_conn_id='google_cloud_default')
     mock_hook.return_value.patch_instance_group_manager.assert_not_called()
     self.assertTrue(result)
 def test_try_to_use_api_v1(self, _):
     with self.assertRaises(AirflowException) as cm:
         GceInstanceGroupManagerUpdateTemplateOperator(
             project_id=GCP_PROJECT_ID,
             zone=GCE_ZONE,
             resource_id=GCE_INSTANCE_GROUP_MANAGER_NAME,
             task_id='id',
             api_version='v1',
             source_template=GCE_INSTANCE_TEMPLATE_SOURCE_URL,
             destination_template=GCE_INSTANCE_TEMPLATE_DESTINATION_URL)
     err = cm.exception
     self.assertIn("Use beta api version or above", str(err))
Esempio n. 8
0
     body_patch=GCE_INSTANCE_TEMPLATE_BODY_UPDATE,
     task_id='gcp_compute_igm_copy_template_task')
 # [END howto_operator_gce_igm_copy_template]
 # Added to check for idempotence
 gce_instance_template_copy2 = GceInstanceTemplateCopyOperator(
     project_id=PROJECT_ID,
     resource_id=TEMPLATE_NAME,
     body_patch=GCE_INSTANCE_TEMPLATE_BODY_UPDATE,
     task_id='gcp_compute_igm_copy_template_task_2')
 # [START howto_operator_gce_igm_update_template]
 gce_instance_group_manager_update_template = \
     GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=PROJECT_ID,
         resource_id=INSTANCE_GROUP_MANAGER_NAME,
         zone=ZONE,
         source_template=SOURCE_TEMPLATE_URL,
         destination_template=DESTINATION_TEMPLATE_URL,
         update_policy=UPDATE_POLICY,
         task_id='gcp_compute_igm_group_manager_update_template'
     )
 # [END howto_operator_gce_igm_update_template]
 # Added to check for idempotence (and without UPDATE_POLICY)
 gce_instance_group_manager_update_template2 = \
     GceInstanceGroupManagerUpdateTemplateOperator(
         project_id=PROJECT_ID,
         resource_id=INSTANCE_GROUP_MANAGER_NAME,
         zone=ZONE,
         source_template=SOURCE_TEMPLATE_URL,
         destination_template=DESTINATION_TEMPLATE_URL,
         task_id='gcp_compute_igm_group_manager_update_template_2'
     )