def test_sagemaker_apply_delete_model_fail( mock_init_project, mock_docker_push, mock_docker_build, mock_check_output ): orig = botocore.client.BaseClient._make_api_call yatai_service = create_yatai_service_mock() sagemaker_deployment_pb = generate_sagemaker_deployment_pb() deployment_operator = SageMakerDeploymentOperator() def fail_delete_model(self, operation_name, kwarg): if operation_name == 'DeleteModel': raise ClientError( {'Error': {'Code': 'ValidationException', 'Message': 'failed message'}}, 'DeleteModel', ) elif operation_name == 'CreateEndpoint': raise ClientError({}, 'CreateEndpoint') else: return orig(self, operation_name, kwarg) with patch('botocore.client.BaseClient._make_api_call', new=fail_delete_model): result = deployment_operator.apply(sagemaker_deployment_pb, yatai_service) assert result.status.status_code == Status.NOT_FOUND assert result.status.error_message.startswith( 'Failed to clean up model after unsuccessfully' )
def test_sagemaker_apply_success( mock_init_project, mock_docker_push, mock_docker_build, mock_check_output ): yatai_service = create_yatai_service_mock() sagemaker_deployment_pb = generate_sagemaker_deployment_pb() deployment_operator = SageMakerDeploymentOperator() result_pb = deployment_operator.apply(sagemaker_deployment_pb, yatai_service) assert result_pb.status.status_code == Status.OK assert result_pb.deployment.name == TEST_DEPLOYMENT_NAME
def test_sagemaker_apply_fail_not_local_repo( mock_init_project, mock_docker_push, mock_docker_build, mock_check_output ): yatai_service = create_yatai_service_mock(repo_storage_type=BentoUri.UNSET) sagemaker_deployment_pb = generate_sagemaker_deployment_pb() deployment_operator = SageMakerDeploymentOperator() result_pb = deployment_operator.apply(sagemaker_deployment_pb, yatai_service) assert result_pb.status.status_code == Status.INTERNAL assert result_pb.status.error_message.startswith('BentoML currently not support')
def test_sagemaker_apply_create_model_fail( mock_init_project, mock_docker_push, mock_docker_build, mock_check_output ): yatai_service = create_yatai_service_mock() sagemaker_deployment_pb = generate_sagemaker_deployment_pb() deployment_operator = SageMakerDeploymentOperator() orig = botocore.client.BaseClient._make_api_call def fail_create_model_random(self, operation_name, kwarg): if operation_name == 'CreateModel': raise ClientError({'Error': {'Code': 'Random'}}, 'CreateModel') else: return orig(self, operation_name, kwarg) with patch( 'botocore.client.BaseClient._make_api_call', new=fail_create_model_random ): failed_result = deployment_operator.apply( sagemaker_deployment_pb, yatai_service ) assert failed_result.status.status_code == Status.INTERNAL assert failed_result.status.error_message.startswith( 'Failed to create model for SageMaker Deployment' ) def fail_create_model_validation(self, operation_name, kwarg): if operation_name == 'CreateModel': raise ClientError( {'Error': {'Code': 'ValidationException', 'Message': 'failed message'}}, 'CreateModel', ) else: return orig(self, operation_name, kwarg) with patch( 'botocore.client.BaseClient._make_api_call', new=fail_create_model_validation ): result = deployment_operator.apply(sagemaker_deployment_pb, yatai_service) assert result.status.status_code == Status.NOT_FOUND assert result.status.error_message.startswith( 'Failed to create model for SageMaker' )
def test_sagemaker_apply_duplicate_endpoint( mock_init_project, mock_docker_push, mock_docker_build, mock_check_output ): orig = botocore.client.BaseClient._make_api_call yatai_service = create_yatai_service_mock() sagemaker_deployment_pb = generate_sagemaker_deployment_pb() deployment_operator = SageMakerDeploymentOperator() deployment_operator.apply(sagemaker_deployment_pb, yatai_service) endpoint_name = '{ns}-{name}'.format( ns=TEST_DEPLOYMENT_NAMESPACE, name=TEST_DEPLOYMENT_BENTO_NAME ) expect_value = 'Endpoint {} already exists'.format(endpoint_name.replace('_', '-')) def mock_ok_return(self, op_name, kwargs): if op_name == 'CreateModel' or op_name == 'CreateEndpointConfig': return '' else: return orig(self, op_name, kwargs) with patch('botocore.client.BaseClient._make_api_call', new=mock_ok_return): with pytest.raises(ValueError) as error: deployment_operator.apply(sagemaker_deployment_pb, yatai_service) assert str(error.value) == expect_value