Commit 95a93fec authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/145-fix-ofc-24-end-to-end-test-for-optical-controller-component' into 'develop'

Resolve "Fix OFC'24 end-to-end test for Optical Controller component"

See merge request !223
parents 6017733c 62a30586
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -29,7 +29,14 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene
#export TFS_COMPONENTS="${TFS_COMPONENTS} bgpls_speaker"

# Uncomment to activate Optical Controller
#export TFS_COMPONENTS="${TFS_COMPONENTS} opticalcontroller"
#   To manage optical connections, "service" requires "opticalcontroller" to be deployed
#   before "service", thus we "hack" the TFS_COMPONENTS environment variable prepending the
#   "opticalcontroller" only if "service" is already in TFS_COMPONENTS, and re-export it.
#if [[ "$TFS_COMPONENTS" == *"service"* ]]; then
#    BEFORE="${TFS_COMPONENTS% service*}"
#    AFTER="${TFS_COMPONENTS#* service}"
#    export TFS_COMPONENTS="${BEFORE} opticalcontroller service ${AFTER}"
#fi

# Uncomment to activate ZTP
#export TFS_COMPONENTS="${TFS_COMPONENTS} ztp"
+2 −4
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer
    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def GetOpticalConfig(self, request : Empty, context : grpc.ServicerContext) -> OpticalConfigList:
        result = get_opticalconfig(self.db_engine)
        return OpticalConfigList(OpticalConfigs=result)
        return OpticalConfigList(opticalconfigs=result)

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def SetOpticalConfig(self, request : OpticalConfig, context : grpc.ServicerContext) -> OpticalConfigId:
@@ -315,6 +315,4 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer
    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def SelectOpticalConfig(self, request : OpticalConfigId, context : grpc.ServicerContext) -> OpticalConfig:
        result = select_opticalconfig(self.db_engine, request)
        optical_config_id = OpticalConfigId()
        optical_config_id.CopyFrom(result.OpticalConfig_id)
        return OpticalConfig(config=result.config, OpticalConfig_id=optical_config_id)
        return OpticalConfig(config=result.config, opticalconfig_id=result.opticalconfig_id)
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ class AddFlexLightpath(Resource):
        if rsa is not None:
            flow_id, optical_band_id = rsa.rsa_fs_computation(src, dst, bitrate, bidir, band)
            print (f"flow_id {flow_id} and optical_band_id {optical_band_id} ")
            LOGGER.debug('flow_id={:s} rsa.db_flows={:s}'.format(str(flow_id), str(rsa.db_flows)))
            if flow_id is not None:
                if rsa.db_flows[flow_id]["op-mode"] == 0:
                    return 'No path found', 404
+4 −5
Original line number Diff line number Diff line
@@ -122,17 +122,16 @@ class TaskExecutor:
        optical_config_id = OpticalConfigId()
        optical_config_id.opticalconfig_uuid = device.device_id.device_uuid.uuid
        optical_config = OpticalConfig()
        setting = settings.value if settings else ""
        setting = settings.value if settings else ''

        new_config = {}
        try:
            result = self._context_client.SelectOpticalConfig(optical_config_id)
            new_config = json.loads(result.config)
            if result is not None:
                new_config = json.loads(result.config)
                new_config["new_config"] = setting
                new_config["is_opticalband"] = is_opticalband
                new_config["flow"] = flows
                result.config = str(new_config)
                result.config = json.dumps(new_config)
                optical_config.CopyFrom(result)
                self._device_client.ConfigureOpticalDevice(optical_config)
            self._store_grpc_object(CacheableObjectType.DEVICE, device_key, device)
+51 −24
Original line number Diff line number Diff line
@@ -13,35 +13,58 @@
# limitations under the License.
# 

import json
import requests
import uuid
from common.Constants import *
import functools, json, logging, requests, uuid
from typing import List
from common.Constants import ServiceNameEnum
from common.proto.context_pb2 import(
    Device, DeviceId, Service, Connection, EndPointId, TopologyId, ContextId, Uuid,
    ConfigRule, ConfigActionEnum, ConfigRule_Custom
)
from common.proto.pathcomp_pb2 import PathCompReply
from common.Settings import (
    ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC, find_environment_variables, get_env_var_name
    ENVVAR_SUFIX_SERVICE_BASEURL_HTTP, ENVVAR_SUFIX_SERVICE_HOST, ENVVAR_SUFIX_SERVICE_PORT_GRPC,
    find_environment_variables, get_env_var_name
)
from service.service.tools.replies import (
    reply_uni_txt, optical_band_uni_txt, reply_bid_txt, optical_band_bid_txt
)
from service.service.tools.replies import reply_uni_txt, optical_band_uni_txt, reply_bid_txt, optical_band_bid_txt

log = logging.getLogger(__name__)

testing = False
TESTING = False

get_optical_controller_setting = functools.partial(get_env_var_name, ServiceNameEnum.OPTICALCONTROLLER)
VAR_NAME_OPTICAL_CTRL_BASEURL_HTTP = get_optical_controller_setting(ENVVAR_SUFIX_SERVICE_BASEURL_HTTP)
VAR_NAME_OPTICAL_CTRL_SCHEMA       = get_optical_controller_setting('SCHEMA')
VAR_NAME_OPTICAL_CTRL_HOST         = get_optical_controller_setting(ENVVAR_SUFIX_SERVICE_HOST)
VAR_NAME_OPTICAL_CTRL_PORT         = get_optical_controller_setting(ENVVAR_SUFIX_SERVICE_PORT_GRPC)

