From b70e8c30d07f8b84579c645ee847bf1129c113be Mon Sep 17 00:00:00 2001 From: Lluis Gifre Date: Fri, 15 Jul 2022 07:57:48 +0000 Subject: [PATCH] Helper scripts: - removed unneeded comments from run_tests_locally*.sh in scripts folder - minor improvement in report_coverage_all.sh - added script to expose through the ingress controller the gRPC interfaces through the ingress controller for debug purposes --- expose_ingress_grpc.sh | 53 +++++++++++++++++++ scripts/report_coverage_all.sh | 2 +- scripts/run_tests_locally-compute.sh | 4 -- scripts/run_tests_locally-device-all.sh | 3 -- scripts/run_tests_locally-device-emulated.sh | 4 -- scripts/run_tests_locally-device-microwave.sh | 4 -- .../run_tests_locally-device-openconfig.sh | 4 -- scripts/run_tests_locally-device-p4.sh | 4 -- scripts/run_tests_locally-device-tapi.sh | 4 -- scripts/run_tests_locally-device.sh | 4 -- scripts/run_tests_locally-service.sh | 4 -- scripts/run_tests_locally-slice.sh | 4 -- scripts/run_tests_locally.sh | 3 -- 13 files changed, 54 insertions(+), 43 deletions(-) create mode 100755 expose_ingress_grpc.sh diff --git a/expose_ingress_grpc.sh b/expose_ingress_grpc.sh new file mode 100755 index 000000000..37d72aa8d --- /dev/null +++ b/expose_ingress_grpc.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/) +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +######################################################################################################################## +# Define your deployment settings here +######################################################################################################################## + +# If not already set, set the name of the Kubernetes namespace to deploy to. +export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs-dev"} + +# If not already set, set the list of components you want to build images for, and deploy. +export TFS_COMPONENTS=${TFS_COMPONENTS:-"context device automation policy service compute monitoring dbscanserving opticalattackmitigator opticalcentralizedattackdetector webui"} + +######################################################################################################################## +# Automated steps start here +######################################################################################################################## + +echo "Exposing GRPC ports for components..." +for COMPONENT in $TFS_COMPONENTS; do + echo "Processing '$COMPONENT' component..." + + SERVICE_GRPC_PORT=$(kubectl get service ${COMPONENT}service --namespace $TFS_K8S_NAMESPACE -o 'jsonpath={.spec.ports[?(@.name=="grpc")].port}') + if [ -z "${SERVICE_GRPC_PORT}" ]; then + printf "\n" + continue; + fi + + PATCH='{"data": {"'${SERVICE_GRPC_PORT}'": "'$TFS_K8S_NAMESPACE'/'${COMPONENT}service':'${SERVICE_GRPC_PORT}'"}}' + #echo "PATCH: ${PATCH}" + kubectl patch configmap nginx-ingress-tcp-microk8s-conf --namespace ingress --patch "${PATCH}" + + PORT_MAP='{"containerPort": '${SERVICE_GRPC_PORT}', "hostPort": '${SERVICE_GRPC_PORT}'}' + CONTAINER='{"name": "nginx-ingress-microk8s", "ports": ['${PORT_MAP}']}' + PATCH='{"spec": {"template": {"spec": {"containers": ['${CONTAINER}']}}}}' + #echo "PATCH: ${PATCH}" + kubectl patch daemonset nginx-ingress-microk8s-controller --namespace ingress --patch "${PATCH}" + + printf "\n" +done + +echo "Done!" diff --git a/scripts/report_coverage_all.sh b/scripts/report_coverage_all.sh index a7e4797f3..3b7df170c 100755 --- a/scripts/report_coverage_all.sh +++ b/scripts/report_coverage_all.sh @@ -16,7 +16,7 @@ PROJECTDIR=`pwd` -cd $(dirname $0)/src +cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc echo diff --git a/scripts/run_tests_locally-compute.sh b/scripts/run_tests_locally-compute.sh index 48ce6e232..d48fe4171 100755 --- a/scripts/run_tests_locally-compute.sh +++ b/scripts/run_tests_locally-compute.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=service.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ compute/tests/test_unitary.py diff --git a/scripts/run_tests_locally-device-all.sh b/scripts/run_tests_locally-device-all.sh index 2cf8faaf5..a60eab0be 100755 --- a/scripts/run_tests_locally-device-all.sh +++ b/scripts/run_tests_locally-device-all.sh @@ -21,9 +21,6 @@ RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary_emulated.py diff --git a/scripts/run_tests_locally-device-emulated.sh b/scripts/run_tests_locally-device-emulated.sh index ab4f77ada..541017f7a 100755 --- a/scripts/run_tests_locally-device-emulated.sh +++ b/scripts/run_tests_locally-device-emulated.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary_emulated.py diff --git a/scripts/run_tests_locally-device-microwave.sh b/scripts/run_tests_locally-device-microwave.sh index e03630c9f..21f3e5ab6 100755 --- a/scripts/run_tests_locally-device-microwave.sh +++ b/scripts/run_tests_locally-device-microwave.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary_microwave.py diff --git a/scripts/run_tests_locally-device-openconfig.sh b/scripts/run_tests_locally-device-openconfig.sh index 83d4a0545..f87346fed 100755 --- a/scripts/run_tests_locally-device-openconfig.sh +++ b/scripts/run_tests_locally-device-openconfig.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary_openconfig.py diff --git a/scripts/run_tests_locally-device-p4.sh b/scripts/run_tests_locally-device-p4.sh index 36b381a3c..4e6754e4d 100755 --- a/scripts/run_tests_locally-device-p4.sh +++ b/scripts/run_tests_locally-device-p4.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary_p4.py diff --git a/scripts/run_tests_locally-device-tapi.sh b/scripts/run_tests_locally-device-tapi.sh index a281466b6..d37e4e2b7 100755 --- a/scripts/run_tests_locally-device-tapi.sh +++ b/scripts/run_tests_locally-device-tapi.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary_tapi.py diff --git a/scripts/run_tests_locally-device.sh b/scripts/run_tests_locally-device.sh index ba6c0b6a5..5cd4adce4 100755 --- a/scripts/run_tests_locally-device.sh +++ b/scripts/run_tests_locally-device.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ device/tests/test_unitary.py diff --git a/scripts/run_tests_locally-service.sh b/scripts/run_tests_locally-service.sh index 853eb9767..8a2a8d0be 100755 --- a/scripts/run_tests_locally-service.sh +++ b/scripts/run_tests_locally-service.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=service.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ service/tests/test_unitary.py diff --git a/scripts/run_tests_locally-slice.sh b/scripts/run_tests_locally-slice.sh index adad39b5b..fa3af4eba 100755 --- a/scripts/run_tests_locally-slice.sh +++ b/scripts/run_tests_locally-slice.sh @@ -20,9 +20,5 @@ cd $PROJECTDIR/src RCFILE=$PROJECTDIR/coverage/.coveragerc # Run unitary tests and analyze coverage of code at same time - -# Useful flags for pytest: -#-o log_cli=true -o log_file=service.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ slice/tests/test_unitary.py diff --git a/scripts/run_tests_locally.sh b/scripts/run_tests_locally.sh index 4a95fd8be..c0e95e527 100755 --- a/scripts/run_tests_locally.sh +++ b/scripts/run_tests_locally.sh @@ -51,9 +51,6 @@ export INFLUXDB_DATABASE=$(kubectl --namespace $K8S_NAMESPACE get secrets influx # First destroy old coverage file rm -f $COVERAGEFILE -# Useful flags for pytest: -#-o log_cli=true -o log_file=device.log -o log_file_level=DEBUG - coverage run --rcfile=$RCFILE --append -m pytest --log-level=INFO --verbose \ common/orm/tests/test_unitary.py \ common/message_broker/tests/test_unitary.py \ -- GitLab