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
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
def simulate_scaling(custom_obj_api, apps_api_instance, headers, namespace, name, replicas): url = ENDPOINT_MANAGEMENT_API_URL_SCALE.format(endpoint_name=name, tenant_name=namespace) data = json.dumps({'replicas': replicas}) response = requests.patch(url, data=data, headers=headers) assert response.status_code == 200 assert "patched" in response.text assert check_replicas_number_matching_provided( custom_obj_api, namespace, name, provided_number=replicas) == CheckResult.CONTENTS_MATCHING assert wait_server_setup(apps_api_instance, namespace, name, replicas) == OperationStatus.SUCCESS
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
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
def simulate_scaling(custom_obj_api, apps_api_instance, headers, namespace, name, replicas): url = ENDPOINT_MANAGEMENT_API_URL_SCALE.format(endpoint_name=name, tenant_name=namespace) scaling_dict = {'replicas': replicas} data = json.dumps(scaling_dict) response = requests.patch(url, data=data, headers=headers) endpoint_url = get_url_from_response(response) assert response.status_code == 200 assert { 'status': 'PATCHED', 'data': { 'url': endpoint_url, 'values': scaling_dict } } == json.loads(response.text) assert check_replicas_number_matching_provided( custom_obj_api, namespace, name, provided_number=replicas) == CheckResult.CONTENTS_MATCHING assert wait_server_setup(apps_api_instance, namespace, name, replicas) == OperationStatus.SUCCESS