Skip to content
Snippets Groups Projects
Commit 253eece4 authored by Carlos Natalino Da Silva's avatar Carlos Natalino Da Silva
Browse files

Fixing tests of the opticalattackmitigator.

parent d68adb73
No related branches found
No related tags found
No related merge requests found
...@@ -6,9 +6,6 @@ __pycache__/ ...@@ -6,9 +6,6 @@ __pycache__/
# C extensions # C extensions
*.so *.so
# workspace configurations
pyproject.toml
# Distribution / packaging # Distribution / packaging
.Python .Python
build/ build/
...@@ -56,6 +53,7 @@ coverage.xml ...@@ -56,6 +53,7 @@ coverage.xml
.pytest_cache/ .pytest_cache/
.benchmarks/ .benchmarks/
cover/ cover/
*_report.xml
# Translations # Translations
*.mo *.mo
...@@ -133,6 +131,9 @@ venv.bak/ ...@@ -133,6 +131,9 @@ venv.bak/
# VSCode project settings # VSCode project settings
.vscode/ .vscode/
# Visual Studio project settings
/.vs
# Rope project settings # Rope project settings
.ropeproject .ropeproject
...@@ -161,11 +162,6 @@ cython_debug/ ...@@ -161,11 +162,6 @@ cython_debug/
# TeraFlowSDN-generated files # TeraFlowSDN-generated files
tfs_runtime_env_vars.sh tfs_runtime_env_vars.sh
# Coverage report files
*_report.xml
delete_local_deployment.sh delete_local_deployment.sh
local_docker_deployment.sh local_docker_deployment.sh
local_k8s_deployment.sh local_k8s_deployment.sh
/src/common/proto/.gitkeep
/src/common/proto/__init__.py
# file containing the configuration for several tools used
# THIS FILE MUST NOT BE CHANGED
[tool.black]
line-length = 88
[tool.isort]
profile = "black"
line_length = 88
src_paths = "."
skip_gitignore = true
\ No newline at end of file
...@@ -19,8 +19,6 @@ LOG_LEVEL = logging.DEBUG ...@@ -19,8 +19,6 @@ LOG_LEVEL = logging.DEBUG
# gRPC settings # gRPC settings
GRPC_SERVICE_PORT = 10008 GRPC_SERVICE_PORT = 10008
GRPC_MAX_WORKERS = 10
GRPC_GRACE_PERIOD = 60
# Prometheus settings # Prometheus settings
METRICS_PORT = 9192 METRICS_PORT = 9192
...@@ -16,8 +16,9 @@ import logging ...@@ -16,8 +16,9 @@ import logging
from concurrent import futures from concurrent import futures
import grpc import grpc
from common.Constants import DEFAULT_GRPC_GRACE_PERIOD, DEFAULT_GRPC_MAX_WORKERS
from common.proto.dbscanserving_pb2_grpc import add_DetectorServicer_to_server from common.proto.dbscanserving_pb2_grpc import add_DetectorServicer_to_server
from dbscanserving.Config import GRPC_GRACE_PERIOD, GRPC_MAX_WORKERS, GRPC_SERVICE_PORT from dbscanserving.Config import GRPC_SERVICE_PORT
from dbscanserving.service.DbscanServiceServicerImpl import DbscanServiceServicerImpl from dbscanserving.service.DbscanServiceServicerImpl import DbscanServiceServicerImpl
from grpc_health.v1.health import OVERALL_HEALTH, HealthServicer from grpc_health.v1.health import OVERALL_HEALTH, HealthServicer
from grpc_health.v1.health_pb2 import HealthCheckResponse from grpc_health.v1.health_pb2 import HealthCheckResponse
...@@ -32,8 +33,8 @@ class DbscanService: ...@@ -32,8 +33,8 @@ class DbscanService:
self, self,
address=BIND_ADDRESS, address=BIND_ADDRESS,
port=GRPC_SERVICE_PORT, port=GRPC_SERVICE_PORT,
max_workers=GRPC_MAX_WORKERS, grace_period=DEFAULT_GRPC_GRACE_PERIOD,
grace_period=GRPC_GRACE_PERIOD, max_workers=DEFAULT_GRPC_MAX_WORKERS,
): ):
self.address = address self.address = address
......
...@@ -17,8 +17,9 @@ import signal ...@@ -17,8 +17,9 @@ import signal
import sys import sys
import threading import threading
from common.Constants import DEFAULT_GRPC_GRACE_PERIOD, DEFAULT_GRPC_MAX_WORKERS
from common.Settings import get_log_level, get_metrics_port, get_setting from common.Settings import get_log_level, get_metrics_port, get_setting
from dbscanserving.Config import GRPC_GRACE_PERIOD, GRPC_MAX_WORKERS, GRPC_SERVICE_PORT from dbscanserving.Config import GRPC_SERVICE_PORT
from dbscanserving.service.DbscanService import DbscanService from dbscanserving.service.DbscanService import DbscanService
from prometheus_client import start_http_server from prometheus_client import start_http_server
...@@ -41,8 +42,8 @@ def main(): ...@@ -41,8 +42,8 @@ def main():
service_port = get_setting( service_port = get_setting(
"DBSCANSERVICE_SERVICE_PORT_GRPC", default=GRPC_SERVICE_PORT "DBSCANSERVICE_SERVICE_PORT_GRPC", default=GRPC_SERVICE_PORT
) )
max_workers = get_setting("MAX_WORKERS", default=GRPC_MAX_WORKERS) grace_period = get_setting("GRACE_PERIOD", default=DEFAULT_GRPC_GRACE_PERIOD)
grace_period = get_setting("GRACE_PERIOD", default=GRPC_GRACE_PERIOD) max_workers = get_setting("MAX_WORKERS", default=DEFAULT_GRPC_MAX_WORKERS)
signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGTERM, signal_handler)
......
...@@ -20,7 +20,7 @@ from unittest.mock import patch ...@@ -20,7 +20,7 @@ from unittest.mock import patch
import pytest import pytest
from common.proto.dbscanserving_pb2 import DetectionRequest, DetectionResponse, Sample from common.proto.dbscanserving_pb2 import DetectionRequest, DetectionResponse, Sample
from dbscanserving.client.DbscanServingClient import DbscanServingClient from dbscanserving.client.DbscanServingClient import DbscanServingClient
from dbscanserving.Config import GRPC_GRACE_PERIOD, GRPC_MAX_WORKERS, GRPC_SERVICE_PORT from dbscanserving.Config import GRPC_SERVICE_PORT
from dbscanserving.service.DbscanService import DbscanService from dbscanserving.service.DbscanService import DbscanService
port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports
...@@ -31,9 +31,7 @@ LOGGER.setLevel(logging.DEBUG) ...@@ -31,9 +31,7 @@ LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def dbscanserving_service(): def dbscanserving_service():
_service = DbscanService( _service = DbscanService(port=port)
port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD
)
_service.start() _service.start()
yield _service yield _service
_service.stop() _service.stop()
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
# limitations under the License. # limitations under the License.
import logging import logging
import os
from unittest.mock import patch
import pytest import pytest
from common.proto.optical_attack_mitigator_pb2 import AttackDescription, AttackResponse from common.proto.optical_attack_mitigator_pb2 import AttackDescription, AttackResponse
...@@ -20,8 +22,6 @@ from opticalattackmitigator.client.OpticalAttackMitigatorClient import ( ...@@ -20,8 +22,6 @@ from opticalattackmitigator.client.OpticalAttackMitigatorClient import (
OpticalAttackMitigatorClient, OpticalAttackMitigatorClient,
) )
from opticalattackmitigator.Config import ( from opticalattackmitigator.Config import (
GRPC_GRACE_PERIOD,
GRPC_MAX_WORKERS,
GRPC_SERVICE_PORT, GRPC_SERVICE_PORT,
) )
from opticalattackmitigator.service.OpticalAttackMitigatorService import ( from opticalattackmitigator.service.OpticalAttackMitigatorService import (
...@@ -37,7 +37,7 @@ LOGGER.setLevel(logging.DEBUG) ...@@ -37,7 +37,7 @@ LOGGER.setLevel(logging.DEBUG)
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def optical_attack_mitigator_service(): def optical_attack_mitigator_service():
_service = OpticalAttackMitigatorService( _service = OpticalAttackMitigatorService(
port=port, max_workers=GRPC_MAX_WORKERS, grace_period=GRPC_GRACE_PERIOD port=port
) )
_service.start() _service.start()
yield _service yield _service
...@@ -46,8 +46,16 @@ def optical_attack_mitigator_service(): ...@@ -46,8 +46,16 @@ def optical_attack_mitigator_service():
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def optical_attack_mitigator_client(optical_attack_mitigator_service): def optical_attack_mitigator_client(optical_attack_mitigator_service):
_client = OpticalAttackMitigatorClient(address="127.0.0.1", port=port) with patch.dict(
yield _client os.environ,
{
"OPTICALATTACKMITIGATORSERVICE_SERVICE_HOST": "127.0.0.1",
"OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC": str(port),
},
clear=True,
):
_client = OpticalAttackMitigatorClient()
yield _client
_client.close() _client.close()
......
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