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

Merge branch 'develop' of https://labs.etsi.org/rep/tfs/controller into feat/tid-bgp-speaker

parents 2f93b46d 1a982871
No related branches found
No related tags found
2 merge requests!235Release TeraFlowSDN 3.0,!151Resolve "(TID) New BGP-LS Speaker component"
...@@ -72,7 +72,12 @@ unit_test opticalattackdetector: ...@@ -72,7 +72,12 @@ unit_test opticalattackdetector:
- sleep 5 - sleep 5
- docker ps -a - docker ps -a
- docker logs $IMAGE_NAME - docker logs $IMAGE_NAME
- docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml; coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml"
- docker logs redis
- docker logs dbscanserving
- docker logs $IMAGE_NAME
- docker exec -i $IMAGE_NAME bash -c "coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
after_script: after_script:
- docker rm -f $IMAGE_NAME - docker rm -f $IMAGE_NAME
......
...@@ -221,7 +221,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi ...@@ -221,7 +221,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
monitoring_client.IncludeKpi(kpi) monitoring_client.IncludeKpi(kpi)
# if -1 in response.cluster_indices: # attack detected # if -1 in response.cluster_indices: # attack detected
if kpi.kpi_value.int32Val == -1: if kpi.kpi_value.int32Val == 1:
attack = AttackDescription() attack = AttackDescription()
attack.cs_id.uuid = request.service_id.service_uuid.uuid attack.cs_id.uuid = request.service_id.service_uuid.uuid
with HISTOGRAM_DURATION.labels(step="mitigation", **METRIC_LABELS).time(): with HISTOGRAM_DURATION.labels(step="mitigation", **METRIC_LABELS).time():
......
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
import logging import logging
import uuid import uuid
import queue import queue
import time
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
from common.proto import dbscanserving_pb2 as dbscan from common.proto import dbscanserving_pb2 as dbscan
from common.proto.optical_attack_detector_pb2 import DetectionRequest from common.proto.optical_attack_detector_pb2 import DetectionRequest
from common.tests.MockServicerImpl_Monitoring import MockServicerImpl_Monitoring
from opticalattackdetector.client.OpticalAttackDetectorClient import \ from opticalattackdetector.client.OpticalAttackDetectorClient import \
OpticalAttackDetectorClient OpticalAttackDetectorClient
...@@ -37,6 +37,7 @@ LOGGER = logging.getLogger(__name__) ...@@ -37,6 +37,7 @@ LOGGER = logging.getLogger(__name__)
def optical_attack_detector_service(): def optical_attack_detector_service():
_service = OpticalAttackDetectorService() _service = OpticalAttackDetectorService()
_service.start() _service.start()
time.sleep(2)
yield _service yield _service
_service.stop() _service.stop()
...@@ -44,7 +45,7 @@ def optical_attack_detector_service(): ...@@ -44,7 +45,7 @@ def optical_attack_detector_service():
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def optical_attack_detector_client(optical_attack_detector_service: OpticalAttackDetectorService): def optical_attack_detector_client(optical_attack_detector_service: OpticalAttackDetectorService):
_client = OpticalAttackDetectorClient( _client = OpticalAttackDetectorClient(
host=optical_attack_detector_service.bind_address, host="127.0.0.1",
port=optical_attack_detector_service.bind_port, port=optical_attack_detector_service.bind_port,
) )
yield _client yield _client
...@@ -56,26 +57,20 @@ def test_detect_attack( ...@@ -56,26 +57,20 @@ def test_detect_attack(
optical_attack_detector_client: OpticalAttackDetectorClient, optical_attack_detector_client: OpticalAttackDetectorClient,
): ):
message = dbscan.DetectionResponse() message = dbscan.DetectionResponse()
message.cluster_indices.extend([0, 1, -1, -1, -1]) message.cluster_indices.extend([0, 1] * 5 + [-1] * 10)
monitoring_mock = MockServicerImpl_Monitoring(queue_samples = queue.Queue())
with patch( with patch(
"opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.attack_mitigator_client" "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.attack_mitigator_client"
) as mitigator, patch( ) as mitigator, patch(
"opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client", "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client.IncludeKpi",
monitoring_mock,
) as monitoring, patch( ) as monitoring, patch(
"opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.dbscanserving_client.Detect", "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.dbscanserving_client.Detect",
# TODO: return dumb object with "cluster_indices" attribute
# idea: create new response object
return_value=message, return_value=message,
) as dbscanserving: ) as dbscanserving:
for _ in range(10): request: DetectionRequest = DetectionRequest()
request: DetectionRequest = DetectionRequest() request.service_id.context_id.context_uuid.uuid = str(uuid.uuid4())
request.service_id.context_id.context_uuid.uuid = str(uuid.uuid4()) request.service_id.service_uuid.uuid = str(uuid.uuid4())
request.service_id.service_uuid.uuid = str(uuid.uuid4()) request.kpi_id.kpi_id.uuid = "1"
request.kpi_id.kpi_id.uuid = "1" optical_attack_detector_client.DetectAttack(request)
optical_attack_detector_client.DetectAttack(request) dbscanserving.assert_called()
dbscanserving.assert_called_once() monitoring.assert_called()
monitoring.IncludeKpi.assert_called_once()
mitigator.NotifyAttack.assert_called()
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
Flask==2.1.3 Flask<3
Flask-WTF==1.0.0 Flask-WTF<2
flask-healthz==0.0.3 flask-healthz<2
flask-unittest==0.1.2 flask-unittest==0.1.3
lorem-text==2.1 lorem-text==2.1
werkzeug==2.3.7 werkzeug==2.3.7
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