コード例 #1
0
def test_create_endpoint(request, function_context, apps_api_instance,
                         get_k8s_custom_obj_client, params, tenant_fix,
                         warning):
    namespace, _ = request.getfixturevalue(tenant_fix)
    data = json.dumps(params)
    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)

    response = requests.post(url, data=data, headers=DEFAULT_HEADERS)
    response_text = json.loads(response.text)
    endpoint_url = get_url_from_response(response)
    assert response.status_code == 200
    if warning:
        assert get_created_message(
            endpoint_url=endpoint_url,
            warning=True,
            model_name=params['modelName']) == response_text
    else:
        assert get_created_message(endpoint_url=endpoint_url,
                                   warning=False) == response_text

    function_context.add_object(object_type='CRD',
                                object_to_delete={
                                    'name': crd_server_name,
                                    'namespace': namespace
                                })
    assert check_server_existence(
        get_k8s_custom_obj_client, namespace,
        crd_server_name) == CheckResult.RESOURCE_AVAILABLE
    assert wait_server_setup(apps_api_instance, namespace, crd_server_name,
                             replicas) == OperationStatus.SUCCESS
コード例 #2
0
def test_create_endpoint_with_2_replicas(get_k8s_custom_obj_client,
                                         apps_api_instance, function_context,
                                         session_tenant):
    crd_server_name = 'predict'
    namespace, _ = session_tenant
    model_name = 'resnet2'
    model_version = 1
    replicas = 2
    data = json.dumps({
        'modelName': model_name,
        'modelVersion': model_version,
        'endpointName': crd_server_name,
        'subjectName': 'client',
        'replicas': replicas,
        'resources': ENDPOINT_RESOURCES
    })

    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)

    response = requests.post(url, data=data, headers=DEFAULT_HEADERS)

    assert response.status_code == 200
    assert "created" in response.text

    function_context.add_object(object_type='CRD',
                                object_to_delete={
                                    'name': crd_server_name,
                                    'namespace': namespace
                                })

    assert check_server_existence(
        get_k8s_custom_obj_client, namespace,
        crd_server_name) == CheckResult.RESOURCE_AVAILABLE
    assert wait_server_setup(apps_api_instance, namespace, crd_server_name,
                             replicas) == OperationStatus.SUCCESS
コード例 #3
0
    def _wait_server_deletion(self, object_to_delete):
        server_status = check_server_existence(self.k8s_client_custom,
                                               object_to_delete['namespace'],
                                               object_to_delete['name'])
        server_pods_status = check_server_pods_existence(
            self.k8s_client_api, object_to_delete['namespace'],
            object_to_delete['name'], 1)
        completed = (server_status == CheckResult.RESOURCE_DOES_NOT_EXIST and
                     server_pods_status == CheckResult.RESOURCE_DOES_NOT_EXIST)

        if server_status == CheckResult.ERROR or server_pods_status == CheckResult.ERROR:
            logging.error("Error occurred during server status check")
            return OperationStatus.TERMINATED

        if completed:
            return OperationStatus.SUCCESS
        raise Exception
コード例 #4
0
def test_delete_endpoint(apps_api_instance, get_k8s_custom_obj_client,
                         tenant_with_endpoint):
    namespace, body = tenant_with_endpoint
    data = json.dumps({
        'endpointName': body['spec']['endpointName'],
    })

    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)
    response = requests.delete(url, data=data, headers=DEFAULT_HEADERS)
    assert response.status_code == 200
    assert "deleted" in response.text
    assert check_server_existence(
        get_k8s_custom_obj_client, namespace,
        body['spec']['endpointName']) == CheckResult.RESOURCE_DOES_NOT_EXIST
    assert wait_server_setup(apps_api_instance, namespace,
                             body['spec']['endpointName'],
                             1) == OperationStatus.TERMINATED
コード例 #5
0
def test_create_endpoint_with_2_replicas(get_k8s_custom_obj_client,
                                         apps_api_instance, function_context,
                                         session_tenant):
    namespace, _ = session_tenant
    model_name = 'resnet2'
    model_version_policy = '{specific {versions: 1}}'
    replicas = 2
    data = json.dumps({
        'modelName': model_name,
        'modelVersionPolicy': model_version_policy,
        'endpointName': crd_server_name,
        'subjectName': 'client',
        'replicas': replicas,
        'resources': ENDPOINT_RESOURCES,
        'servingName': 'tf-serving'
    })

    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)

    response = requests.post(url, data=data, headers=DEFAULT_HEADERS)
    endpoint_url = get_url_from_response(response)

    assert response.status_code == 200
    assert get_created_message(endpoint_url=endpoint_url,
                               warning=True,
                               model_name=model_name) == json.loads(
                                   response.text)

    function_context.add_object(object_type='CRD',
                                object_to_delete={
                                    'name': crd_server_name,
                                    'namespace': namespace
                                })

    assert check_server_existence(
        get_k8s_custom_obj_client, namespace,
        crd_server_name) == CheckResult.RESOURCE_AVAILABLE
    assert wait_server_setup(apps_api_instance, namespace, crd_server_name,
                             replicas) == OperationStatus.SUCCESS