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(model_name, endpoint_name): params = { 'modelName': model_name, 'modelVersionPolicy': CREATE_ENDPOINT_VP, 'endpointName': endpoint_name, 'subjectName': 'client', 'resources': SENSIBLE_ENDPOINT_RESOURCES, 'servingName': 'tf-serving', } endpoint_response = create_endpoint(params) endpoint_url = get_url_from_response(endpoint_response) assert { 'status': 'CREATED', 'data': { 'url': endpoint_url, 'warning': '' } } == json.loads(endpoint_response.text) assert endpoint_response.status_code == 200 running, pod_name = wait_endpoint_setup() assert running is True endpoint_info.info = endpoint_url endpoint_info.pod_name = pod_name subject_name = get_ingress_subject_name(endpoint_name, TENANT_NAME) assert subject_name == 'CN=client' return endpoint_response
def test_update_endpoint(get_k8s_custom_obj_client, apps_api_instance, api_instance, tenant_with_endpoint, new_values): namespace, body = tenant_with_endpoint crd_server_name = body['spec']['endpointName'] data = json.dumps(new_values) if 'modelVersionPolicy' in new_values: new_values['modelVersionPolicy'] = \ normalize_version_policy(new_values['modelVersionPolicy']) url = ENDPOINT_MANAGEMENT_API_URL.format(endpoint_name=crd_server_name, tenant_name=namespace) response = requests.patch(url, data=data, headers=DEFAULT_HEADERS) endpoint_url = get_url_from_response(response) assert response.status_code == 200 assert { 'status': 'PATCHED', 'data': { 'url': endpoint_url, 'values': new_values } } == json.loads(response.text) time.sleep(2) assert check_model_params_matching_provided( get_k8s_custom_obj_client, namespace, crd_server_name, provided_params=new_values) == CheckResult.CONTENTS_MATCHING assert check_server_update_result( apps_api_instance, api_instance, namespace, crd_server_name, new_values) == CheckResult.CONTENTS_MATCHING
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) endpoint_url = get_url_from_response(response) assert response.status_code == 200 assert get_created_message( endpoint_url=endpoint_url, warning=True, model_name=body['spec']['modelName']) == json.loads(response.text)
def test_update_version_policy(): params = {'modelVersionPolicy': UPDATE_ENDPOINT_VP} endpoint_response = update_endpoint(params) endpoint_url = get_url_from_response(endpoint_response) assert { 'status': 'PATCHED', 'data': { 'url': endpoint_url, 'values': params } } == json.loads(endpoint_response.text) assert endpoint_response.status_code == 200 time.sleep(10) running, pod_name = wait_endpoint_setup() endpoint_info.pod_name = pod_name assert running is True return endpoint_response
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 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) endpoint_url = get_url_from_response(response) assert response.status_code == 200 assert { 'status': 'DELETED', 'data': { 'url': endpoint_url } } == json.loads(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 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