Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
eab4d7bc
Commit
eab4d7bc
authored
1 year ago
by
Carlos Natalino Da Silva
Browse files
Options
Downloads
Patches
Plain Diff
Initial fix of the attack detector tests.
parent
f0a126e6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!142
Release TeraFlowSDN 2.1
,
!138
Fixing the tests of the optical cybersecurity components
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/opticalattackdetector/.gitlab-ci.yml
+19
-1
19 additions, 1 deletion
src/opticalattackdetector/.gitlab-ci.yml
src/opticalattackdetector/tests/test_unitary.py
+7
-35
7 additions, 35 deletions
src/opticalattackdetector/tests/test_unitary.py
with
26 additions
and
36 deletions
src/opticalattackdetector/.gitlab-ci.yml
+
19
−
1
View file @
eab4d7bc
...
@@ -45,13 +45,30 @@ unit_test opticalattackdetector:
...
@@ -45,13 +45,30 @@ unit_test opticalattackdetector:
stage
:
unit_test
stage
:
unit_test
needs
:
needs
:
-
build opticalattackdetector
-
build opticalattackdetector
-
build dbscanserving
-
unit_test dbscanserving
before_script
:
before_script
:
-
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
-
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 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 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
:
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 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
-
sleep
5
-
docker ps -a
-
docker ps -a
-
docker logs $IMAGE_NAME
-
docker logs $IMAGE_NAME
...
@@ -59,6 +76,7 @@ unit_test opticalattackdetector:
...
@@ -59,6 +76,7 @@ unit_test opticalattackdetector:
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
-
docker rm -f redis
-
docker network rm teraflowbridge
-
docker network rm teraflowbridge
rules
:
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"merge_request_event"
&&
($CI_MERGE_REQUEST_TARGET_BRANCH_NAME
==
"develop"
||
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
==
$CI_DEFAULT_BRANCH)'
-
if
:
'
$CI_PIPELINE_SOURCE
==
"merge_request_event"
&&
($CI_MERGE_REQUEST_TARGET_BRANCH_NAME
==
"develop"
||
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME
==
$CI_DEFAULT_BRANCH)'
...
...
This diff is collapsed.
Click to expand it.
src/opticalattackdetector/tests/test_unitary.py
+
7
−
35
View file @
eab4d7bc
...
@@ -17,61 +17,33 @@ import os
...
@@ -17,61 +17,33 @@ import os
from
unittest.mock
import
patch
from
unittest.mock
import
patch
import
pytest
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
import
dbscanserving_pb2
as
dbscan
from
common.proto.optical_attack_detector_pb2
import
DetectionRequest
from
common.proto.optical_attack_detector_pb2
import
DetectionRequest
from
opticalattackdetector.client.OpticalAttackDetectorClient
import
\
from
opticalattackdetector.client.OpticalAttackDetectorClient
import
\
OpticalAttackDetectorClient
OpticalAttackDetectorClient
from
opticalattackdetector.Config
import
GRPC_SERVICE_PORT
from
opticalattackdetector.service.OpticalAttackDetectorService
import
\
from
opticalattackdetector.service.OpticalAttackDetectorService
import
\
OpticalAttackDetectorService
OpticalAttackDetectorService
# from .example_objects import CONTEXT_ID, CONTEXT_ID_2, SERVICE_DEV1_DEV2
# 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
=
logging
.
getLogger
(
__name__
)
LOGGER
.
setLevel
(
logging
.
DEBUG
)
LOGGER
.
setLevel
(
logging
.
DEBUG
)
@pytest.fixture
(
scope
=
"
session
"
)
@pytest.fixture
(
scope
=
"
session
"
)
def
optical_attack_detector_service
():
def
optical_attack_detector_service
():
with
patch
.
dict
(
_service
=
OpticalAttackDetectorService
()
os
.
environ
,
_service
.
start
()
{
yield
_service
"
OPTICALATTACKDETECTORSERVICE_SERVICE_HOST
"
:
"
127.0.0.1
"
,
_service
.
stop
()
"
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
()
@pytest.fixture
(
scope
=
"
session
"
)
@pytest.fixture
(
scope
=
"
session
"
)
def
optical_attack_detector_client
(
optical_attack_detector_service
):
def
optical_attack_detector_client
(
optical_attack_detector_service
):
with
patch
.
dict
(
_client
=
OpticalAttackDetectorClient
()
os
.
environ
,
yield
_client
{
"
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
.
close
()
_client
.
close
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment