Example #1
0
def test_not_create_endpoint_with_incompliant_resource_quota(
        session_tenant, incompliant_quota, expected_error):

    crd_server_name = 'predict'
    namespace, _ = session_tenant

    model_name = 'resnet'
    model_version = 1
    replicas = 1
    data = json.dumps({
        'modelName': model_name,
        'modelVersion': model_version,
        'endpointName': crd_server_name,
        'subjectName': 'client',
        'replicas': replicas,
        'resources': incompliant_quota
    })

    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)

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

    assert response.status_code == 400
    assert expected_error in response.text
Example #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
Example #3
0
def test_list_endpoints(request, tenant_fix, auth_headers, expected_status,
                        expected_message):
    namespace, _ = request.getfixturevalue(tenant_fix)
    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)
    response = requests.get(url, headers=auth_headers)

    assert expected_status == response.status_code
    assert expected_message.format(namespace) in response.text
Example #4
0
def test_try_create_the_same_endpoint(tenant_with_endpoint):
    namespace, body = tenant_with_endpoint
    body['spec']['resources'] = ENDPOINT_RESOURCES
    data = json.dumps(body['spec'])

    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)

    response = requests.post(url, data=data, headers=DEFAULT_HEADERS)
    assert response.status_code == 400
    assert "Conflict" in response.text
Example #5
0
def test_fail_to_create_second_endpoint_with_max_endpoints_eq_one(
        tenant_with_endpoint_parametrized_max_endpoints):
    namespace, body = tenant_with_endpoint_parametrized_max_endpoints
    body['spec']['endpointName'] = "predict-2"
    body['spec']['resources'] = ENDPOINT_RESOURCES
    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)
    response = requests.post(url,
                             data=json.dumps(body['spec']),
                             headers=DEFAULT_HEADERS)
    assert response.status_code == 409
    assert "Endpoints have reached the quantity limit" in response.text
Example #6
0
def test_success_to_create_second_endpoint_with_max_endpoints_gt_one(
        tenant_with_endpoint_parametrized_max_endpoints):
    namespace, body = tenant_with_endpoint_parametrized_max_endpoints
    endpoint_name = "predict-2"
    body['spec']['endpointName'] = endpoint_name
    body['spec']['resources'] = ENDPOINT_RESOURCES
    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=namespace)
    response = requests.post(url,
                             data=json.dumps(body['spec']),
                             headers=DEFAULT_HEADERS)
    assert response.status_code == 200
    assert "Endpoint created" in response.text
    assert f"{endpoint_name}-{namespace}" in response.text
def create_endpoint(headers=DEFAULT_HEADERS, name=MODEL_NAME,
                    resources=SENSIBLE_ENDPOINT_RESOURCES,
                    tenant=TENANT_NAME):
    data = json.dumps({
        'modelName': name,
        'modelVersion': 1,
        'endpointName': name + 'endpoint',
        'subjectName': 'client',
        'resources': resources,
    })
    url = ENDPOINTS_MANAGEMENT_API_URL.format(tenant_name=tenant)

    response = requests.post(url, data=data, headers=headers, verify=False)
    return response
Example #8
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
Example #9
0
def test_not_create_endpoint_tenant_not_exist():
    headers = USER2_HEADERS
    crd_server_name = 'predict'
    namespace = 'saturn'
    replicas = 1
    data = json.dumps({
        'modelName': 'resnet',
        'modelVersion': 1,
        '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=headers)

    assert response.status_code == 404
    assert "Tenant {} does not exist".format(namespace) in response.text