Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch tests #353

Merged
merged 18 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ spec:
fieldRef:
fieldPath: metadata.namespace
- name: APP_INSTANCE_NAME
value: ${APP_INSTANCE_NAME}
value: "${APP_INSTANCE_NAME}"
- name: REPLICAS
value: "${REPLICAS}"
restartPolicy: Never
1 change: 1 addition & 0 deletions k8s/elasticsearch/apptest/tester/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
jq \
uuid-runtime \
wget \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN wget -q -O /bin/kubectl \
Expand Down
3 changes: 3 additions & 0 deletions k8s/elasticsearch/apptest/tester/tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
set -xeo pipefail
shopt -s nullglob

export ELASTIC_URL="http://${APP_INSTANCE_NAME}-elasticsearch-svc:9200"
export HEALTH_URL="${ELASTIC_URL}/_cluster/health"

for test in /tests/*; do
testrunner -logtostderr "--test_spec=${test}"
done
85 changes: 83 additions & 2 deletions k8s/elasticsearch/apptest/tester/tests/basic-suite.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,89 @@
actions:
- name: dummy test
- name: Wait until all expected nodes are connected to the cluster
bashTest:
script: |-
exit 0
function get_nodes_count() {
curl -s "${HEALTH_URL}" | jq '.number_of_nodes'
}

expected_nodes="${REPLICAS}"

timeout=300
timeout_time=$(( $(date +%s) + timeout ))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cluster might not be formed - do you mean not having timeouts in the test and rely on the deployer's timeout or Cloud Build's timeout? Then we rely on the execution environment for a container, which should rather be environment-agnostic.


# Wait for all nodes to join the cluster
nodes_count="$(get_nodes_count)"
while [[ "${nodes_count}" -ne "${expected_nodes}" ]] \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: Does it mean that running Pod can be still not connected to the cluster?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

&& [[ "$(date +%s)" -le "${timeout_time}" ]]; do
sleep 3
nodes_count="$(get_nodes_count)"
done

if [[ "${nodes_count}" -eq "${expected_nodes}" ]]; then
echo "OK - all nodes joined"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer stdout checks for ease of debugging in case of failure, even if I agree that checking the exitCode is more readable. We can return to checking the exitCode once testrunner prints the logs from both stdout and stderr in case of failure.

else
echo "FAIL - nodes count: ${nodes_count}"
fi
expect:
stdout:
contains: OK - all nodes joined

- name: Wait for green status in the cluster
bashTest:
script: |-
function get_cluster_status() {
curl -s "${HEALTH_URL}" | jq '.status'
}

timeout=300
timeout_time=$(( $(date +%s) + timeout ))

# Wait for green status
status="$(get_cluster_status)"
while [[ "${status}" != '"green"' ]] \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you modify jq in get_cluster_status function as following: jqlang/jq#250, then you can drop ugly " here and below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, it's nice. Corrected.

&& [[ "$(date +%s)" -le "${timeout_time}" ]]; do
sleep 3
status="$(get_cluster_status)"
done

if [[ "${status}" == '"green"' ]]; then
echo "OK - green status"
else
echo "FAIL - status: ${status}"
fi
expect:
stdout:
contains: OK - green status

- name: Add a document
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you name steps in a question form? Can add a document instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rephrased the names.

bashTest:
script: |-
curl -s -f -X PUT -H 'Content-Type:application/json' -d '{
"name": "John",
"surname": "Smith"
}' "${ELASTIC_URL}/employees/person/1"
expect:
exitCode:
equals: 0

- name: Update the document
bashTest:
script: |-
curl -s -f -X POST -H 'Content-Type:application/json' -d '{
"doc": {
"lastname": "Jones"
}
}' "${ELASTIC_URL}/employees/person/1/_update"
expect:
exitCode:
equals: 0

- name: Search for the document
bashTest:
script: |-
# Wait to allow the object to be propagated between all nodes
sleep 5
curl -s -f "${ELASTIC_URL}/_search?q=jones"
expect:
stdout:
contains: "\"name\":\"John\""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOF

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

4 changes: 4 additions & 0 deletions k8s/elasticsearch/deployer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ COPY apptest/deployer /data-test/
# Provide registry prefix and tag for default values for images.
ARG REGISTRY
ARG TAG

ENV WAIT_FOR_READY_TIMEOUT 600
ENV TESTER_TIMEOUT 600

RUN cat /data/schema.yaml \
| env -i "REGISTRY=$REGISTRY" "TAG=$TAG" envsubst \
> /data/schema.yaml.new \
Expand Down