From 22cd4e2a82e705ca8bd9243c2aeadd76a74be34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Roth?= Date: Tue, 3 Dec 2024 19:03:21 +0800 Subject: [PATCH] unit-tests: allow running as user --- Makefile | 2 +- system/lib.py | 4 ++-- system/t13_etcd/install-etcd.sh | 15 +++++++++++---- system/t13_etcd/start-etcd.sh | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 28bb95a88..3635a0e97 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ swagger: swagger-install etcd-install: # Install etcd - test -d /srv/etcd || system/t13_etcd/install-etcd.sh + test -d /tmp/aptly-etcd || system/t13_etcd/install-etcd.sh flake8: ## run flake8 on system test python files flake8 system/ diff --git a/system/lib.py b/system/lib.py index 2918d8053..caba606c4 100644 --- a/system/lib.py +++ b/system/lib.py @@ -242,7 +242,7 @@ def prepare_fixture(self): os.environ["HOME"], self.aptlyDir, "pool"), ignore=shutil.ignore_patterns(".git")) if self.databaseType == "etcd": - if not os.path.exists("/srv/etcd"): + if not os.path.exists("/tmp/aptly-etcd"): self.run_cmd([os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "t13_etcd/install-etcd.sh")]) if self.fixtureDB and self.databaseType != "etcd": @@ -258,7 +258,7 @@ def prepare_fixture(self): if self.fixtureDB: print("import etcd") - self.run_cmd(["/srv/etcd/etcdctl", "--data-dir=/tmp/etcd-data", "snapshot", "restore", os.path.join(os.environ["HOME"], "etcd.db")]) + self.run_cmd(["/tmp/aptly-etcd/etcdctl", "--data-dir=/tmp/aptly-etcd-data", "snapshot", "restore", os.path.join(os.environ["HOME"], "etcd.db")]) print("starting etcd") self.EtcdServer = self._start_process([os.path.join(os.path.dirname(inspect.getsourcefile(BaseTest)), "t13_etcd/start-etcd.sh")], stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/system/t13_etcd/install-etcd.sh b/system/t13_etcd/install-etcd.sh index 163a3f85d..1521511d9 100755 --- a/system/t13_etcd/install-etcd.sh +++ b/system/t13_etcd/install-etcd.sh @@ -4,9 +4,16 @@ ETCD_VER=v3.5.2 DOWNLOAD_URL=https://storage.googleapis.com/etcd -if [ ! -e /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz ]; then - curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-amd64.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz +ARCH="" +case $(uname -m) in + x86_64) ARCH="amd64" ;; + aarch64) ARCH="arm64" ;; + *) echo "unsupported cpu arch"; exit 1 ;; +esac + +if [ ! -e /tmp/etcd-${ETCD_VER}-linux-$ARCH.tar.gz ]; then + curl -L ${DOWNLOAD_URL}/${ETCD_VER}/etcd-${ETCD_VER}-linux-$ARCH.tar.gz -o /tmp/etcd-${ETCD_VER}-linux-$ARCH.tar.gz fi -mkdir /srv/etcd -tar xf /tmp/etcd-${ETCD_VER}-linux-amd64.tar.gz -C /srv/etcd --strip-components=1 +mkdir /tmp/aptly-etcd +tar xf /tmp/etcd-${ETCD_VER}-linux-$ARCH.tar.gz -C /tmp/aptly-etcd --strip-components=1 diff --git a/system/t13_etcd/start-etcd.sh b/system/t13_etcd/start-etcd.sh index ae6c0a45e..05908defb 100755 --- a/system/t13_etcd/start-etcd.sh +++ b/system/t13_etcd/start-etcd.sh @@ -16,7 +16,7 @@ finish() } trap finish INT -/srv/etcd/etcd --max-request-bytes '1073741824' --data-dir /tmp/etcd-data & +/tmp/aptly-etcd/etcd --max-request-bytes '1073741824' --data-dir /tmp/aptly-etcd-data & echo $! > /tmp/etcd.pid etcdpid=`cat /tmp/etcd.pid` wait $etcdpid