-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bazelified python services are tested for missing modules
Signed-off-by: Krisztián Varga <krisztian.varga@tngtech.com>
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################ | ||
# Copyright 2022 The Magma Authors. | ||
|
||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
# 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. | ||
################################################################################ | ||
|
||
set -euo pipefail | ||
|
||
############################################################################### | ||
# FUNCTION DECLARATIONS | ||
############################################################################### | ||
|
||
help() { | ||
echo "Tests all python services for missing imports or the ones found in" | ||
echo "the specified directory (recursively), or one single service if a" | ||
echo "service name is provided." | ||
echo "Usage:" | ||
echo " $(basename "$0") # test all python services in the magma repository" | ||
echo " $(basename "$0") path_to_services_directory/" | ||
echo " $(basename "$0") path_to_services_directory:service_name" | ||
exit 1 | ||
} | ||
|
||
collect_services() { | ||
if [[ "${SERVICE_PATH}" == *":"* ]]; | ||
then | ||
echo "Single service specified:" | ||
SERVICES=( "${SERVICE_PATH}" ) | ||
else | ||
echo "Multiple services specified:" | ||
mapfile -t SERVICES < <(bazel query "attr(main, main.py, kind(py_binary, //${SERVICE_PATH}...))") | ||
fi | ||
if [[ "${#SERVICES[@]}" -eq 0 ]]; | ||
then | ||
echo "ERROR: No services found." | ||
help | ||
exit 1 | ||
fi | ||
for SERVICE in "${SERVICES[@]}" | ||
do | ||
echo "${SERVICE}" | ||
done | ||
} | ||
|
||
############################################################################### | ||
# SCRIPT SECTION | ||
############################################################################### | ||
|
||
SERVICE_PATH="${1:-}" | ||
|
||
echo "Collecting services" | ||
declare -a SERVICES | ||
LOGGING_FILE="/tmp/test_import_logging.log" | ||
NUM_SUCCESS=0 | ||
|
||
collect_services | ||
|
||
for SERVICE in "${SERVICES[@]}" | ||
do | ||
echo "Building service: ${SERVICE}" | ||
bazel build "${SERVICE}" | ||
echo "Testing service: ${SERVICE}" | ||
if timeout --preserve-status 5 bazel run "${SERVICE}" 2>&1 | tee "${LOGGING_FILE}"; | ||
then | ||
echo "Service successfully started." | ||
NUM_SUCCESS=$((NUM_SUCCESS + 1)) | ||
else | ||
echo "Checking if ModuleNotFoundError is present in logs." | ||
RESULT=$(grep -m 1 "ModuleNotFoundError" "${LOGGING_FILE}" || [[ $? == 1 ]]) | ||
if [[ "${RESULT}" != "" ]]; | ||
then | ||
echo "ModuleNotFoundError found in logs from ${SERVICE}:" | ||
echo "${RESULT}" | ||
else | ||
echo "ModuleNotFoundError not found in logs from ${SERVICE}:" | ||
NUM_SUCCESS=$((NUM_SUCCESS + 1)) | ||
fi | ||
fi | ||
echo -e "\n################################################################################\n" | ||
done | ||
|
||
echo "$NUM_SUCCESS/${#SERVICES[@]} succeeded." | ||
|
||
[[ "${NUM_SUCCESS}" == "${#SERVICES[@]}" ]] |