* Make lazy upgrade test work reliable

* Allow Docker image to take parameters to overwrite unittest
execution
  * Add documentation for running individual tests
  * Fixed String encoding in Patorni state check and error case
This commit is contained in:
Jan Mußler 2020-10-20 19:20:38 +02:00
parent 4fc8ca384d
commit c6c4c4cc8a
4 changed files with 32 additions and 8 deletions

View File

@ -21,4 +21,5 @@ RUN apt-get update \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["python3", "-m", "unittest", "discover", "--failfast", "--start-directory", "/tests", "-v"]
ENTRYPOINT ["python3", "-m", "unittest", "--failfast", "-v"]
CMD ["discover","--start-directory","/tests"]

View File

@ -40,6 +40,25 @@ To run the end 2 end test and keep the kind state execute:
NOCLEANUP=True ./run.sh
```
## Run indidual test
After having executed a normal E2E run with `NOCLEANUP=True` Kind still continues to run, allowing you subsequent test runs.
To run an individual test, run the following command in the `e2e` directory
```bash
NOCLEANUP=True ./run.sh main tests.test_e2e.EndToEndTestCase.test_lazy_spilo_upgrade
```
## Inspecting Kind
If you want to inspect Kind/Kubernetes cluster, use the following script to exec into the K8s setup and then use `kubectl`
```bash
./run_test_image.sh
kubectl get pods
```
## Covered use cases
The current tests are all bundled in [`test_e2e.py`](tests/test_e2e.py):

View File

@ -48,8 +48,8 @@ function set_kind_api_server_ip(){
}
function run_tests(){
echo "Running tests..."
echo "Running tests... image: ${e2e_test_runner_image}"
echo $@
# tests modify files in ./manifests, so we mount a copy of this directory done by the e2e Makefile
docker run --rm --network=host -e "TERM=xterm-256color" \
@ -57,7 +57,7 @@ function run_tests(){
--mount type=bind,source="$(readlink -f manifests)",target=/manifests \
--mount type=bind,source="$(readlink -f tests)",target=/tests \
--mount type=bind,source="$(readlink -f exec.sh)",target=/exec.sh \
-e OPERATOR_IMAGE="${operator_image}" "${e2e_test_runner_image}"
-e OPERATOR_IMAGE="${operator_image}" "${e2e_test_runner_image}" $@
}
function clean_up(){
@ -68,13 +68,14 @@ function clean_up(){
}
function main(){
echo "Entering main function..."
[[ -z ${NOCLEANUP-} ]] && trap "clean_up" QUIT TERM EXIT
pull_images
[[ ! -f ${kubeconfig_path} ]] && start_kind
set_kind_api_server_ip
run_tests
shift
run_tests $@
exit 0
}
"$@"
"$1" $@

View File

@ -1069,7 +1069,10 @@ class K8s:
stderr=subprocess.PIPE)
def get_patroni_state(self, pod):
return json.loads(self.exec_with_kubectl(pod, "patronictl list -f json").stdout)
r = self.exec_with_kubectl(pod, "patronictl list -f json")
if not r.returncode == 0 or not r.stdout.decode()[0:1]=="[":
return []
return json.loads(r.stdout.decode())
def get_patroni_running_members(self, pod):
result = self.get_patroni_state(pod)