Skip to content
Snippets Groups Projects
Commit 58251afe authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Fixed Compute unit tests.

- Added Mock Slice service
- Corrected Compute unit tests
parent c6699878
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!42Interdomain Component
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import grpc, logging
from common.Settings import get_setting
from common.tools.grpc.Tools import grpc_message_to_json_string
from context.client.ContextClient import ContextClient
from slice.proto.context_pb2 import Empty, Slice, SliceId, SliceStatusEnum
from slice.proto.slice_pb2_grpc import SliceServiceServicer
LOGGER = logging.getLogger(__name__)
class MockServicerImpl_Slice(SliceServiceServicer):
def __init__(self):
LOGGER.info('[__init__] Creating Servicer...')
self.context_client = ContextClient(
get_setting('CONTEXTSERVICE_SERVICE_HOST'),
get_setting('CONTEXTSERVICE_SERVICE_PORT_GRPC'))
LOGGER.info('[__init__] Servicer Created')
def CreateSlice(self, request : Slice, context : grpc.ServicerContext) -> SliceId:
LOGGER.info('[CreateSlice] request={:s}'.format(grpc_message_to_json_string(request)))
return self.context_client.SetSlice(request)
def UpdateSlice(self, request : Slice, context : grpc.ServicerContext) -> SliceId:
LOGGER.info('[UpdateSlice] request={:s}'.format(grpc_message_to_json_string(request)))
slice_ = Slice()
slice_.CopyFrom(request)
slice_.slice_status.slice_status = SliceStatusEnum.SLICESTATUS_ACTIVE # pylint: disable=no-member
return self.context_client.SetSlice(slice_)
def DeleteSlice(self, request : SliceId, context : grpc.ServicerContext) -> Empty:
LOGGER.info('[DeleteSlice] request={:s}'.format(grpc_message_to_json_string(request)))
return self.context_client.RemoveSlice(request)
...@@ -16,10 +16,12 @@ import logging, os, pytest, time ...@@ -16,10 +16,12 @@ import logging, os, pytest, time
from common.tests.MockService import MockService from common.tests.MockService import MockService
from common.tests.MockServicerImpl_Context import MockServicerImpl_Context from common.tests.MockServicerImpl_Context import MockServicerImpl_Context
from common.tests.MockServicerImpl_Service import MockServicerImpl_Service from common.tests.MockServicerImpl_Service import MockServicerImpl_Service
from common.tests.MockServicerImpl_Slice import MockServicerImpl_Slice
from compute.Config import RESTAPI_SERVICE_PORT, RESTAPI_BASE_URL from compute.Config import RESTAPI_SERVICE_PORT, RESTAPI_BASE_URL
from compute.service.rest_server.RestServer import RestServer from compute.service.rest_server.RestServer import RestServer
from context.proto.context_pb2_grpc import add_ContextServiceServicer_to_server from context.proto.context_pb2_grpc import add_ContextServiceServicer_to_server
from service.proto.service_pb2_grpc import add_ServiceServiceServicer_to_server from service.proto.service_pb2_grpc import add_ServiceServiceServicer_to_server
from slice.proto.slice_pb2_grpc import add_SliceServiceServicer_to_server
from .mock_osm.MockOSM import MockOSM from .mock_osm.MockOSM import MockOSM
from .Constants import ( from .Constants import (
SERVICE_CONNECTION_POINTS_1, SERVICE_CONNECTION_POINTS_2, SERVICE_TYPE, WIM_MAPPING, WIM_USERNAME, WIM_PASSWORD) SERVICE_CONNECTION_POINTS_1, SERVICE_CONNECTION_POINTS_2, SERVICE_TYPE, WIM_MAPPING, WIM_USERNAME, WIM_PASSWORD)
...@@ -43,11 +45,15 @@ class MockService_ContextService(MockService): ...@@ -43,11 +45,15 @@ class MockService_ContextService(MockService):
add_ContextServiceServicer_to_server(self.context_servicer, self.server) add_ContextServiceServicer_to_server(self.context_servicer, self.server)
self.service_servicer = MockServicerImpl_Service() self.service_servicer = MockServicerImpl_Service()
add_ServiceServiceServicer_to_server(self.service_servicer, self.server) add_ServiceServiceServicer_to_server(self.service_servicer, self.server)
self.slice_servicer = MockServicerImpl_Slice()
add_SliceServiceServicer_to_server(self.slice_servicer, self.server)
os.environ['CONTEXTSERVICE_SERVICE_HOST'] = LOCALHOST os.environ['CONTEXTSERVICE_SERVICE_HOST'] = LOCALHOST
os.environ['CONTEXTSERVICE_SERVICE_PORT_GRPC'] = str(MOCKSERVER_GRPC_PORT) os.environ['CONTEXTSERVICE_SERVICE_PORT_GRPC'] = str(MOCKSERVER_GRPC_PORT)
os.environ['SERVICESERVICE_SERVICE_HOST'] = LOCALHOST os.environ['SERVICESERVICE_SERVICE_HOST'] = LOCALHOST
os.environ['SERVICESERVICE_SERVICE_PORT_GRPC'] = str(MOCKSERVER_GRPC_PORT) os.environ['SERVICESERVICE_SERVICE_PORT_GRPC'] = str(MOCKSERVER_GRPC_PORT)
os.environ['SLICESERVICE_SERVICE_HOST'] = LOCALHOST
os.environ['SLICESERVICE_SERVICE_PORT_GRPC'] = str(MOCKSERVER_GRPC_PORT)
# NBI Plugin IETF L2VPN requires environment variables CONTEXTSERVICE_SERVICE_HOST, CONTEXTSERVICE_SERVICE_PORT_GRPC, # NBI Plugin IETF L2VPN requires environment variables CONTEXTSERVICE_SERVICE_HOST, CONTEXTSERVICE_SERVICE_PORT_GRPC,
# SERVICESERVICE_SERVICE_HOST, and SERVICESERVICE_SERVICE_PORT_GRPC to work properly. # SERVICESERVICE_SERVICE_HOST, and SERVICESERVICE_SERVICE_PORT_GRPC to work properly.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment