From b95fdd5a76c41f25cae5412a6ce3bc1a33e01580 Mon Sep 17 00:00:00 2001 From: Lluis Gifre <lluis.gifre@cttc.es> Date: Wed, 3 Aug 2022 15:49:20 +0000 Subject: [PATCH] PathComp component - Added curl as dependency for unitary tests - Added configuration settings in Frontend - Removed unneeded logs --- src/pathcomp/backend/Dockerfile | 2 +- src/pathcomp/frontend/Config.py | 17 ++++++++++++++--- .../service/PathCompServiceServicerImpl.py | 8 ++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/pathcomp/backend/Dockerfile b/src/pathcomp/backend/Dockerfile index c131f8b64..869e4b649 100644 --- a/src/pathcomp/backend/Dockerfile +++ b/src/pathcomp/backend/Dockerfile @@ -19,7 +19,7 @@ FROM ubuntu:20.04 AS builder ARG DEBIAN_FRONTEND=noninteractive # Install build software -RUN apt-get update -y && apt-get install build-essential gcovr libglib2.0-dev -y +RUN apt-get update -y && apt-get install build-essential curl gcovr libglib2.0-dev -y # mkdir RUN mkdir -p /var/teraflow diff --git a/src/pathcomp/frontend/Config.py b/src/pathcomp/frontend/Config.py index af7c277c5..75f910e36 100644 --- a/src/pathcomp/frontend/Config.py +++ b/src/pathcomp/frontend/Config.py @@ -12,6 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -BACKEND_URL = 'http://{:s}:{:d}/pathComp/api/v1/compRoute' -BACKEND_HOST = '172.28.0.2' -BACKEND_PORT = 8081 +import os + +DEFAULT_PATHCOMP_BACKEND_SCHEME = 'http' +DEFAULT_PATHCOMP_BACKEND_HOST = '127.0.0.1' +DEFAULT_PATHCOMP_BACKEND_PORT = 8081 +DEFAULT_PATHCOMP_BACKEND_BASEURL = '/pathComp/api/v1/compRoute' + +PATHCOMP_BACKEND_SCHEME = str(os.environ.get('PATHCOMP_BACKEND_SCHEME', DEFAULT_PATHCOMP_BACKEND_SCHEME )) +PATHCOMP_BACKEND_HOST = str(os.environ.get('PATHCOMP_BACKEND_HOST', DEFAULT_PATHCOMP_BACKEND_HOST )) +PATHCOMP_BACKEND_PORT = int(os.environ.get('PATHCOMP_BACKEND_PORT', DEFAULT_PATHCOMP_BACKEND_PORT )) +PATHCOMP_BACKEND_BASEURL = str(os.environ.get('PATHCOMP_BACKEND_BASEURL', DEFAULT_PATHCOMP_BACKEND_BASEURL)) + +BACKEND_URL = '{:s}://{:s}:{:d}{:s}'.format( + PATHCOMP_BACKEND_SCHEME, PATHCOMP_BACKEND_HOST, PATHCOMP_BACKEND_PORT, PATHCOMP_BACKEND_BASEURL) diff --git a/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py b/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py index 3cf112191..b1da51563 100644 --- a/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py +++ b/src/pathcomp/frontend/service/PathCompServiceServicerImpl.py @@ -20,7 +20,7 @@ from common.proto.pathcomp_pb2_grpc import PathCompServiceServicer from common.rpc_method_wrapper.Decorator import create_metrics, safe_and_metered_rpc_method from common.tools.grpc.Tools import grpc_message_to_json_string from context.client.ContextClient import ContextClient -from pathcomp.frontend.Config import BACKEND_HOST, BACKEND_PORT, BACKEND_URL +from pathcomp.frontend.Config import BACKEND_URL from pathcomp.frontend.service.tools.ComposeRequest import compose_device, compose_link, compose_service #from pathcomp.frontend.service.tools.Constants import CapacityUnit @@ -37,9 +37,6 @@ class PathCompServiceServicerImpl(PathCompServiceServicer): @safe_and_metered_rpc_method(METRICS, LOGGER) def Compute(self, request : PathCompRequest, context : grpc.ServicerContext) -> PathCompReply: - import os - LOGGER.info('os.environ={:s}'.format(str(os.environ))) - LOGGER.info('[Compute] begin ; request = {:s}'.format(grpc_message_to_json_string(request))) algorithm = request.WhichOneof('algorithm') @@ -105,8 +102,7 @@ class PathCompServiceServicerImpl(PathCompServiceServicer): #with open('pc-req.json', 'w', encoding='UTF-8') as f: # f.write(json.dumps(request, sort_keys=True, indent=4)) - backend_url = BACKEND_URL.format(BACKEND_HOST, BACKEND_PORT) - reply = requests.post(backend_url, json=request) + reply = requests.post(BACKEND_URL, json=request) if reply.status_code not in {requests.codes.ok}: raise Exception('Backend error({:s}) for request({:s})'.format( str(reply.content.decode('UTF-8')), json.dumps(request, sort_keys=True))) -- GitLab