Commit e6dfa488 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

First functional version of Compute component with IETF L2VPN REST-API endpoint for OSM.

Common:
- added chk_attribute to type_checkers module.
- recovered run_tests_locally.sh

Compute:
- updated requirements.in
- updated Config.py
- updated RestServer
- implemented IETF-L2VPN NBI plugin
- implemented unitary tests for IETF-L2VPN NBI plugin including a Mock OSM client, and Mock Context and Service components
parent 32072654
Loading
Loading
Loading
Loading
+36 −36
Original line number Diff line number Diff line
@@ -19,46 +19,46 @@ cat $PROJECTDIR/coverage/.coveragerc.template | sed s+~/teraflow/controller+$PRO
#kubectl --namespace tf-dev expose deployment contextservice --port=6379 --type=NodePort --name=redis-tests
#echo "Waiting 10 seconds for Redis to start..."
#sleep 10
#export REDIS_SERVICE_HOST=$(kubectl get node kubernetes-master -o 'jsonpath={.status.addresses[?(@.type=="InternalIP")].address}')
#export REDIS_SERVICE_PORT=$(kubectl get service redis-tests --namespace tf-dev -o 'jsonpath={.spec.ports[?(@.port==6379)].nodePort}')
export REDIS_SERVICE_HOST=$(kubectl get node kubernetes-master -o 'jsonpath={.status.addresses[?(@.type=="InternalIP")].address}')
export REDIS_SERVICE_PORT=$(kubectl get service redis-tests --namespace tf-dev -o 'jsonpath={.spec.ports[?(@.port==6379)].nodePort}')

# First destroy old coverage file
rm -f $COVERAGEFILE

#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    common/orm/tests/test_unitary.py \
#    common/message_broker/tests/test_unitary.py \
#    common/rpc_method_wrapper/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    centralizedattackdetector/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    context/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    device/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
#    l3_centralizedattackdetector/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
#    l3_distributedattackdetector/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
#    l3_attackmitigator/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    opticalcentralizedattackdetector/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    dbscanserving/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    opticalattackmitigator/tests/test_unitary.py
#
#coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
#    service/tests/test_unitary.py
coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    common/orm/tests/test_unitary.py \
    common/message_broker/tests/test_unitary.py \
    common/rpc_method_wrapper/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    centralizedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    context/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    device/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
    l3_centralizedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
    l3_distributedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest -s --log-level=INFO --verbose \
    l3_attackmitigator/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    opticalcentralizedattackdetector/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    dbscanserving/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    opticalattackmitigator/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    service/tests/test_unitary.py

coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \
    compute/tests/test_unitary.py
+6 −1
Original line number Diff line number Diff line
import re
from typing import Any, Container, List, Optional, Pattern, Set, Sized, Tuple, Union
from typing import Any, Container, Dict, List, Optional, Pattern, Set, Sized, Tuple, Union

def chk_none(name : str, value : Any, reason=None) -> Any:
    if value is None: return value
@@ -11,6 +11,11 @@ def chk_not_none(name : str, value : Any, reason=None) -> Any:
    if reason is None: reason = 'must not be None.'
    raise ValueError('{}({}) {}'.format(str(name), str(value), str(reason)))

def chk_attribute(name : str, container : Dict, container_name : str, **kwargs):
    if name in container: return container[name]
    if 'default' in kwargs: return kwargs['default']
    raise AttributeError('Missing object({:s}) in container({:s})'.format(str(name), str(container_name)))

def chk_type(name : str, value : Any, type_or_types : Union[type, Set[type]] = set()) -> Any:
    if isinstance(value, type_or_types): return value
    msg = '{}({}) is of a wrong type({}). Accepted type_or_types({}).'
+5 −1
Original line number Diff line number Diff line
import logging
from werkzeug.security import generate_password_hash

# General settings
LOG_LEVEL = logging.WARNING
@@ -10,7 +11,10 @@ GRPC_GRACE_PERIOD = 60

# REST-API settings
RESTAPI_SERVICE_PORT = 8080
RESTAPI_BASE_URL = '/restconf/data/ietf-l2vpn-svc:l2vpn-svc'
RESTAPI_BASE_URL = '/restconf/data'
RESTAPI_USERS = {   # TODO: implement a database of credentials and permissions
    'admin': generate_password_hash('admin'),
}

# Prometheus settings
METRICS_PORT = 9192
+4 −0
Original line number Diff line number Diff line
Flask
Flask-HTTPAuth
Flask-RESTful
grpcio-health-checking
grpcio
jsonschema
prometheus-client
pytest
pytest-benchmark
+5 −6
Original line number Diff line number Diff line
@@ -4,9 +4,9 @@ from common.Settings import get_setting
from compute.Config import (
    GRPC_SERVICE_PORT, GRPC_MAX_WORKERS, GRPC_GRACE_PERIOD, LOG_LEVEL, RESTAPI_SERVICE_PORT, RESTAPI_BASE_URL,
    METRICS_PORT)
from compute.service.ComputeService import ComputeService
from compute.service.rest_server.Server import Server
from compute.service.rest_server.resources.Compute import Compute
from .ComputeService import ComputeService
from .rest_server.RestServer import RestServer
from .rest_server.nbi_plugins.ietf_l2vpn import register_ietf_l2vpn

terminate = threading.Event()
LOGGER = None
@@ -41,9 +41,8 @@ def main():
    grpc_service = ComputeService(port=grpc_service_port, max_workers=max_workers, grace_period=grace_period)
    grpc_service.start()

    rest_server = Server(port=restapi_service_port, base_url=restapi_base_url)
    rest_server.add_resource(
        Compute, '/restconf/config/compute', endpoint='api.compute')
    rest_server = RestServer(port=restapi_service_port, base_url=restapi_base_url)
    register_ietf_l2vpn(rest_server)
    rest_server.start()

    # Wait for Ctrl+C or termination signal
Loading