def test_create_app_catalog_subscription_raises_service_error( compute_client, call_with_backoff_patch, get_app_catalog_subscription_patch): # Places when a ServiceError can be raised are get_app_catalog_subscription or call_with_backoff. Test both. # Test when call_with_backoff raises ServiceError get_app_catalog_subscription_patch.return_value = None call_with_backoff_patch.side_effect = ServiceError( 500, "InternalServerError", dict(), "Internal Server Error") with pytest.raises(ServiceError) as exc_info: oci_app_catalog_subscription.create_app_catalog_subscription( compute_client, get_module()) se = exc_info.value assert se.status == 500 assert se.code == "InternalServerError" assert se.message == "Internal Server Error" # Test when get_app_catalog_subscription raises ServiceError get_app_catalog_subscription_patch.side_effect = ServiceError( 500, "InternalServerError", dict(), "Internal Server Error") # set call_with_backoff_patch side effect to None to make sure that the exception is not raised from call_with_backoff call_with_backoff_patch.side_effect = None with pytest.raises(ServiceError) as exc_info: oci_app_catalog_subscription.create_app_catalog_subscription( compute_client, get_module()) se = exc_info.value assert se.status == 500 assert se.code == "InternalServerError" assert se.message == "Internal Server Error"
def test_delete_load_balancer_no_existing_lb(lb_client, get_existing_resource_patch): module = get_module(dict()) get_existing_resource_patch.side_effect = ServiceError( 404, 'NotFound', dict(), None) result = oci_load_balancer.delete_load_balancer(lb_client, module) assert result['changed'] is False
def delete_app_catalog_subscription(compute_client, module): result = dict() try: existing_app_catalog_subscription = get_app_catalog_subscription( compute_client, module) if not existing_app_catalog_subscription: raise ServiceError( 404, "NotAuthorizedOrNotFound", dict(), "The app catalog subscription does not exist.", ) # Directly calling delete_app_catalog_subscription instead of # ansible.module_utils.oracle.oci_utils.delete_and_wait as app catalog subscriptions do not offer a GET function oci_utils.call_with_backoff( compute_client.delete_app_catalog_subscription, listing_id=module.params["listing_id"], compartment_id=module.params["compartment_id"], resource_version=module.params["listing_resource_version"], ) except ServiceError as se: if se.status == 404: result["changed"] = False result["msg"] = "The app catalog subscription does not exist." result["app_catalog_subscription"] = dict() else: raise else: result["changed"] = True result["app_catalog_subscription"] = existing_app_catalog_subscription return result
def test_get_existing_backend_not_found(lb_client): module = get_module() lb_client.get_backend.side_effect = ServiceError( 404, 'NotFoundError', dict(), None) result = oci_load_balancer_backend.get_existing_backend( lb_client, module, 'ocid1.loadbalancer.oc1.iad.aaaaa', '10.159.34.21:8181') assert result is None
def test_get_exisiting_bucket_failure_service_error(object_storage_client): error_message = "Namespace does not exist" object_storage_client.get_bucket.side_effect = ServiceError( 500, "NoNameSpaceExists", dict(), error_message) try: oci_bucket.get_existing_bucket(object_storage_client, get_module()) except Exception as ex: assert error_message in ex.args[0]
def test_get_existing_health_checker_not_found(lb_client): module = get_module() health_checker = get_health_checker() lb_client.get_health_checker.side_effect = ServiceError( 404, 'NotFound', dict(), None) result = oci_load_balancer_health_checker.get_existing_health_checker( lb_client, module, 'ocid1.loadbalancer.aaaa', 'backend_set') assert result is None
def test_delete_bucket_service_error(object_storage_client): error_message = "Bucket Exists but not deleted due to other error" object_storage_client.delete_bucket.side_effect = ServiceError( 400, "OtherError", dict(), error_message) try: oci_bucket.delete_bucket(object_storage_client, get_module()) except Exception as e: assert error_message in e.args[0]
def test_create_or_update_smtp_credentiale_service_error(identity_client, check_and_create_resource_patch): error_message = 'Internal Server Error' module = get_module() check_and_create_resource_patch.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_smtp_credential.create_or_update_smtp_credential(identity_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_data_guard_associations_service_error(db_client, list_all_resources_patch): error_message = 'Internal Server Error' module = get_module(dict({'database_id': 'ocid1.database.aaaa'})) list_all_resources_patch.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_data_guard_association_facts.list_data_guard_associations(db_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_users_failure_service_error(identity_client, list_all_resources_patch): error_message = "Internal Server Error" list_all_resources_patch.side_effect = ServiceError( 499, "InternalServerError", dict(), error_message) try: oci_user_facts.list_users(identity_client, get_module(dict())) except Exception as ex: assert error_message in ex.args[0]
def test_list_sender_service_error(email_client): error_message = "Internal Server Error" module = get_module(dict({"sender_id": "ocid1.sender.aaaa"})) email_client.get_db_system.side_effect = ServiceError( 499, "InternalServerError", dict(), error_message) try: oci_sender_facts.list_senders(email_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_user_groups_failure_service_error(identity_client, list_all_resources_patch): error_message = 'Operation failed due to Internal Error' list_all_resources_patch.side_effect = ServiceError( 499, 'InternalError', dict(), error_message) try: oci_group_facts.list_user_groups(identity_client, get_module(dict())) except Exception as ex: assert error_message in ex.args[0]
def test_list_db_versions_service_error(db_client, list_all_resources_patch): error_message = 'Internal Server Error' module = get_module(dict({'compartment_id': 'ocid1.compartment.aaaa', 'availability_domain': 'AD2'})) list_all_resources_patch.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_db_version_facts.list_db_versions(db_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_buckets_failure(object_storage_client): error_message = 'You do not have authorization to perform this request,\ or the requested resource could not be found.' object_storage_client.list_buckets.side_effect = ServiceError(404, 'NamespaceNotFound', dict(), error_message) try: oci_bucket_facts.list_buckets(object_storage_client, get_module()) except Exception as ex: assert error_message in ex.args[0]
def test_list_db_home_patch_history_entries_service_error(db_client, list_all_resources_patch): error_message = 'Internal Server Error' module = get_module(dict({'db_home_id': 'ocid1.dbhome.aaaa'})) list_all_resources_patch.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_db_home_patch_history_entry_facts.list_db_home_patch_history_entries(db_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_file_systems_service_error(file_storage_client): error_message = "Internal Server Error" module = get_module(dict({"file_system_id": "ocid1.filesystem.aaaa"})) file_storage_client.get_file_system.side_effect = ServiceError( 499, "InternalServerError", dict(), error_message) try: oci_file_system_facts.list_file_systems(file_storage_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_snapshots_service_error(file_storage_client): error_message = 'Internal Server Error' module = get_module(dict({'snapshot_id': 'ocid1.filesystem.aaaa'})) file_storage_client.get_snapshot.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_snapshot_facts.list_snapshots(file_storage_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_suppression_service_error(email_client): error_message = 'Internal Server Error' module = get_module(dict({'suppression_id': 'ocid1.suppression.aaaa'})) email_client.get_db_system.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_suppression_facts.list_suppressions(email_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_databases_service_error(db_client): error_message = 'Internal Server Error' module = get_module(dict({'database_id': 'ocid1.dbsystem.aaaa'})) db_client.get_database.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_database_facts.list_databases(db_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_launch_or_update_db_system_service_error( db_client, check_and_create_resource_patch): error_message = 'Internal Server Error' module = get_module(dict()) check_and_create_resource_patch.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_db_system.launch_or_update_db_system(db_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_get_load_balancer_backend_set_health_service_error(lb_client): error_message = "Internal Server Error" module = get_module() lb_client.get_backend_health.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_load_balancer_backend_set_health_facts.get_load_balancer_backend_set_health( lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_create_certificate_service_error(lb_client, get_certificate_patch): error_message = "Internal Server Error" module = get_module(dict()) get_certificate_patch.return_value = None lb_client.create_certificate.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_load_balancer_certificate.create_certificate(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_create_or_update_snapshote_service_error( file_storage_client, check_and_create_resource_patch): error_message = "Internal Server Error" module = get_module() check_and_create_resource_patch.side_effect = ServiceError( 499, "InternalServerError", dict(), error_message) try: oci_snapshot.create_or_update_snapshot(file_storage_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_delete_load_balancer_service_error(lb_client, get_existing_resource_patch): error_message = 'Internal Server Error' module = get_module(dict()) get_existing_resource_patch.side_effect = ServiceError( 500, 'InternalServerError', dict(), error_message) try: oci_load_balancer.delete_load_balancer(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_get_existing_health_checker_service_error(lb_client): error_message = "Internal Server Error" module = get_module() lb_client.get_health_checker.side_effect = ServiceError( 499, 'NotFound', dict(), error_message) try: oci_load_balancer_health_checker.get_existing_health_checker( lb_client, module, 'ocid1.loadbalancer.aaaa', 'backend_set') except Exception as ex: assert error_message in ex.args[0]
def test_list_load_balancer_policies_service_error(lb_client, list_all_resources_patch): error_message = "Internal Server Error" module = get_module() list_all_resources_patch.side_effect = ServiceError( 499, "InternalServerError", dict(), error_message ) try: oci_load_balancer_policy_facts.list_load_balancer_policies(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_db_systems_service_error(db_client): error_message = "Internal Server Error" module = get_module(dict({"backup_id": "ocid1.backup.aaaa"})) db_client.get_db_system.side_effect = ServiceError(499, "InternalServerError", dict(), error_message) try: oci_backup_facts.list_backups(db_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_list_load_balancer_backend_sets_service_error(lb_client, list_all_resources_patch): error_message = 'Internal Server Error' module = get_module(dict({'name': 'backend_set1', 'load_balancer_id': 'ocid1.lodbalancer.xcds'})) list_all_resources_patch.side_effect = ServiceError( 500, 'InternalServerError', dict(), error_message) try: oci_load_balancer_backend_set_facts.list_load_balancer_backend_sets(lb_client, module) except Exception as ex: assert error_message in ex.args[0]
def test_get_existing_backend_service_error(lb_client): module = get_module() error_message = "Internal Server Error" lb_client.get_backend.side_effect = ServiceError( 499, 'InternalServerError', dict(), error_message) try: oci_load_balancer_backend.get_existing_backend( lb_client, module, 'ocid1.loadbalancer.oc1.iad.aaaaa', '10.159.34.21:8181') except Exception as ex: assert error_message in ex.args[0]
def test_create_or_update_backend_service_error(lb_client, check_and_create_resource_patch, get_existing_backend_patch): module = get_module() error_message = "Internal Server Error" check_and_create_resource_patch.side_effect = ServiceError( 500, 'InternalServerError', dict(), error_message) get_existing_backend_patch.return_value = None try: oci_load_balancer_backend.create_or_update_backend(lb_client, module) except Exception as ex: assert error_message in ex.args[0]