From d23662e50f6ff9f04603db89f0f65e6908d4e1bd Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Fri, 5 Aug 2022 17:48:25 +0000 Subject: [PATCH] Update unit test container setup and instructions Update the TESTING.rst file to reflect that just installing and starting zookeeperd is no longer sufficient now that we require TLS and auth for the connection. Suggest the container-based setup script instead. Also improve that script to allow it to be invoked as a normal user, with root command escalation tool choice (e.g. "sudo") supplied through a ROOTCMD environment variable, so that things created inside the git worktree like the CA don't end up root-owned. Change-Id: Ia00f5514ba0bd97b2ef17fb798b7c2dc68d9a55e --- TESTING.rst | 14 ++++++-------- tools/test-setup-docker.sh | 13 ++++++++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/TESTING.rst b/TESTING.rst index 71c79d263..cde310095 100644 --- a/TESTING.rst +++ b/TESTING.rst @@ -18,15 +18,13 @@ More information on pip here: http://www.pip-installer.org/en/latest/ sudo pip3 install tox -A running zookeeper is required to execute tests. +A running zookeeper is required to execute tests, but it also needs to be +configured for TLS and a certificate authority set up to handle socket +authentication. Because of these complexities, it's recommended to use a +helper script to set up these dependencies:: -*Install zookeeper*:: - - sudo apt-get install zookeeperd - -*Start zookeeper*:: - - sudo service zookeeper start + sudo apt-get install docker-compose # or podman-compose if preferred + ROOTCMD=sudo tools/test-setup-docker.sh Run The Tests ------------- diff --git a/tools/test-setup-docker.sh b/tools/test-setup-docker.sh index 39be68213..06d849b6f 100755 --- a/tools/test-setup-docker.sh +++ b/tools/test-setup-docker.sh @@ -3,9 +3,12 @@ # This runs ZooKeeper in a docker container, which is required for # tests. -# This setup needs to be run as a user that can run docker or podman. +# This setup needs to be run as a user that can run docker or podman, or by +# setting $ROOTCMD to a user substitution tool like "sudo" in the calling +# environment. set -xeu +ROOTCMD=${ROOTCMD:-} cd $(dirname $0) SCRIPT_DIR="$(pwd)" @@ -13,8 +16,8 @@ SCRIPT_DIR="$(pwd)" # Select docker or podman if command -v docker > /dev/null; then DOCKER=docker - if ! docker ps; then - systemctl start docker + if ! ${ROOTCMD} docker ps; then + ${ROOTCMD} systemctl start docker fi elif command -v podman > /dev/null; then DOCKER=podman @@ -38,8 +41,8 @@ CA_DIR=$SCRIPT_DIR/ca mkdir -p $CA_DIR $SCRIPT_DIR/zk-ca.sh $CA_DIR nodepool-test-zookeeper -${COMPOSE} down +${ROOTCMD} ${COMPOSE} down -${COMPOSE} up -d +${ROOTCMD} ${COMPOSE} up -d echo "Finished"