-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minimal containers and ports clean up before test (#1291)
Signed-off-by: chensuyue <[email protected]>
- Loading branch information
Showing
5 changed files
with
62 additions
and
14 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
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
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
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,42 @@ | ||
#!/bin/bash | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# The test machine used by several opea projects, so the test scripts can't use `docker compose down` to clean up | ||
# the all the containers, ports and networks directly. | ||
# So we need to use the following script to minimize the impact of the clean up. | ||
|
||
test_case=${test_case:-"test_compose_on_gaudi.sh"} | ||
hardware=${hardware:-"gaudi"} | ||
flag=${test_case%_on_*} | ||
flag=${flag#test_} | ||
yaml_file=$(find . -type f -wholename "*${hardware}/${flag}.yaml") | ||
echo $yaml_file | ||
|
||
case "$1" in | ||
containers) | ||
echo "Stop and remove all containers used by the services in $yaml_file ..." | ||
containers=$(cat $yaml_file | grep container_name | cut -d':' -f2) | ||
for container_name in $containers; do | ||
cid=$(docker ps -aq --filter "name=$container_name") | ||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi | ||
done | ||
;; | ||
ports) | ||
echo "Release all ports used by the services in $yaml_file ..." | ||
pip install jq yq | ||
ports=$(yq '.services[].ports[] | split(":")[0]' $yaml_file | grep -o '[0-9a-zA-Z_-]\+') | ||
echo "$ports" | ||
for port in $ports; do | ||
if [[ $port =~ [a-zA-Z_-] ]]; then | ||
port=$(grep -E "export $port=" tests/$test_case | cut -d'=' -f2) | ||
fi | ||
echo $port | ||
cid=$(docker ps --filter "publish=${port}" --format "{{.ID}}") | ||
if [[ ! -z "$cid" ]]; then docker stop $cid && docker rm $cid && sleep 1s; fi | ||
done | ||
;; | ||
*) | ||
echo "Unknown function: $1" | ||
;; | ||
esac |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#!/bin/bash | ||
|
||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
|