Skip to content

Commit 66c8a91

Browse files
tests: fix environment test issues (#181)
1 parent 0bdc10c commit 66c8a91

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

packages/google-cloud-logging/.kokoro/environment_tests.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
4343
export PROJECT_ID=$(cat "${KOKORO_GFILE_DIR}/project-id.json")
4444
gcloud config set project $PROJECT_ID
4545

46+
# set a default zone.
47+
gcloud config set compute/zone us-central1-b
48+
4649
# authenticate docker
4750
gcloud auth configure-docker -q
4851

@@ -53,6 +56,15 @@ python3.6 -m pip uninstall --yes --quiet nox-automation
5356
python3.6 -m pip install --upgrade --quiet nox
5457
python3.6 -m nox --version
5558

59+
# Install kubectl
60+
if [[ "${ENVIRONMENT}" == "kubernetes" ]]; then
61+
curl -LO https://dl.k8s.io/release/v1.20.0/bin/linux/amd64/kubectl
62+
chmod +x kubectl
63+
mkdir -p ~/.local/bin
64+
mv ./kubectl ~/.local/bin
65+
export PATH=$PATH:~/.local/bin
66+
fi
67+
5668
# create a unique id for this run
5769
UUID=$(python -c 'import uuid; print(uuid.uuid1())' | head -c 7)
5870
export ENVCTL_ID=ci-$UUID

packages/google-cloud-logging/tests/environment/envctl/env_scripts/python/appengine_standard.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ EOF
7373
pushd $TMP_DIR
7474
gcloud app deploy -q
7575
popd
76+
# wait for the pub/sub subscriber to start
77+
NUM_SUBSCRIBERS=0
78+
TRIES=0
79+
while [[ "${NUM_SUBSCRIBERS}" -lt 1 && "${TRIES}" -lt 10 ]]; do
80+
sleep 30
81+
NUM_SUBSCRIBERS=$(gcloud pubsub topics list-subscriptions $SERVICE_NAME 2> /dev/null | wc -l)
82+
TRIES=$((TRIES + 1))
83+
done
7684
}
7785

7886
filter-string() {

packages/google-cloud-logging/tests/environment/envctl/env_scripts/python/compute.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ verify() {
4747

4848
deploy() {
4949
build_container
50-
gcloud beta compute instances create-with-container \
50+
gcloud compute instances create-with-container \
5151
$SERVICE_NAME \
5252
--container-image $GCR_PATH \
5353
--container-env PUBSUB_TOPIC="$SERVICE_NAME",ENABLE_SUBSCRIBER="true"
54+
# wait for the pub/sub subscriber to start
55+
NUM_SUBSCRIBERS=0
56+
TRIES=0
57+
while [[ "${NUM_SUBSCRIBERS}" -lt 1 && "${TRIES}" -lt 10 ]]; do
58+
sleep 30
59+
NUM_SUBSCRIBERS=$(gcloud pubsub topics list-subscriptions $SERVICE_NAME 2> /dev/null | wc -l)
60+
TRIES=$((TRIES + 1))
61+
done
62+
5463
}
5564

5665
filter-string() {

packages/google-cloud-logging/tests/environment/envctl/env_scripts/python/kubernetes.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ destroy() {
3535

3636
verify() {
3737
set +e
38+
gcloud pubsub subscriptions describe $SERVICE_NAME-subscriber 2> /dev/null
39+
if [[ $? != 0 ]]; then
40+
echo "FALSE"
41+
exit 1
42+
fi
3843
gcloud container clusters describe --zone $ZONE $SERVICE_NAME > /dev/null 2> /dev/null
3944
if [[ $? == 0 ]]; then
4045
echo "TRUE"
@@ -93,6 +98,16 @@ EOF
9398
set -e
9499
# deploy test container
95100
kubectl apply -f $TMP_DIR
101+
# wait for pod to spin up
102+
kubectl wait --for=condition=ready pod -l app=$SERVICE_NAME
103+
# wait for the pub/sub subscriber to start
104+
NUM_SUBSCRIBERS=0
105+
TRIES=0
106+
while [[ "${NUM_SUBSCRIBERS}" -lt 1 && "${TRIES}" -lt 10 ]]; do
107+
sleep 30
108+
NUM_SUBSCRIBERS=$(gcloud pubsub topics list-subscriptions $SERVICE_NAME 2> /dev/null | wc -l)
109+
TRIES=$((TRIES + 1))
110+
done
96111
}
97112

98113
filter-string() {

packages/google-cloud-logging/tests/environment/noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def blacken(session: nox.sessions.Session) -> None:
124124
"appengine_standard",
125125
"appengine_flex_python",
126126
"appengine_flex_container",
127-
"kubernetesengine",
127+
"kubernetes",
128128
"cloudrun",
129129
"functions",
130130
],

tests/environment

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit aec50a9122b0ff3a41c20925d171d51d948f4b80
1+
Subproject commit e4cab8acdbf0054a9e4b5b3b3a2bbc68f108d982

0 commit comments

Comments
 (0)