VAR_NAME_OPTICAL_CONTROLLER_HOST = get_env_var_name(ServiceNameEnum.OPTICALCONTROLLER, ENVVAR_SUFIX_SERVICE_HOST)
VAR_NAME_OPTICAL_CONTROLLER_PORT = get_env_var_name(ServiceNameEnum.OPTICALCONTROLLER, ENVVAR_SUFIX_SERVICE_PORT_GRPC)
OPTICAL_CTRL_BASE_URL = '{:s}://{:s}:{:d}/OpticalTFS'

opticalcontrollers_url = find_environment_variables([
    VAR_NAME_OPTICAL_CONTROLLER_HOST,
    VAR_NAME_OPTICAL_CONTROLLER_PORT,
def get_optical_controller_base_url() -> str:
    settings = find_environment_variables([
        VAR_NAME_OPTICAL_CTRL_BASEURL_HTTP,
        VAR_NAME_OPTICAL_CTRL_SCHEMA,
        VAR_NAME_OPTICAL_CTRL_HOST,
        VAR_NAME_OPTICAL_CTRL_PORT,
    ])
OPTICAL_IP   = opticalcontrollers_url.get(VAR_NAME_OPTICAL_CONTROLLER_HOST)
OPTICAL_PORT = opticalcontrollers_url.get(VAR_NAME_OPTICAL_CONTROLLER_PORT)
log.info(str(OPTICAL_IP), str(OPTICAL_PORT))
    base_url = settings.get(VAR_NAME_OPTICAL_CTRL_BASEURL_HTTP)
    if base_url is not None:
        log.debug('Optical Controller: base_url={:s}'.format(str(base_url)))
        return base_url

    host = settings.get(VAR_NAME_OPTICAL_CTRL_HOST)
    port = int(settings.get(VAR_NAME_OPTICAL_CTRL_PORT, 80))

    MSG = 'Optical Controller not found: settings={:s}'
    if host is None: raise Exception(MSG.format(str(settings)))
    if port is None: raise Exception(MSG.format(str(settings)))

    schema = settings.get(VAR_NAME_OPTICAL_CTRL_SCHEMA, 'http')
    base_url = OPTICAL_CTRL_BASE_URL.format(schema, host, port)
    log.debug('Optical Controller: base_url={:s}'.format(str(base_url)))
    return base_url


def get_uuids_from_names(devices: List[Device], device_name: str, port_name: str):
    device_uuid = ""
@@ -79,17 +102,18 @@ def get_device_name_from_uuid(devices: List[Device], device_uuid: str):


def add_lightpath(src, dst, bitrate, bidir, ob_band) -> str:
    if not testing:
    if not TESTING:
        urlx = ""
        headers = {"Content-Type": "application/json"}
        base_url = get_optical_controller_base_url()
        if ob_band is None:
            if bidir is None:
                bidir = 1
            urlx = "http://{}:{}/OpticalTFS/AddFlexLightpath/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, src, dst, bitrate, bidir)
            urlx = "{:s}/AddFlexLightpath/{:s}/{:s}/{:s}/{:s}".format(base_url, src, dst, str(bitrate), str(bidir))
        else:
            if bidir is None:
                bidir = 1
            urlx = "http://{}:{}/OpticalTFS/AddFlexLightpath/{}/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, src, dst, bitrate, bidir, ob_band)
            urlx = "{:s}/AddFlexLightpath/{:s}/{:s}/{:s}/{:s}/{:s}".format(base_url, src, dst, str(bitrate), str(bidir), str(ob_band))
        r = requests.put(urlx, headers=headers)
        reply = r.text 
        return reply
@@ -101,8 +125,9 @@ def add_lightpath(src, dst, bitrate, bidir, ob_band) -> str:
                

def get_optical_band(idx) -> str:
    if not testing:
        urlx = "http://{}:{}/OpticalTFS/GetOpticalBand/{}".format(OPTICAL_IP, OPTICAL_PORT, idx)
    if not TESTING:
        base_url = get_optical_controller_base_url()
        urlx = "{:s}/GetOpticalBand/{:s}".format(base_url, str(idx))
        headers = {"Content-Type": "application/json"}
        r = requests.get(urlx, headers=headers)
        reply = r.text 
@@ -116,8 +141,9 @@ def get_optical_band(idx) -> str:
    
def delete_lightpath(flow_id, src, dst, bitrate) -> str:
    reply = "200"
    if not testing:
        urlx = "http://{}:{}/OpticalTFS/DelLightpath/{}/{}/{}/{}".format(OPTICAL_IP, OPTICAL_PORT, flow_id, src, dst, bitrate)
    if not TESTING:
        base_url = get_optical_controller_base_url()
        urlx = "{:s}/DelLightpath/{:s}/{:s}/{:s}/{:s}".format(base_url, str(flow_id), src, dst, str(bitrate))

        headers = {"Content-Type": "application/json"}
        r = requests.delete(urlx, headers=headers)
@@ -126,7 +152,8 @@ def delete_lightpath(flow_id, src, dst, bitrate) -> str:


def get_lightpaths() -> str:
    urlx = "http://{}:{}/OpticalTFS/GetLightpaths".format(OPTICAL_IP, OPTICAL_PORT)
    base_url = get_optical_controller_base_url()
    urlx = "{:s}/GetLightpaths".format(base_url)

    headers = {"Content-Type": "application/json"}
    r = requests.get(urlx, headers=headers)
Loading