From 1d7d91783c6e232619407486133ec39ddb00a2c2 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 12:16:08 +0000 Subject: [PATCH 01/22] Fixing tests of the mitigator. --- src/opticalattackmitigator/.gitlab-ci.yml | 6 ++---- src/opticalattackmitigator/tests/test_unitary.py | 13 ++----------- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/opticalattackmitigator/.gitlab-ci.yml b/src/opticalattackmitigator/.gitlab-ci.yml index 44f13aa20..30eb94b1b 100644 --- a/src/opticalattackmitigator/.gitlab-ci.yml +++ b/src/opticalattackmitigator/.gitlab-ci.yml @@ -33,7 +33,6 @@ build opticalattackmitigator: - src/$IMAGE_NAME/**/*.{py,in,yml} - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - - src/$IMAGE_NAME/tests/Dockerfile - manifests/${IMAGE_NAME}service.yaml - .gitlab-ci.yml @@ -48,7 +47,7 @@ unit_test opticalattackmitigator: before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi - - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi + - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME container is not in the system"; fi script: - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - docker run --name $IMAGE_NAME -d -p 10007:10007 -v "$PWD/src/$IMAGE_NAME/tests:/home/${IMAGE_NAME}/results" --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG @@ -66,8 +65,7 @@ unit_test opticalattackmitigator: - src/$IMAGE_NAME/**/*.{py,in,yml} - src/$IMAGE_NAME/Dockerfile - src/$IMAGE_NAME/tests/*.py - - src/$IMAGE_NAME/tests/Dockerfile - - manifests/$IMAGE_NAMEservice.yaml + - manifests/${IMAGE_NAME}service.yaml - .gitlab-ci.yml artifacts: when: always diff --git a/src/opticalattackmitigator/tests/test_unitary.py b/src/opticalattackmitigator/tests/test_unitary.py index 68836c4e8..76b31c3a8 100644 --- a/src/opticalattackmitigator/tests/test_unitary.py +++ b/src/opticalattackmitigator/tests/test_unitary.py @@ -17,29 +17,20 @@ import os from unittest.mock import patch import pytest -from common.Constants import (DEFAULT_GRPC_GRACE_PERIOD, - DEFAULT_GRPC_MAX_WORKERS) from common.proto.optical_attack_mitigator_pb2 import AttackDescription from opticalattackmitigator.client.OpticalAttackMitigatorClient import \ OpticalAttackMitigatorClient -from opticalattackmitigator.Config import GRPC_SERVICE_PORT from opticalattackmitigator.service.OpticalAttackMitigatorService import \ OpticalAttackMitigatorService -port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports - LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @pytest.fixture(scope="session") def optical_attack_mitigator_service(): - _service = OpticalAttackMitigatorService( - port=port, - max_workers=DEFAULT_GRPC_MAX_WORKERS, - grace_period=DEFAULT_GRPC_GRACE_PERIOD, - ) + _service = OpticalAttackMitigatorService() _service.start() yield _service _service.stop() @@ -51,7 +42,7 @@ def optical_attack_mitigator_client(optical_attack_mitigator_service): os.environ, { "OPTICALATTACKMITIGATORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC": str(port), + "OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC": str(optical_attack_mitigator_service.bind_port), }, clear=True, ): -- GitLab From f0a126e66065f9884fadd8f68419bfe640ba918d Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 12:29:08 +0000 Subject: [PATCH 02/22] Fixing tests for dbscanserving. --- src/dbscanserving/.gitlab-ci.yml | 2 +- src/dbscanserving/tests/test_unitary.py | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/dbscanserving/.gitlab-ci.yml b/src/dbscanserving/.gitlab-ci.yml index 5d5204cdd..d665bdaf2 100644 --- a/src/dbscanserving/.gitlab-ci.yml +++ b/src/dbscanserving/.gitlab-ci.yml @@ -54,7 +54,7 @@ unit_test dbscanserving: - sleep 5 - docker ps -a - docker logs $IMAGE_NAME - - docker exec ps -a + - docker ps -a - sleep 5 - docker logs $IMAGE_NAME - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/${IMAGE_NAME}/results/${IMAGE_NAME}_report.xml" diff --git a/src/dbscanserving/tests/test_unitary.py b/src/dbscanserving/tests/test_unitary.py index 7349978e5..a9d5c7e13 100644 --- a/src/dbscanserving/tests/test_unitary.py +++ b/src/dbscanserving/tests/test_unitary.py @@ -23,30 +23,27 @@ from common.proto.dbscanserving_pb2 import (DetectionRequest, DetectionResponse, Sample) from dbscanserving.client.DbscanServingClient import DbscanServingClient -from dbscanserving.Config import GRPC_SERVICE_PORT from dbscanserving.service.DbscanService import DbscanService -port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports - LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @pytest.fixture(scope="session") def dbscanserving_service(): - _service = DbscanService(port=port) + _service = DbscanService() _service.start() yield _service _service.stop() @pytest.fixture(scope="session") -def dbscanserving_client(): +def dbscanserving_client(dbscanserving_service: DbscanService): with patch.dict( os.environ, { "DBSCANSERVINGSERVICE_SERVICE_HOST": "127.0.0.1", - "DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC": str(port), + "DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC": str(dbscanserving_service.bind_port), }, clear=True, ): -- GitLab From eab4d7bc165d8323a32408ad2273303fd5b8ebb3 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 13:32:30 +0000 Subject: [PATCH 03/22] Initial fix of the attack detector tests. --- src/opticalattackdetector/.gitlab-ci.yml | 20 ++++++++- .../tests/test_unitary.py | 42 ++++--------------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index b06725852..ce0911536 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -45,13 +45,30 @@ unit_test opticalattackdetector: stage: unit_test needs: - build opticalattackdetector + - build dbscanserving + - unit_test dbscanserving before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi + - if docker container ls | grep redis; then docker rm -f redis; else echo "redis image is not in the system"; fi + - if docker container ls | grep dbscanserving; then docker rm -f dbscanserving; else echo "dbscanserving image is not in the system"; fi script: + - export REDIS_PASSWORD=`uuidgen` + - docker pull "redis:7.0-alpine" + - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine "redis-server --requirepass $(REDIS_PASSWORD)" + - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") + - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" + - docker run --name dbscanserving -d -p 10008:10008 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG + - DBSCANSERVING_ADDRESS=$(docker inspect dbscanserving --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker run --name $IMAGE_NAME -d -p 10006:10006 --env-file "$PWD/src/$IMAGE_NAME/.env" -v "$PWD/src/$IMAGE_NAME/tests:/home/${IMAGE_NAME}/results" --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG + - > + docker run --name $IMAGE_NAME -d -p 10006:10006 + -v "$PWD/src/$IMAGE_NAME/tests:/home/${IMAGE_NAME}/results" + -e REDIS_PASSWORD=${REDIS_PASSWORD} + -e DBSCANSERVINGSERVICE_SERVICE_HOST=${DBSCANSERVING_ADDRESS} + -e CACHINGSERVICE_SERVICE_HOST=${REDIS_ADDRESS} + --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - sleep 5 - docker ps -a - docker logs $IMAGE_NAME @@ -59,6 +76,7 @@ unit_test opticalattackdetector: coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: - docker rm -f $IMAGE_NAME + - docker rm -f redis - docker network rm teraflowbridge rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' diff --git a/src/opticalattackdetector/tests/test_unitary.py b/src/opticalattackdetector/tests/test_unitary.py index 72e3a4ac1..90af22075 100644 --- a/src/opticalattackdetector/tests/test_unitary.py +++ b/src/opticalattackdetector/tests/test_unitary.py @@ -17,61 +17,33 @@ import os from unittest.mock import patch import pytest -from common.Constants import (DEFAULT_GRPC_GRACE_PERIOD, - DEFAULT_GRPC_MAX_WORKERS) + from common.proto import dbscanserving_pb2 as dbscan from common.proto.optical_attack_detector_pb2 import DetectionRequest from opticalattackdetector.client.OpticalAttackDetectorClient import \ OpticalAttackDetectorClient -from opticalattackdetector.Config import GRPC_SERVICE_PORT from opticalattackdetector.service.OpticalAttackDetectorService import \ OpticalAttackDetectorService # from .example_objects import CONTEXT_ID, CONTEXT_ID_2, SERVICE_DEV1_DEV2 -port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports - LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) @pytest.fixture(scope="session") def optical_attack_detector_service(): - with patch.dict( - os.environ, - { - "OPTICALATTACKDETECTORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKDETECTORSERVICE_SERVICE_PORT_GRPC": str(port), - "DBSCANSERVINGSERVICE_SERVICE_HOST": "127.0.0.1", - "DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC": str(port), - }, - clear=True, - ): - _service = OpticalAttackDetectorService( - port=port, - max_workers=DEFAULT_GRPC_MAX_WORKERS, - grace_period=DEFAULT_GRPC_GRACE_PERIOD, - ) - _service.start() - yield _service - _service.stop() + _service = OpticalAttackDetectorService() + _service.start() + yield _service + _service.stop() @pytest.fixture(scope="session") def optical_attack_detector_client(optical_attack_detector_service): - with patch.dict( - os.environ, - { - "OPTICALATTACKDETECTORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKDETECTORSERVICE_SERVICE_PORT_GRPC": str(port), - "DBSCANSERVINGSERVICE_SERVICE_HOST": "127.0.0.1", - "DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC": str(port), - }, - clear=True, - ): - _client = OpticalAttackDetectorClient() - yield _client + _client = OpticalAttackDetectorClient() + yield _client _client.close() -- GitLab From 0b82fc35a22e327f29aa7ade739a45024eee2d86 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 13:34:28 +0000 Subject: [PATCH 04/22] Removing issues with the pipeline descriptor. --- src/opticalattackdetector/.gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index ce0911536..5aa39f3a2 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -45,8 +45,6 @@ unit_test opticalattackdetector: stage: unit_test needs: - build opticalattackdetector - - build dbscanserving - - unit_test dbscanserving before_script: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi -- GitLab From a8deb58a1cf2425a18e35274052e12d561a43210 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 13:47:41 +0000 Subject: [PATCH 05/22] Fixing part of the commands to execute REDIS. --- src/opticalattackdetector/.gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index 5aa39f3a2..b04c34d19 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -52,9 +52,9 @@ unit_test opticalattackdetector: - if docker container ls | grep redis; then docker rm -f redis; else echo "redis image is not in the system"; fi - if docker container ls | grep dbscanserving; then docker rm -f dbscanserving; else echo "dbscanserving image is not in the system"; fi script: - - export REDIS_PASSWORD=`uuidgen` + - export REDIS_PASSWORD=$(uuidgen) - docker pull "redis:7.0-alpine" - - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine "redis-server --requirepass $(REDIS_PASSWORD)" + - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=$(REDIS_PASSWORD) --rm redis:7.0-alpine "redis-server --requirepass $(REDIS_PASSWORD)" - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" - docker run --name dbscanserving -d -p 10008:10008 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG -- GitLab From 26749159698d5d4690f67dfcf58b1f33c60343c1 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 13:50:37 +0000 Subject: [PATCH 06/22] Fixing the command for Redis password. --- src/opticalattackdetector/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index b04c34d19..c884b47c6 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -54,7 +54,7 @@ unit_test opticalattackdetector: script: - export REDIS_PASSWORD=$(uuidgen) - docker pull "redis:7.0-alpine" - - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=$(REDIS_PASSWORD) --rm redis:7.0-alpine "redis-server --requirepass $(REDIS_PASSWORD)" + - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine "redis-server --requirepass ${REDIS_PASSWORD}" - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" - docker run --name dbscanserving -d -p 10008:10008 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG -- GitLab From 464a569b170270bfa86e060570f8fd9ae0f0cfdd Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 13:54:42 +0000 Subject: [PATCH 07/22] Including command to run the dbscanserving. --- src/opticalattackdetector/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index c884b47c6..8d5c16de6 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -57,7 +57,7 @@ unit_test opticalattackdetector: - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine "redis-server --requirepass ${REDIS_PASSWORD}" - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" - - docker run --name dbscanserving -d -p 10008:10008 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG + - docker run --name dbscanserving -d -p 10008:10008 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG "python -m dbscanserving.service" - DBSCANSERVING_ADDRESS=$(docker inspect dbscanserving --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - > -- GitLab From 9c9c737604c8f07fdc718fb9207a1860458e2c56 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 14:01:02 +0000 Subject: [PATCH 08/22] Exposing logs on the tests. --- src/opticalattackdetector/.gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index 8d5c16de6..51ed231b9 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -55,9 +55,11 @@ unit_test opticalattackdetector: - export REDIS_PASSWORD=$(uuidgen) - docker pull "redis:7.0-alpine" - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine "redis-server --requirepass ${REDIS_PASSWORD}" + - docker logs redis - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" - docker run --name dbscanserving -d -p 10008:10008 --network=teraflowbridge --rm $CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG "python -m dbscanserving.service" + - docker logs dbscanserving - DBSCANSERVING_ADDRESS=$(docker inspect dbscanserving --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - > -- GitLab From 444bee868e99e2526f2c6b1d467d73801177a933 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Mon, 10 Jul 2023 14:25:43 +0000 Subject: [PATCH 09/22] Fixing redis init command. --- src/opticalattackdetector/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index 51ed231b9..6d9d0313c 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -54,7 +54,7 @@ unit_test opticalattackdetector: script: - export REDIS_PASSWORD=$(uuidgen) - docker pull "redis:7.0-alpine" - - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine "redis-server --requirepass ${REDIS_PASSWORD}" + - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine redis-server --requirepass ${REDIS_PASSWORD} - docker logs redis - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" -- GitLab From 144282424d6cf01eb2849abf083ccd36c04acc7b Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 05:07:04 +0000 Subject: [PATCH 10/22] Improving tests for the OAD. --- src/opticalattackdetector/.gitlab-ci.yml | 2 +- .../tests/test_unitary.py | 27 ++++++++++++------- src/opticalattackmanager/utils/monitor.py | 1 - .../optical/ofc23/run_experiment_demo.py | 3 +-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index 6d9d0313c..917ce53ba 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -54,7 +54,7 @@ unit_test opticalattackdetector: script: - export REDIS_PASSWORD=$(uuidgen) - docker pull "redis:7.0-alpine" - - docker run --name redis -d --network=teraflowbridge -p 6379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine redis-server --requirepass ${REDIS_PASSWORD} + - docker run --name redis -d --network=teraflowbridge -p 16379:6379 -e REDIS_PASSWORD=${REDIS_PASSWORD} --rm redis:7.0-alpine redis-server --requirepass ${REDIS_PASSWORD} - docker logs redis - REDIS_ADDRESS=$(docker inspect redis --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}") - docker pull "$CI_REGISTRY_IMAGE/dbscanserving:$IMAGE_TAG" diff --git a/src/opticalattackdetector/tests/test_unitary.py b/src/opticalattackdetector/tests/test_unitary.py index 90af22075..586a724df 100644 --- a/src/opticalattackdetector/tests/test_unitary.py +++ b/src/opticalattackdetector/tests/test_unitary.py @@ -13,13 +13,15 @@ # limitations under the License. import logging -import os +import uuid +import queue from unittest.mock import patch import pytest from common.proto import dbscanserving_pb2 as dbscan from common.proto.optical_attack_detector_pb2 import DetectionRequest +from common.tests.MockServicerImpl_Monitoring import MockServicerImpl_Monitoring from opticalattackdetector.client.OpticalAttackDetectorClient import \ OpticalAttackDetectorClient @@ -48,25 +50,30 @@ def optical_attack_detector_client(optical_attack_detector_service): def test_detect_attack( + optical_attack_detector_service: OpticalAttackDetectorService, optical_attack_detector_client: OpticalAttackDetectorClient, ): message = dbscan.DetectionResponse() message.cluster_indices.extend([0, 1, -1, -1, -1]) + + monitoring_mock = MockServicerImpl_Monitoring(queue_samples = queue.Queue()) with patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.attack_mitigator_client" ) as mitigator, patch( - "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client" + "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.monitoring_client", + monitoring_mock, ) as monitoring, patch( "opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.dbscanserving_client.Detect", # TODO: return dumb object with "cluster_indices" attribute # idea: create new response object return_value=message, ) as dbscanserving: - request: DetectionRequest = DetectionRequest() - request.service_id.context_id.context_uuid.uuid = "" - request.service_id.service_uuid.uuid = str("") - request.kpi_id.kpi_id.uuid = "" - optical_attack_detector_client.DetectAttack(request) - mitigator.NotifyAttack.assert_called_once() - monitoring.IncludeKpi.assert_called_once() - dbscanserving.assert_called_once() + for _ in range(10): + request: DetectionRequest = DetectionRequest() + request.service_id.context_id.context_uuid.uuid = str(uuid.uuid4()) + request.service_id.service_uuid.uuid = str(uuid.uuid4()) + request.kpi_id.kpi_id.uuid = "1" + optical_attack_detector_client.DetectAttack(request) + dbscanserving.assert_called_once() + monitoring.IncludeKpi.assert_called_once() + mitigator.NotifyAttack.assert_called() diff --git a/src/opticalattackmanager/utils/monitor.py b/src/opticalattackmanager/utils/monitor.py index c34ac217c..9889c0caf 100644 --- a/src/opticalattackmanager/utils/monitor.py +++ b/src/opticalattackmanager/utils/monitor.py @@ -17,7 +17,6 @@ import logging import traceback from grpclib.client import Channel -from prometheus_client import Counter from common.proto.asyncio.optical_attack_detector_grpc import \ OpticalAttackDetectorServiceStub diff --git a/src/tests/scenario3/optical/ofc23/run_experiment_demo.py b/src/tests/scenario3/optical/ofc23/run_experiment_demo.py index 16ddb9c31..2f09f8d5a 100644 --- a/src/tests/scenario3/optical/ofc23/run_experiment_demo.py +++ b/src/tests/scenario3/optical/ofc23/run_experiment_demo.py @@ -21,8 +21,7 @@ import threading import redis from kubernetes import client, config -from common.Constants import ServiceNameEnum -from common.Settings import get_service_host, get_setting, wait_for_environment_variables +from common.Settings import get_setting, wait_for_environment_variables # Configs can be set in Configuration class directly or using helper utility namespace = get_setting("TFS_K8S_NAMESPACE", default="tfs") -- GitLab From 68ced8ae66ac68e2ff32243a6ab1799e0a821803 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 07:02:19 +0000 Subject: [PATCH 11/22] Fixing bind address and clearning services. --- src/opticalattackdetector/.gitlab-ci.yml | 1 + src/opticalattackdetector/tests/test_unitary.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/opticalattackdetector/.gitlab-ci.yml b/src/opticalattackdetector/.gitlab-ci.yml index 917ce53ba..2a89b5c54 100644 --- a/src/opticalattackdetector/.gitlab-ci.yml +++ b/src/opticalattackdetector/.gitlab-ci.yml @@ -77,6 +77,7 @@ unit_test opticalattackdetector: after_script: - docker rm -f $IMAGE_NAME - docker rm -f redis + - docker rm -f dbscanserving - docker network rm teraflowbridge rules: - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)' diff --git a/src/opticalattackdetector/tests/test_unitary.py b/src/opticalattackdetector/tests/test_unitary.py index 586a724df..d2fe74903 100644 --- a/src/opticalattackdetector/tests/test_unitary.py +++ b/src/opticalattackdetector/tests/test_unitary.py @@ -43,8 +43,11 @@ def optical_attack_detector_service(): @pytest.fixture(scope="session") -def optical_attack_detector_client(optical_attack_detector_service): - _client = OpticalAttackDetectorClient() +def optical_attack_detector_client(optical_attack_detector_service: OpticalAttackDetectorService): + _client = OpticalAttackDetectorClient( + host=optical_attack_detector_service.bind_address, + port=optical_attack_detector_service.bind_port, + ) yield _client _client.close() -- GitLab From dc22fc8f98131bd9e11245d62d393145e9723e99 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 07:31:19 +0000 Subject: [PATCH 12/22] Fixing the optical attack manager tests. --- .../tests/test_unitary.py | 84 +------------------ 1 file changed, 1 insertion(+), 83 deletions(-) diff --git a/src/opticalattackmanager/tests/test_unitary.py b/src/opticalattackmanager/tests/test_unitary.py index 5d29079d7..0baecf925 100644 --- a/src/opticalattackmanager/tests/test_unitary.py +++ b/src/opticalattackmanager/tests/test_unitary.py @@ -25,96 +25,14 @@ from common.proto import dbscanserving_pb2 as dbscan from common.proto.optical_attack_detector_pb2 import DetectionRequest from opticalattackdetector.client.OpticalAttackDetectorClient import \ OpticalAttackDetectorClient -from opticalattackdetector.Config import GRPC_SERVICE_PORT from opticalattackdetector.service.OpticalAttackDetectorService import \ OpticalAttackDetectorService # from .example_objects import CONTEXT_ID, CONTEXT_ID_2, SERVICE_DEV1_DEV2 -port = 10000 + GRPC_SERVICE_PORT # avoid privileged ports - LOGGER = logging.getLogger(__name__) LOGGER.setLevel(logging.DEBUG) -@pytest.fixture(scope="session") -def optical_attack_detector_service(): - with patch.dict( - os.environ, - { - "OPTICALATTACKDETECTORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKDETECTORSERVICE_SERVICE_PORT_GRPC": str( - 1000 - + DEFAULT_SERVICE_GRPC_PORTS.get( - ServiceNameEnum.OPTICALATTACKDETECTOR.value - ) - ), - "OPTICALATTACKMITIGATORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC": str( - 1000 - + DEFAULT_SERVICE_GRPC_PORTS.get( - ServiceNameEnum.OPTICALATTACKMITIGATOR.value - ) - ), - "DBSCANSERVINGSERVICE_SERVICE_HOST": "127.0.0.1", - "DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC": str( - 1000 - + DEFAULT_SERVICE_GRPC_PORTS.get(ServiceNameEnum.DBSCANSERVING.value) - ), - }, - clear=True, - ): - _service = OpticalAttackDetectorService( - port=port, - max_workers=DEFAULT_GRPC_MAX_WORKERS, - grace_period=DEFAULT_GRPC_GRACE_PERIOD, - ) - # mocker_context_client = mock.patch('opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.context_client') - # mocker_context_client.start() - - # mocker_influx_db = mock.patch('opticalattackdetector.service.OpticalAttackDetectorServiceServicerImpl.influxdb_client') - # mocker_influx_db.start() - - _service.start() - yield _service - _service.stop() - # mocker_context_client.stop() - # mocker_influx_db.stop() - - -@pytest.fixture(scope="session") -def optical_attack_detector_client(optical_attack_detector_service): - with patch.dict( - os.environ, - { - "OPTICALATTACKDETECTORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKDETECTORSERVICE_SERVICE_PORT_GRPC": str( - 1000 - + DEFAULT_SERVICE_GRPC_PORTS.get( - ServiceNameEnum.OPTICALATTACKDETECTOR.value - ) - ), - "OPTICALATTACKMITIGATORSERVICE_SERVICE_HOST": "127.0.0.1", - "OPTICALATTACKMITIGATORSERVICE_SERVICE_PORT_GRPC": str( - 1000 - + DEFAULT_SERVICE_GRPC_PORTS.get( - ServiceNameEnum.OPTICALATTACKMITIGATOR.value - ) - ), - "DBSCANSERVINGSERVICE_SERVICE_HOST": "127.0.0.1", - "DBSCANSERVINGSERVICE_SERVICE_PORT_GRPC": str( - 1000 - + DEFAULT_SERVICE_GRPC_PORTS.get(ServiceNameEnum.DBSCANSERVING.value) - ), - }, - clear=True, - ): - _client = OpticalAttackDetectorClient() - yield _client - _client.close() - - -def test_detect_attack( - optical_attack_detector_client: OpticalAttackDetectorClient, -): +def test_detect_attack(): LOGGER.info("placeholder") -- GitLab From a045f9fe0072405e01c5fb203bf83edbda8560bd Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 07:44:45 +0000 Subject: [PATCH 13/22] Improving tests. --- .../tests/test_unitary.py | 1 - .../tests/test_unitary.py | 35 ++++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/opticalattackdetector/tests/test_unitary.py b/src/opticalattackdetector/tests/test_unitary.py index d2fe74903..6c7579238 100644 --- a/src/opticalattackdetector/tests/test_unitary.py +++ b/src/opticalattackdetector/tests/test_unitary.py @@ -31,7 +31,6 @@ from opticalattackdetector.service.OpticalAttackDetectorService import \ # from .example_objects import CONTEXT_ID, CONTEXT_ID_2, SERVICE_DEV1_DEV2 LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) @pytest.fixture(scope="session") diff --git a/src/opticalattackmanager/tests/test_unitary.py b/src/opticalattackmanager/tests/test_unitary.py index 0baecf925..0f50b3333 100644 --- a/src/opticalattackmanager/tests/test_unitary.py +++ b/src/opticalattackmanager/tests/test_unitary.py @@ -13,26 +13,27 @@ # limitations under the License. import logging -import os -from unittest.mock import patch +import uuid -import pytest +from opticalattackmanager.utils.monitor import delegate_services -from common.Constants import (DEFAULT_GRPC_GRACE_PERIOD, - DEFAULT_GRPC_MAX_WORKERS, - DEFAULT_SERVICE_GRPC_PORTS, ServiceNameEnum) -from common.proto import dbscanserving_pb2 as dbscan -from common.proto.optical_attack_detector_pb2 import DetectionRequest -from opticalattackdetector.client.OpticalAttackDetectorClient import \ - OpticalAttackDetectorClient -from opticalattackdetector.service.OpticalAttackDetectorService import \ - OpticalAttackDetectorService - -# from .example_objects import CONTEXT_ID, CONTEXT_ID_2, SERVICE_DEV1_DEV2 LOGGER = logging.getLogger(__name__) -LOGGER.setLevel(logging.DEBUG) -def test_detect_attack(): - LOGGER.info("placeholder") +def test_delegate_services(): + service_list = [ + { + "context": uuid.uuid4(), + "service": uuid.uuid4(), + "kpi": 10, + } + for _ in range(10)] + delegate_services( + service_list=service_list, + start_index=0, + end_index=9, + host="127.0.0.1", + port="10006", + monitoring_interval=10, + ) -- GitLab From ff7eb27ef8e1d5837f52b08ec05988232622714e Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 07:57:15 +0000 Subject: [PATCH 14/22] Improving test execution. --- src/opticalattackmanager/.gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index 08136e490..53528c109 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -55,8 +55,7 @@ unit_test opticalattackmanager: - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/home/teraflow/$IMAGE_NAME/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker ps -a - docker logs $IMAGE_NAME - - docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_unitary.py --junitxml=/home/teraflow/$IMAGE_NAME/results/${IMAGE_NAME}_report.xml" - - docker exec -i $IMAGE_NAME bash -c "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; coverage xml -o /home/${IMAGE_NAME}/results/${IMAGE_NAME}_coverage.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: - docker rm -f $IMAGE_NAME -- GitLab From 03e79c5a6ea5f3aa70efc262ef684901dc680d87 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 08:18:06 +0000 Subject: [PATCH 15/22] Checking if the file is being generated. --- src/opticalattackmanager/.gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index 53528c109..b3dbdd4fa 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -55,7 +55,8 @@ unit_test opticalattackmanager: - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/home/teraflow/$IMAGE_NAME/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker ps -a - 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; coverage report --include='${IMAGE_NAME}/*' --show-missing" + - ls -la /home/${IMAGE_NAME}/results/ coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: - docker rm -f $IMAGE_NAME -- GitLab From 8eae8a05382b6536cf252390f6f9988c1313e86a Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 09:09:25 +0000 Subject: [PATCH 16/22] Removing the need for the artifact. --- src/opticalattackmanager/.gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index b3dbdd4fa..69adc82b6 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -73,10 +73,10 @@ unit_test opticalattackmanager: - src/$IMAGE_NAME/tests/Dockerfile - manifests/${IMAGE_NAME}service.yaml - .gitlab-ci.yml - artifacts: - when: always - reports: - junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml + # artifacts: + # when: always + # reports: + # junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml # Deployment of the service in Kubernetes Cluster # deploy opticalattackmanager: -- GitLab From 79a937978f716c08de6d2ab5df3d65ad55599c09 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 10:04:14 +0000 Subject: [PATCH 17/22] Fixing issue with the path. --- src/opticalattackmanager/.gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index 69adc82b6..3873e956d 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -52,7 +52,7 @@ unit_test opticalattackmanager: - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi script: - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/home/teraflow/$IMAGE_NAME/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG + - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/home/$IMAGE_NAME/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker ps -a - 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 report --include='${IMAGE_NAME}/*' --show-missing" @@ -73,10 +73,10 @@ unit_test opticalattackmanager: - src/$IMAGE_NAME/tests/Dockerfile - manifests/${IMAGE_NAME}service.yaml - .gitlab-ci.yml - # artifacts: - # when: always - # reports: - # junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml + artifacts: + when: always + reports: + junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml # Deployment of the service in Kubernetes Cluster # deploy opticalattackmanager: -- GitLab From cdb5345bb0120cdf33d792bb86d411b94fe2873b Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 10:33:01 +0000 Subject: [PATCH 18/22] Fixing indentation of the YAML file. --- src/opticalattackmanager/.gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index 3873e956d..8ce0be9c5 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -56,7 +56,7 @@ unit_test opticalattackmanager: - docker ps -a - 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 report --include='${IMAGE_NAME}/*' --show-missing" - - ls -la /home/${IMAGE_NAME}/results/ + - ls -la src/$IMAGE_NAME/tests coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: - docker rm -f $IMAGE_NAME @@ -74,9 +74,9 @@ unit_test opticalattackmanager: - manifests/${IMAGE_NAME}service.yaml - .gitlab-ci.yml artifacts: - when: always - reports: - junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml + when: always + reports: + junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml # Deployment of the service in Kubernetes Cluster # deploy opticalattackmanager: -- GitLab From 671bcc2ec89184091a22401db3828abdacce60b8 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 10:52:30 +0000 Subject: [PATCH 19/22] Changing the mounting point for the junit report. --- src/opticalattackmanager/.gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index 8ce0be9c5..41b4c6023 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -52,10 +52,10 @@ unit_test opticalattackmanager: - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi script: - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/home/$IMAGE_NAME/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG + - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker ps -a - 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 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=/opt/results/${IMAGE_NAME}_report.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" - ls -la src/$IMAGE_NAME/tests coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: -- GitLab From 6af4328dacf8360d26228f8158d9ff60e3900ca3 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 12:20:53 +0000 Subject: [PATCH 20/22] Including log level debug --- src/opticalattackmanager/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index 41b4c6023..f153b20bf 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -52,7 +52,7 @@ unit_test opticalattackmanager: - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi script: - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker run --name $IMAGE_NAME -d -p 10005:10005 -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG + - docker run --name $IMAGE_NAME -d -p 10005:10005 -e LOG_LEVEL=DEBUG -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker ps -a - 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=/opt/results/${IMAGE_NAME}_report.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" -- GitLab From bcfd98201e416e102e1d5a564894f49ea95f715b Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 14:28:26 +0000 Subject: [PATCH 21/22] Testing a different approach for the XML. --- src/opticalattackmanager/.gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/opticalattackmanager/.gitlab-ci.yml b/src/opticalattackmanager/.gitlab-ci.yml index f153b20bf..1fe77d315 100644 --- a/src/opticalattackmanager/.gitlab-ci.yml +++ b/src/opticalattackmanager/.gitlab-ci.yml @@ -52,10 +52,10 @@ unit_test opticalattackmanager: - if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi script: - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG" - - docker run --name $IMAGE_NAME -d -p 10005:10005 -e LOG_LEVEL=DEBUG -v "$PWD/src/$IMAGE_NAME/tests:/opt/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG + - docker run --name $IMAGE_NAME -d -p 10005:10005 -e LOG_LEVEL=DEBUG -v "$PWD/src/$IMAGE_NAME/tests:/home/teraflow/controller/$IMAGE_NAME/results" --network=teraflowbridge $CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG - docker ps -a - 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=/opt/results/${IMAGE_NAME}_report.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/teraflow/controller/$IMAGE_NAME/results/${IMAGE_NAME}_report.xml; coverage report --include='${IMAGE_NAME}/*' --show-missing" - ls -la src/$IMAGE_NAME/tests coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/' after_script: -- GitLab From fb05ab70a13b21d5de3c20c1255f3c8f5521a7a4 Mon Sep 17 00:00:00 2001 From: Carlos Natalino Date: Tue, 11 Jul 2023 17:24:36 +0000 Subject: [PATCH 22/22] Removing manager from the pipeline. --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6a00c6eed..8fe5e6c5d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -31,7 +31,7 @@ include: - local: '/src/dbscanserving/.gitlab-ci.yml' - local: '/src/opticalattackmitigator/.gitlab-ci.yml' - local: '/src/opticalattackdetector/.gitlab-ci.yml' - - local: '/src/opticalattackmanager/.gitlab-ci.yml' + # - local: '/src/opticalattackmanager/.gitlab-ci.yml' - local: '/src/automation/.gitlab-ci.yml' - local: '/src/policy/.gitlab-ci.yml' #- local: '/src/webui/.gitlab-ci.yml' -- GitLab