Skip to content

Commit 8136d36

Browse files
authored
Merge pull request #289 from zeeke/avoid-sleep
Optionally avoid sleeping in `entrypoint.sh`
2 parents 07ecbf9 + c9c49b5 commit 8136d36

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ fmt: ; $(info Running gofmt...) @ ## Run gofmt on all source files
139139
image: | $(BASE) ; $(info Building Docker image...) @ ## Build SR-IOV CNI docker image
140140
@$(IMAGE_BUILDER) build -t $(TAG) -f $(DOCKERFILE) $(CURDIR) $(DOCKERARGS)
141141

142+
test-image: image
143+
$Q $(BASE)/images/image_test.sh $(IMAGE_BUILDER) $(TAG)
144+
142145
# Misc
143146

144147
.PHONY: deps-update

images/entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -e
66
# Set known directories.
77
CNI_BIN_DIR="/host/opt/cni/bin"
88
SRIOV_BIN_FILE="/usr/bin/sriov"
9+
NO_SLEEP=0
910

1011
# Give help text for parameters.
1112
usage()
@@ -18,6 +19,7 @@ usage()
1819
printf "\t-h --help\n"
1920
printf "\t--cni-bin-dir=%s\n" "$CNI_BIN_DIR"
2021
printf "\t--sriov-bin-file=%s\n" "$SRIOV_BIN_FILE"
22+
printf "\t--no-sleep\n"
2123
}
2224

2325
# Parse parameters given as arguments to this script.
@@ -35,6 +37,9 @@ while [ "$1" != "" ]; do
3537
--sriov-bin-file)
3638
SRIOV_BIN_FILE=$VALUE
3739
;;
40+
--no-sleep)
41+
NO_SLEEP=1
42+
;;
3843
*)
3944
/bin/echo "ERROR: unknown parameter \"$PARAM\""
4045
usage
@@ -57,6 +62,10 @@ done
5762
# Copy file into proper place.
5863
cp -f "$SRIOV_BIN_FILE" "$CNI_BIN_DIR"
5964

65+
if [ $NO_SLEEP -eq 1 ]; then
66+
exit 0
67+
fi
68+
6069
echo "Entering sleep... (success)"
6170
trap : TERM INT
6271

images/image_test.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
3+
set -x
4+
5+
OCI_RUNTIME=$1
6+
IMAGE_UNDER_TEST=$2
7+
8+
OUTPUT_DIR=$(mktemp -d)
9+
10+
"${OCI_RUNTIME}" run -v "${OUTPUT_DIR}:/out" "${IMAGE_UNDER_TEST}" --cni-bin-dir=/out --no-sleep
11+
12+
if [ ! -e "${OUTPUT_DIR}/sriov" ]; then
13+
echo "Output file ${OUTPUT_DIR}/sriov not found"
14+
exit 1
15+
fi
16+
17+
if [ ! -s "${OUTPUT_DIR}/sriov" ]; then
18+
echo "Output file ${OUTPUT_DIR}/sriov is empty"
19+
exit 1
20+
fi
21+
22+
exit 0

0 commit comments

Comments
 (0)